specsmd 0.0.0-dev.54 → 0.0.0-dev.56
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/flows/fire/agents/builder/skills/run-execute/SKILL.md +4 -4
- package/flows/fire/agents/builder/skills/run-execute/scripts/complete-run.js +549 -0
- package/flows/fire/agents/builder/skills/run-execute/scripts/init-run.js +454 -0
- package/flows/fire/memory-bank.yaml +2 -0
- package/package.json +1 -1
- package/flows/fire/agents/builder/skills/run-execute/scripts/complete-run.ts +0 -806
- package/flows/fire/agents/builder/skills/run-execute/scripts/init-run.ts +0 -575
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* FIRE Run Initialization Script
|
|
5
|
+
*
|
|
6
|
+
* Creates run record in state.yaml and run folder structure.
|
|
7
|
+
* Supports both single work item and batch/wide runs with multiple items.
|
|
8
|
+
*
|
|
9
|
+
* Ensures deterministic run ID generation by checking BOTH:
|
|
10
|
+
* - runs.completed history in state.yaml
|
|
11
|
+
* - existing run folders in .specs-fire/runs/
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* Single item: node init-run.js <rootPath> <workItemId> <intentId> <mode>
|
|
15
|
+
* Batch/Wide: node init-run.js <rootPath> --batch '<workItemsJson>'
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
* node init-run.js /project login-endpoint user-auth confirm
|
|
19
|
+
* node init-run.js /project --batch '[{"id":"wi-1","intent":"int-1","mode":"autopilot"}]'
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
const yaml = require('yaml');
|
|
25
|
+
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Error Helper
|
|
28
|
+
// =============================================================================
|
|
29
|
+
|
|
30
|
+
function fireError(message, code, suggestion) {
|
|
31
|
+
const err = new Error(`FIRE Error [${code}]: ${message} ${suggestion}`);
|
|
32
|
+
err.code = code;
|
|
33
|
+
err.suggestion = suggestion;
|
|
34
|
+
return err;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// =============================================================================
|
|
38
|
+
// Validation
|
|
39
|
+
// =============================================================================
|
|
40
|
+
|
|
41
|
+
const VALID_MODES = ['autopilot', 'confirm', 'validate'];
|
|
42
|
+
const VALID_SCOPES = ['single', 'batch', 'wide'];
|
|
43
|
+
|
|
44
|
+
function validateRootPath(rootPath) {
|
|
45
|
+
if (!rootPath || typeof rootPath !== 'string' || rootPath.trim() === '') {
|
|
46
|
+
throw fireError('rootPath is required.', 'INIT_001', 'Provide a valid project root path.');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!fs.existsSync(rootPath)) {
|
|
50
|
+
throw fireError(
|
|
51
|
+
`Project root not found: "${rootPath}".`,
|
|
52
|
+
'INIT_040',
|
|
53
|
+
'Ensure the path exists and is accessible.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function validateWorkItem(item, index) {
|
|
59
|
+
if (!item.id || typeof item.id !== 'string' || item.id.trim() === '') {
|
|
60
|
+
throw fireError(
|
|
61
|
+
`Work item at index ${index} missing 'id'.`,
|
|
62
|
+
'INIT_010',
|
|
63
|
+
'Each work item must have an id.'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!item.intent || typeof item.intent !== 'string' || item.intent.trim() === '') {
|
|
68
|
+
throw fireError(
|
|
69
|
+
`Work item "${item.id}" missing 'intent'.`,
|
|
70
|
+
'INIT_020',
|
|
71
|
+
'Each work item must have an intent.'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!item.mode || !VALID_MODES.includes(item.mode)) {
|
|
76
|
+
throw fireError(
|
|
77
|
+
`Work item "${item.id}" has invalid mode: "${item.mode}".`,
|
|
78
|
+
'INIT_030',
|
|
79
|
+
`Valid modes are: ${VALID_MODES.join(', ')}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function validateWorkItems(workItems) {
|
|
85
|
+
if (!Array.isArray(workItems) || workItems.length === 0) {
|
|
86
|
+
throw fireError(
|
|
87
|
+
'Work items array is empty or invalid.',
|
|
88
|
+
'INIT_011',
|
|
89
|
+
'Provide at least one work item.'
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
workItems.forEach((item, index) => validateWorkItem(item, index));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function validateFireProject(rootPath) {
|
|
97
|
+
const fireDir = path.join(rootPath, '.specs-fire');
|
|
98
|
+
const statePath = path.join(fireDir, 'state.yaml');
|
|
99
|
+
const runsPath = path.join(fireDir, 'runs');
|
|
100
|
+
|
|
101
|
+
if (!fs.existsSync(fireDir)) {
|
|
102
|
+
throw fireError(
|
|
103
|
+
`FIRE project not initialized at: "${rootPath}".`,
|
|
104
|
+
'INIT_041',
|
|
105
|
+
'Run fire-init first to initialize the project.'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!fs.existsSync(statePath)) {
|
|
110
|
+
throw fireError(
|
|
111
|
+
`State file not found at: "${statePath}".`,
|
|
112
|
+
'INIT_042',
|
|
113
|
+
'The project may be corrupted. Try re-initializing.'
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { fireDir, statePath, runsPath };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// =============================================================================
|
|
121
|
+
// State Operations
|
|
122
|
+
// =============================================================================
|
|
123
|
+
|
|
124
|
+
function readState(statePath) {
|
|
125
|
+
try {
|
|
126
|
+
const content = fs.readFileSync(statePath, 'utf8');
|
|
127
|
+
const state = yaml.parse(content);
|
|
128
|
+
if (!state || typeof state !== 'object') {
|
|
129
|
+
throw fireError('State file is empty or invalid.', 'INIT_050', 'Check state.yaml format.');
|
|
130
|
+
}
|
|
131
|
+
return state;
|
|
132
|
+
} catch (err) {
|
|
133
|
+
if (err.code && err.code.startsWith('INIT_')) throw err;
|
|
134
|
+
throw fireError(
|
|
135
|
+
`Failed to read state file: ${err.message}`,
|
|
136
|
+
'INIT_051',
|
|
137
|
+
'Check file permissions and YAML syntax.'
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function writeState(statePath, state) {
|
|
143
|
+
try {
|
|
144
|
+
fs.writeFileSync(statePath, yaml.stringify(state));
|
|
145
|
+
} catch (err) {
|
|
146
|
+
throw fireError(
|
|
147
|
+
`Failed to write state file: ${err.message}`,
|
|
148
|
+
'INIT_052',
|
|
149
|
+
'Check file permissions and disk space.'
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// =============================================================================
|
|
155
|
+
// Run ID Generation (CRITICAL - checks both history and file system)
|
|
156
|
+
// =============================================================================
|
|
157
|
+
|
|
158
|
+
function generateRunId(runsPath, state) {
|
|
159
|
+
// Ensure runs directory exists
|
|
160
|
+
if (!fs.existsSync(runsPath)) {
|
|
161
|
+
fs.mkdirSync(runsPath, { recursive: true });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Source 1: Get max from state.yaml runs.completed history
|
|
165
|
+
let maxFromHistory = 0;
|
|
166
|
+
if (state.runs && Array.isArray(state.runs.completed)) {
|
|
167
|
+
for (const run of state.runs.completed) {
|
|
168
|
+
if (run.id) {
|
|
169
|
+
const match = run.id.match(/^run-(\d+)$/);
|
|
170
|
+
if (match) {
|
|
171
|
+
const num = parseInt(match[1], 10);
|
|
172
|
+
if (num > maxFromHistory) maxFromHistory = num;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Source 2: Get max from file system (defensive)
|
|
179
|
+
let maxFromFileSystem = 0;
|
|
180
|
+
try {
|
|
181
|
+
const entries = fs.readdirSync(runsPath);
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
if (/^run-\d{3,}$/.test(entry)) {
|
|
184
|
+
const num = parseInt(entry.replace('run-', ''), 10);
|
|
185
|
+
if (num > maxFromFileSystem) maxFromFileSystem = num;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch (err) {
|
|
189
|
+
throw fireError(
|
|
190
|
+
`Failed to read runs directory: ${err.message}`,
|
|
191
|
+
'INIT_060',
|
|
192
|
+
'Check directory permissions.'
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Use MAX of both to ensure no duplicates
|
|
197
|
+
const maxNum = Math.max(maxFromHistory, maxFromFileSystem);
|
|
198
|
+
const nextNum = maxNum + 1;
|
|
199
|
+
|
|
200
|
+
return `run-${String(nextNum).padStart(3, '0')}`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// =============================================================================
|
|
204
|
+
// Scope Detection
|
|
205
|
+
// =============================================================================
|
|
206
|
+
|
|
207
|
+
function detectScope(workItems) {
|
|
208
|
+
if (workItems.length === 1) {
|
|
209
|
+
return 'single';
|
|
210
|
+
}
|
|
211
|
+
// For multiple items, default to batch
|
|
212
|
+
// (wide would be explicitly set by the caller if all compatible items are included)
|
|
213
|
+
return 'batch';
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// =============================================================================
|
|
217
|
+
// Run Folder Creation
|
|
218
|
+
// =============================================================================
|
|
219
|
+
|
|
220
|
+
function createRunFolder(runPath) {
|
|
221
|
+
try {
|
|
222
|
+
fs.mkdirSync(runPath, { recursive: true });
|
|
223
|
+
} catch (err) {
|
|
224
|
+
throw fireError(
|
|
225
|
+
`Failed to create run folder: ${err.message}`,
|
|
226
|
+
'INIT_070',
|
|
227
|
+
'Check directory permissions and disk space.'
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function createRunLog(runPath, runId, workItems, scope, startTime) {
|
|
233
|
+
// Format work items for run.md
|
|
234
|
+
const workItemsList = workItems.map((item, index) => {
|
|
235
|
+
const status = index === 0 ? 'in_progress' : 'pending';
|
|
236
|
+
return ` - id: ${item.id}\n intent: ${item.intent}\n mode: ${item.mode}\n status: ${status}`;
|
|
237
|
+
}).join('\n');
|
|
238
|
+
|
|
239
|
+
const currentItem = workItems[0];
|
|
240
|
+
|
|
241
|
+
const runLog = `---
|
|
242
|
+
id: ${runId}
|
|
243
|
+
scope: ${scope}
|
|
244
|
+
work_items:
|
|
245
|
+
${workItemsList}
|
|
246
|
+
current_item: ${currentItem.id}
|
|
247
|
+
status: in_progress
|
|
248
|
+
started: ${startTime}
|
|
249
|
+
completed: null
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
# Run: ${runId}
|
|
253
|
+
|
|
254
|
+
## Scope
|
|
255
|
+
${scope} (${workItems.length} work item${workItems.length > 1 ? 's' : ''})
|
|
256
|
+
|
|
257
|
+
## Work Items
|
|
258
|
+
${workItems.map((item, i) => `${i + 1}. **${item.id}** (${item.mode}) — ${i === 0 ? 'in_progress' : 'pending'}`).join('\n')}
|
|
259
|
+
|
|
260
|
+
## Current Item
|
|
261
|
+
${currentItem.id} (${currentItem.mode})
|
|
262
|
+
|
|
263
|
+
## Files Created
|
|
264
|
+
(none yet)
|
|
265
|
+
|
|
266
|
+
## Files Modified
|
|
267
|
+
(none yet)
|
|
268
|
+
|
|
269
|
+
## Decisions
|
|
270
|
+
(none yet)
|
|
271
|
+
`;
|
|
272
|
+
|
|
273
|
+
const runLogPath = path.join(runPath, 'run.md');
|
|
274
|
+
try {
|
|
275
|
+
fs.writeFileSync(runLogPath, runLog);
|
|
276
|
+
} catch (err) {
|
|
277
|
+
throw fireError(
|
|
278
|
+
`Failed to create run log: ${err.message}`,
|
|
279
|
+
'INIT_071',
|
|
280
|
+
'Check file permissions.'
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// =============================================================================
|
|
286
|
+
// Main Function
|
|
287
|
+
// =============================================================================
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Initialize a run with one or more work items.
|
|
291
|
+
*
|
|
292
|
+
* @param {string} rootPath - Project root directory
|
|
293
|
+
* @param {Array<{id: string, intent: string, mode: string}>} workItems - Work items to include in run
|
|
294
|
+
* @param {string} [scope] - Optional scope override ('single', 'batch', 'wide')
|
|
295
|
+
* @returns {object} Result with runId, runPath, workItems, scope, started
|
|
296
|
+
*/
|
|
297
|
+
function initRun(rootPath, workItems, scope) {
|
|
298
|
+
// Validate root path
|
|
299
|
+
validateRootPath(rootPath);
|
|
300
|
+
|
|
301
|
+
// Validate work items
|
|
302
|
+
validateWorkItems(workItems);
|
|
303
|
+
|
|
304
|
+
// Detect or validate scope
|
|
305
|
+
const detectedScope = scope || detectScope(workItems);
|
|
306
|
+
if (scope && !VALID_SCOPES.includes(scope)) {
|
|
307
|
+
throw fireError(
|
|
308
|
+
`Invalid scope: "${scope}".`,
|
|
309
|
+
'INIT_035',
|
|
310
|
+
`Valid scopes are: ${VALID_SCOPES.join(', ')}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Validate FIRE project structure
|
|
315
|
+
const { statePath, runsPath } = validateFireProject(rootPath);
|
|
316
|
+
|
|
317
|
+
// Read state
|
|
318
|
+
const state = readState(statePath);
|
|
319
|
+
|
|
320
|
+
// Check for existing active run
|
|
321
|
+
if (state.active_run) {
|
|
322
|
+
throw fireError(
|
|
323
|
+
`A run is already active: "${state.active_run.id}".`,
|
|
324
|
+
'INIT_080',
|
|
325
|
+
`Complete or cancel run "${state.active_run.id}" before starting a new one.`
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Generate run ID (checks both history AND file system)
|
|
330
|
+
const runId = generateRunId(runsPath, state);
|
|
331
|
+
const runPath = path.join(runsPath, runId);
|
|
332
|
+
|
|
333
|
+
// Create run folder
|
|
334
|
+
createRunFolder(runPath);
|
|
335
|
+
|
|
336
|
+
// Create run log
|
|
337
|
+
const startTime = new Date().toISOString();
|
|
338
|
+
createRunLog(runPath, runId, workItems, detectedScope, startTime);
|
|
339
|
+
|
|
340
|
+
// Prepare work items for state with status tracking
|
|
341
|
+
const stateWorkItems = workItems.map((item, index) => ({
|
|
342
|
+
id: item.id,
|
|
343
|
+
intent: item.intent,
|
|
344
|
+
mode: item.mode,
|
|
345
|
+
status: index === 0 ? 'in_progress' : 'pending',
|
|
346
|
+
}));
|
|
347
|
+
|
|
348
|
+
// Update state with active run
|
|
349
|
+
state.active_run = {
|
|
350
|
+
id: runId,
|
|
351
|
+
scope: detectedScope,
|
|
352
|
+
work_items: stateWorkItems,
|
|
353
|
+
current_item: workItems[0].id,
|
|
354
|
+
started: startTime,
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Save state
|
|
358
|
+
writeState(statePath, state);
|
|
359
|
+
|
|
360
|
+
// Return result
|
|
361
|
+
return {
|
|
362
|
+
success: true,
|
|
363
|
+
runId: runId,
|
|
364
|
+
runPath: runPath,
|
|
365
|
+
scope: detectedScope,
|
|
366
|
+
workItems: stateWorkItems,
|
|
367
|
+
currentItem: workItems[0].id,
|
|
368
|
+
started: startTime,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// =============================================================================
|
|
373
|
+
// CLI Interface
|
|
374
|
+
// =============================================================================
|
|
375
|
+
|
|
376
|
+
function printUsage() {
|
|
377
|
+
console.error('Usage:');
|
|
378
|
+
console.error(' Single item: node init-run.js <rootPath> <workItemId> <intentId> <mode>');
|
|
379
|
+
console.error(' Batch/Wide: node init-run.js <rootPath> --batch \'<workItemsJson>\' [--scope=<scope>]');
|
|
380
|
+
console.error('');
|
|
381
|
+
console.error('Arguments:');
|
|
382
|
+
console.error(' rootPath - Project root directory');
|
|
383
|
+
console.error(' workItemId - Work item ID (single mode)');
|
|
384
|
+
console.error(' intentId - Intent ID (single mode)');
|
|
385
|
+
console.error(' mode - Execution mode: autopilot, confirm, validate');
|
|
386
|
+
console.error('');
|
|
387
|
+
console.error('Options:');
|
|
388
|
+
console.error(' --batch - JSON array of work items');
|
|
389
|
+
console.error(' --scope - Override scope: single, batch, wide');
|
|
390
|
+
console.error('');
|
|
391
|
+
console.error('Work item JSON format:');
|
|
392
|
+
console.error(' [{"id": "wi-1", "intent": "int-1", "mode": "autopilot"}, ...]');
|
|
393
|
+
console.error('');
|
|
394
|
+
console.error('Examples:');
|
|
395
|
+
console.error(' node init-run.js /project login-endpoint user-auth confirm');
|
|
396
|
+
console.error(' node init-run.js /project --batch \'[{"id":"wi-1","intent":"int-1","mode":"autopilot"}]\'');
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (require.main === module) {
|
|
400
|
+
const args = process.argv.slice(2);
|
|
401
|
+
|
|
402
|
+
if (args.length < 2) {
|
|
403
|
+
printUsage();
|
|
404
|
+
process.exit(1);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const rootPath = args[0];
|
|
408
|
+
let workItems = [];
|
|
409
|
+
let scope = null;
|
|
410
|
+
|
|
411
|
+
// Check if batch mode
|
|
412
|
+
if (args[1] === '--batch') {
|
|
413
|
+
if (args.length < 3) {
|
|
414
|
+
console.error('Error: --batch requires a JSON array of work items');
|
|
415
|
+
printUsage();
|
|
416
|
+
process.exit(1);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
try {
|
|
420
|
+
workItems = JSON.parse(args[2]);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
console.error(`Error: Failed to parse work items JSON: ${err.message}`);
|
|
423
|
+
process.exit(1);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Check for --scope option
|
|
427
|
+
for (let i = 3; i < args.length; i++) {
|
|
428
|
+
if (args[i].startsWith('--scope=')) {
|
|
429
|
+
scope = args[i].substring('--scope='.length);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
// Single item mode (backwards compatible)
|
|
434
|
+
if (args.length < 4) {
|
|
435
|
+
printUsage();
|
|
436
|
+
process.exit(1);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const [, workItemId, intentId, mode] = args;
|
|
440
|
+
workItems = [{ id: workItemId, intent: intentId, mode: mode }];
|
|
441
|
+
scope = 'single';
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
const result = initRun(rootPath, workItems, scope);
|
|
446
|
+
console.log(JSON.stringify(result, null, 2));
|
|
447
|
+
process.exit(0);
|
|
448
|
+
} catch (err) {
|
|
449
|
+
console.error(err.message);
|
|
450
|
+
process.exit(1);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
module.exports = { initRun };
|
|
@@ -42,6 +42,8 @@ state:
|
|
|
42
42
|
- work_items: "List of work items in this run"
|
|
43
43
|
- current_item: "Work item currently being executed"
|
|
44
44
|
- started: "ISO 8601 timestamp"
|
|
45
|
+
runs:
|
|
46
|
+
- completed: "List of completed runs with id, work_item, intent, completed timestamp"
|
|
45
47
|
|
|
46
48
|
# Data Conventions
|
|
47
49
|
conventions:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specsmd",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.56",
|
|
4
4
|
"description": "Multi-agent orchestration system for AI-native software development. Delivers AI-DLC, Agile, and custom SDLC flows as markdown-based agent systems.",
|
|
5
5
|
"main": "lib/installer.js",
|
|
6
6
|
"bin": {
|