agileflow 2.75.0 → 2.76.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/package.json +1 -1
- package/scripts/agileflow-configure.js +105 -27
- package/scripts/agileflow-welcome.js +95 -2
- package/scripts/auto-self-improve.js +301 -0
- package/scripts/ralph-loop.js +491 -0
- package/src/core/agents/design.md +1 -1
- package/src/core/agents/documentation.md +1 -1
- package/src/core/agents/integrations.md +1 -1
- package/src/core/agents/mobile.md +1 -1
- package/src/core/agents/monitoring.md +1 -1
- package/src/core/agents/performance.md +1 -1
- package/src/core/commands/babysit.md +73 -0
- package/src/core/commands/configure.md +50 -7
- package/src/core/experts/documentation/expertise.yaml +4 -0
- package/src/core/experts/research/expertise.yaml +2 -2
- package/tools/cli/lib/docs-setup.js +1 -1
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ralph-loop.js - Autonomous Story Processing Loop
|
|
5
|
+
*
|
|
6
|
+
* This script is the brain of AgileFlow's autonomous work mode.
|
|
7
|
+
* It runs as a Stop hook and handles:
|
|
8
|
+
* 1. Checking if loop mode is enabled
|
|
9
|
+
* 2. Running test validation
|
|
10
|
+
* 3. Updating story status on success
|
|
11
|
+
* 4. Feeding context back for next iteration
|
|
12
|
+
* 5. Tracking iterations and enforcing limits
|
|
13
|
+
*
|
|
14
|
+
* Named after the "Ralph Wiggum" pattern from Anthropic.
|
|
15
|
+
*
|
|
16
|
+
* Usage (as Stop hook):
|
|
17
|
+
* node scripts/ralph-loop.js
|
|
18
|
+
*
|
|
19
|
+
* Manual control:
|
|
20
|
+
* node scripts/ralph-loop.js --status # Check loop status
|
|
21
|
+
* node scripts/ralph-loop.js --stop # Stop the loop
|
|
22
|
+
* node scripts/ralph-loop.js --reset # Reset loop state
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const path = require('path');
|
|
27
|
+
const { execSync, spawnSync } = require('child_process');
|
|
28
|
+
|
|
29
|
+
// ANSI colors
|
|
30
|
+
const c = {
|
|
31
|
+
reset: '\x1b[0m',
|
|
32
|
+
bold: '\x1b[1m',
|
|
33
|
+
dim: '\x1b[2m',
|
|
34
|
+
red: '\x1b[31m',
|
|
35
|
+
green: '\x1b[32m',
|
|
36
|
+
yellow: '\x1b[33m',
|
|
37
|
+
blue: '\x1b[34m',
|
|
38
|
+
cyan: '\x1b[36m',
|
|
39
|
+
brand: '\x1b[38;2;232;104;58m',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Find project root
|
|
43
|
+
function getProjectRoot() {
|
|
44
|
+
let dir = process.cwd();
|
|
45
|
+
while (!fs.existsSync(path.join(dir, '.agileflow')) && dir !== '/') {
|
|
46
|
+
dir = path.dirname(dir);
|
|
47
|
+
}
|
|
48
|
+
return dir !== '/' ? dir : process.cwd();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Read session state
|
|
52
|
+
function getSessionState(rootDir) {
|
|
53
|
+
const statePath = path.join(rootDir, 'docs/09-agents/session-state.json');
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync(statePath)) {
|
|
56
|
+
return JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {}
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Write session state
|
|
63
|
+
function saveSessionState(rootDir, state) {
|
|
64
|
+
const statePath = path.join(rootDir, 'docs/09-agents/session-state.json');
|
|
65
|
+
const dir = path.dirname(statePath);
|
|
66
|
+
if (!fs.existsSync(dir)) {
|
|
67
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
fs.writeFileSync(statePath, JSON.stringify(state, null, 2) + '\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Read status.json for stories
|
|
73
|
+
function getStatus(rootDir) {
|
|
74
|
+
const statusPath = path.join(rootDir, 'docs/09-agents/status.json');
|
|
75
|
+
try {
|
|
76
|
+
if (fs.existsSync(statusPath)) {
|
|
77
|
+
return JSON.parse(fs.readFileSync(statusPath, 'utf8'));
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {}
|
|
80
|
+
return { stories: {}, epics: {} };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Save status.json
|
|
84
|
+
function saveStatus(rootDir, status) {
|
|
85
|
+
const statusPath = path.join(rootDir, 'docs/09-agents/status.json');
|
|
86
|
+
fs.writeFileSync(statusPath, JSON.stringify(status, null, 2) + '\n');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Get test command from package.json or metadata
|
|
90
|
+
function getTestCommand(rootDir) {
|
|
91
|
+
// Check agileflow metadata first
|
|
92
|
+
try {
|
|
93
|
+
const metadataPath = path.join(rootDir, 'docs/00-meta/agileflow-metadata.json');
|
|
94
|
+
if (fs.existsSync(metadataPath)) {
|
|
95
|
+
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));
|
|
96
|
+
if (metadata.ralph_loop?.test_command) {
|
|
97
|
+
return metadata.ralph_loop.test_command;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {}
|
|
101
|
+
|
|
102
|
+
// Default to npm test
|
|
103
|
+
return 'npm test';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Run tests and return result
|
|
107
|
+
function runTests(rootDir, testCommand) {
|
|
108
|
+
const result = { passed: false, output: '', duration: 0 };
|
|
109
|
+
const startTime = Date.now();
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const output = execSync(testCommand, {
|
|
113
|
+
cwd: rootDir,
|
|
114
|
+
encoding: 'utf8',
|
|
115
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
116
|
+
timeout: 300000, // 5 minute timeout
|
|
117
|
+
});
|
|
118
|
+
result.passed = true;
|
|
119
|
+
result.output = output;
|
|
120
|
+
} catch (e) {
|
|
121
|
+
result.passed = false;
|
|
122
|
+
result.output = e.stdout || '' + '\n' + (e.stderr || '');
|
|
123
|
+
if (e.message) {
|
|
124
|
+
result.output += '\n' + e.message;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
result.duration = Date.now() - startTime;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Get next ready story in epic
|
|
133
|
+
function getNextStory(status, epicId, currentStoryId) {
|
|
134
|
+
const stories = status.stories || {};
|
|
135
|
+
|
|
136
|
+
// Get all stories in this epic that are ready
|
|
137
|
+
const readyStories = Object.entries(stories)
|
|
138
|
+
.filter(([id, story]) => {
|
|
139
|
+
return story.epic === epicId &&
|
|
140
|
+
story.status === 'ready' &&
|
|
141
|
+
id !== currentStoryId;
|
|
142
|
+
})
|
|
143
|
+
.sort((a, b) => {
|
|
144
|
+
// Sort by story number if possible
|
|
145
|
+
const numA = parseInt(a[0].replace(/\D/g, '')) || 0;
|
|
146
|
+
const numB = parseInt(b[0].replace(/\D/g, '')) || 0;
|
|
147
|
+
return numA - numB;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (readyStories.length > 0) {
|
|
151
|
+
return { id: readyStories[0][0], ...readyStories[0][1] };
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Mark story as completed
|
|
157
|
+
function markStoryComplete(rootDir, storyId) {
|
|
158
|
+
const status = getStatus(rootDir);
|
|
159
|
+
if (status.stories && status.stories[storyId]) {
|
|
160
|
+
status.stories[storyId].status = 'completed';
|
|
161
|
+
status.stories[storyId].completed_at = new Date().toISOString();
|
|
162
|
+
saveStatus(rootDir, status);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Mark story as in_progress
|
|
169
|
+
function markStoryInProgress(rootDir, storyId) {
|
|
170
|
+
const status = getStatus(rootDir);
|
|
171
|
+
if (status.stories && status.stories[storyId]) {
|
|
172
|
+
status.stories[storyId].status = 'in_progress';
|
|
173
|
+
status.stories[storyId].started_at = new Date().toISOString();
|
|
174
|
+
saveStatus(rootDir, status);
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Get story details
|
|
181
|
+
function getStoryDetails(rootDir, storyId) {
|
|
182
|
+
const status = getStatus(rootDir);
|
|
183
|
+
if (status.stories && status.stories[storyId]) {
|
|
184
|
+
return { id: storyId, ...status.stories[storyId] };
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Count stories in epic by status
|
|
190
|
+
function getEpicProgress(status, epicId) {
|
|
191
|
+
const stories = status.stories || {};
|
|
192
|
+
const epicStories = Object.entries(stories).filter(([_, s]) => s.epic === epicId);
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
total: epicStories.length,
|
|
196
|
+
completed: epicStories.filter(([_, s]) => s.status === 'completed').length,
|
|
197
|
+
in_progress: epicStories.filter(([_, s]) => s.status === 'in_progress').length,
|
|
198
|
+
ready: epicStories.filter(([_, s]) => s.status === 'ready').length,
|
|
199
|
+
blocked: epicStories.filter(([_, s]) => s.status === 'blocked').length,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Main loop logic
|
|
204
|
+
function handleLoop(rootDir) {
|
|
205
|
+
const state = getSessionState(rootDir);
|
|
206
|
+
const loop = state.ralph_loop;
|
|
207
|
+
|
|
208
|
+
// Check if loop mode is enabled
|
|
209
|
+
if (!loop || !loop.enabled) {
|
|
210
|
+
return; // Silent exit - not in loop mode
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const status = getStatus(rootDir);
|
|
214
|
+
const iteration = (loop.iteration || 0) + 1;
|
|
215
|
+
const maxIterations = loop.max_iterations || 20;
|
|
216
|
+
|
|
217
|
+
console.log('');
|
|
218
|
+
console.log(`${c.brand}${c.bold}══════════════════════════════════════════════════════════${c.reset}`);
|
|
219
|
+
console.log(`${c.brand}${c.bold} RALPH LOOP - Iteration ${iteration}/${maxIterations}${c.reset}`);
|
|
220
|
+
console.log(`${c.brand}${c.bold}══════════════════════════════════════════════════════════${c.reset}`);
|
|
221
|
+
console.log('');
|
|
222
|
+
|
|
223
|
+
// Check iteration limit
|
|
224
|
+
if (iteration > maxIterations) {
|
|
225
|
+
console.log(`${c.yellow}⚠ Max iterations (${maxIterations}) reached. Stopping loop.${c.reset}`);
|
|
226
|
+
console.log(`${c.dim}Run /agileflow:babysit MODE=loop to restart${c.reset}`);
|
|
227
|
+
state.ralph_loop.enabled = false;
|
|
228
|
+
state.ralph_loop.stopped_reason = 'max_iterations';
|
|
229
|
+
saveSessionState(rootDir, state);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Get current story
|
|
234
|
+
const currentStoryId = loop.current_story;
|
|
235
|
+
const currentStory = getStoryDetails(rootDir, currentStoryId);
|
|
236
|
+
const epicId = loop.epic;
|
|
237
|
+
|
|
238
|
+
if (!currentStory) {
|
|
239
|
+
console.log(`${c.red}✗ Current story ${currentStoryId} not found${c.reset}`);
|
|
240
|
+
state.ralph_loop.enabled = false;
|
|
241
|
+
state.ralph_loop.stopped_reason = 'story_not_found';
|
|
242
|
+
saveSessionState(rootDir, state);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
console.log(`${c.cyan}Current Story:${c.reset} ${currentStoryId} - ${currentStory.title || 'Untitled'}`);
|
|
247
|
+
console.log('');
|
|
248
|
+
|
|
249
|
+
// Run tests
|
|
250
|
+
const testCommand = getTestCommand(rootDir);
|
|
251
|
+
console.log(`${c.blue}Running:${c.reset} ${testCommand}`);
|
|
252
|
+
console.log(`${c.dim}${'─'.repeat(58)}${c.reset}`);
|
|
253
|
+
|
|
254
|
+
const testResult = runTests(rootDir, testCommand);
|
|
255
|
+
|
|
256
|
+
if (testResult.passed) {
|
|
257
|
+
console.log(`${c.green}✓ Tests passed${c.reset} (${(testResult.duration / 1000).toFixed(1)}s)`);
|
|
258
|
+
console.log('');
|
|
259
|
+
|
|
260
|
+
// Mark story complete
|
|
261
|
+
markStoryComplete(rootDir, currentStoryId);
|
|
262
|
+
console.log(`${c.green}✓ Marked ${currentStoryId} as completed${c.reset}`);
|
|
263
|
+
|
|
264
|
+
// Get next story
|
|
265
|
+
const nextStory = getNextStory(status, epicId, currentStoryId);
|
|
266
|
+
|
|
267
|
+
if (nextStory) {
|
|
268
|
+
// Move to next story
|
|
269
|
+
markStoryInProgress(rootDir, nextStory.id);
|
|
270
|
+
state.ralph_loop.current_story = nextStory.id;
|
|
271
|
+
state.ralph_loop.iteration = iteration;
|
|
272
|
+
saveSessionState(rootDir, state);
|
|
273
|
+
|
|
274
|
+
const progress = getEpicProgress(getStatus(rootDir), epicId);
|
|
275
|
+
console.log('');
|
|
276
|
+
console.log(`${c.cyan}━━━ Next Story ━━━${c.reset}`);
|
|
277
|
+
console.log(`${c.bold}${nextStory.id}:${c.reset} ${nextStory.title || 'Untitled'}`);
|
|
278
|
+
if (nextStory.acceptance_criteria) {
|
|
279
|
+
console.log(`${c.dim}Acceptance Criteria:${c.reset}`);
|
|
280
|
+
const criteria = Array.isArray(nextStory.acceptance_criteria)
|
|
281
|
+
? nextStory.acceptance_criteria
|
|
282
|
+
: [nextStory.acceptance_criteria];
|
|
283
|
+
criteria.slice(0, 3).forEach(ac => console.log(` • ${ac}`));
|
|
284
|
+
}
|
|
285
|
+
console.log('');
|
|
286
|
+
console.log(`${c.dim}Epic Progress: ${progress.completed}/${progress.total} stories complete${c.reset}`);
|
|
287
|
+
console.log('');
|
|
288
|
+
console.log(`${c.brand}▶ Continue implementing ${nextStory.id}${c.reset}`);
|
|
289
|
+
console.log(`${c.dim} Run tests when ready. Loop will validate and continue.${c.reset}`);
|
|
290
|
+
|
|
291
|
+
} else {
|
|
292
|
+
// No more stories - epic complete!
|
|
293
|
+
const progress = getEpicProgress(getStatus(rootDir), epicId);
|
|
294
|
+
state.ralph_loop.enabled = false;
|
|
295
|
+
state.ralph_loop.stopped_reason = 'epic_complete';
|
|
296
|
+
state.ralph_loop.completed_at = new Date().toISOString();
|
|
297
|
+
saveSessionState(rootDir, state);
|
|
298
|
+
|
|
299
|
+
console.log('');
|
|
300
|
+
console.log(`${c.green}${c.bold}════════════════════════════════════════════════════════${c.reset}`);
|
|
301
|
+
console.log(`${c.green}${c.bold} 🎉 EPIC COMPLETE!${c.reset}`);
|
|
302
|
+
console.log(`${c.green}${c.bold}════════════════════════════════════════════════════════${c.reset}`);
|
|
303
|
+
console.log('');
|
|
304
|
+
console.log(`${c.green}Epic ${epicId} finished in ${iteration} iterations${c.reset}`);
|
|
305
|
+
console.log(`${c.dim}${progress.completed} stories completed${c.reset}`);
|
|
306
|
+
console.log('');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
} else {
|
|
310
|
+
// Tests failed - feed back to Claude
|
|
311
|
+
console.log(`${c.red}✗ Tests failed${c.reset} (${(testResult.duration / 1000).toFixed(1)}s)`);
|
|
312
|
+
console.log('');
|
|
313
|
+
|
|
314
|
+
state.ralph_loop.iteration = iteration;
|
|
315
|
+
state.ralph_loop.last_failure = new Date().toISOString();
|
|
316
|
+
saveSessionState(rootDir, state);
|
|
317
|
+
|
|
318
|
+
console.log(`${c.yellow}━━━ Test Failures ━━━${c.reset}`);
|
|
319
|
+
|
|
320
|
+
// Show truncated output (last 50 lines most relevant)
|
|
321
|
+
const outputLines = testResult.output.split('\n');
|
|
322
|
+
const relevantLines = outputLines.slice(-50);
|
|
323
|
+
console.log(relevantLines.join('\n'));
|
|
324
|
+
|
|
325
|
+
console.log('');
|
|
326
|
+
console.log(`${c.brand}▶ Fix the failing tests and continue${c.reset}`);
|
|
327
|
+
console.log(`${c.dim} Loop will re-run tests when you stop.${c.reset}`);
|
|
328
|
+
console.log(`${c.dim} Iteration ${iteration}/${maxIterations}${c.reset}`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
console.log('');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Handle CLI arguments
|
|
335
|
+
function handleCLI() {
|
|
336
|
+
const args = process.argv.slice(2);
|
|
337
|
+
const rootDir = getProjectRoot();
|
|
338
|
+
|
|
339
|
+
if (args.includes('--status')) {
|
|
340
|
+
const state = getSessionState(rootDir);
|
|
341
|
+
const loop = state.ralph_loop;
|
|
342
|
+
|
|
343
|
+
if (!loop || !loop.enabled) {
|
|
344
|
+
console.log(`${c.dim}Ralph Loop: not active${c.reset}`);
|
|
345
|
+
} else {
|
|
346
|
+
console.log(`${c.green}Ralph Loop: active${c.reset}`);
|
|
347
|
+
console.log(` Epic: ${loop.epic}`);
|
|
348
|
+
console.log(` Current Story: ${loop.current_story}`);
|
|
349
|
+
console.log(` Iteration: ${loop.iteration || 0}/${loop.max_iterations || 20}`);
|
|
350
|
+
}
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (args.includes('--stop')) {
|
|
355
|
+
const state = getSessionState(rootDir);
|
|
356
|
+
if (state.ralph_loop) {
|
|
357
|
+
state.ralph_loop.enabled = false;
|
|
358
|
+
state.ralph_loop.stopped_reason = 'manual';
|
|
359
|
+
saveSessionState(rootDir, state);
|
|
360
|
+
console.log(`${c.yellow}Ralph Loop stopped${c.reset}`);
|
|
361
|
+
} else {
|
|
362
|
+
console.log(`${c.dim}Ralph Loop was not active${c.reset}`);
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (args.includes('--reset')) {
|
|
368
|
+
const state = getSessionState(rootDir);
|
|
369
|
+
delete state.ralph_loop;
|
|
370
|
+
saveSessionState(rootDir, state);
|
|
371
|
+
console.log(`${c.green}Ralph Loop state reset${c.reset}`);
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Handle --init
|
|
376
|
+
if (args.some(a => a.startsWith('--init'))) {
|
|
377
|
+
const epicArg = args.find(a => a.startsWith('--epic='));
|
|
378
|
+
const maxArg = args.find(a => a.startsWith('--max='));
|
|
379
|
+
|
|
380
|
+
if (!epicArg) {
|
|
381
|
+
console.log(`${c.red}Error: --epic=EP-XXXX is required${c.reset}`);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const epicId = epicArg.split('=')[1];
|
|
386
|
+
const maxIterations = maxArg ? parseInt(maxArg.split('=')[1]) : 20;
|
|
387
|
+
|
|
388
|
+
// Find first ready story in epic
|
|
389
|
+
const status = getStatus(rootDir);
|
|
390
|
+
const stories = status.stories || {};
|
|
391
|
+
const readyStories = Object.entries(stories)
|
|
392
|
+
.filter(([_, s]) => s.epic === epicId && s.status === 'ready')
|
|
393
|
+
.sort((a, b) => {
|
|
394
|
+
const numA = parseInt(a[0].replace(/\D/g, '')) || 0;
|
|
395
|
+
const numB = parseInt(b[0].replace(/\D/g, '')) || 0;
|
|
396
|
+
return numA - numB;
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
if (readyStories.length === 0) {
|
|
400
|
+
console.log(`${c.yellow}No ready stories found in ${epicId}${c.reset}`);
|
|
401
|
+
console.log(`${c.dim}Create stories with status "ready" first${c.reset}`);
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const firstStory = readyStories[0];
|
|
406
|
+
const storyId = firstStory[0];
|
|
407
|
+
|
|
408
|
+
// Mark first story as in_progress
|
|
409
|
+
markStoryInProgress(rootDir, storyId);
|
|
410
|
+
|
|
411
|
+
// Initialize loop state
|
|
412
|
+
const state = getSessionState(rootDir);
|
|
413
|
+
state.ralph_loop = {
|
|
414
|
+
enabled: true,
|
|
415
|
+
epic: epicId,
|
|
416
|
+
current_story: storyId,
|
|
417
|
+
iteration: 0,
|
|
418
|
+
max_iterations: maxIterations,
|
|
419
|
+
started_at: new Date().toISOString(),
|
|
420
|
+
};
|
|
421
|
+
saveSessionState(rootDir, state);
|
|
422
|
+
|
|
423
|
+
const progress = getEpicProgress(status, epicId);
|
|
424
|
+
|
|
425
|
+
console.log('');
|
|
426
|
+
console.log(`${c.green}${c.bold}Ralph Loop Initialized${c.reset}`);
|
|
427
|
+
console.log(`${c.dim}${'─'.repeat(40)}${c.reset}`);
|
|
428
|
+
console.log(` Epic: ${c.cyan}${epicId}${c.reset}`);
|
|
429
|
+
console.log(` Stories: ${progress.ready} ready, ${progress.total} total`);
|
|
430
|
+
console.log(` Max Iterations: ${maxIterations}`);
|
|
431
|
+
console.log(`${c.dim}${'─'.repeat(40)}${c.reset}`);
|
|
432
|
+
console.log('');
|
|
433
|
+
console.log(`${c.brand}▶ Starting Story:${c.reset} ${storyId}`);
|
|
434
|
+
console.log(` ${firstStory[1].title || 'Untitled'}`);
|
|
435
|
+
if (firstStory[1].acceptance_criteria) {
|
|
436
|
+
const criteria = Array.isArray(firstStory[1].acceptance_criteria)
|
|
437
|
+
? firstStory[1].acceptance_criteria
|
|
438
|
+
: [firstStory[1].acceptance_criteria];
|
|
439
|
+
console.log(`${c.dim} Acceptance Criteria:${c.reset}`);
|
|
440
|
+
criteria.slice(0, 3).forEach(ac => console.log(` • ${ac}`));
|
|
441
|
+
}
|
|
442
|
+
console.log('');
|
|
443
|
+
console.log(`${c.dim}Work on this story. When you stop, tests will run automatically.${c.reset}`);
|
|
444
|
+
console.log(`${c.dim}If tests pass, the next story will be loaded.${c.reset}`);
|
|
445
|
+
console.log('');
|
|
446
|
+
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (args.includes('--help')) {
|
|
451
|
+
console.log(`
|
|
452
|
+
${c.brand}${c.bold}ralph-loop.js${c.reset} - Autonomous Story Processing
|
|
453
|
+
|
|
454
|
+
${c.bold}Usage:${c.reset}
|
|
455
|
+
node scripts/ralph-loop.js Run loop check (Stop hook)
|
|
456
|
+
node scripts/ralph-loop.js --init --epic=EP-XXX Initialize loop for epic
|
|
457
|
+
node scripts/ralph-loop.js --status Check loop status
|
|
458
|
+
node scripts/ralph-loop.js --stop Stop the loop
|
|
459
|
+
node scripts/ralph-loop.js --reset Reset loop state
|
|
460
|
+
|
|
461
|
+
${c.bold}Options:${c.reset}
|
|
462
|
+
--epic=EP-XXXX Epic ID to process (required for --init)
|
|
463
|
+
--max=N Max iterations (default: 20)
|
|
464
|
+
|
|
465
|
+
${c.bold}How it works:${c.reset}
|
|
466
|
+
1. Start loop with /agileflow:babysit EPIC=EP-XXX MODE=loop
|
|
467
|
+
2. Work on the current story
|
|
468
|
+
3. When you stop, this hook runs tests
|
|
469
|
+
4. If tests pass → story marked complete, next story loaded
|
|
470
|
+
5. If tests fail → failures shown, you continue fixing
|
|
471
|
+
6. Loop repeats until epic done or max iterations
|
|
472
|
+
`);
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Main
|
|
480
|
+
function main() {
|
|
481
|
+
// Handle CLI commands first
|
|
482
|
+
if (handleCLI()) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Otherwise run the loop handler
|
|
487
|
+
const rootDir = getProjectRoot();
|
|
488
|
+
handleLoop(rootDir);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
main();
|
|
@@ -70,7 +70,7 @@ FIRST ACTION PROTOCOL:
|
|
|
70
70
|
4. For complete features: Use workflow.md (Plan → Build → Self-Improve)
|
|
71
71
|
5. After work: Run self-improve.md to update expertise
|
|
72
72
|
|
|
73
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
73
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
74
74
|
<!-- COMPACT_SUMMARY_END -->
|
|
75
75
|
|
|
76
76
|
You are AG-DESIGN, the Design Specialist for AgileFlow projects.
|
|
@@ -76,7 +76,7 @@ DOCUMENTATION PRINCIPLES:
|
|
|
76
76
|
- Include troubleshooting (users will have problems)
|
|
77
77
|
- Document breaking changes (critical for users)
|
|
78
78
|
|
|
79
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
79
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
80
80
|
<!-- COMPACT_SUMMARY_END -->
|
|
81
81
|
|
|
82
82
|
You are AG-DOCUMENTATION, the Documentation Specialist for AgileFlow projects.
|
|
@@ -82,7 +82,7 @@ FIRST ACTION PROTOCOL:
|
|
|
82
82
|
4. For complete features: Use workflow.md (Plan → Build → Self-Improve)
|
|
83
83
|
5. After work: Run self-improve.md to update expertise
|
|
84
84
|
|
|
85
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:status
|
|
85
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:status
|
|
86
86
|
<!-- COMPACT_SUMMARY_END -->
|
|
87
87
|
|
|
88
88
|
You are AG-INTEGRATIONS, the Integration Specialist for AgileFlow projects.
|
|
@@ -84,7 +84,7 @@ FIRST ACTION PROTOCOL:
|
|
|
84
84
|
4. For complete features: Use workflow.md (Plan → Build → Self-Improve)
|
|
85
85
|
5. After work: Run self-improve.md to update expertise
|
|
86
86
|
|
|
87
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:status
|
|
87
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:status
|
|
88
88
|
<!-- COMPACT_SUMMARY_END -->
|
|
89
89
|
|
|
90
90
|
You are AG-MOBILE, the Mobile Specialist for AgileFlow projects.
|
|
@@ -84,7 +84,7 @@ FIRST ACTION PROTOCOL:
|
|
|
84
84
|
4. For complete features: Use workflow.md (Plan → Build → Self-Improve)
|
|
85
85
|
5. After work: Run self-improve.md to update expertise
|
|
86
86
|
|
|
87
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
87
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:status
|
|
88
88
|
<!-- COMPACT_SUMMARY_END -->
|
|
89
89
|
|
|
90
90
|
You are AG-MONITORING, the Monitoring & Observability Specialist for AgileFlow projects.
|
|
@@ -91,7 +91,7 @@ FIRST ACTION PROTOCOL:
|
|
|
91
91
|
|
|
92
92
|
PLAN MODE REQUIRED: Performance work requires measurement first. Always use EnterPlanMode to profile before optimizing.
|
|
93
93
|
|
|
94
|
-
SLASH COMMANDS: /agileflow:context, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:impact-analysis, /agileflow:status
|
|
94
|
+
SLASH COMMANDS: /agileflow:context:full, /agileflow:ai-code-review, /agileflow:adr-new, /agileflow:tech-debt, /agileflow:impact-analysis, /agileflow:status
|
|
95
95
|
<!-- COMPACT_SUMMARY_END -->
|
|
96
96
|
|
|
97
97
|
You are AG-PERFORMANCE, the Performance Specialist for AgileFlow projects.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
description: Interactive mentor for end-to-end feature implementation
|
|
3
|
+
argument-hint: "[EPIC=<id>] [MODE=loop] [MAX=<iterations>]"
|
|
3
4
|
compact_context:
|
|
4
5
|
priority: critical
|
|
5
6
|
preserve_rules:
|
|
@@ -34,6 +35,78 @@ This gathers: git status, stories/epics, session state, docs structure, research
|
|
|
34
35
|
|
|
35
36
|
---
|
|
36
37
|
|
|
38
|
+
## LOOP MODE (Autonomous Execution)
|
|
39
|
+
|
|
40
|
+
When invoked with `MODE=loop`, babysit runs autonomously through an epic's stories:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
/agileflow:babysit EPIC=EP-0042 MODE=loop MAX=20
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### How Loop Mode Works
|
|
47
|
+
|
|
48
|
+
1. **Initialization**: Writes loop config to `session-state.json`
|
|
49
|
+
2. **First Story**: Picks first "ready" story, marks it "in_progress"
|
|
50
|
+
3. **Work**: You implement the story normally
|
|
51
|
+
4. **Stop Hook**: When you stop, `ralph-loop.js` runs:
|
|
52
|
+
- Runs `npm test` (or configured test command)
|
|
53
|
+
- If tests pass → marks story complete, loads next story
|
|
54
|
+
- If tests fail → shows failures, you continue fixing
|
|
55
|
+
5. **Loop**: Continues until epic complete or MAX iterations reached
|
|
56
|
+
|
|
57
|
+
### Parameters
|
|
58
|
+
|
|
59
|
+
| Parameter | Required | Description |
|
|
60
|
+
|-----------|----------|-------------|
|
|
61
|
+
| `EPIC` | Yes | Epic ID to process (e.g., EP-0042) |
|
|
62
|
+
| `MODE` | Yes | Must be `loop` for autonomous mode |
|
|
63
|
+
| `MAX` | No | Max iterations (default: 20) |
|
|
64
|
+
|
|
65
|
+
### To Start Loop Mode
|
|
66
|
+
|
|
67
|
+
After running the context script, if EPIC and MODE=loop are specified:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Initialize the loop
|
|
71
|
+
node scripts/ralph-loop.js --init --epic=EP-0042 --max=20
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Or manually write to session-state.json:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"ralph_loop": {
|
|
79
|
+
"enabled": true,
|
|
80
|
+
"epic": "EP-0042",
|
|
81
|
+
"current_story": "US-0015",
|
|
82
|
+
"iteration": 0,
|
|
83
|
+
"max_iterations": 20
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Loop Control Commands
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
node scripts/ralph-loop.js --status # Check loop status
|
|
92
|
+
node scripts/ralph-loop.js --stop # Stop the loop
|
|
93
|
+
node scripts/ralph-loop.js --reset # Reset loop state
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### When to Use Loop Mode
|
|
97
|
+
|
|
98
|
+
**Good for:**
|
|
99
|
+
- Working through a well-defined epic with clear stories
|
|
100
|
+
- Test-driven development (tests define "done")
|
|
101
|
+
- Batch processing multiple stories overnight
|
|
102
|
+
|
|
103
|
+
**Not good for:**
|
|
104
|
+
- Exploratory work without clear acceptance criteria
|
|
105
|
+
- Stories requiring human review before proceeding
|
|
106
|
+
- Complex multi-domain work needing coordination
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
37
110
|
<!-- COMPACT_SUMMARY_START -->
|
|
38
111
|
|
|
39
112
|
## Compact Summary
|