@kaynooo/cli-check 0.13.0 → 0.15.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 +2 -2
- package/dist/cli.js +398 -139
- package/dist/errs-cli.js +355 -108
- package/dist/fix-cli.js +373 -126
- package/dist/j-cli.js +1032 -208
- package/package.json +2 -2
package/dist/errs-cli.js
CHANGED
|
@@ -2,16 +2,37 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/errs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process7 from "process";
|
|
12
12
|
|
|
13
|
-
// ../kit/src/
|
|
13
|
+
// ../kit/src/mode.ts
|
|
14
14
|
import process2 from "process";
|
|
15
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
|
+
function isSet(value) {
|
|
18
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
|
+
}
|
|
20
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
21
|
+
const chosen = env.KIT_MODE;
|
|
22
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
23
|
+
return chosen;
|
|
24
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
25
|
+
return "agent";
|
|
26
|
+
if (stream.isTTY === true)
|
|
27
|
+
return "terminal";
|
|
28
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
|
+
}
|
|
30
|
+
function isInteractive(streams = process2) {
|
|
31
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ../kit/src/style.ts
|
|
35
|
+
import process6 from "process";
|
|
15
36
|
|
|
16
37
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
38
|
function x(s) {
|
|
@@ -274,36 +295,252 @@ function le(i = {}) {
|
|
|
274
295
|
}
|
|
275
296
|
var t = le();
|
|
276
297
|
|
|
277
|
-
// ../kit/src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
298
|
+
// ../kit/src/theme.ts
|
|
299
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
300
|
+
import { homedir as homedir2 } from "os";
|
|
301
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
302
|
+
import process5 from "process";
|
|
303
|
+
|
|
304
|
+
// ../kit/src/config.ts
|
|
305
|
+
import { existsSync } from "fs";
|
|
306
|
+
import { dirname, join, resolve } from "path";
|
|
307
|
+
import process3 from "process";
|
|
308
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
309
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
310
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
311
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
312
|
+
if (found !== undefined)
|
|
313
|
+
return found;
|
|
314
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ../kit/src/user-config.ts
|
|
320
|
+
import { homedir } from "os";
|
|
321
|
+
import { join as join2 } from "path";
|
|
322
|
+
import process4 from "process";
|
|
323
|
+
function configBase(where = {}) {
|
|
324
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
325
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
326
|
+
}
|
|
327
|
+
function userConfigPath(bin, where = {}) {
|
|
328
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ../kit/src/theme.ts
|
|
332
|
+
var DEFAULT = {
|
|
333
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
334
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
335
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
336
|
+
bins: {}
|
|
283
337
|
};
|
|
284
|
-
|
|
285
|
-
|
|
338
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
339
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
340
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
341
|
+
var PRESETS = {
|
|
342
|
+
default: {},
|
|
343
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
344
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
345
|
+
ascii: { glyphs: ASCII }
|
|
346
|
+
};
|
|
347
|
+
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
348
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
349
|
+
var CONTROL = /\p{Cc}/u;
|
|
350
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
351
|
+
var SPACES = /\s+/;
|
|
352
|
+
function isColorSpec(spec) {
|
|
353
|
+
if (typeof spec === "number")
|
|
354
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
355
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
356
|
+
}
|
|
357
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
358
|
+
function cubeLevel(channel) {
|
|
359
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
360
|
+
}
|
|
361
|
+
function nearest256(hex) {
|
|
362
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
363
|
+
const levels = rgb.map(cubeLevel);
|
|
364
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
365
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
366
|
+
const greyValue = 8 + grey * 10;
|
|
367
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
368
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
369
|
+
}
|
|
370
|
+
function hasTrueColor(env) {
|
|
371
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
372
|
+
}
|
|
373
|
+
function tinted(colors, spec, env = process5.env) {
|
|
374
|
+
if (typeof spec === "number")
|
|
375
|
+
return colors.ansi256(spec);
|
|
376
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
377
|
+
if (HEX.test(token))
|
|
378
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
379
|
+
return chain[token] ?? chain;
|
|
380
|
+
}, colors);
|
|
381
|
+
}
|
|
382
|
+
function isRecord(value) {
|
|
383
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
384
|
+
}
|
|
385
|
+
function readThemeFile(path, warn) {
|
|
386
|
+
try {
|
|
387
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
388
|
+
if (stat === undefined)
|
|
389
|
+
return;
|
|
390
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
391
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
395
|
+
if (isRecord(parsed))
|
|
396
|
+
return parsed;
|
|
397
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
function applyPreset(theme, name, warn, where) {
|
|
404
|
+
if (name === undefined)
|
|
405
|
+
return;
|
|
406
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
407
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const preset = PRESETS[name];
|
|
411
|
+
Object.assign(theme.colors, preset.colors);
|
|
412
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
413
|
+
if (preset.accents !== undefined)
|
|
414
|
+
theme.accents = [...preset.accents];
|
|
415
|
+
return name;
|
|
416
|
+
}
|
|
417
|
+
function applyFile(theme, file, where, warn) {
|
|
418
|
+
if (isRecord(file.colors)) {
|
|
419
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
420
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
421
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
422
|
+
else if (!isColorSpec(value))
|
|
423
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
424
|
+
else
|
|
425
|
+
theme.colors[key] = value;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (isRecord(file.glyphs)) {
|
|
429
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
430
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
431
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
432
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
433
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
434
|
+
else
|
|
435
|
+
theme.glyphs[key] = value;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
439
|
+
theme.accents = [...file.accents];
|
|
440
|
+
else if (file.accents !== undefined)
|
|
441
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
442
|
+
if (isRecord(file.bins)) {
|
|
443
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
444
|
+
if (isColorSpec(value))
|
|
445
|
+
theme.bins[bin] = value;
|
|
446
|
+
else
|
|
447
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function endsWalk(home) {
|
|
452
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
453
|
+
}
|
|
454
|
+
var warned = new Set;
|
|
455
|
+
function warnOnce(message) {
|
|
456
|
+
if (warned.has(message))
|
|
457
|
+
return;
|
|
458
|
+
warned.add(message);
|
|
459
|
+
console.error(`warning: theme ${message}`);
|
|
460
|
+
}
|
|
461
|
+
function isPath(chosen) {
|
|
462
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
463
|
+
}
|
|
464
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
465
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
466
|
+
const sources = [];
|
|
467
|
+
const chosen = env.KIT_THEME ?? "";
|
|
468
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
469
|
+
if (isPath(chosen))
|
|
470
|
+
wanted.push(resolve2(from, chosen));
|
|
471
|
+
const files = [];
|
|
472
|
+
for (const path of wanted) {
|
|
473
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
474
|
+
if (path !== undefined && file !== undefined)
|
|
475
|
+
files.push({ path, file });
|
|
476
|
+
}
|
|
477
|
+
let preset = "default";
|
|
478
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
479
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
480
|
+
} else {
|
|
481
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
482
|
+
if (named !== undefined)
|
|
483
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
484
|
+
}
|
|
485
|
+
for (const { path, file } of files) {
|
|
486
|
+
applyFile(theme, file, path, warn);
|
|
487
|
+
sources.push(path);
|
|
488
|
+
}
|
|
489
|
+
return { theme, sources, preset };
|
|
286
490
|
}
|
|
287
|
-
|
|
491
|
+
var current;
|
|
492
|
+
var currentKey = "";
|
|
493
|
+
function activeTheme() {
|
|
494
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
495
|
+
if (current === undefined || key !== currentKey) {
|
|
496
|
+
current = loadTheme();
|
|
497
|
+
currentKey = key;
|
|
498
|
+
}
|
|
499
|
+
return current;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ../kit/src/style.ts
|
|
503
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
504
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
505
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
506
|
+
}
|
|
507
|
+
function paint(stream, env = process6.env) {
|
|
288
508
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
289
509
|
}
|
|
290
|
-
function marked(mark, text, stream, detail, env =
|
|
510
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
291
511
|
const colors = paint(stream, env);
|
|
292
|
-
|
|
293
|
-
|
|
512
|
+
let head = MARK_WORDS[mark];
|
|
513
|
+
if (takesControlCodes(stream, env)) {
|
|
514
|
+
const { theme } = activeTheme();
|
|
515
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
516
|
+
}
|
|
294
517
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
295
518
|
}
|
|
296
519
|
function warn(text, detail) {
|
|
297
|
-
console.error(marked("warn", text,
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
520
|
+
console.error(marked("warn", text, process6.stderr, detail));
|
|
521
|
+
}
|
|
522
|
+
function role(name, stream, env = process6.env) {
|
|
523
|
+
const colors = paint(stream, env);
|
|
524
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
525
|
+
}
|
|
526
|
+
var STATUS_WORDS = {
|
|
527
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
528
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
529
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
530
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
531
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
305
532
|
};
|
|
306
|
-
var STATUS_OF = new Map(Object.entries(
|
|
533
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
534
|
+
function header(bin, context, stream, env = process6.env) {
|
|
535
|
+
if (!takesControlCodes(stream, env))
|
|
536
|
+
return "";
|
|
537
|
+
const colors = paint(stream, env);
|
|
538
|
+
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
539
|
+
const { theme } = activeTheme();
|
|
540
|
+
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
541
|
+
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
542
|
+
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
543
|
+
}
|
|
307
544
|
|
|
308
545
|
// ../kit/src/format.ts
|
|
309
546
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -335,15 +572,18 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
335
572
|
function textWidth(text) {
|
|
336
573
|
return Bun.stringWidth(text);
|
|
337
574
|
}
|
|
338
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
575
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
339
576
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
577
|
+
if (outputMode(stream, env) === "agent")
|
|
578
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
579
|
+
`);
|
|
340
580
|
const widths = [];
|
|
341
581
|
for (const row of cells) {
|
|
342
582
|
for (const [index, cell] of row.entries())
|
|
343
583
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
344
584
|
}
|
|
345
585
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
346
|
-
const colors = paint(
|
|
586
|
+
const colors = paint(stream);
|
|
347
587
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
348
588
|
const width = widths[index] ?? 0;
|
|
349
589
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -351,7 +591,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
351
591
|
return `${gap}${cell}`;
|
|
352
592
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
353
593
|
}).join(" ").trimEnd());
|
|
354
|
-
|
|
594
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
595
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
355
596
|
`);
|
|
356
597
|
}
|
|
357
598
|
function narrow(rows, widths, limit) {
|
|
@@ -370,32 +611,35 @@ function narrow(rows, widths, limit) {
|
|
|
370
611
|
}
|
|
371
612
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
372
613
|
}
|
|
614
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
615
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
616
|
+
}
|
|
373
617
|
function printJson(value) {
|
|
374
|
-
console.log(
|
|
618
|
+
console.log(jsonText(value));
|
|
375
619
|
}
|
|
376
620
|
|
|
377
621
|
// ../kit/src/help.ts
|
|
378
|
-
import
|
|
622
|
+
import process8 from "process";
|
|
379
623
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
380
624
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
381
625
|
var FULL_STOP = /\.$/;
|
|
382
|
-
function usageLine(usage, colors = paint(
|
|
626
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
383
627
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
384
628
|
}
|
|
385
|
-
function helpText(usage, options, colors = paint(
|
|
629
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
386
630
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
387
631
|
`);
|
|
388
632
|
}
|
|
389
|
-
function exitRows(exits, colors = paint(
|
|
633
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
390
634
|
if (exits.length === 0)
|
|
391
635
|
return [];
|
|
392
636
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
393
637
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
394
638
|
}
|
|
395
|
-
function replacesRows(replaces, colors = paint(
|
|
396
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
639
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
640
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
397
641
|
}
|
|
398
|
-
function wantsHelpJson(env =
|
|
642
|
+
function wantsHelpJson(env = process8.env) {
|
|
399
643
|
return env.KIT_HELP === "json";
|
|
400
644
|
}
|
|
401
645
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -414,12 +658,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
414
658
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
415
659
|
};
|
|
416
660
|
}
|
|
417
|
-
function exampleRows(examples, colors = paint(
|
|
418
|
-
if (examples.length === 0)
|
|
661
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
662
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
419
663
|
return [];
|
|
420
664
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
421
665
|
}
|
|
422
|
-
function optionRows(options, colors = paint(
|
|
666
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
423
667
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
424
668
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
425
669
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -454,7 +698,7 @@ function closest(name, names) {
|
|
|
454
698
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
455
699
|
}
|
|
456
700
|
// ../kit/src/input.ts
|
|
457
|
-
import
|
|
701
|
+
import process9 from "process";
|
|
458
702
|
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
459
703
|
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
460
704
|
function duration(value, name, fallback, unit = "s") {
|
|
@@ -468,7 +712,7 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
468
712
|
}
|
|
469
713
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
470
714
|
if (path === "-") {
|
|
471
|
-
if (
|
|
715
|
+
if (process9.stdin.isTTY)
|
|
472
716
|
fail(noStdin);
|
|
473
717
|
return Bun.stdin.text();
|
|
474
718
|
}
|
|
@@ -527,7 +771,7 @@ var OUTPUT_OPTIONS = {
|
|
|
527
771
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
528
772
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
529
773
|
};
|
|
530
|
-
function applyOutput(color, plain, env =
|
|
774
|
+
function applyOutput(color, plain, env = process10.env) {
|
|
531
775
|
const when = plain === true ? "never" : color ?? "auto";
|
|
532
776
|
if (when === "auto")
|
|
533
777
|
return;
|
|
@@ -698,7 +942,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
698
942
|
}
|
|
699
943
|
// ../kit/src/process.ts
|
|
700
944
|
import { constants } from "os";
|
|
701
|
-
import
|
|
945
|
+
import process11 from "process";
|
|
702
946
|
var KILL_GRACE_MS = 2000;
|
|
703
947
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
704
948
|
function exitCodeOf(code, signal) {
|
|
@@ -720,7 +964,7 @@ function holdSignals(cleanup) {
|
|
|
720
964
|
},
|
|
721
965
|
release: () => {
|
|
722
966
|
for (const signal of SIGNALS)
|
|
723
|
-
|
|
967
|
+
process11.off(signal, onSignal);
|
|
724
968
|
}
|
|
725
969
|
};
|
|
726
970
|
function onSignal(signal) {
|
|
@@ -733,10 +977,10 @@ function holdSignals(cleanup) {
|
|
|
733
977
|
return;
|
|
734
978
|
held.release();
|
|
735
979
|
cleanup(signal);
|
|
736
|
-
|
|
980
|
+
process11.kill(process11.pid, signal);
|
|
737
981
|
}
|
|
738
982
|
for (const signal of SIGNALS)
|
|
739
|
-
|
|
983
|
+
process11.on(signal, onSignal);
|
|
740
984
|
return held;
|
|
741
985
|
}
|
|
742
986
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -750,7 +994,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
750
994
|
return;
|
|
751
995
|
try {
|
|
752
996
|
if (grouped)
|
|
753
|
-
|
|
997
|
+
process11.kill(-proc.pid, killing);
|
|
754
998
|
else
|
|
755
999
|
proc.kill(killing);
|
|
756
1000
|
} catch {}
|
|
@@ -824,42 +1068,42 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
824
1068
|
var RESET_STYLE = `${ESC}[0m`;
|
|
825
1069
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
826
1070
|
// ../kit/src/cli.ts
|
|
827
|
-
import { readFileSync, realpathSync } from "fs";
|
|
828
|
-
import { dirname as
|
|
829
|
-
import
|
|
1071
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1072
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1073
|
+
import process14 from "process";
|
|
830
1074
|
|
|
831
1075
|
// ../kit/src/usage.ts
|
|
832
1076
|
import { appendFileSync, mkdirSync } from "fs";
|
|
833
|
-
import { homedir as
|
|
834
|
-
import { dirname, isAbsolute, join as
|
|
835
|
-
import
|
|
1077
|
+
import { homedir as homedir4 } from "os";
|
|
1078
|
+
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
1079
|
+
import process13 from "process";
|
|
836
1080
|
|
|
837
1081
|
// ../kit/src/logs.ts
|
|
838
1082
|
import { lstatSync, openSync } from "fs";
|
|
839
1083
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
840
|
-
import { homedir, tmpdir } from "os";
|
|
841
|
-
import { join } from "path";
|
|
842
|
-
import
|
|
1084
|
+
import { homedir as homedir3, tmpdir } from "os";
|
|
1085
|
+
import { join as join4 } from "path";
|
|
1086
|
+
import process12 from "process";
|
|
843
1087
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
844
1088
|
var CLI_FOLDER = "kaynooo-cli";
|
|
845
1089
|
function isPrivateDirectory(path) {
|
|
846
1090
|
try {
|
|
847
1091
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
848
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1092
|
+
return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
849
1093
|
} catch {
|
|
850
1094
|
return false;
|
|
851
1095
|
}
|
|
852
1096
|
}
|
|
853
|
-
async function privateLogDirectory(name, env =
|
|
1097
|
+
async function privateLogDirectory(name, env = process12.env) {
|
|
854
1098
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
855
|
-
const base = runtime === undefined || runtime === "" ?
|
|
856
|
-
const path =
|
|
1099
|
+
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1100
|
+
const path = join4(base, name);
|
|
857
1101
|
try {
|
|
858
1102
|
await mkdir(path, { recursive: true, mode: 448 });
|
|
859
1103
|
if (isPrivateDirectory(path))
|
|
860
1104
|
return path;
|
|
861
1105
|
} catch {}
|
|
862
|
-
return mkdtemp(
|
|
1106
|
+
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
863
1107
|
}
|
|
864
1108
|
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
865
1109
|
let names;
|
|
@@ -869,7 +1113,7 @@ async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
|
869
1113
|
return;
|
|
870
1114
|
}
|
|
871
1115
|
for (const name of names) {
|
|
872
|
-
const path =
|
|
1116
|
+
const path = join4(dir, name);
|
|
873
1117
|
try {
|
|
874
1118
|
const info = await stat(path);
|
|
875
1119
|
if (info.isDirectory())
|
|
@@ -890,14 +1134,14 @@ var usageError;
|
|
|
890
1134
|
function noteUsageError(message) {
|
|
891
1135
|
usageError = message;
|
|
892
1136
|
}
|
|
893
|
-
function stateHome(env =
|
|
1137
|
+
function stateHome(env = process13.env) {
|
|
894
1138
|
const dir = env.XDG_STATE_HOME;
|
|
895
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1139
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
896
1140
|
}
|
|
897
|
-
function usagePath(env =
|
|
898
|
-
return
|
|
1141
|
+
function usagePath(env = process13.env) {
|
|
1142
|
+
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
899
1143
|
}
|
|
900
|
-
function usageRecorded(env =
|
|
1144
|
+
function usageRecorded(env = process13.env) {
|
|
901
1145
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
902
1146
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
903
1147
|
}
|
|
@@ -911,12 +1155,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
911
1155
|
usageError = undefined;
|
|
912
1156
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
913
1157
|
}
|
|
914
|
-
function recordUsage(entry, env =
|
|
1158
|
+
function recordUsage(entry, env = process13.env) {
|
|
915
1159
|
if (!usageRecorded(env))
|
|
916
1160
|
return;
|
|
917
1161
|
try {
|
|
918
1162
|
const path = usagePath(env);
|
|
919
|
-
mkdirSync(
|
|
1163
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
920
1164
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
921
1165
|
`, { mode: 384 });
|
|
922
1166
|
} catch {}
|
|
@@ -929,8 +1173,8 @@ var LEVEL_OPTIONS = {
|
|
|
929
1173
|
};
|
|
930
1174
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
931
1175
|
function printError(prefix, message, hint, cause) {
|
|
932
|
-
const colors = paint(
|
|
933
|
-
const styled = takesControlCodes(
|
|
1176
|
+
const colors = paint(process14.stderr);
|
|
1177
|
+
const styled = takesControlCodes(process14.stderr);
|
|
934
1178
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
935
1179
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
936
1180
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1013,17 +1257,17 @@ async function printCandidates(found) {
|
|
|
1013
1257
|
return 0;
|
|
1014
1258
|
}
|
|
1015
1259
|
function packageVersion(entry = Bun.main) {
|
|
1016
|
-
for (let dir =
|
|
1260
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1017
1261
|
try {
|
|
1018
|
-
const { version } = JSON.parse(
|
|
1262
|
+
const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
|
|
1019
1263
|
if (typeof version === "string")
|
|
1020
1264
|
return version;
|
|
1021
1265
|
} catch {}
|
|
1022
|
-
if (
|
|
1266
|
+
if (dirname3(dir) === dir)
|
|
1023
1267
|
return "0.0.0";
|
|
1024
1268
|
}
|
|
1025
1269
|
}
|
|
1026
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1270
|
+
async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
|
|
1027
1271
|
if (argv[0] === COMPLETE)
|
|
1028
1272
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1029
1273
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1050,17 +1294,17 @@ var {Glob } = globalThis.Bun;
|
|
|
1050
1294
|
var SESSION_FILES = new Glob("*.json");
|
|
1051
1295
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1052
1296
|
// package.json
|
|
1053
|
-
var version = "0.
|
|
1297
|
+
var version = "0.15.0";
|
|
1054
1298
|
|
|
1055
1299
|
// src/errs.ts
|
|
1056
1300
|
import { relative as relative2 } from "path";
|
|
1057
|
-
import
|
|
1301
|
+
import process18 from "process";
|
|
1058
1302
|
|
|
1059
1303
|
// src/compose.ts
|
|
1060
|
-
import { existsSync } from "fs";
|
|
1061
|
-
import { homedir as
|
|
1062
|
-
import { basename, dirname as
|
|
1063
|
-
import
|
|
1304
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1305
|
+
import { homedir as homedir5 } from "os";
|
|
1306
|
+
import { basename, dirname as dirname4, join as join7, relative, resolve as resolve3 } from "path";
|
|
1307
|
+
import process16 from "process";
|
|
1064
1308
|
|
|
1065
1309
|
// ../kit/src/shell.ts
|
|
1066
1310
|
var SEPARATORS = new Set([`
|
|
@@ -1138,7 +1382,7 @@ function toolWords(program) {
|
|
|
1138
1382
|
}
|
|
1139
1383
|
async function readFiles(dir, names) {
|
|
1140
1384
|
for (const name of names) {
|
|
1141
|
-
const handle = Bun.file(
|
|
1385
|
+
const handle = Bun.file(join7(dir, name));
|
|
1142
1386
|
if (await handle.exists())
|
|
1143
1387
|
return { name, text: await handle.text() };
|
|
1144
1388
|
}
|
|
@@ -1153,7 +1397,7 @@ async function variables(composeDir) {
|
|
|
1153
1397
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1154
1398
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1155
1399
|
}
|
|
1156
|
-
for (const [key, value] of Object.entries(
|
|
1400
|
+
for (const [key, value] of Object.entries(process16.env)) {
|
|
1157
1401
|
if (value !== undefined)
|
|
1158
1402
|
env[key] = value;
|
|
1159
1403
|
}
|
|
@@ -1173,10 +1417,10 @@ function interpolate(text, env) {
|
|
|
1173
1417
|
function bindSource(source, composeDir, env) {
|
|
1174
1418
|
const path = interpolate(source, env);
|
|
1175
1419
|
if (path.startsWith("~"))
|
|
1176
|
-
return
|
|
1420
|
+
return join7(homedir5(), path.slice(1));
|
|
1177
1421
|
if (path.startsWith("/"))
|
|
1178
|
-
return
|
|
1179
|
-
return path.startsWith(".") ?
|
|
1422
|
+
return resolve3(path);
|
|
1423
|
+
return path.startsWith(".") ? resolve3(composeDir, path) : undefined;
|
|
1180
1424
|
}
|
|
1181
1425
|
function mountsOf(volumes, composeDir, env) {
|
|
1182
1426
|
if (!Array.isArray(volumes))
|
|
@@ -1218,9 +1462,9 @@ async function composeFiles(composeDir, env) {
|
|
|
1218
1462
|
const files = [];
|
|
1219
1463
|
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1220
1464
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1221
|
-
const file = Bun.file(
|
|
1465
|
+
const file = Bun.file(resolve3(composeDir, name));
|
|
1222
1466
|
if (!await file.exists())
|
|
1223
|
-
fail(`COMPOSE_FILE names ${
|
|
1467
|
+
fail(`COMPOSE_FILE names ${join7(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1224
1468
|
files.push({ name, text: await file.text() });
|
|
1225
1469
|
}
|
|
1226
1470
|
return files;
|
|
@@ -1242,7 +1486,7 @@ async function readServices(composeDir) {
|
|
|
1242
1486
|
try {
|
|
1243
1487
|
parsed = parseServices(file.text, composeDir, env);
|
|
1244
1488
|
} catch (error) {
|
|
1245
|
-
fail(`cannot read ${
|
|
1489
|
+
fail(`cannot read ${join7(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1246
1490
|
}
|
|
1247
1491
|
for (const [name, extra] of parsed) {
|
|
1248
1492
|
const known = services.get(name);
|
|
@@ -1254,11 +1498,11 @@ async function readServices(composeDir) {
|
|
|
1254
1498
|
function climb(dir) {
|
|
1255
1499
|
const folders = [dir];
|
|
1256
1500
|
let current = dir;
|
|
1257
|
-
while (!
|
|
1258
|
-
current =
|
|
1501
|
+
while (!existsSync3(join7(current, ".git")) && dirname4(current) !== current) {
|
|
1502
|
+
current = dirname4(current);
|
|
1259
1503
|
folders.push(current);
|
|
1260
1504
|
}
|
|
1261
|
-
return
|
|
1505
|
+
return existsSync3(join7(current, ".git")) ? folders : [dir];
|
|
1262
1506
|
}
|
|
1263
1507
|
function containerPath(service, dir) {
|
|
1264
1508
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1269,7 +1513,7 @@ function containerPath(service, dir) {
|
|
|
1269
1513
|
if (deepest === undefined)
|
|
1270
1514
|
return;
|
|
1271
1515
|
const inside = relative(deepest.source, dir);
|
|
1272
|
-
return inside === "" ? deepest.target :
|
|
1516
|
+
return inside === "" ? deepest.target : join7(deepest.target, inside);
|
|
1273
1517
|
}
|
|
1274
1518
|
var noticed = new Set;
|
|
1275
1519
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1289,7 +1533,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1289
1533
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1290
1534
|
return;
|
|
1291
1535
|
}
|
|
1292
|
-
if (Bun.which("docker", { PATH:
|
|
1536
|
+
if (Bun.which("docker", { PATH: process16.env.PATH ?? "" }) === null) {
|
|
1293
1537
|
if (service !== undefined)
|
|
1294
1538
|
fail(`--in ${service}: docker not found`);
|
|
1295
1539
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1341,7 +1585,7 @@ class Stack {
|
|
|
1341
1585
|
}
|
|
1342
1586
|
static async running(composeDir) {
|
|
1343
1587
|
try {
|
|
1344
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1588
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process16.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1345
1589
|
if (ran.code !== 0)
|
|
1346
1590
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1347
1591
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -2000,15 +2244,15 @@ function parseErrors(output) {
|
|
|
2000
2244
|
|
|
2001
2245
|
// src/run.ts
|
|
2002
2246
|
import { mkdir as mkdir2, readdir as readdir2, stat as stat2, writeFile } from "fs/promises";
|
|
2003
|
-
import { basename as basename2, join as
|
|
2004
|
-
import
|
|
2247
|
+
import { basename as basename2, join as join8 } from "path";
|
|
2248
|
+
import process17 from "process";
|
|
2005
2249
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
2006
2250
|
var RESULTS_FILE = "results.json";
|
|
2007
2251
|
var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
2008
2252
|
async function logDirectory(cwd) {
|
|
2009
2253
|
const root = await privateLogDirectory("check");
|
|
2010
2254
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2011
|
-
const path =
|
|
2255
|
+
const path = join8(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process17.pid}`);
|
|
2012
2256
|
await mkdir2(path, { mode: 448 });
|
|
2013
2257
|
return path;
|
|
2014
2258
|
}
|
|
@@ -2019,7 +2263,7 @@ async function lastFailed(cwd) {
|
|
|
2019
2263
|
for (const name of await readdir2(root)) {
|
|
2020
2264
|
if (!name.startsWith(prefix))
|
|
2021
2265
|
continue;
|
|
2022
|
-
const file =
|
|
2266
|
+
const file = join8(root, name, RESULTS_FILE);
|
|
2023
2267
|
try {
|
|
2024
2268
|
const { mtimeMs } = await stat2(file);
|
|
2025
2269
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2034,7 +2278,7 @@ async function lastFailed(cwd) {
|
|
|
2034
2278
|
async function saveLog(output) {
|
|
2035
2279
|
const root = await privateLogDirectory("errs");
|
|
2036
2280
|
await sweepLogs(root);
|
|
2037
|
-
const path =
|
|
2281
|
+
const path = join8(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process17.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2038
2282
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2039
2283
|
return path;
|
|
2040
2284
|
}
|
|
@@ -2042,7 +2286,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2042
2286
|
const started = Date.now();
|
|
2043
2287
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2044
2288
|
cwd,
|
|
2045
|
-
env: { ...
|
|
2289
|
+
env: { ...process17.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2046
2290
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2047
2291
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2048
2292
|
});
|
|
@@ -2058,14 +2302,17 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2058
2302
|
return { name, command, ...service === undefined ? {} : { in: service }, ok: outcome.ok, ms: outcome.ms, log: logFile, ...outcome.timedOut === true ? { timedOut: true } : {}, ...outcome.ok ? {} : { failed: failureExcerpt(outcome.output) } };
|
|
2059
2303
|
}
|
|
2060
2304
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2305
|
+
const colors = paint(process17.stdout);
|
|
2306
|
+
const path = role("path", process17.stdout);
|
|
2307
|
+
const took = colors.dim(formatDuration(outcome.ms));
|
|
2061
2308
|
if (outcome.ok) {
|
|
2062
|
-
console.log(
|
|
2309
|
+
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
2063
2310
|
return;
|
|
2064
2311
|
}
|
|
2065
|
-
const label = outcome.timedOut === true ? "TIME " : "FAIL ";
|
|
2066
|
-
console.log(`${label} ${name.padEnd(width)} ${
|
|
2312
|
+
const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
|
|
2313
|
+
console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
|
|
2067
2314
|
if (outcome.timedOut === true)
|
|
2068
|
-
console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
|
|
2315
|
+
console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
|
|
2069
2316
|
console.log(failureExcerpt(outcome.output).split(`
|
|
2070
2317
|
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
2071
2318
|
`));
|
|
@@ -2113,7 +2360,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2113
2360
|
const held = holdSignals();
|
|
2114
2361
|
let ran;
|
|
2115
2362
|
try {
|
|
2116
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...
|
|
2363
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process18.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
2117
2364
|
} catch (error) {
|
|
2118
2365
|
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2119
2366
|
} finally {
|
|
@@ -2121,7 +2368,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
2121
2368
|
}
|
|
2122
2369
|
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
2123
2370
|
}
|
|
2124
|
-
async function errs(args, cwd =
|
|
2371
|
+
async function errs(args, cwd = process18.cwd()) {
|
|
2125
2372
|
const first = args[0];
|
|
2126
2373
|
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2127
2374
|
const parsed = parse(bare ? [] : args, usage2, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
@@ -2145,4 +2392,4 @@ ${usage2}`);
|
|
|
2145
2392
|
}
|
|
2146
2393
|
|
|
2147
2394
|
// src/errs-cli.ts
|
|
2148
|
-
|
|
2395
|
+
process19.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|