specsmd 0.0.0-dev.9 → 0.0.0-dev.90
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 +190 -224
- package/bin/cli.js +28 -1
- package/flows/aidlc/commands/construction-agent.md +5 -1
- package/flows/aidlc/commands/inception-agent.md +4 -0
- package/flows/aidlc/commands/master-agent.md +4 -0
- package/flows/aidlc/commands/operations-agent.md +4 -0
- package/flows/aidlc/memory-bank.yaml +2 -1
- package/{scripts/artifact-validator.js → flows/aidlc/scripts/artifact-validator.cjs} +3 -3
- package/{scripts/bolt-complete.js → flows/aidlc/scripts/bolt-complete.cjs} +36 -5
- package/{scripts/status-integrity.js → flows/aidlc/scripts/status-integrity.cjs} +5 -5
- package/flows/aidlc/skills/construction/bolt-list.md +1 -1
- package/flows/aidlc/skills/construction/bolt-start.md +3 -3
- package/flows/aidlc/skills/construction/bolt-status.md +1 -1
- package/flows/aidlc/skills/construction/prototype-apply.md +311 -0
- package/flows/aidlc/skills/inception/vibe-to-spec.md +410 -0
- package/flows/aidlc/skills/master/analyze-context.md +1 -1
- package/flows/aidlc/templates/construction/bolt-template.md +2 -2
- package/flows/aidlc/templates/construction/bolt-types/ddd-construction-bolt.md +73 -11
- package/flows/aidlc/templates/standards/decision-index-template.md +32 -0
- package/flows/fire/README.md +19 -0
- package/flows/fire/agents/builder/agent.md +260 -0
- package/flows/fire/agents/builder/skills/code-review/SKILL.md +257 -0
- package/flows/fire/agents/builder/skills/code-review/references/auto-fix-rules.md +218 -0
- package/flows/fire/agents/builder/skills/code-review/references/review-categories.md +154 -0
- package/flows/fire/agents/builder/skills/code-review/templates/review-report.md.hbs +120 -0
- package/flows/fire/agents/builder/skills/run-execute/SKILL.md +714 -0
- package/flows/fire/agents/builder/skills/run-execute/scripts/complete-run.cjs +800 -0
- package/flows/fire/agents/builder/skills/run-execute/scripts/init-run.cjs +500 -0
- package/flows/fire/agents/builder/skills/run-execute/scripts/update-checkpoint.cjs +254 -0
- package/flows/fire/agents/builder/skills/run-execute/scripts/update-phase.cjs +250 -0
- package/flows/fire/agents/builder/skills/run-execute/templates/plan.md.hbs +61 -0
- package/flows/fire/agents/builder/skills/run-execute/templates/test-report.md.hbs +81 -0
- package/flows/fire/agents/builder/skills/run-plan/SKILL.md +378 -0
- package/flows/fire/agents/builder/skills/run-status/SKILL.md +96 -0
- package/flows/fire/agents/builder/skills/walkthrough-generate/SKILL.md +267 -0
- package/flows/fire/agents/builder/skills/walkthrough-generate/templates/walkthrough.md.hbs +176 -0
- package/flows/fire/agents/orchestrator/agent.md +144 -0
- package/flows/fire/agents/orchestrator/skills/project-init/SKILL.md +226 -0
- package/flows/fire/agents/orchestrator/skills/project-init/templates/coding-standards.md.hbs +149 -0
- package/flows/fire/agents/orchestrator/skills/project-init/templates/constitution.md.hbs +43 -0
- package/flows/fire/agents/orchestrator/skills/project-init/templates/system-architecture.md.hbs +101 -0
- package/flows/fire/agents/orchestrator/skills/project-init/templates/tech-stack.md.hbs +136 -0
- package/flows/fire/agents/orchestrator/skills/project-init/templates/testing-standards.md.hbs +94 -0
- package/flows/fire/agents/orchestrator/skills/route/SKILL.md +146 -0
- package/flows/fire/agents/orchestrator/skills/status/SKILL.md +696 -0
- package/flows/fire/agents/planner/agent.md +143 -0
- package/flows/fire/agents/planner/skills/design-doc-generate/SKILL.md +156 -0
- package/flows/fire/agents/planner/skills/design-doc-generate/templates/design.md.hbs +124 -0
- package/flows/fire/agents/planner/skills/intent-capture/SKILL.md +125 -0
- package/flows/fire/agents/planner/skills/intent-capture/templates/brief.md.hbs +40 -0
- package/flows/fire/agents/planner/skills/work-item-decompose/SKILL.md +166 -0
- package/flows/fire/agents/planner/skills/work-item-decompose/templates/work-item.md.hbs +40 -0
- package/flows/fire/commands/fire-builder.md +56 -0
- package/flows/fire/commands/fire-planner.md +48 -0
- package/flows/fire/commands/fire.md +46 -0
- package/flows/fire/memory-bank.yaml +240 -0
- package/flows/fire/quick-start.md +146 -0
- package/flows/ideation/README.md +35 -0
- package/flows/ideation/agents/orchestrator/agent.md +103 -0
- package/flows/ideation/agents/orchestrator/skills/flame/SKILL.md +132 -0
- package/flows/ideation/agents/orchestrator/skills/flame/references/evaluation-criteria.md +81 -0
- package/flows/ideation/agents/orchestrator/skills/flame/references/six-hats-method.md +87 -0
- package/flows/ideation/agents/orchestrator/skills/flame/templates/flame-report.md.hbs +81 -0
- package/flows/ideation/agents/orchestrator/skills/forge/SKILL.md +153 -0
- package/flows/ideation/agents/orchestrator/skills/forge/references/disney-method.md +94 -0
- package/flows/ideation/agents/orchestrator/skills/forge/references/pitch-framework.md +87 -0
- package/flows/ideation/agents/orchestrator/skills/forge/templates/concept-brief.md.hbs +83 -0
- package/flows/ideation/agents/orchestrator/skills/spark/SKILL.md +152 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/anti-bias.md +43 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/analogy.md +60 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/first-principles.md +56 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/index.yaml +76 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/inversion.md +52 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/questorming.md +57 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/random-word.md +35 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/scamper.md +67 -0
- package/flows/ideation/agents/orchestrator/skills/spark/references/techniques/what-if.md +55 -0
- package/flows/ideation/agents/orchestrator/skills/spark/templates/spark-bank.md.hbs +72 -0
- package/flows/ideation/commands/flame.md +43 -0
- package/flows/ideation/commands/forge.md +43 -0
- package/flows/ideation/commands/ideation.md +51 -0
- package/flows/ideation/commands/spark.md +43 -0
- package/flows/ideation/memory-bank.yaml +177 -0
- package/flows/ideation/quick-start.md +84 -0
- package/flows/ideation/shared/protocols/anti-bias.md +79 -0
- package/flows/ideation/shared/protocols/deep-thinking.md +92 -0
- package/flows/ideation/shared/protocols/diverge-converge.md +72 -0
- package/flows/ideation/shared/protocols/interaction-adaptation.md +88 -0
- package/flows/simple/README.md +190 -0
- package/flows/simple/agents/agent.md +404 -0
- package/flows/simple/commands/agent.md +60 -0
- package/flows/simple/context-config.yaml +34 -0
- package/flows/simple/memory-bank.yaml +66 -0
- package/flows/simple/quick-start.md +231 -0
- package/flows/simple/skills/design.md +96 -0
- package/flows/simple/skills/execute.md +190 -0
- package/flows/simple/skills/requirements.md +94 -0
- package/flows/simple/skills/tasks.md +136 -0
- package/flows/simple/templates/design-template.md +138 -0
- package/flows/simple/templates/requirements-template.md +85 -0
- package/flows/simple/templates/tasks-template.md +104 -0
- package/lib/analytics/tracker.js +6 -2
- package/lib/constants.js +25 -8
- package/lib/dashboard/aidlc/parser.js +581 -0
- package/lib/dashboard/fire/model.js +382 -0
- package/lib/dashboard/fire/parser.js +470 -0
- package/lib/dashboard/flow-detect.js +86 -0
- package/lib/dashboard/git/changes.js +362 -0
- package/lib/dashboard/git/worktrees.js +248 -0
- package/lib/dashboard/index.js +709 -0
- package/lib/dashboard/runtime/watch-runtime.js +122 -0
- package/lib/dashboard/simple/parser.js +293 -0
- package/lib/dashboard/tui/app.js +1675 -0
- package/lib/dashboard/tui/components/error-banner.js +35 -0
- package/lib/dashboard/tui/components/header.js +60 -0
- package/lib/dashboard/tui/components/help-footer.js +15 -0
- package/lib/dashboard/tui/components/stats-strip.js +35 -0
- package/lib/dashboard/tui/file-entries.js +383 -0
- package/lib/dashboard/tui/flow-builders.js +991 -0
- package/lib/dashboard/tui/git-builders.js +218 -0
- package/lib/dashboard/tui/helpers.js +236 -0
- package/lib/dashboard/tui/overlays.js +242 -0
- package/lib/dashboard/tui/preview.js +220 -0
- package/lib/dashboard/tui/renderer.js +76 -0
- package/lib/dashboard/tui/row-builders.js +797 -0
- package/lib/dashboard/tui/sections.js +45 -0
- package/lib/dashboard/tui/store.js +44 -0
- package/lib/dashboard/tui/views/overview-view.js +61 -0
- package/lib/dashboard/tui/views/runs-view.js +93 -0
- package/lib/dashboard/tui/worktree-builders.js +229 -0
- package/lib/dashboard/web/extension-adapter.js +726 -0
- package/lib/dashboard/web/public/app.js +9 -0
- package/lib/dashboard/web/public/index.html +14 -0
- package/lib/dashboard/web/public/styles.css +36 -0
- package/lib/dashboard/web/public/webview-bundle.js +7596 -0
- package/lib/dashboard/web/server.js +376 -0
- package/lib/dashboard/web/snapshot.js +299 -0
- package/lib/installer.js +19 -15
- package/lib/installers/CodexInstaller.js +72 -1
- package/lib/installers/KiroInstaller.js +55 -0
- package/lib/installers/OpenCodeInstaller.js +9 -1
- package/lib/installers/ToolInstaller.js +4 -1
- package/lib/installers/WindsurfInstaller.js +0 -54
- package/package.json +15 -55
- package/scripts/check-webview-bundle-sync.cjs +38 -0
- package/scripts/sync-webview-bundle.cjs +19 -0
|
@@ -0,0 +1,500 @@
|
|
|
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.cjs <rootPath> <workItemId> <intentId> <mode>
|
|
15
|
+
* Batch/Wide: node init-run.cjs <rootPath> --batch '<workItemsJson>'
|
|
16
|
+
*
|
|
17
|
+
* Examples:
|
|
18
|
+
* node init-run.cjs /project login-endpoint user-auth confirm
|
|
19
|
+
* node init-run.cjs /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 state and file system)
|
|
156
|
+
// =============================================================================
|
|
157
|
+
|
|
158
|
+
function sanitizeWorktreeToken(value) {
|
|
159
|
+
const normalized = String(value || '')
|
|
160
|
+
.toLowerCase()
|
|
161
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
162
|
+
.replace(/^-+|-+$/g, '');
|
|
163
|
+
return normalized || 'workspace';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function resolveWorktreeToken(rootPath) {
|
|
167
|
+
const baseName = path.basename(path.resolve(String(rootPath || '')));
|
|
168
|
+
return sanitizeWorktreeToken(baseName);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parseRunSequence(runId, worktreeToken) {
|
|
172
|
+
if (typeof runId !== 'string' || runId.trim() === '') {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const legacyMatch = runId.match(/^run-(\d+)$/);
|
|
177
|
+
if (legacyMatch) {
|
|
178
|
+
const parsed = parseInt(legacyMatch[1], 10);
|
|
179
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const worktreeMatch = runId.match(/^run-([a-z0-9][a-z0-9-]*)-(\d+)$/);
|
|
183
|
+
if (worktreeMatch && worktreeMatch[1] === worktreeToken) {
|
|
184
|
+
const parsed = parseInt(worktreeMatch[2], 10);
|
|
185
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function generateRunId(rootPath, runsPath, state) {
|
|
192
|
+
// Ensure runs directory exists
|
|
193
|
+
if (!fs.existsSync(runsPath)) {
|
|
194
|
+
fs.mkdirSync(runsPath, { recursive: true });
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const worktreeToken = resolveWorktreeToken(rootPath);
|
|
198
|
+
let maxFromState = 0;
|
|
199
|
+
|
|
200
|
+
// Source 1: Get max from state.yaml run history (active + completed)
|
|
201
|
+
const stateRuns = state?.runs || {};
|
|
202
|
+
const stateRunRecords = [
|
|
203
|
+
...(Array.isArray(stateRuns.active) ? stateRuns.active : []),
|
|
204
|
+
...(Array.isArray(stateRuns.completed) ? stateRuns.completed : [])
|
|
205
|
+
];
|
|
206
|
+
for (const run of stateRunRecords) {
|
|
207
|
+
const num = parseRunSequence(run?.id, worktreeToken);
|
|
208
|
+
if (num != null && num > maxFromState) {
|
|
209
|
+
maxFromState = num;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Source 2: Get max from file system (defensive)
|
|
214
|
+
let maxFromFileSystem = 0;
|
|
215
|
+
try {
|
|
216
|
+
const entries = fs.readdirSync(runsPath);
|
|
217
|
+
for (const entry of entries) {
|
|
218
|
+
const num = parseRunSequence(entry, worktreeToken);
|
|
219
|
+
if (num != null && num > maxFromFileSystem) {
|
|
220
|
+
maxFromFileSystem = num;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} catch (err) {
|
|
224
|
+
throw fireError(
|
|
225
|
+
`Failed to read runs directory: ${err.message}`,
|
|
226
|
+
'INIT_060',
|
|
227
|
+
'Check directory permissions.'
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Use MAX of both to ensure no duplicates
|
|
232
|
+
const maxNum = Math.max(maxFromState, maxFromFileSystem);
|
|
233
|
+
const nextNum = maxNum + 1;
|
|
234
|
+
|
|
235
|
+
return `run-${worktreeToken}-${String(nextNum).padStart(3, '0')}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// =============================================================================
|
|
239
|
+
// Scope Detection
|
|
240
|
+
// =============================================================================
|
|
241
|
+
|
|
242
|
+
function detectScope(workItems) {
|
|
243
|
+
if (workItems.length === 1) {
|
|
244
|
+
return 'single';
|
|
245
|
+
}
|
|
246
|
+
// For multiple items, default to batch
|
|
247
|
+
// (wide would be explicitly set by the caller if all compatible items are included)
|
|
248
|
+
return 'batch';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// =============================================================================
|
|
252
|
+
// Run Folder Creation
|
|
253
|
+
// =============================================================================
|
|
254
|
+
|
|
255
|
+
function createRunFolder(runPath) {
|
|
256
|
+
try {
|
|
257
|
+
fs.mkdirSync(runPath, { recursive: true });
|
|
258
|
+
} catch (err) {
|
|
259
|
+
throw fireError(
|
|
260
|
+
`Failed to create run folder: ${err.message}`,
|
|
261
|
+
'INIT_070',
|
|
262
|
+
'Check directory permissions and disk space.'
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function createRunLog(runPath, runId, workItems, scope, startTime) {
|
|
268
|
+
// Format work items for run.md
|
|
269
|
+
const workItemsList = workItems.map((item, index) => {
|
|
270
|
+
const status = index === 0 ? 'in_progress' : 'pending';
|
|
271
|
+
const currentPhase = index === 0 ? 'plan' : 'null';
|
|
272
|
+
const currentCheckpoint = index === 0 && (item.mode === 'confirm' || item.mode === 'validate')
|
|
273
|
+
? 'plan'
|
|
274
|
+
: 'null';
|
|
275
|
+
return ` - id: ${item.id}\n intent: ${item.intent}\n mode: ${item.mode}\n status: ${status}\n current_phase: ${currentPhase}\n checkpoint_state: none\n current_checkpoint: ${currentCheckpoint}`;
|
|
276
|
+
}).join('\n');
|
|
277
|
+
|
|
278
|
+
const currentItem = workItems[0];
|
|
279
|
+
|
|
280
|
+
const runLog = `---
|
|
281
|
+
id: ${runId}
|
|
282
|
+
scope: ${scope}
|
|
283
|
+
work_items:
|
|
284
|
+
${workItemsList}
|
|
285
|
+
current_item: ${currentItem.id}
|
|
286
|
+
status: in_progress
|
|
287
|
+
started: ${startTime}
|
|
288
|
+
completed: null
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
# Run: ${runId}
|
|
292
|
+
|
|
293
|
+
## Scope
|
|
294
|
+
${scope} (${workItems.length} work item${workItems.length > 1 ? 's' : ''})
|
|
295
|
+
|
|
296
|
+
## Work Items
|
|
297
|
+
${workItems.map((item, i) => `${i + 1}. **${item.id}** (${item.mode}) — ${i === 0 ? 'in_progress' : 'pending'}`).join('\n')}
|
|
298
|
+
|
|
299
|
+
## Current Item
|
|
300
|
+
${currentItem.id} (${currentItem.mode})
|
|
301
|
+
|
|
302
|
+
## Files Created
|
|
303
|
+
(none yet)
|
|
304
|
+
|
|
305
|
+
## Files Modified
|
|
306
|
+
(none yet)
|
|
307
|
+
|
|
308
|
+
## Decisions
|
|
309
|
+
(none yet)
|
|
310
|
+
`;
|
|
311
|
+
|
|
312
|
+
const runLogPath = path.join(runPath, 'run.md');
|
|
313
|
+
try {
|
|
314
|
+
fs.writeFileSync(runLogPath, runLog);
|
|
315
|
+
} catch (err) {
|
|
316
|
+
throw fireError(
|
|
317
|
+
`Failed to create run log: ${err.message}`,
|
|
318
|
+
'INIT_071',
|
|
319
|
+
'Check file permissions.'
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// =============================================================================
|
|
325
|
+
// Main Function
|
|
326
|
+
// =============================================================================
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Initialize a run with one or more work items.
|
|
330
|
+
*
|
|
331
|
+
* @param {string} rootPath - Project root directory
|
|
332
|
+
* @param {Array<{id: string, intent: string, mode: string}>} workItems - Work items to include in run
|
|
333
|
+
* @param {string} [scope] - Optional scope override ('single', 'batch', 'wide')
|
|
334
|
+
* @returns {object} Result with runId, runPath, workItems, scope, started
|
|
335
|
+
*/
|
|
336
|
+
function initRun(rootPath, workItems, scope) {
|
|
337
|
+
// Validate root path
|
|
338
|
+
validateRootPath(rootPath);
|
|
339
|
+
|
|
340
|
+
// Validate work items
|
|
341
|
+
validateWorkItems(workItems);
|
|
342
|
+
|
|
343
|
+
// Detect or validate scope
|
|
344
|
+
const detectedScope = scope || detectScope(workItems);
|
|
345
|
+
if (scope && !VALID_SCOPES.includes(scope)) {
|
|
346
|
+
throw fireError(
|
|
347
|
+
`Invalid scope: "${scope}".`,
|
|
348
|
+
'INIT_035',
|
|
349
|
+
`Valid scopes are: ${VALID_SCOPES.join(', ')}`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Validate FIRE project structure
|
|
354
|
+
const { statePath, runsPath } = validateFireProject(rootPath);
|
|
355
|
+
|
|
356
|
+
// Read state
|
|
357
|
+
const state = readState(statePath);
|
|
358
|
+
|
|
359
|
+
// Initialize runs structure if needed
|
|
360
|
+
if (!state.runs) {
|
|
361
|
+
state.runs = { active: [], completed: [] };
|
|
362
|
+
}
|
|
363
|
+
if (!Array.isArray(state.runs.active)) {
|
|
364
|
+
state.runs.active = [];
|
|
365
|
+
}
|
|
366
|
+
if (!Array.isArray(state.runs.completed)) {
|
|
367
|
+
state.runs.completed = [];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Generate run ID (checks both history AND file system)
|
|
371
|
+
const runId = generateRunId(rootPath, runsPath, state);
|
|
372
|
+
const runPath = path.join(runsPath, runId);
|
|
373
|
+
|
|
374
|
+
// Create run folder
|
|
375
|
+
createRunFolder(runPath);
|
|
376
|
+
|
|
377
|
+
// Create run log
|
|
378
|
+
const startTime = new Date().toISOString();
|
|
379
|
+
createRunLog(runPath, runId, workItems, detectedScope, startTime);
|
|
380
|
+
|
|
381
|
+
// Prepare work items for state with status and phase tracking
|
|
382
|
+
const stateWorkItems = workItems.map((item, index) => ({
|
|
383
|
+
id: item.id,
|
|
384
|
+
intent: item.intent,
|
|
385
|
+
mode: item.mode,
|
|
386
|
+
status: index === 0 ? 'in_progress' : 'pending',
|
|
387
|
+
current_phase: index === 0 ? 'plan' : null,
|
|
388
|
+
checkpoint_state: 'none',
|
|
389
|
+
current_checkpoint: (index === 0 && (item.mode === 'confirm' || item.mode === 'validate'))
|
|
390
|
+
? 'plan'
|
|
391
|
+
: null,
|
|
392
|
+
}));
|
|
393
|
+
|
|
394
|
+
// Add to active runs list (supports multiple parallel runs)
|
|
395
|
+
state.runs.active.push({
|
|
396
|
+
id: runId,
|
|
397
|
+
scope: detectedScope,
|
|
398
|
+
work_items: stateWorkItems,
|
|
399
|
+
current_item: workItems[0].id,
|
|
400
|
+
started: startTime,
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Save state
|
|
404
|
+
writeState(statePath, state);
|
|
405
|
+
|
|
406
|
+
// Return result
|
|
407
|
+
return {
|
|
408
|
+
success: true,
|
|
409
|
+
runId: runId,
|
|
410
|
+
runPath: runPath,
|
|
411
|
+
scope: detectedScope,
|
|
412
|
+
workItems: stateWorkItems,
|
|
413
|
+
currentItem: workItems[0].id,
|
|
414
|
+
started: startTime,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// =============================================================================
|
|
419
|
+
// CLI Interface
|
|
420
|
+
// =============================================================================
|
|
421
|
+
|
|
422
|
+
function printUsage() {
|
|
423
|
+
console.error('Usage:');
|
|
424
|
+
console.error(' Single item: node init-run.cjs <rootPath> <workItemId> <intentId> <mode>');
|
|
425
|
+
console.error(' Batch/Wide: node init-run.cjs <rootPath> --batch \'<workItemsJson>\' [--scope=<scope>]');
|
|
426
|
+
console.error('');
|
|
427
|
+
console.error('Arguments:');
|
|
428
|
+
console.error(' rootPath - Project root directory');
|
|
429
|
+
console.error(' workItemId - Work item ID (single mode)');
|
|
430
|
+
console.error(' intentId - Intent ID (single mode)');
|
|
431
|
+
console.error(' mode - Execution mode: autopilot, confirm, validate');
|
|
432
|
+
console.error('');
|
|
433
|
+
console.error('Options:');
|
|
434
|
+
console.error(' --batch - JSON array of work items');
|
|
435
|
+
console.error(' --scope - Override scope: single, batch, wide');
|
|
436
|
+
console.error('');
|
|
437
|
+
console.error('Work item JSON format:');
|
|
438
|
+
console.error(' [{"id": "wi-1", "intent": "int-1", "mode": "autopilot"}, ...]');
|
|
439
|
+
console.error('');
|
|
440
|
+
console.error('Examples:');
|
|
441
|
+
console.error(' node init-run.cjs /project login-endpoint user-auth confirm');
|
|
442
|
+
console.error(' node init-run.cjs /project --batch \'[{"id":"wi-1","intent":"int-1","mode":"autopilot"}]\'');
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (require.main === module) {
|
|
446
|
+
const args = process.argv.slice(2);
|
|
447
|
+
|
|
448
|
+
if (args.length < 2) {
|
|
449
|
+
printUsage();
|
|
450
|
+
process.exit(1);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const rootPath = args[0];
|
|
454
|
+
let workItems = [];
|
|
455
|
+
let scope = null;
|
|
456
|
+
|
|
457
|
+
// Check if batch mode
|
|
458
|
+
if (args[1] === '--batch') {
|
|
459
|
+
if (args.length < 3) {
|
|
460
|
+
console.error('Error: --batch requires a JSON array of work items');
|
|
461
|
+
printUsage();
|
|
462
|
+
process.exit(1);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
workItems = JSON.parse(args[2]);
|
|
467
|
+
} catch (err) {
|
|
468
|
+
console.error(`Error: Failed to parse work items JSON: ${err.message}`);
|
|
469
|
+
process.exit(1);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Check for --scope option
|
|
473
|
+
for (let i = 3; i < args.length; i++) {
|
|
474
|
+
if (args[i].startsWith('--scope=')) {
|
|
475
|
+
scope = args[i].substring('--scope='.length);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
} else {
|
|
479
|
+
// Single item mode (backwards compatible)
|
|
480
|
+
if (args.length < 4) {
|
|
481
|
+
printUsage();
|
|
482
|
+
process.exit(1);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const [, workItemId, intentId, mode] = args;
|
|
486
|
+
workItems = [{ id: workItemId, intent: intentId, mode: mode }];
|
|
487
|
+
scope = 'single';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
try {
|
|
491
|
+
const result = initRun(rootPath, workItems, scope);
|
|
492
|
+
console.log(JSON.stringify(result, null, 2));
|
|
493
|
+
process.exit(0);
|
|
494
|
+
} catch (err) {
|
|
495
|
+
console.error(err.message);
|
|
496
|
+
process.exit(1);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
module.exports = { initRun };
|