ai-sdlc 0.1.0-alpha.9 → 0.1.0
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/README.md +161 -17
- package/dist/agents/implementation.d.ts +80 -2
- package/dist/agents/implementation.d.ts.map +1 -1
- package/dist/agents/implementation.js +466 -1
- package/dist/agents/implementation.js.map +1 -1
- package/dist/agents/planning.d.ts +20 -1
- package/dist/agents/planning.d.ts.map +1 -1
- package/dist/agents/planning.js +73 -12
- package/dist/agents/planning.js.map +1 -1
- package/dist/agents/review.d.ts +21 -1
- package/dist/agents/review.d.ts.map +1 -1
- package/dist/agents/review.js +67 -3
- package/dist/agents/review.js.map +1 -1
- package/dist/cli/story-utils.d.ts.map +1 -1
- package/dist/cli/story-utils.js +2 -0
- package/dist/cli/story-utils.js.map +1 -1
- package/dist/core/config.d.ts +5 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +52 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/kanban.d.ts.map +1 -1
- package/dist/core/kanban.js +59 -22
- package/dist/core/kanban.js.map +1 -1
- package/dist/core/story.d.ts +13 -0
- package/dist/core/story.d.ts.map +1 -1
- package/dist/core/story.js +81 -1
- package/dist/core/story.js.map +1 -1
- package/dist/core/theme.d.ts.map +1 -1
- package/dist/core/theme.js +3 -0
- package/dist/core/theme.js.map +1 -1
- package/dist/types/index.d.ts +37 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
1
|
+
import { execSync, spawn } from 'child_process';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { parseStory, writeStory, moveStory, updateStoryField } from '../core/story.js';
|
|
4
4
|
import { runAgentQuery } from '../core/client.js';
|
|
5
|
+
import { loadConfig, DEFAULT_TDD_CONFIG } from '../core/config.js';
|
|
6
|
+
export const TDD_SYSTEM_PROMPT = `You are practicing strict Test-Driven Development.
|
|
7
|
+
|
|
8
|
+
Your workflow MUST follow this exact cycle:
|
|
9
|
+
|
|
10
|
+
**RED Phase**:
|
|
11
|
+
1. Write ONE test that expresses the next acceptance criterion
|
|
12
|
+
2. The test MUST fail because the functionality doesn't exist
|
|
13
|
+
3. Run the test and verify it fails
|
|
14
|
+
4. Explain why it fails and what it's testing
|
|
15
|
+
|
|
16
|
+
**GREEN Phase**:
|
|
17
|
+
1. Write the MINIMUM code to make this ONE test pass
|
|
18
|
+
2. Do NOT add extra features
|
|
19
|
+
3. Run the test to verify it passes
|
|
20
|
+
4. Run ALL tests to ensure nothing broke
|
|
21
|
+
|
|
22
|
+
**REFACTOR Phase**:
|
|
23
|
+
1. Look for improvements (DRY, clarity, performance)
|
|
24
|
+
2. Make changes ONLY if tests stay green
|
|
25
|
+
3. Run ALL tests after each change
|
|
26
|
+
|
|
27
|
+
Complete one full cycle before starting the next test.
|
|
28
|
+
Never write code before writing a test.
|
|
29
|
+
Never write multiple tests before making the first one pass.`;
|
|
5
30
|
const IMPLEMENTATION_SYSTEM_PROMPT = `You are a senior software engineer implementing features based on a detailed plan. Your job is to execute each phase of the implementation plan.
|
|
6
31
|
|
|
7
32
|
When implementing:
|
|
@@ -15,6 +40,415 @@ When implementing:
|
|
|
15
40
|
8. Do NOT commit changes - that happens in the review phase
|
|
16
41
|
|
|
17
42
|
You have access to tools for reading and writing files, running commands, and searching the codebase.`;
|
|
43
|
+
/**
|
|
44
|
+
* Run a single test file and return pass/fail result
|
|
45
|
+
*/
|
|
46
|
+
export async function runSingleTest(testFile, workingDir, testTimeout) {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
const outputChunks = [];
|
|
49
|
+
let killed = false;
|
|
50
|
+
const child = spawn('npm', ['test', '--', testFile], {
|
|
51
|
+
cwd: workingDir,
|
|
52
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
53
|
+
});
|
|
54
|
+
const timeoutId = setTimeout(() => {
|
|
55
|
+
killed = true;
|
|
56
|
+
child.kill('SIGTERM');
|
|
57
|
+
setTimeout(() => child.kill('SIGKILL'), 5000);
|
|
58
|
+
}, testTimeout);
|
|
59
|
+
child.stdout?.on('data', (data) => {
|
|
60
|
+
outputChunks.push(data.toString());
|
|
61
|
+
});
|
|
62
|
+
child.stderr?.on('data', (data) => {
|
|
63
|
+
outputChunks.push(data.toString());
|
|
64
|
+
});
|
|
65
|
+
child.on('close', (code) => {
|
|
66
|
+
clearTimeout(timeoutId);
|
|
67
|
+
const output = outputChunks.join('');
|
|
68
|
+
if (killed) {
|
|
69
|
+
resolve({
|
|
70
|
+
passed: false,
|
|
71
|
+
output: output + `\n[Command timed out after ${Math.round(testTimeout / 1000)} seconds]`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
resolve({
|
|
76
|
+
passed: code === 0,
|
|
77
|
+
output,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
child.on('error', (error) => {
|
|
82
|
+
clearTimeout(timeoutId);
|
|
83
|
+
resolve({
|
|
84
|
+
passed: false,
|
|
85
|
+
output: outputChunks.join('') + `\n[Command error: ${error.message}]`,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run all tests and return pass/fail result
|
|
92
|
+
*/
|
|
93
|
+
export async function runAllTests(workingDir, testTimeout) {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const outputChunks = [];
|
|
96
|
+
let killed = false;
|
|
97
|
+
const child = spawn('npm', ['test'], {
|
|
98
|
+
cwd: workingDir,
|
|
99
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
100
|
+
});
|
|
101
|
+
const timeoutId = setTimeout(() => {
|
|
102
|
+
killed = true;
|
|
103
|
+
child.kill('SIGTERM');
|
|
104
|
+
setTimeout(() => child.kill('SIGKILL'), 5000);
|
|
105
|
+
}, testTimeout);
|
|
106
|
+
child.stdout?.on('data', (data) => {
|
|
107
|
+
outputChunks.push(data.toString());
|
|
108
|
+
});
|
|
109
|
+
child.stderr?.on('data', (data) => {
|
|
110
|
+
outputChunks.push(data.toString());
|
|
111
|
+
});
|
|
112
|
+
child.on('close', (code) => {
|
|
113
|
+
clearTimeout(timeoutId);
|
|
114
|
+
const output = outputChunks.join('');
|
|
115
|
+
if (killed) {
|
|
116
|
+
resolve({
|
|
117
|
+
passed: false,
|
|
118
|
+
output: output + `\n[Command timed out after ${Math.round(testTimeout / 1000)} seconds]`,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
resolve({
|
|
123
|
+
passed: code === 0,
|
|
124
|
+
output,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
child.on('error', (error) => {
|
|
129
|
+
clearTimeout(timeoutId);
|
|
130
|
+
resolve({
|
|
131
|
+
passed: false,
|
|
132
|
+
output: outputChunks.join('') + `\n[Command error: ${error.message}]`,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Extract test file path from agent output
|
|
139
|
+
*/
|
|
140
|
+
function extractTestFile(agentOutput) {
|
|
141
|
+
// Look for common patterns in agent output
|
|
142
|
+
const patterns = [
|
|
143
|
+
/(?:created|wrote|added|test file[:\s]+)[\s`'"]*([^\s`'"]+\.test\.[tj]sx?)/i,
|
|
144
|
+
/([^\s`'"]+\.test\.[tj]sx?)/i,
|
|
145
|
+
/([^\s`'"]+\.spec\.[tj]sx?)/i,
|
|
146
|
+
];
|
|
147
|
+
for (const pattern of patterns) {
|
|
148
|
+
const match = agentOutput.match(pattern);
|
|
149
|
+
if (match) {
|
|
150
|
+
return match[1];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Default fallback
|
|
154
|
+
return 'src/unknown.test.ts';
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Extract test name from agent output or story content
|
|
158
|
+
*/
|
|
159
|
+
function extractTestName(agentOutput, story) {
|
|
160
|
+
// Try to extract from agent output
|
|
161
|
+
const patterns = [
|
|
162
|
+
/(?:test|it|describe)[(\s]+['"`]([^'"`]+)['"`]/i,
|
|
163
|
+
/testing[:\s]+([^\n]+)/i,
|
|
164
|
+
/for[:\s]+([^\n]+)/i,
|
|
165
|
+
];
|
|
166
|
+
for (const pattern of patterns) {
|
|
167
|
+
const match = agentOutput.match(pattern);
|
|
168
|
+
if (match) {
|
|
169
|
+
return match[1].trim();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Fallback: extract first unchecked AC
|
|
173
|
+
const acMatch = story.content.match(/- \[ \] ([^\n]+)/);
|
|
174
|
+
if (acMatch) {
|
|
175
|
+
return acMatch[1].trim();
|
|
176
|
+
}
|
|
177
|
+
return 'Unknown test';
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* RED Phase: Write a failing test
|
|
181
|
+
*
|
|
182
|
+
* Creates a test that expresses the next acceptance criterion.
|
|
183
|
+
* The test MUST fail because the functionality doesn't exist yet.
|
|
184
|
+
*/
|
|
185
|
+
export async function executeRedPhase(story, cycleNumber, options) {
|
|
186
|
+
const agentQuery = options.runAgentQuery || runAgentQuery;
|
|
187
|
+
const timestamp = new Date().toISOString();
|
|
188
|
+
const prompt = `You are in the RED phase of TDD (cycle ${cycleNumber}).
|
|
189
|
+
|
|
190
|
+
Story: ${story.frontmatter.title}
|
|
191
|
+
|
|
192
|
+
Current acceptance criteria (unchecked = not yet implemented):
|
|
193
|
+
${story.content}
|
|
194
|
+
|
|
195
|
+
Your task:
|
|
196
|
+
1. Look at the FIRST unchecked acceptance criterion (- [ ])
|
|
197
|
+
2. Write ONE failing test that validates this criterion
|
|
198
|
+
3. The test should be minimal but meaningful
|
|
199
|
+
4. Return the test file path where you created/modified the test
|
|
200
|
+
|
|
201
|
+
Remember: The test MUST fail because no implementation exists yet.
|
|
202
|
+
Write the test now.`;
|
|
203
|
+
const output = await agentQuery({
|
|
204
|
+
prompt,
|
|
205
|
+
systemPrompt: TDD_SYSTEM_PROMPT,
|
|
206
|
+
workingDirectory: options.workingDir,
|
|
207
|
+
onProgress: options.onProgress,
|
|
208
|
+
});
|
|
209
|
+
const testFile = extractTestFile(output);
|
|
210
|
+
const testName = extractTestName(output, story);
|
|
211
|
+
return {
|
|
212
|
+
testName,
|
|
213
|
+
testFile,
|
|
214
|
+
timestamp,
|
|
215
|
+
output,
|
|
216
|
+
success: true,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* GREEN Phase: Write minimum code to pass the test
|
|
221
|
+
*
|
|
222
|
+
* Implements just enough code to make the failing test pass.
|
|
223
|
+
* Does NOT add extra features or optimizations.
|
|
224
|
+
*/
|
|
225
|
+
export async function executeGreenPhase(story, cycleNumber, testFile, options) {
|
|
226
|
+
const agentQuery = options.runAgentQuery || runAgentQuery;
|
|
227
|
+
const timestamp = new Date().toISOString();
|
|
228
|
+
const prompt = `You are in the GREEN phase of TDD (cycle ${cycleNumber}).
|
|
229
|
+
|
|
230
|
+
Story: ${story.frontmatter.title}
|
|
231
|
+
Test file: ${testFile}
|
|
232
|
+
|
|
233
|
+
The test you wrote in the RED phase is now failing.
|
|
234
|
+
|
|
235
|
+
Your task:
|
|
236
|
+
1. Write the MINIMUM code to make this ONE test pass
|
|
237
|
+
2. Do NOT add extra features or optimizations
|
|
238
|
+
3. Do NOT refactor yet - that comes in the next phase
|
|
239
|
+
4. Keep the implementation simple and focused
|
|
240
|
+
|
|
241
|
+
Remember: Only write enough code to make the test pass. Nothing more.
|
|
242
|
+
Implement the code now.`;
|
|
243
|
+
const output = await agentQuery({
|
|
244
|
+
prompt,
|
|
245
|
+
systemPrompt: TDD_SYSTEM_PROMPT,
|
|
246
|
+
workingDirectory: options.workingDir,
|
|
247
|
+
onProgress: options.onProgress,
|
|
248
|
+
});
|
|
249
|
+
const testName = extractTestName(output, story);
|
|
250
|
+
return {
|
|
251
|
+
testName,
|
|
252
|
+
testFile,
|
|
253
|
+
timestamp,
|
|
254
|
+
output,
|
|
255
|
+
success: true,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* REFACTOR Phase: Improve code while keeping tests green
|
|
260
|
+
*
|
|
261
|
+
* Improves code quality without changing behavior.
|
|
262
|
+
* All tests must remain passing after each change.
|
|
263
|
+
*/
|
|
264
|
+
export async function executeRefactorPhase(story, cycleNumber, testFile, options) {
|
|
265
|
+
const agentQuery = options.runAgentQuery || runAgentQuery;
|
|
266
|
+
const timestamp = new Date().toISOString();
|
|
267
|
+
const prompt = `You are in the REFACTOR phase of TDD (cycle ${cycleNumber}).
|
|
268
|
+
|
|
269
|
+
Story: ${story.frontmatter.title}
|
|
270
|
+
Test file: ${testFile}
|
|
271
|
+
|
|
272
|
+
The test is now passing. Time to improve the code.
|
|
273
|
+
|
|
274
|
+
Your task:
|
|
275
|
+
1. Look for opportunities to improve the code:
|
|
276
|
+
- Remove duplication (DRY)
|
|
277
|
+
- Improve naming and clarity
|
|
278
|
+
- Simplify complex logic
|
|
279
|
+
- Performance improvements (if obvious)
|
|
280
|
+
2. Make changes incrementally
|
|
281
|
+
3. Ensure ALL tests stay green after each change
|
|
282
|
+
4. If no refactoring is needed, that's fine - skip to the next cycle
|
|
283
|
+
|
|
284
|
+
Remember: The goal is cleaner code, not new features.
|
|
285
|
+
Refactor now (or skip if the code is already clean).`;
|
|
286
|
+
const output = await agentQuery({
|
|
287
|
+
prompt,
|
|
288
|
+
systemPrompt: TDD_SYSTEM_PROMPT,
|
|
289
|
+
workingDirectory: options.workingDir,
|
|
290
|
+
onProgress: options.onProgress,
|
|
291
|
+
});
|
|
292
|
+
const testName = extractTestName(output, story);
|
|
293
|
+
return {
|
|
294
|
+
testName,
|
|
295
|
+
testFile,
|
|
296
|
+
timestamp,
|
|
297
|
+
output,
|
|
298
|
+
success: true,
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Record a completed TDD cycle to the story frontmatter
|
|
303
|
+
*/
|
|
304
|
+
export function recordTDDCycle(cycleNumber, redResult, greenResult, refactorResult) {
|
|
305
|
+
return {
|
|
306
|
+
test_name: redResult.testName,
|
|
307
|
+
test_file: redResult.testFile,
|
|
308
|
+
red_timestamp: redResult.timestamp,
|
|
309
|
+
green_timestamp: greenResult.timestamp,
|
|
310
|
+
refactor_timestamp: refactorResult.timestamp,
|
|
311
|
+
test_output_red: redResult.output,
|
|
312
|
+
test_output_green: greenResult.output,
|
|
313
|
+
all_tests_green: true,
|
|
314
|
+
cycle_number: cycleNumber,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Check if all acceptance criteria have been covered (checked off)
|
|
319
|
+
*/
|
|
320
|
+
export function checkACCoverage(story) {
|
|
321
|
+
// Find the Acceptance Criteria section
|
|
322
|
+
const acSectionMatch = story.content.match(/## Acceptance Criteria\s*\n([\s\S]*?)(?=\n##|$)/i);
|
|
323
|
+
if (!acSectionMatch) {
|
|
324
|
+
// No AC section = nothing to check = done
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
const acSection = acSectionMatch[1];
|
|
328
|
+
// Find all checkbox items
|
|
329
|
+
const uncheckedItems = acSection.match(/- \[ \]/g);
|
|
330
|
+
const checkedItems = acSection.match(/- \[x\]/gi);
|
|
331
|
+
// If there are unchecked items, coverage is incomplete
|
|
332
|
+
if (uncheckedItems && uncheckedItems.length > 0) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
// If there are checked items (and no unchecked), coverage is complete
|
|
336
|
+
// If there are no checkboxes at all, consider it complete
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Run the full TDD implementation loop
|
|
341
|
+
*
|
|
342
|
+
* Executes Red-Green-Refactor cycles until all acceptance criteria are covered
|
|
343
|
+
* or the maximum number of cycles is reached.
|
|
344
|
+
*/
|
|
345
|
+
export async function runTDDImplementation(story, sdlcRoot, options = {}) {
|
|
346
|
+
const workingDir = path.dirname(sdlcRoot);
|
|
347
|
+
const config = loadConfig(workingDir);
|
|
348
|
+
const tddConfig = config.tdd || DEFAULT_TDD_CONFIG;
|
|
349
|
+
const changesMade = [];
|
|
350
|
+
const agentQuery = options.runAgentQuery || runAgentQuery;
|
|
351
|
+
const singleTest = options.runSingleTest || runSingleTest;
|
|
352
|
+
const allTests = options.runAllTests || runAllTests;
|
|
353
|
+
const testTimeout = config.timeouts?.testTimeout || 300000;
|
|
354
|
+
// Get starting cycle number from history
|
|
355
|
+
let cycleNumber = (story.frontmatter.tdd_test_history?.length || 0) + 1;
|
|
356
|
+
while (cycleNumber <= tddConfig.maxCycles) {
|
|
357
|
+
changesMade.push(`Starting TDD cycle ${cycleNumber}`);
|
|
358
|
+
// RED Phase: Write failing test
|
|
359
|
+
const redResult = await executeRedPhase(story, cycleNumber, {
|
|
360
|
+
workingDir,
|
|
361
|
+
runAgentQuery: agentQuery,
|
|
362
|
+
onProgress: options.onProgress,
|
|
363
|
+
});
|
|
364
|
+
// Verify test fails (expected in RED phase)
|
|
365
|
+
const redTestResult = await singleTest(redResult.testFile, workingDir, testTimeout);
|
|
366
|
+
if (redTestResult.passed) {
|
|
367
|
+
return {
|
|
368
|
+
success: false,
|
|
369
|
+
story,
|
|
370
|
+
changesMade,
|
|
371
|
+
error: `TDD Violation: Test passed immediately in RED phase (cycle ${cycleNumber}). Tests must fail before implementation.`,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
changesMade.push(`RED: Test "${redResult.testName}" fails as expected`);
|
|
375
|
+
// GREEN Phase: Write minimum code
|
|
376
|
+
const greenResult = await executeGreenPhase(story, cycleNumber, redResult.testFile, {
|
|
377
|
+
workingDir,
|
|
378
|
+
runAgentQuery: agentQuery,
|
|
379
|
+
onProgress: options.onProgress,
|
|
380
|
+
});
|
|
381
|
+
// Verify test now passes
|
|
382
|
+
const greenTestResult = await singleTest(redResult.testFile, workingDir, testTimeout);
|
|
383
|
+
if (!greenTestResult.passed) {
|
|
384
|
+
return {
|
|
385
|
+
success: false,
|
|
386
|
+
story,
|
|
387
|
+
changesMade,
|
|
388
|
+
error: `TDD Violation: Test still failing in GREEN phase (cycle ${cycleNumber}). Implementation must make test pass.`,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
changesMade.push(`GREEN: Test "${redResult.testName}" now passes`);
|
|
392
|
+
// Verify no regression (all tests still pass)
|
|
393
|
+
const regressionCheck = await allTests(workingDir, testTimeout);
|
|
394
|
+
if (!regressionCheck.passed) {
|
|
395
|
+
return {
|
|
396
|
+
success: false,
|
|
397
|
+
story,
|
|
398
|
+
changesMade,
|
|
399
|
+
error: `TDD Violation: Regression detected after GREEN phase (cycle ${cycleNumber}). New code broke existing tests.`,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
changesMade.push('GREEN: No regression - all tests pass');
|
|
403
|
+
// REFACTOR Phase: Improve code
|
|
404
|
+
const refactorResult = await executeRefactorPhase(story, cycleNumber, redResult.testFile, {
|
|
405
|
+
workingDir,
|
|
406
|
+
runAgentQuery: agentQuery,
|
|
407
|
+
onProgress: options.onProgress,
|
|
408
|
+
});
|
|
409
|
+
// Verify tests still pass after refactoring
|
|
410
|
+
const refactorCheck = await allTests(workingDir, testTimeout);
|
|
411
|
+
if (!refactorCheck.passed) {
|
|
412
|
+
return {
|
|
413
|
+
success: false,
|
|
414
|
+
story,
|
|
415
|
+
changesMade,
|
|
416
|
+
error: `TDD Violation: Refactoring broke tests (cycle ${cycleNumber}). Undo changes and refactor more carefully.`,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
changesMade.push('REFACTOR: All tests still pass');
|
|
420
|
+
// Record the completed cycle
|
|
421
|
+
const cycle = recordTDDCycle(cycleNumber, redResult, greenResult, refactorResult);
|
|
422
|
+
// Update story with cycle history
|
|
423
|
+
const history = story.frontmatter.tdd_test_history || [];
|
|
424
|
+
history.push(cycle);
|
|
425
|
+
// Trim to last 100 cycles to prevent unbounded growth
|
|
426
|
+
story.frontmatter.tdd_test_history = history.slice(-100);
|
|
427
|
+
story.frontmatter.tdd_current_test = cycle;
|
|
428
|
+
// Persist the TDD cycle history to disk
|
|
429
|
+
writeStory(story);
|
|
430
|
+
changesMade.push(`Completed TDD cycle ${cycleNumber}`);
|
|
431
|
+
// Check if all AC are now covered
|
|
432
|
+
// Re-read story to get latest content (agent may have updated checkboxes)
|
|
433
|
+
const updatedStory = parseStory(story.path);
|
|
434
|
+
if (checkACCoverage(updatedStory)) {
|
|
435
|
+
changesMade.push('All acceptance criteria covered');
|
|
436
|
+
return {
|
|
437
|
+
success: true,
|
|
438
|
+
story: updatedStory,
|
|
439
|
+
changesMade,
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
cycleNumber++;
|
|
443
|
+
}
|
|
444
|
+
// Max cycles reached
|
|
445
|
+
return {
|
|
446
|
+
success: false,
|
|
447
|
+
story,
|
|
448
|
+
changesMade,
|
|
449
|
+
error: `TDD: Maximum cycles (${tddConfig.maxCycles}) reached without completing all acceptance criteria.`,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
18
452
|
/**
|
|
19
453
|
* Implementation Agent
|
|
20
454
|
*
|
|
@@ -59,6 +493,37 @@ export async function runImplementationAgent(storyPath, sdlcRoot, options = {})
|
|
|
59
493
|
currentStoryPath = story.path;
|
|
60
494
|
changesMade.push('Moved story to in-progress/');
|
|
61
495
|
}
|
|
496
|
+
// Check if TDD is enabled for this story
|
|
497
|
+
const config = loadConfig(workingDir);
|
|
498
|
+
const tddEnabled = story.frontmatter.tdd_enabled ?? config.tdd?.enabled ?? false;
|
|
499
|
+
if (tddEnabled) {
|
|
500
|
+
changesMade.push('TDD mode enabled - using Red-Green-Refactor implementation');
|
|
501
|
+
// Run TDD implementation loop
|
|
502
|
+
const tddResult = await runTDDImplementation(story, sdlcRoot, {
|
|
503
|
+
onProgress: options.onProgress,
|
|
504
|
+
});
|
|
505
|
+
// Merge changes
|
|
506
|
+
changesMade.push(...tddResult.changesMade);
|
|
507
|
+
if (tddResult.success) {
|
|
508
|
+
// Mark implementation as complete
|
|
509
|
+
updateStoryField(tddResult.story, 'implementation_complete', true);
|
|
510
|
+
changesMade.push('Marked implementation_complete: true');
|
|
511
|
+
return {
|
|
512
|
+
success: true,
|
|
513
|
+
story: parseStory(currentStoryPath),
|
|
514
|
+
changesMade,
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
return {
|
|
519
|
+
success: false,
|
|
520
|
+
story: tddResult.story,
|
|
521
|
+
changesMade,
|
|
522
|
+
error: tddResult.error,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
// Standard implementation (non-TDD mode)
|
|
62
527
|
let prompt = `Implement this story based on the plan:
|
|
63
528
|
|
|
64
529
|
Title: ${story.frontmatter.title}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/agents/implementation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAyB,MAAM,mBAAmB,CAAC;AAOzE,MAAM,4BAA4B,GAAG;;;;;;;;;;;;sGAYiE,CAAC;AAEvG;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,SAAiB,EACjB,QAAgB,EAChB,UAAwB,EAAE;IAE1B,IAAI,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IAClC,IAAI,gBAAgB,GAAG,SAAS,CAAC;IACjC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC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';
|
|
2
2
|
import { AgentOptions } from './research.js';
|
|
3
|
+
/**
|
|
4
|
+
* System prompt for the planning agent
|
|
5
|
+
*/
|
|
6
|
+
export declare const PLANNING_SYSTEM_PROMPT = "You are a technical planning specialist. Your job is to create detailed, step-by-step implementation plans for user stories.\n\nWhen creating a plan, you should:\n1. Break the work into phases (setup, implementation, testing, etc.)\n2. Create specific, actionable tasks within each phase\n3. Use checkbox format for tracking progress\n4. Consider test-driven development (write tests first)\n5. Include verification steps\n\nOutput your plan in markdown format with checkboxes. Each task should be small enough to complete in one focused session.";
|
|
7
|
+
/**
|
|
8
|
+
* TDD-specific planning instructions
|
|
9
|
+
* When TDD is enabled, this is appended to the planning prompt to ensure
|
|
10
|
+
* the plan follows the Red-Green-Refactor cycle structure.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TDD_PLANNING_INSTRUCTIONS = "\n**TDD Mode Enabled - Use Red-Green-Refactor Cycle Structure**\n\nStructure your plan using the TDD cycle for EACH feature/acceptance criterion:\n\nFor each task that involves writing code:\n- \uD83D\uDD34 RED: Write a failing test first that expresses the expected behavior\n- \uD83D\uDFE2 GREEN: Write the MINIMUM code to make the test pass\n- \uD83D\uDD35 REFACTOR: Improve the code while keeping all tests green\n\nExample TDD task structure:\n### Feature: User Login\n- [ ] \uD83D\uDD34 Write failing test for successful login with valid credentials (expect fail)\n- [ ] \uD83D\uDFE2 Implement login function to make test pass (expect pass)\n- [ ] \uD83D\uDD35 Refactor login code if needed (keep passing)\n\n- [ ] \uD83D\uDD34 Write failing test for login rejection with invalid password (expect fail)\n- [ ] \uD83D\uDFE2 Implement password validation to make test pass (expect pass)\n- [ ] \uD83D\uDD35 Refactor validation code if needed (keep passing)\n\nIMPORTANT TDD Rules:\n1. NEVER write implementation code before writing a test\n2. Each test should verify ONE specific behavior\n3. Tests must fail before implementation (verify the test is actually testing something)\n4. After GREEN phase, run ALL tests to check for regressions\n5. REFACTOR phase is optional but should not change behavior";
|
|
13
|
+
/**
|
|
14
|
+
* Build a planning prompt for a story, optionally with TDD instructions
|
|
15
|
+
*
|
|
16
|
+
* @param story - The story to create a plan for
|
|
17
|
+
* @param tddEnabledInConfig - Whether TDD is enabled in the global config
|
|
18
|
+
* @param reworkContext - Optional context from a failed review
|
|
19
|
+
* @returns The complete planning prompt
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildPlanningPrompt(story: Story, tddEnabledInConfig: boolean, reworkContext?: string): string;
|
|
3
22
|
/**
|
|
4
23
|
* Planning Agent
|
|
5
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planning.d.ts","sourceRoot":"","sources":["../../src/agents/planning.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"planning.d.ts","sourceRoot":"","sources":["../../src/agents/planning.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,sBAAsB,uiBASuF,CAAC;AAE3H;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,+xCAyBuB,CAAC;AAE9D;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,kBAAkB,EAAE,OAAO,EAC3B,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,CA+CR;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,CA8CtB"}
|
package/dist/agents/planning.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { parseStory, appendToSection, updateStoryField } from '../core/story.js';
|
|
2
2
|
import { runAgentQuery } from '../core/client.js';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* System prompt for the planning agent
|
|
6
|
+
*/
|
|
7
|
+
export const PLANNING_SYSTEM_PROMPT = `You are a technical planning specialist. Your job is to create detailed, step-by-step implementation plans for user stories.
|
|
5
8
|
|
|
6
9
|
When creating a plan, you should:
|
|
7
10
|
1. Break the work into phases (setup, implementation, testing, etc.)
|
|
@@ -12,33 +15,70 @@ When creating a plan, you should:
|
|
|
12
15
|
|
|
13
16
|
Output your plan in markdown format with checkboxes. Each task should be small enough to complete in one focused session.`;
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
18
|
+
* TDD-specific planning instructions
|
|
19
|
+
* When TDD is enabled, this is appended to the planning prompt to ensure
|
|
20
|
+
* the plan follows the Red-Green-Refactor cycle structure.
|
|
21
|
+
*/
|
|
22
|
+
export const TDD_PLANNING_INSTRUCTIONS = `
|
|
23
|
+
**TDD Mode Enabled - Use Red-Green-Refactor Cycle Structure**
|
|
24
|
+
|
|
25
|
+
Structure your plan using the TDD cycle for EACH feature/acceptance criterion:
|
|
26
|
+
|
|
27
|
+
For each task that involves writing code:
|
|
28
|
+
- 🔴 RED: Write a failing test first that expresses the expected behavior
|
|
29
|
+
- 🟢 GREEN: Write the MINIMUM code to make the test pass
|
|
30
|
+
- 🔵 REFACTOR: Improve the code while keeping all tests green
|
|
31
|
+
|
|
32
|
+
Example TDD task structure:
|
|
33
|
+
### Feature: User Login
|
|
34
|
+
- [ ] 🔴 Write failing test for successful login with valid credentials (expect fail)
|
|
35
|
+
- [ ] 🟢 Implement login function to make test pass (expect pass)
|
|
36
|
+
- [ ] 🔵 Refactor login code if needed (keep passing)
|
|
37
|
+
|
|
38
|
+
- [ ] 🔴 Write failing test for login rejection with invalid password (expect fail)
|
|
39
|
+
- [ ] 🟢 Implement password validation to make test pass (expect pass)
|
|
40
|
+
- [ ] 🔵 Refactor validation code if needed (keep passing)
|
|
41
|
+
|
|
42
|
+
IMPORTANT TDD Rules:
|
|
43
|
+
1. NEVER write implementation code before writing a test
|
|
44
|
+
2. Each test should verify ONE specific behavior
|
|
45
|
+
3. Tests must fail before implementation (verify the test is actually testing something)
|
|
46
|
+
4. After GREEN phase, run ALL tests to check for regressions
|
|
47
|
+
5. REFACTOR phase is optional but should not change behavior`;
|
|
48
|
+
/**
|
|
49
|
+
* Build a planning prompt for a story, optionally with TDD instructions
|
|
16
50
|
*
|
|
17
|
-
*
|
|
51
|
+
* @param story - The story to create a plan for
|
|
52
|
+
* @param tddEnabledInConfig - Whether TDD is enabled in the global config
|
|
53
|
+
* @param reworkContext - Optional context from a failed review
|
|
54
|
+
* @returns The complete planning prompt
|
|
18
55
|
*/
|
|
19
|
-
export
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
let prompt = `Please create an implementation plan for this story:
|
|
56
|
+
export function buildPlanningPrompt(story, tddEnabledInConfig, reworkContext) {
|
|
57
|
+
const tddEnabled = story.frontmatter.tdd_enabled ?? tddEnabledInConfig;
|
|
58
|
+
let prompt = `Please create an implementation plan for this story:
|
|
24
59
|
|
|
25
60
|
Title: ${story.frontmatter.title}
|
|
26
61
|
|
|
27
62
|
Story content:
|
|
28
63
|
${story.content}`;
|
|
29
|
-
|
|
30
|
-
|
|
64
|
+
if (reworkContext) {
|
|
65
|
+
prompt += `
|
|
31
66
|
|
|
32
67
|
---
|
|
33
|
-
${
|
|
68
|
+
${reworkContext}
|
|
34
69
|
---
|
|
35
70
|
|
|
36
71
|
IMPORTANT: This is a refinement iteration. The previous implementation did not pass review.
|
|
37
72
|
Your plan MUST specifically address all the issues listed above. Include explicit tasks
|
|
38
73
|
to fix each identified problem. Do not repeat the same approach that failed.`;
|
|
39
|
-
|
|
74
|
+
}
|
|
75
|
+
if (tddEnabled) {
|
|
40
76
|
prompt += `
|
|
41
77
|
|
|
78
|
+
${TDD_PLANNING_INSTRUCTIONS}`;
|
|
79
|
+
}
|
|
80
|
+
prompt += `
|
|
81
|
+
|
|
42
82
|
Create a detailed implementation plan including:
|
|
43
83
|
1. Phases (e.g., Setup, Implementation, Testing, Verification)
|
|
44
84
|
2. Specific tasks within each phase (as checkboxes)
|
|
@@ -54,6 +94,27 @@ Format the plan with markdown checkboxes like:
|
|
|
54
94
|
### Phase 2: Implementation
|
|
55
95
|
- [ ] Task 3
|
|
56
96
|
...`;
|
|
97
|
+
return prompt;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Planning Agent
|
|
101
|
+
*
|
|
102
|
+
* Creates a step-by-step implementation plan from the research findings.
|
|
103
|
+
*/
|
|
104
|
+
export async function runPlanningAgent(storyPath, sdlcRoot, options = {}) {
|
|
105
|
+
const story = parseStory(storyPath);
|
|
106
|
+
const changesMade = [];
|
|
107
|
+
const workingDir = path.dirname(sdlcRoot);
|
|
108
|
+
try {
|
|
109
|
+
// Load config to check if TDD is enabled globally
|
|
110
|
+
const { loadConfig } = await import('../core/config.js');
|
|
111
|
+
const config = loadConfig(workingDir);
|
|
112
|
+
const tddEnabledInConfig = config.tdd?.enabled ?? false;
|
|
113
|
+
// Build the planning prompt with TDD support if enabled
|
|
114
|
+
const prompt = buildPlanningPrompt(story, tddEnabledInConfig, options.reworkContext);
|
|
115
|
+
if (story.frontmatter.tdd_enabled ?? tddEnabledInConfig) {
|
|
116
|
+
changesMade.push('TDD mode enabled - plan will use Red-Green-Refactor structure');
|
|
117
|
+
}
|
|
57
118
|
const planContent = await runAgentQuery({
|
|
58
119
|
prompt,
|
|
59
120
|
systemPrompt: PLANNING_SYSTEM_PROMPT,
|