infernoflow 0.33.0 → 0.34.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 +208 -120
- package/dist/bin/infernoflow.mjs +271 -85
- package/dist/lib/adopters/angular.mjs +128 -1
- package/dist/lib/adopters/css.mjs +111 -1
- package/dist/lib/adopters/react.mjs +104 -1
- package/dist/lib/ai/ideDetection.mjs +31 -1
- package/dist/lib/ai/localProvider.mjs +88 -1
- package/dist/lib/ai/providerRouter.mjs +295 -2
- package/dist/lib/commands/adopt.mjs +869 -20
- package/dist/lib/commands/adoptWizard.mjs +320 -9
- package/dist/lib/commands/agent.mjs +191 -5
- package/dist/lib/commands/ai.mjs +407 -2
- package/dist/lib/commands/ask.mjs +299 -0
- package/dist/lib/commands/audit.mjs +300 -13
- package/dist/lib/commands/changelog.mjs +594 -26
- package/dist/lib/commands/check.mjs +184 -3
- package/dist/lib/commands/ci.mjs +208 -3
- package/dist/lib/commands/claudeMd.mjs +139 -28
- package/dist/lib/commands/cloud.mjs +521 -5
- package/dist/lib/commands/context.mjs +346 -34
- package/dist/lib/commands/coverage.mjs +282 -2
- package/dist/lib/commands/dashboard.mjs +635 -123
- package/dist/lib/commands/demo.mjs +465 -8
- package/dist/lib/commands/diff.mjs +274 -5
- package/dist/lib/commands/docGate.mjs +81 -2
- package/dist/lib/commands/doctor.mjs +321 -3
- package/dist/lib/commands/explain.mjs +438 -8
- package/dist/lib/commands/export.mjs +239 -10
- package/dist/lib/commands/generateSkills.mjs +163 -38
- package/dist/lib/commands/graph.mjs +378 -11
- package/dist/lib/commands/health.mjs +309 -2
- package/dist/lib/commands/impact.mjs +325 -2
- package/dist/lib/commands/implement.mjs +103 -7
- package/dist/lib/commands/init.mjs +545 -23
- package/dist/lib/commands/installCursorHooks.mjs +36 -1
- package/dist/lib/commands/installVsCodeCopilotHooks.mjs +37 -1
- package/dist/lib/commands/link.mjs +342 -2
- package/dist/lib/commands/log.mjs +164 -16
- package/dist/lib/commands/monorepo.mjs +428 -4
- package/dist/lib/commands/notify.mjs +258 -4
- package/dist/lib/commands/onboard.mjs +296 -4
- package/dist/lib/commands/prComment.mjs +361 -2
- package/dist/lib/commands/prImpact.mjs +157 -2
- package/dist/lib/commands/publish.mjs +316 -15
- package/dist/lib/commands/recap.mjs +359 -0
- package/dist/lib/commands/report.mjs +272 -28
- package/dist/lib/commands/review.mjs +223 -9
- package/dist/lib/commands/run.mjs +336 -8
- package/dist/lib/commands/scaffold.mjs +419 -54
- package/dist/lib/commands/scan.mjs +1118 -5
- package/dist/lib/commands/scout.mjs +291 -2
- package/dist/lib/commands/setup.mjs +310 -5
- package/dist/lib/commands/share.mjs +196 -13
- package/dist/lib/commands/snapshot.mjs +383 -3
- package/dist/lib/commands/stability.mjs +293 -2
- package/dist/lib/commands/stats.mjs +402 -0
- package/dist/lib/commands/status.mjs +172 -4
- package/dist/lib/commands/suggest.mjs +563 -21
- package/dist/lib/commands/switch.mjs +310 -0
- package/dist/lib/commands/syncAuto.mjs +96 -1
- package/dist/lib/commands/synthesize.mjs +228 -10
- package/dist/lib/commands/teamSync.mjs +388 -2
- package/dist/lib/commands/test.mjs +363 -6
- package/dist/lib/commands/theme.mjs +195 -18
- package/dist/lib/commands/upgrade.mjs +153 -0
- package/dist/lib/commands/version.mjs +282 -2
- package/dist/lib/commands/vibe.mjs +357 -7
- package/dist/lib/commands/watch.mjs +203 -4
- package/dist/lib/commands/why.mjs +358 -4
- package/dist/lib/cursorHooksInstall.mjs +60 -1
- package/dist/lib/draftToolingInstall.mjs +68 -7
- package/dist/lib/git/detect-drift.mjs +208 -4
- package/dist/lib/learning/adapt.mjs +101 -6
- package/dist/lib/learning/observe.mjs +119 -1
- package/dist/lib/learning/patternDetector.mjs +298 -1
- package/dist/lib/learning/profile.mjs +279 -2
- package/dist/lib/learning/skillSynthesizer.mjs +145 -24
- package/dist/lib/templates/index.mjs +131 -1
- package/dist/lib/theme/scanner.mjs +343 -4
- package/dist/lib/ui/errors.mjs +142 -1
- package/dist/lib/ui/output.mjs +72 -6
- package/dist/lib/ui/prompts.mjs +147 -6
- package/dist/lib/vsCodeCopilotHooksInstall.mjs +42 -1
- package/package.json +1 -1
|
@@ -1,6 +1,363 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* infernoflow test
|
|
3
|
+
*
|
|
4
|
+
* Run registered scenarios for a capability and report pass/fail.
|
|
5
|
+
* When no test runner is configured, generates a minimal ad-hoc harness
|
|
6
|
+
* from the scenario + source file and runs it with Node.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* infernoflow test Run all caps with scenarios
|
|
10
|
+
* infernoflow test user-auth Run scenarios for one cap
|
|
11
|
+
* infernoflow test user-auth payment-process Run multiple caps
|
|
12
|
+
* infernoflow test --all Run every cap (including no-scenario)
|
|
13
|
+
* infernoflow test --generate user-auth Print generated test file, don't run
|
|
14
|
+
* infernoflow test --json Machine-readable output
|
|
15
|
+
* infernoflow test --bail Stop on first failure
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as fs from "node:fs";
|
|
19
|
+
import * as path from "node:path";
|
|
20
|
+
import * as os from "node:os";
|
|
21
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
22
|
+
import { bold, cyan, gray, green, yellow, red } from "../ui/output.mjs";
|
|
23
|
+
|
|
24
|
+
// ── helpers ───────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
function loadJson(p) {
|
|
27
|
+
try { return JSON.parse(fs.readFileSync(p, "utf8")); }
|
|
28
|
+
catch { return null; }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stability(cap) { return cap?.stability || "experimental"; }
|
|
32
|
+
|
|
33
|
+
const PASS_ICON = green("✓");
|
|
34
|
+
const FAIL_ICON = red("✗");
|
|
35
|
+
const SKIP_ICON = gray("○");
|
|
36
|
+
|
|
37
|
+
// ── scenario loader ───────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
function loadScenarios(capId, infernoDir) {
|
|
40
|
+
const dir = path.join(infernoDir, "scenarios");
|
|
41
|
+
if (!fs.existsSync(dir)) return [];
|
|
42
|
+
const found = [];
|
|
43
|
+
for (const f of fs.readdirSync(dir)) {
|
|
44
|
+
if (!f.endsWith(".json")) continue;
|
|
45
|
+
try {
|
|
46
|
+
const s = JSON.parse(fs.readFileSync(path.join(dir, f), "utf8"));
|
|
47
|
+
const covered = s.capabilitiesCovered || s.capabilities || [];
|
|
48
|
+
if (covered.some(c => c.toLowerCase() === capId.toLowerCase())) {
|
|
49
|
+
found.push({ ...s, _file: f });
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
return found;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── test runner detection ─────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
function detectTestRunner(cwd) {
|
|
59
|
+
const pkg = loadJson(path.join(cwd, "package.json"));
|
|
60
|
+
if (!pkg) return null;
|
|
61
|
+
|
|
62
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
63
|
+
if (deps?.vitest) return "vitest";
|
|
64
|
+
if (deps?.jest) return "jest";
|
|
65
|
+
if (deps?.mocha) return "mocha";
|
|
66
|
+
if (pkg.scripts?.test && !pkg.scripts.test.includes("no test")) {
|
|
67
|
+
return { custom: pkg.scripts.test };
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ── ad-hoc test generator ─────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
function generateAdHocTest(capId, cap, scenario, scanEntry) {
|
|
75
|
+
const name = cap.name || cap.title || capId;
|
|
76
|
+
const desc = cap.description || "(no description)";
|
|
77
|
+
const files = scanEntry?.codeAnalysis?.sourceFiles || [];
|
|
78
|
+
const fns = scanEntry?.codeAnalysis?.functions || [];
|
|
79
|
+
const steps = scenario?.steps || scenario?.actions || [];
|
|
80
|
+
const expects = scenario?.expects || scenario?.assertions || [];
|
|
81
|
+
|
|
82
|
+
const lines = [
|
|
83
|
+
`// Auto-generated smoke test for: ${capId}`,
|
|
84
|
+
`// Generated by infernoflow test — edit as needed`,
|
|
85
|
+
``,
|
|
86
|
+
`import { strict as assert } from "node:assert";`,
|
|
87
|
+
``,
|
|
88
|
+
`// Capability: ${name}`,
|
|
89
|
+
`// ${desc}`,
|
|
90
|
+
``,
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
// Import source if we know the file
|
|
94
|
+
if (files.length) {
|
|
95
|
+
lines.push(`// Source: ${files[0]}`);
|
|
96
|
+
lines.push(`// import { ${fns[0] || capId} } from "./${path.basename(files[0])}";`);
|
|
97
|
+
lines.push(``);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
lines.push(`async function run() {`);
|
|
101
|
+
lines.push(` const results = [];`);
|
|
102
|
+
lines.push(``);
|
|
103
|
+
|
|
104
|
+
// Generate test cases from scenario steps
|
|
105
|
+
if (steps.length) {
|
|
106
|
+
steps.forEach((step, i) => {
|
|
107
|
+
const desc = typeof step === "string" ? step : (step.action || step.description || `step ${i + 1}`);
|
|
108
|
+
lines.push(` // Step ${i + 1}: ${desc}`);
|
|
109
|
+
lines.push(` results.push({ step: ${JSON.stringify(desc)}, status: "manual" });`);
|
|
110
|
+
lines.push(``);
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
lines.push(` // No explicit steps — running basic smoke test`);
|
|
114
|
+
lines.push(` results.push({ step: "capability exists", status: "pass" });`);
|
|
115
|
+
lines.push(``);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Add assertion checks
|
|
119
|
+
if (expects.length) {
|
|
120
|
+
expects.forEach((exp, i) => {
|
|
121
|
+
const desc = typeof exp === "string" ? exp : (exp.condition || exp.description || `assertion ${i + 1}`);
|
|
122
|
+
lines.push(` // Assert: ${desc}`);
|
|
123
|
+
lines.push(` // assert(condition, ${JSON.stringify(desc)});`);
|
|
124
|
+
});
|
|
125
|
+
lines.push(``);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
lines.push(` return results;`);
|
|
129
|
+
lines.push(`}`);
|
|
130
|
+
lines.push(``);
|
|
131
|
+
lines.push(`run().then(results => {`);
|
|
132
|
+
lines.push(` const failed = results.filter(r => r.status === "fail");`);
|
|
133
|
+
lines.push(` results.forEach(r => {`);
|
|
134
|
+
lines.push(` const icon = r.status === "pass" ? "✓" : r.status === "fail" ? "✗" : "○";`);
|
|
135
|
+
lines.push(` console.log(\` \${icon} \${r.step}\`);`);
|
|
136
|
+
lines.push(` });`);
|
|
137
|
+
lines.push(` if (failed.length) { console.error(\`\\n \${failed.length} failed\`); process.exit(1); }`);
|
|
138
|
+
lines.push(` else console.log(\`\\n All steps passed\`);`);
|
|
139
|
+
lines.push(`}).catch(err => { console.error(err); process.exit(1); });`);
|
|
140
|
+
|
|
141
|
+
return lines.join("\n");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ── run a single scenario ─────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
function runScenario(capId, cap, scenario, scanEntry, cwd) {
|
|
147
|
+
const scenarioId = scenario?.scenarioId || scenario?.id || scenario?._file?.replace(".json", "") || "unnamed";
|
|
148
|
+
const runner = detectTestRunner(cwd);
|
|
149
|
+
|
|
150
|
+
// If there are testFiles registered in the scenario, run those
|
|
151
|
+
const testFiles = scenario?.testFiles || scenario?.testFile ? [scenario.testFile].flat().filter(Boolean) : [];
|
|
152
|
+
if (testFiles.length) {
|
|
153
|
+
for (const tf of testFiles) {
|
|
154
|
+
const absPath = path.resolve(cwd, tf);
|
|
155
|
+
if (!fs.existsSync(absPath)) {
|
|
156
|
+
return { scenarioId, status: "skip", reason: `test file not found: ${tf}` };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Run with detected test runner
|
|
161
|
+
if (runner && typeof runner === "string") {
|
|
162
|
+
const cmd = runner === "vitest"
|
|
163
|
+
? `npx vitest run ${testFiles.join(" ")} --reporter verbose`
|
|
164
|
+
: runner === "jest"
|
|
165
|
+
? `npx jest ${testFiles.join(" ")} --no-coverage`
|
|
166
|
+
: runner === "mocha"
|
|
167
|
+
? `npx mocha ${testFiles.join(" ")}`
|
|
168
|
+
: null;
|
|
169
|
+
|
|
170
|
+
if (cmd) {
|
|
171
|
+
const result = spawnSync(cmd, { shell: true, cwd, encoding: "utf8", timeout: 60_000 });
|
|
172
|
+
const passed = result.status === 0;
|
|
173
|
+
return {
|
|
174
|
+
scenarioId,
|
|
175
|
+
status: passed ? "pass" : "fail",
|
|
176
|
+
output: (result.stdout || "") + (result.stderr || ""),
|
|
177
|
+
runner,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Custom script runner
|
|
183
|
+
if (runner?.custom) {
|
|
184
|
+
const result = spawnSync(runner.custom, { shell: true, cwd, encoding: "utf8", timeout: 60_000 });
|
|
185
|
+
return {
|
|
186
|
+
scenarioId,
|
|
187
|
+
status: result.status === 0 ? "pass" : "fail",
|
|
188
|
+
output: (result.stdout || "") + (result.stderr || ""),
|
|
189
|
+
runner: "npm test",
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// No test files — generate and run ad-hoc test
|
|
195
|
+
const testSrc = generateAdHocTest(capId, cap, scenario, scanEntry);
|
|
196
|
+
const tmpFile = path.join(os.tmpdir(), `infernoflow-test-${capId}-${Date.now()}.mjs`);
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
fs.writeFileSync(tmpFile, testSrc);
|
|
200
|
+
const result = spawnSync(process.execPath, [tmpFile], {
|
|
201
|
+
cwd,
|
|
202
|
+
encoding: "utf8",
|
|
203
|
+
timeout: 30_000,
|
|
204
|
+
});
|
|
205
|
+
const passed = result.status === 0;
|
|
206
|
+
return {
|
|
207
|
+
scenarioId,
|
|
208
|
+
status: passed ? "pass" : "fail",
|
|
209
|
+
output: (result.stdout || "") + (result.stderr || ""),
|
|
210
|
+
runner: "ad-hoc",
|
|
211
|
+
generated: true,
|
|
212
|
+
};
|
|
213
|
+
} finally {
|
|
214
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ── print result ──────────────────────────────────────────────────────────────
|
|
219
|
+
|
|
220
|
+
function printCapResult(capId, cap, results, verbose) {
|
|
221
|
+
const level = stability(cap);
|
|
222
|
+
const badge = level === "frozen" ? red("frozen") : level === "stable" ? yellow("stable") : gray("experimental");
|
|
223
|
+
const total = results.length;
|
|
224
|
+
const passed = results.filter(r => r.status === "pass").length;
|
|
225
|
+
const failed = results.filter(r => r.status === "fail").length;
|
|
226
|
+
const skipped = results.filter(r => r.status === "skip").length;
|
|
227
|
+
|
|
228
|
+
const statusIcon = failed > 0 ? red("✗") : passed > 0 ? green("✓") : gray("○");
|
|
229
|
+
console.log(` ${statusIcon} ${bold(capId)} ${gray(`[${badge}]`)}`);
|
|
230
|
+
|
|
231
|
+
for (const r of results) {
|
|
232
|
+
const icon = r.status === "pass" ? PASS_ICON : r.status === "fail" ? FAIL_ICON : SKIP_ICON;
|
|
233
|
+
const note = r.generated ? gray(" (generated)") : r.runner ? gray(` (${r.runner})`) : "";
|
|
234
|
+
console.log(` ${icon} ${gray(r.scenarioId)}${note}`);
|
|
235
|
+
if (r.reason) console.log(` ${gray(r.reason)}`);
|
|
236
|
+
if (verbose && r.output) {
|
|
237
|
+
const trimmed = r.output.trim().split("\n").slice(0, 10).join("\n");
|
|
238
|
+
console.log(trimmed.split("\n").map(l => ` ${gray(l)}`).join("\n"));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return { total, passed, failed, skipped };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ── entry point ───────────────────────────────────────────────────────────────
|
|
246
|
+
|
|
247
|
+
export async function testCommand(rawArgs) {
|
|
248
|
+
const args = (rawArgs || []).slice(1);
|
|
249
|
+
const jsonMode = args.includes("--json");
|
|
250
|
+
const bail = args.includes("--bail");
|
|
251
|
+
const generateMode = args.includes("--generate");
|
|
252
|
+
const runAll = args.includes("--all");
|
|
253
|
+
const verbose = args.includes("--verbose") || args.includes("-v");
|
|
254
|
+
|
|
255
|
+
const capArgs = args.filter(a => !a.startsWith("--") && a !== "-v");
|
|
256
|
+
|
|
257
|
+
const cwd = process.cwd();
|
|
258
|
+
const infernoDir = path.join(cwd, "inferno");
|
|
259
|
+
|
|
260
|
+
if (!fs.existsSync(infernoDir)) {
|
|
261
|
+
if (!jsonMode) console.error(red("✗ inferno/ not found. Run: infernoflow init"));
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Load capabilities
|
|
266
|
+
let allCaps = [];
|
|
267
|
+
const rawCaps = loadJson(path.join(infernoDir, "capabilities.json"));
|
|
268
|
+
if (rawCaps) allCaps = Array.isArray(rawCaps) ? rawCaps : (rawCaps.capabilities || []);
|
|
269
|
+
|
|
270
|
+
const scanData = loadJson(path.join(infernoDir, "scan.json"));
|
|
271
|
+
|
|
272
|
+
// Determine which caps to test
|
|
273
|
+
let targetCaps;
|
|
274
|
+
if (capArgs.length) {
|
|
275
|
+
targetCaps = capArgs.map(id => {
|
|
276
|
+
const cap = allCaps.find(c => c.id === id);
|
|
277
|
+
if (!cap) {
|
|
278
|
+
if (!jsonMode) console.error(red(`✗ Capability "${id}" not found in capabilities.json`));
|
|
279
|
+
process.exit(1);
|
|
280
|
+
}
|
|
281
|
+
return cap;
|
|
282
|
+
});
|
|
283
|
+
} else if (runAll) {
|
|
284
|
+
targetCaps = allCaps;
|
|
285
|
+
} else {
|
|
286
|
+
// Default: caps that have scenarios registered
|
|
287
|
+
targetCaps = allCaps.filter(cap => loadScenarios(cap.id, infernoDir).length > 0);
|
|
288
|
+
if (!targetCaps.length) {
|
|
289
|
+
if (!jsonMode) {
|
|
290
|
+
console.log();
|
|
291
|
+
console.log(` ${gray("No scenarios registered. Use --all to test all capabilities, or")} `);
|
|
292
|
+
console.log(` ${gray("add scenarios to inferno/scenarios/ first.")}`);
|
|
293
|
+
console.log();
|
|
294
|
+
}
|
|
295
|
+
process.exit(0);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!jsonMode) {
|
|
300
|
+
console.log();
|
|
301
|
+
console.log(` ${bold("🧪 infernoflow test")}`);
|
|
302
|
+
console.log();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// --generate mode: print generated test for first cap
|
|
306
|
+
if (generateMode) {
|
|
307
|
+
const cap = targetCaps[0];
|
|
308
|
+
const scenarios = loadScenarios(cap.id, infernoDir);
|
|
309
|
+
const scenario = scenarios[0] || {};
|
|
310
|
+
const scanEntry = scanData?.capabilities?.find(c => c.id === cap.id);
|
|
311
|
+
const src = generateAdHocTest(cap.id, cap, scenario, scanEntry);
|
|
312
|
+
console.log(src);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Run tests
|
|
317
|
+
const summary = { total: 0, passed: 0, failed: 0, skipped: 0, caps: [] };
|
|
318
|
+
let bailed = false;
|
|
319
|
+
|
|
320
|
+
for (const cap of targetCaps) {
|
|
321
|
+
const scenarios = loadScenarios(cap.id, infernoDir);
|
|
322
|
+
const scanEntry = scanData?.capabilities?.find(c => c.id === cap.id);
|
|
323
|
+
|
|
324
|
+
let capResults = [];
|
|
325
|
+
|
|
326
|
+
if (!scenarios.length) {
|
|
327
|
+
capResults = [{ scenarioId: "(no scenarios)", status: "skip", reason: "register scenarios in inferno/scenarios/" }];
|
|
328
|
+
} else {
|
|
329
|
+
for (const scenario of scenarios) {
|
|
330
|
+
const r = runScenario(cap.id, cap, scenario, scanEntry, cwd);
|
|
331
|
+
capResults.push(r);
|
|
332
|
+
if (bail && r.status === "fail") { bailed = true; break; }
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const counts = printCapResult(cap.id, cap, capResults, verbose);
|
|
337
|
+
summary.total += counts.total;
|
|
338
|
+
summary.passed += counts.passed;
|
|
339
|
+
summary.failed += counts.failed;
|
|
340
|
+
summary.skipped += counts.skipped;
|
|
341
|
+
summary.caps.push({ id: cap.id, stability: stability(cap), results: capResults });
|
|
342
|
+
|
|
343
|
+
if (bailed) break;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!jsonMode) {
|
|
347
|
+
console.log();
|
|
348
|
+
const statusColor = summary.failed > 0 ? red : summary.passed > 0 ? green : gray;
|
|
349
|
+
console.log(` ${statusColor(bold(String(summary.passed)))} passed ${summary.failed > 0 ? red(bold(String(summary.failed))) : gray("0")} failed ${gray(String(summary.skipped))} skipped`);
|
|
350
|
+
if (bailed) console.log(` ${yellow("(bailed on first failure)")}`);
|
|
351
|
+
console.log();
|
|
352
|
+
if (!summary.failed) {
|
|
353
|
+
console.log(gray(" ── infernoflow test complete"));
|
|
354
|
+
}
|
|
355
|
+
console.log();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (jsonMode) {
|
|
359
|
+
console.log(JSON.stringify(summary, null, 2));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
process.exit(summary.failed > 0 ? 1 : 0);
|
|
363
|
+
}
|
|
@@ -1,18 +1,195 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/**
|
|
2
|
+
* infernoflow theme
|
|
3
|
+
*
|
|
4
|
+
* Scans the project for design tokens — fonts, colors, CSS variables —
|
|
5
|
+
* and writes inferno/theme.json so AI agents always know the visual system.
|
|
6
|
+
*
|
|
7
|
+
* This captures what AI can't reliably infer from scattered style files:
|
|
8
|
+
* the actual palette, typography, and spacing tokens in use.
|
|
9
|
+
*
|
|
10
|
+
* When theme.json changes between runs, the delta is auto-logged to sessions.jsonl
|
|
11
|
+
* so agents know the design system evolved (not just the code).
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* infernoflow theme Scan + write inferno/theme.json
|
|
15
|
+
* infernoflow theme --show Print current theme.json
|
|
16
|
+
* infernoflow theme --json Output as JSON
|
|
17
|
+
* infernoflow theme --dry-run Scan but don't write
|
|
18
|
+
* infernoflow theme --watch Re-scan on style file changes
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as fs from "node:fs";
|
|
22
|
+
import * as path from "node:path";
|
|
23
|
+
import { scanTheme } from "../theme/scanner.mjs";
|
|
24
|
+
import { bold, cyan, gray, green, yellow, red } from "../ui/output.mjs";
|
|
25
|
+
|
|
26
|
+
const INFERNO_DIR = "inferno";
|
|
27
|
+
const THEME_FILE = path.join(INFERNO_DIR, "theme.json");
|
|
28
|
+
const SESSIONS_FILE = path.join(INFERNO_DIR, "sessions.jsonl");
|
|
29
|
+
|
|
30
|
+
function readJSON(f) { try { return JSON.parse(fs.readFileSync(f, "utf8")); } catch { return null; } }
|
|
31
|
+
|
|
32
|
+
function appendSession(entry) {
|
|
33
|
+
if (!fs.existsSync(SESSIONS_FILE)) return;
|
|
34
|
+
fs.appendFileSync(SESSIONS_FILE, JSON.stringify(entry) + "\n", "utf8");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function diffTheme(prev, next) {
|
|
38
|
+
const changes = [];
|
|
39
|
+
|
|
40
|
+
// Font changes
|
|
41
|
+
if (prev?.fonts?.primary !== next?.fonts?.primary) {
|
|
42
|
+
changes.push(`primary font: ${prev?.fonts?.primary || "none"} → ${next?.fonts?.primary || "none"}`);
|
|
43
|
+
}
|
|
44
|
+
if (prev?.fonts?.mono !== next?.fonts?.mono) {
|
|
45
|
+
changes.push(`mono font: ${prev?.fonts?.mono || "none"} → ${next?.fonts?.mono || "none"}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Mode change
|
|
49
|
+
if (prev?.colors?.mode !== next?.colors?.mode) {
|
|
50
|
+
changes.push(`color mode: ${prev?.colors?.mode || "unknown"} → ${next?.colors?.mode}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Palette changes
|
|
54
|
+
const prevPalette = prev?.colors?.palette || {};
|
|
55
|
+
const nextPalette = next?.colors?.palette || {};
|
|
56
|
+
for (const key of new Set([...Object.keys(prevPalette), ...Object.keys(nextPalette)])) {
|
|
57
|
+
if (prevPalette[key] !== nextPalette[key]) {
|
|
58
|
+
changes.push(`${key} color: ${prevPalette[key] || "none"} → ${nextPalette[key] || "none"}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// CSS var changes (new or changed vars only)
|
|
63
|
+
const prevVars = prev?.cssVars || {};
|
|
64
|
+
const nextVars = next?.cssVars || {};
|
|
65
|
+
const newVars = Object.keys(nextVars).filter(k => !prevVars[k]);
|
|
66
|
+
const changedVars = Object.keys(nextVars).filter(k => prevVars[k] && prevVars[k] !== nextVars[k]);
|
|
67
|
+
if (newVars.length) changes.push(`new CSS vars: ${newVars.slice(0,5).join(", ")}`);
|
|
68
|
+
if (changedVars.length) changes.push(`changed CSS vars: ${changedVars.slice(0,5).join(", ")}`);
|
|
69
|
+
|
|
70
|
+
return changes;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function printTheme(theme) {
|
|
74
|
+
const { fonts, colors, cssVars, framework, stats } = theme;
|
|
75
|
+
|
|
76
|
+
console.log("\n " + bold("🎨 Design System"));
|
|
77
|
+
console.log(" " + "─".repeat(50));
|
|
78
|
+
|
|
79
|
+
console.log(cyan("\n Fonts"));
|
|
80
|
+
if (fonts.primary) console.log(` Primary : ${fonts.primary}`);
|
|
81
|
+
if (fonts.mono) console.log(` Mono : ${fonts.mono}`);
|
|
82
|
+
if (fonts.all?.length > 2) console.log(gray(` All : ${fonts.all.join(", ")}`));
|
|
83
|
+
if (fonts.sources?.length) console.log(gray(` Sources : ${fonts.sources.join(", ")}`));
|
|
84
|
+
|
|
85
|
+
console.log(cyan("\n Colors") + gray(` (${colors.mode} mode)`));
|
|
86
|
+
for (const [role, hex] of Object.entries(colors.palette)) {
|
|
87
|
+
const swatch = `\x1b[48;2;${parseInt(hex.slice(1,3),16)};${parseInt(hex.slice(3,5),16)};${parseInt(hex.slice(5,7),16)}m \x1b[0m`;
|
|
88
|
+
console.log(` ${role.padEnd(14)} ${swatch} ${hex}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Object.keys(cssVars).length) {
|
|
92
|
+
console.log(cyan("\n CSS Variables") + gray(` (${Object.keys(cssVars).length} found)`));
|
|
93
|
+
const entries = Object.entries(cssVars).slice(0, 12);
|
|
94
|
+
for (const [name, val] of entries) {
|
|
95
|
+
console.log(` ${name.padEnd(24)} ${gray(val)}`);
|
|
96
|
+
}
|
|
97
|
+
if (Object.keys(cssVars).length > 12) {
|
|
98
|
+
console.log(gray(` … and ${Object.keys(cssVars).length - 12} more`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log(cyan("\n Framework") + ` ${framework}`);
|
|
103
|
+
console.log(gray(`\n Scanned: ${stats.styleFiles} style files · ${stats.colorsFound} colors · ${stats.varsFound} CSS vars\n`));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function themeCommand(args) {
|
|
107
|
+
const has = (f) => args.includes(f);
|
|
108
|
+
const dryRun = has("--dry-run");
|
|
109
|
+
const showOnly = has("--show") || has("-s");
|
|
110
|
+
const jsonFlag = has("--json");
|
|
111
|
+
const watchFlag = has("--watch");
|
|
112
|
+
|
|
113
|
+
console.log("\n " + bold("🔥 infernoflow — theme"));
|
|
114
|
+
console.log(" " + "─".repeat(50) + "\n");
|
|
115
|
+
|
|
116
|
+
if (!fs.existsSync(INFERNO_DIR)) {
|
|
117
|
+
console.error(red(" ✘ inferno/ not found — run: infernoflow init\n"));
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ── Show existing theme ────────────────────────────────────────────────────
|
|
122
|
+
if (showOnly) {
|
|
123
|
+
const existing = readJSON(THEME_FILE);
|
|
124
|
+
if (!existing) {
|
|
125
|
+
console.log(yellow(" ⚠ No theme.json yet — run: infernoflow theme\n"));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (jsonFlag) { console.log(JSON.stringify(existing, null, 2)); return; }
|
|
129
|
+
printTheme(existing);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const runScan = () => {
|
|
134
|
+
console.log(gray(" Scanning style files…"));
|
|
135
|
+
const cwd = process.cwd();
|
|
136
|
+
const theme = scanTheme(cwd);
|
|
137
|
+
|
|
138
|
+
if (jsonFlag) { console.log(JSON.stringify(theme, null, 2)); return; }
|
|
139
|
+
|
|
140
|
+
printTheme(theme);
|
|
141
|
+
|
|
142
|
+
if (dryRun) {
|
|
143
|
+
console.log(yellow(" ⚑ Dry run — theme.json not written\n"));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Read previous theme to diff
|
|
148
|
+
const prev = readJSON(THEME_FILE);
|
|
149
|
+
|
|
150
|
+
const output = {
|
|
151
|
+
...theme,
|
|
152
|
+
scannedAt: new Date().toISOString(),
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
fs.writeFileSync(THEME_FILE, JSON.stringify(output, null, 2) + "\n", "utf8");
|
|
156
|
+
console.log(green(" ✔ Written → inferno/theme.json\n"));
|
|
157
|
+
|
|
158
|
+
// Auto-log changes to sessions.jsonl if theme changed
|
|
159
|
+
if (prev) {
|
|
160
|
+
const changes = diffTheme(prev, theme);
|
|
161
|
+
if (changes.length) {
|
|
162
|
+
appendSession({
|
|
163
|
+
ts: new Date().toISOString(),
|
|
164
|
+
agent: "infernoflow",
|
|
165
|
+
type: "theme",
|
|
166
|
+
summary: "Theme changed: " + changes.join("; "),
|
|
167
|
+
});
|
|
168
|
+
console.log(yellow(" ⚡ Theme changes logged to sessions.jsonl"));
|
|
169
|
+
for (const c of changes) console.log(gray(` • ${c}`));
|
|
170
|
+
console.log();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
runScan();
|
|
176
|
+
|
|
177
|
+
// ── Watch mode ─────────────────────────────────────────────────────────────
|
|
178
|
+
if (watchFlag) {
|
|
179
|
+
console.log(cyan(" Watching style files for changes… (Ctrl+C to stop)\n"));
|
|
180
|
+
const { watch } = await import("node:fs");
|
|
181
|
+
let debounce = null;
|
|
182
|
+
watch(process.cwd(), { recursive: true }, (_, filename) => {
|
|
183
|
+
if (!filename) return;
|
|
184
|
+
const ext = path.extname(filename);
|
|
185
|
+
if (![".css",".scss",".sass",".less",".styl"].includes(ext)) return;
|
|
186
|
+
if (debounce) clearTimeout(debounce);
|
|
187
|
+
debounce = setTimeout(() => {
|
|
188
|
+
console.log(gray(`\n Change detected: ${filename}`));
|
|
189
|
+
runScan();
|
|
190
|
+
}, 1000);
|
|
191
|
+
});
|
|
192
|
+
// Keep alive
|
|
193
|
+
await new Promise(() => {});
|
|
194
|
+
}
|
|
195
|
+
}
|