@blazediff/agent 0.6.0 → 0.7.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/dist/cli.js +182 -166
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -16,10 +16,10 @@ var sharp = require('sharp');
|
|
|
16
16
|
var pc = require('picocolors');
|
|
17
17
|
var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
|
|
18
18
|
var coreNative = require('@blazediff/core-native');
|
|
19
|
-
var promises$1 = require('readline/promises');
|
|
20
19
|
var net = require('net');
|
|
21
20
|
var util = require('util');
|
|
22
21
|
var treeKill = require('tree-kill');
|
|
22
|
+
var promises$1 = require('readline/promises');
|
|
23
23
|
var http = require('http');
|
|
24
24
|
|
|
25
25
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -51,7 +51,7 @@ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
|
|
|
51
51
|
|
|
52
52
|
// package.json
|
|
53
53
|
var package_default = {
|
|
54
|
-
version: "0.
|
|
54
|
+
version: "0.7.0"};
|
|
55
55
|
var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
|
|
56
56
|
var STABILITY_CSS = `
|
|
57
57
|
*,*::before,*::after{
|
|
@@ -3201,6 +3201,170 @@ async function resumeGraph(opts) {
|
|
|
3201
3201
|
junitPath: opts.junitPath
|
|
3202
3202
|
});
|
|
3203
3203
|
}
|
|
3204
|
+
var execFileP = util.promisify(child_process.execFile);
|
|
3205
|
+
async function isPortOpen(port, host = "127.0.0.1") {
|
|
3206
|
+
return new Promise((resolve) => {
|
|
3207
|
+
const socket = net.createConnection({ port, host });
|
|
3208
|
+
socket.setTimeout(500);
|
|
3209
|
+
socket.once("connect", () => {
|
|
3210
|
+
socket.destroy();
|
|
3211
|
+
resolve(true);
|
|
3212
|
+
});
|
|
3213
|
+
socket.once("error", () => resolve(false));
|
|
3214
|
+
socket.once("timeout", () => {
|
|
3215
|
+
socket.destroy();
|
|
3216
|
+
resolve(false);
|
|
3217
|
+
});
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
async function waitForPort(port, timeoutMs = 6e4) {
|
|
3221
|
+
const deadline = Date.now() + timeoutMs;
|
|
3222
|
+
while (Date.now() < deadline) {
|
|
3223
|
+
if (await isPortOpen(port)) return;
|
|
3224
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
3225
|
+
}
|
|
3226
|
+
throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
|
|
3227
|
+
}
|
|
3228
|
+
async function findPidByPort(port) {
|
|
3229
|
+
const platform = process.platform;
|
|
3230
|
+
try {
|
|
3231
|
+
if (platform === "darwin" || platform === "linux") {
|
|
3232
|
+
const { stdout } = await execFileP("lsof", [
|
|
3233
|
+
"-ti",
|
|
3234
|
+
`tcp:${port}`,
|
|
3235
|
+
"-sTCP:LISTEN"
|
|
3236
|
+
]);
|
|
3237
|
+
const pid = Number(stdout.trim().split("\n")[0]);
|
|
3238
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
3239
|
+
}
|
|
3240
|
+
if (platform === "win32") {
|
|
3241
|
+
const { stdout } = await execFileP("netstat", ["-ano"]);
|
|
3242
|
+
const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
|
|
3243
|
+
if (!line) return null;
|
|
3244
|
+
const parts = line.trim().split(/\s+/);
|
|
3245
|
+
const pid = Number(parts[parts.length - 1]);
|
|
3246
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
3247
|
+
}
|
|
3248
|
+
} catch {
|
|
3249
|
+
return null;
|
|
3250
|
+
}
|
|
3251
|
+
return null;
|
|
3252
|
+
}
|
|
3253
|
+
async function startServer(opts) {
|
|
3254
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
3255
|
+
const logPath = opts.logPath ?? paths(cwd).serverLog;
|
|
3256
|
+
const pidPath = opts.pidPath ?? paths(cwd).serverPid;
|
|
3257
|
+
await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
|
|
3258
|
+
if (await isPortOpen(opts.port)) {
|
|
3259
|
+
const discoveredPid = await findPidByPort(opts.port);
|
|
3260
|
+
if (discoveredPid) {
|
|
3261
|
+
await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
return {
|
|
3265
|
+
pid: discoveredPid ?? 0,
|
|
3266
|
+
port: opts.port,
|
|
3267
|
+
url: `http://127.0.0.1:${opts.port}`,
|
|
3268
|
+
attached: true
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
const child = child_process.spawn(opts.command, {
|
|
3272
|
+
cwd,
|
|
3273
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3274
|
+
detached: true,
|
|
3275
|
+
shell: true,
|
|
3276
|
+
env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
|
|
3277
|
+
});
|
|
3278
|
+
const logStream = await import('fs').then(
|
|
3279
|
+
(m) => m.createWriteStream(logPath, { flags: "a" })
|
|
3280
|
+
);
|
|
3281
|
+
child.stdout?.pipe(logStream);
|
|
3282
|
+
child.stderr?.pipe(logStream);
|
|
3283
|
+
if (!child.pid) throw new Error("failed to spawn dev server");
|
|
3284
|
+
await promises.writeFile(pidPath, String(child.pid), "utf8");
|
|
3285
|
+
installSignalHandlers(child);
|
|
3286
|
+
try {
|
|
3287
|
+
await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
|
|
3288
|
+
} catch (err) {
|
|
3289
|
+
await stopProcess(child.pid);
|
|
3290
|
+
throw err;
|
|
3291
|
+
}
|
|
3292
|
+
return {
|
|
3293
|
+
pid: child.pid,
|
|
3294
|
+
port: opts.port,
|
|
3295
|
+
url: `http://127.0.0.1:${opts.port}`
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
async function stopServer(cwd = process.cwd(), portFallback) {
|
|
3299
|
+
const pidPath = paths(cwd).serverPid;
|
|
3300
|
+
let pid = null;
|
|
3301
|
+
let via = "none";
|
|
3302
|
+
if (fs.existsSync(pidPath)) {
|
|
3303
|
+
const raw = (await promises.readFile(pidPath, "utf8")).trim();
|
|
3304
|
+
const parsed = Number(raw);
|
|
3305
|
+
if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
|
|
3306
|
+
pid = parsed;
|
|
3307
|
+
via = "pidfile";
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
if (!pid && portFallback) {
|
|
3311
|
+
pid = await findPidByPort(portFallback);
|
|
3312
|
+
if (pid) via = "port";
|
|
3313
|
+
}
|
|
3314
|
+
if (!pid) {
|
|
3315
|
+
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
3316
|
+
});
|
|
3317
|
+
return { killed: false, pid: null, via: "none" };
|
|
3318
|
+
}
|
|
3319
|
+
await stopProcess(pid);
|
|
3320
|
+
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
3321
|
+
});
|
|
3322
|
+
return { killed: true, pid, via };
|
|
3323
|
+
}
|
|
3324
|
+
function processExists(pid) {
|
|
3325
|
+
try {
|
|
3326
|
+
process.kill(pid, 0);
|
|
3327
|
+
return true;
|
|
3328
|
+
} catch {
|
|
3329
|
+
return false;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
async function stopProcess(pid) {
|
|
3333
|
+
if (!pid) return;
|
|
3334
|
+
await new Promise((resolve) => {
|
|
3335
|
+
treeKill__default.default(pid, "SIGTERM", (err) => {
|
|
3336
|
+
if (err) {
|
|
3337
|
+
treeKill__default.default(pid, "SIGKILL", () => resolve());
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
resolve();
|
|
3341
|
+
});
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
var signalsInstalled = false;
|
|
3345
|
+
function installSignalHandlers(child) {
|
|
3346
|
+
if (signalsInstalled) return;
|
|
3347
|
+
signalsInstalled = true;
|
|
3348
|
+
const cleanup = () => {
|
|
3349
|
+
if (child.pid) {
|
|
3350
|
+
try {
|
|
3351
|
+
process.kill(-child.pid, "SIGTERM");
|
|
3352
|
+
} catch {
|
|
3353
|
+
}
|
|
3354
|
+
treeKill__default.default(child.pid, "SIGKILL", () => {
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
};
|
|
3358
|
+
process.on("SIGINT", () => {
|
|
3359
|
+
cleanup();
|
|
3360
|
+
process.exit(130);
|
|
3361
|
+
});
|
|
3362
|
+
process.on("SIGTERM", () => {
|
|
3363
|
+
cleanup();
|
|
3364
|
+
process.exit(143);
|
|
3365
|
+
});
|
|
3366
|
+
process.on("exit", cleanup);
|
|
3367
|
+
}
|
|
3204
3368
|
|
|
3205
3369
|
// src/cli/check-output.ts
|
|
3206
3370
|
function slimResult(r) {
|
|
@@ -3399,6 +3563,21 @@ report: ${relPath(reportPath)}`;
|
|
|
3399
3563
|
function exitCodeFor(report) {
|
|
3400
3564
|
return report.failed > 0 ? 1 : void 0;
|
|
3401
3565
|
}
|
|
3566
|
+
async function ensureDevServer(config, out) {
|
|
3567
|
+
const port = config?.devServer?.port;
|
|
3568
|
+
if (!config?.devServer || !port || await isPortOpen(port)) return;
|
|
3569
|
+
await startServer({
|
|
3570
|
+
command: config.devServer.command,
|
|
3571
|
+
port,
|
|
3572
|
+
readyTimeoutMs: config.devServer.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS
|
|
3573
|
+
});
|
|
3574
|
+
if (!out.isQuiet()) {
|
|
3575
|
+
process.stderr.write(
|
|
3576
|
+
`${dim(`dev server started on :${port} (serve-status --kill to stop)`)}
|
|
3577
|
+
`
|
|
3578
|
+
);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3402
3581
|
function registerCheck(program, out) {
|
|
3403
3582
|
program.command("check").description("run the visual regression check (CI verb)").option("--base-url <url>", "override base URL").option(
|
|
3404
3583
|
"--threshold <n>",
|
|
@@ -3436,6 +3615,7 @@ function registerCheck(program, out) {
|
|
|
3436
3615
|
}
|
|
3437
3616
|
const config = await loadConfig();
|
|
3438
3617
|
const baseUrl = resolveBaseUrl(config, opts.baseUrl);
|
|
3618
|
+
if (!opts.baseUrl) await ensureDevServer(config, out);
|
|
3439
3619
|
const report = await runGraph({
|
|
3440
3620
|
baseUrl,
|
|
3441
3621
|
threshold: parseThreshold(opts.threshold),
|
|
@@ -4470,170 +4650,6 @@ async function installStack(stack, cwd, opts = {}) {
|
|
|
4470
4650
|
}
|
|
4471
4651
|
return { stack, path: target, status: combineStatuses(statuses) };
|
|
4472
4652
|
}
|
|
4473
|
-
var execFileP = util.promisify(child_process.execFile);
|
|
4474
|
-
async function isPortOpen(port, host = "127.0.0.1") {
|
|
4475
|
-
return new Promise((resolve) => {
|
|
4476
|
-
const socket = net.createConnection({ port, host });
|
|
4477
|
-
socket.setTimeout(500);
|
|
4478
|
-
socket.once("connect", () => {
|
|
4479
|
-
socket.destroy();
|
|
4480
|
-
resolve(true);
|
|
4481
|
-
});
|
|
4482
|
-
socket.once("error", () => resolve(false));
|
|
4483
|
-
socket.once("timeout", () => {
|
|
4484
|
-
socket.destroy();
|
|
4485
|
-
resolve(false);
|
|
4486
|
-
});
|
|
4487
|
-
});
|
|
4488
|
-
}
|
|
4489
|
-
async function waitForPort(port, timeoutMs = 6e4) {
|
|
4490
|
-
const deadline = Date.now() + timeoutMs;
|
|
4491
|
-
while (Date.now() < deadline) {
|
|
4492
|
-
if (await isPortOpen(port)) return;
|
|
4493
|
-
await new Promise((r) => setTimeout(r, 250));
|
|
4494
|
-
}
|
|
4495
|
-
throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
|
|
4496
|
-
}
|
|
4497
|
-
async function findPidByPort(port) {
|
|
4498
|
-
const platform = process.platform;
|
|
4499
|
-
try {
|
|
4500
|
-
if (platform === "darwin" || platform === "linux") {
|
|
4501
|
-
const { stdout } = await execFileP("lsof", [
|
|
4502
|
-
"-ti",
|
|
4503
|
-
`tcp:${port}`,
|
|
4504
|
-
"-sTCP:LISTEN"
|
|
4505
|
-
]);
|
|
4506
|
-
const pid = Number(stdout.trim().split("\n")[0]);
|
|
4507
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
4508
|
-
}
|
|
4509
|
-
if (platform === "win32") {
|
|
4510
|
-
const { stdout } = await execFileP("netstat", ["-ano"]);
|
|
4511
|
-
const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
|
|
4512
|
-
if (!line) return null;
|
|
4513
|
-
const parts = line.trim().split(/\s+/);
|
|
4514
|
-
const pid = Number(parts[parts.length - 1]);
|
|
4515
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
4516
|
-
}
|
|
4517
|
-
} catch {
|
|
4518
|
-
return null;
|
|
4519
|
-
}
|
|
4520
|
-
return null;
|
|
4521
|
-
}
|
|
4522
|
-
async function startServer(opts) {
|
|
4523
|
-
const cwd = opts.cwd ?? process.cwd();
|
|
4524
|
-
const logPath = opts.logPath ?? paths(cwd).serverLog;
|
|
4525
|
-
const pidPath = opts.pidPath ?? paths(cwd).serverPid;
|
|
4526
|
-
await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
|
|
4527
|
-
if (await isPortOpen(opts.port)) {
|
|
4528
|
-
const discoveredPid = await findPidByPort(opts.port);
|
|
4529
|
-
if (discoveredPid) {
|
|
4530
|
-
await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
|
|
4531
|
-
});
|
|
4532
|
-
}
|
|
4533
|
-
return {
|
|
4534
|
-
pid: discoveredPid ?? 0,
|
|
4535
|
-
port: opts.port,
|
|
4536
|
-
url: `http://127.0.0.1:${opts.port}`,
|
|
4537
|
-
attached: true
|
|
4538
|
-
};
|
|
4539
|
-
}
|
|
4540
|
-
const child = child_process.spawn(opts.command, {
|
|
4541
|
-
cwd,
|
|
4542
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
4543
|
-
detached: true,
|
|
4544
|
-
shell: true,
|
|
4545
|
-
env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
|
|
4546
|
-
});
|
|
4547
|
-
const logStream = await import('fs').then(
|
|
4548
|
-
(m) => m.createWriteStream(logPath, { flags: "a" })
|
|
4549
|
-
);
|
|
4550
|
-
child.stdout?.pipe(logStream);
|
|
4551
|
-
child.stderr?.pipe(logStream);
|
|
4552
|
-
if (!child.pid) throw new Error("failed to spawn dev server");
|
|
4553
|
-
await promises.writeFile(pidPath, String(child.pid), "utf8");
|
|
4554
|
-
installSignalHandlers(child);
|
|
4555
|
-
try {
|
|
4556
|
-
await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
|
|
4557
|
-
} catch (err) {
|
|
4558
|
-
await stopProcess(child.pid);
|
|
4559
|
-
throw err;
|
|
4560
|
-
}
|
|
4561
|
-
return {
|
|
4562
|
-
pid: child.pid,
|
|
4563
|
-
port: opts.port,
|
|
4564
|
-
url: `http://127.0.0.1:${opts.port}`
|
|
4565
|
-
};
|
|
4566
|
-
}
|
|
4567
|
-
async function stopServer(cwd = process.cwd(), portFallback) {
|
|
4568
|
-
const pidPath = paths(cwd).serverPid;
|
|
4569
|
-
let pid = null;
|
|
4570
|
-
let via = "none";
|
|
4571
|
-
if (fs.existsSync(pidPath)) {
|
|
4572
|
-
const raw = (await promises.readFile(pidPath, "utf8")).trim();
|
|
4573
|
-
const parsed = Number(raw);
|
|
4574
|
-
if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
|
|
4575
|
-
pid = parsed;
|
|
4576
|
-
via = "pidfile";
|
|
4577
|
-
}
|
|
4578
|
-
}
|
|
4579
|
-
if (!pid && portFallback) {
|
|
4580
|
-
pid = await findPidByPort(portFallback);
|
|
4581
|
-
if (pid) via = "port";
|
|
4582
|
-
}
|
|
4583
|
-
if (!pid) {
|
|
4584
|
-
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
4585
|
-
});
|
|
4586
|
-
return { killed: false, pid: null, via: "none" };
|
|
4587
|
-
}
|
|
4588
|
-
await stopProcess(pid);
|
|
4589
|
-
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
4590
|
-
});
|
|
4591
|
-
return { killed: true, pid, via };
|
|
4592
|
-
}
|
|
4593
|
-
function processExists(pid) {
|
|
4594
|
-
try {
|
|
4595
|
-
process.kill(pid, 0);
|
|
4596
|
-
return true;
|
|
4597
|
-
} catch {
|
|
4598
|
-
return false;
|
|
4599
|
-
}
|
|
4600
|
-
}
|
|
4601
|
-
async function stopProcess(pid) {
|
|
4602
|
-
if (!pid) return;
|
|
4603
|
-
await new Promise((resolve) => {
|
|
4604
|
-
treeKill__default.default(pid, "SIGTERM", (err) => {
|
|
4605
|
-
if (err) {
|
|
4606
|
-
treeKill__default.default(pid, "SIGKILL", () => resolve());
|
|
4607
|
-
return;
|
|
4608
|
-
}
|
|
4609
|
-
resolve();
|
|
4610
|
-
});
|
|
4611
|
-
});
|
|
4612
|
-
}
|
|
4613
|
-
var signalsInstalled = false;
|
|
4614
|
-
function installSignalHandlers(child) {
|
|
4615
|
-
if (signalsInstalled) return;
|
|
4616
|
-
signalsInstalled = true;
|
|
4617
|
-
const cleanup = () => {
|
|
4618
|
-
if (child.pid) {
|
|
4619
|
-
try {
|
|
4620
|
-
process.kill(-child.pid, "SIGTERM");
|
|
4621
|
-
} catch {
|
|
4622
|
-
}
|
|
4623
|
-
treeKill__default.default(child.pid, "SIGKILL", () => {
|
|
4624
|
-
});
|
|
4625
|
-
}
|
|
4626
|
-
};
|
|
4627
|
-
process.on("SIGINT", () => {
|
|
4628
|
-
cleanup();
|
|
4629
|
-
process.exit(130);
|
|
4630
|
-
});
|
|
4631
|
-
process.on("SIGTERM", () => {
|
|
4632
|
-
cleanup();
|
|
4633
|
-
process.exit(143);
|
|
4634
|
-
});
|
|
4635
|
-
process.on("exit", cleanup);
|
|
4636
|
-
}
|
|
4637
4653
|
|
|
4638
4654
|
// src/cli/commands/onboard.ts
|
|
4639
4655
|
async function promptForStacks() {
|
package/package.json
CHANGED