@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/cli.js
CHANGED
|
@@ -2,16 +2,37 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process20 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: {}
|
|
337
|
+
};
|
|
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 }
|
|
283
346
|
};
|
|
284
|
-
|
|
285
|
-
|
|
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;
|
|
286
402
|
}
|
|
287
|
-
function
|
|
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 };
|
|
490
|
+
}
|
|
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,12 +1294,12 @@ 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/check.ts
|
|
1056
1300
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
1057
|
-
import { join as
|
|
1058
|
-
import
|
|
1301
|
+
import { basename as basename4, join as join13 } from "path";
|
|
1302
|
+
import process19 from "process";
|
|
1059
1303
|
|
|
1060
1304
|
// ../kit/src/shell.ts
|
|
1061
1305
|
var SEPARATORS = new Set([`
|
|
@@ -1105,10 +1349,10 @@ function shellQuote(word) {
|
|
|
1105
1349
|
}
|
|
1106
1350
|
|
|
1107
1351
|
// src/compose.ts
|
|
1108
|
-
import { existsSync } from "fs";
|
|
1109
|
-
import { homedir as
|
|
1110
|
-
import { basename, dirname as
|
|
1111
|
-
import
|
|
1352
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1353
|
+
import { homedir as homedir5 } from "os";
|
|
1354
|
+
import { basename, dirname as dirname4, join as join7, relative, resolve as resolve3 } from "path";
|
|
1355
|
+
import process16 from "process";
|
|
1112
1356
|
var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
|
|
1113
1357
|
var OVERRIDE_FILES = ["compose.override.yaml", "compose.override.yml", "docker-compose.override.yaml", "docker-compose.override.yml"];
|
|
1114
1358
|
var PS_TIMEOUT_MS = 20000;
|
|
@@ -1137,7 +1381,7 @@ function toolWords(program) {
|
|
|
1137
1381
|
}
|
|
1138
1382
|
async function readFiles(dir, names) {
|
|
1139
1383
|
for (const name of names) {
|
|
1140
|
-
const handle = Bun.file(
|
|
1384
|
+
const handle = Bun.file(join7(dir, name));
|
|
1141
1385
|
if (await handle.exists())
|
|
1142
1386
|
return { name, text: await handle.text() };
|
|
1143
1387
|
}
|
|
@@ -1152,7 +1396,7 @@ async function variables(composeDir) {
|
|
|
1152
1396
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1153
1397
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1154
1398
|
}
|
|
1155
|
-
for (const [key, value] of Object.entries(
|
|
1399
|
+
for (const [key, value] of Object.entries(process16.env)) {
|
|
1156
1400
|
if (value !== undefined)
|
|
1157
1401
|
env[key] = value;
|
|
1158
1402
|
}
|
|
@@ -1172,10 +1416,10 @@ function interpolate(text, env) {
|
|
|
1172
1416
|
function bindSource(source, composeDir, env) {
|
|
1173
1417
|
const path = interpolate(source, env);
|
|
1174
1418
|
if (path.startsWith("~"))
|
|
1175
|
-
return
|
|
1419
|
+
return join7(homedir5(), path.slice(1));
|
|
1176
1420
|
if (path.startsWith("/"))
|
|
1177
|
-
return
|
|
1178
|
-
return path.startsWith(".") ?
|
|
1421
|
+
return resolve3(path);
|
|
1422
|
+
return path.startsWith(".") ? resolve3(composeDir, path) : undefined;
|
|
1179
1423
|
}
|
|
1180
1424
|
function mountsOf(volumes, composeDir, env) {
|
|
1181
1425
|
if (!Array.isArray(volumes))
|
|
@@ -1217,9 +1461,9 @@ async function composeFiles(composeDir, env) {
|
|
|
1217
1461
|
const files = [];
|
|
1218
1462
|
const separator = env.COMPOSE_PATH_SEPARATOR;
|
|
1219
1463
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1220
|
-
const file = Bun.file(
|
|
1464
|
+
const file = Bun.file(resolve3(composeDir, name));
|
|
1221
1465
|
if (!await file.exists())
|
|
1222
|
-
fail(`COMPOSE_FILE names ${
|
|
1466
|
+
fail(`COMPOSE_FILE names ${join7(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1223
1467
|
files.push({ name, text: await file.text() });
|
|
1224
1468
|
}
|
|
1225
1469
|
return files;
|
|
@@ -1241,7 +1485,7 @@ async function readServices(composeDir) {
|
|
|
1241
1485
|
try {
|
|
1242
1486
|
parsed = parseServices(file.text, composeDir, env);
|
|
1243
1487
|
} catch (error) {
|
|
1244
|
-
fail(`cannot read ${
|
|
1488
|
+
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");
|
|
1245
1489
|
}
|
|
1246
1490
|
for (const [name, extra] of parsed) {
|
|
1247
1491
|
const known = services.get(name);
|
|
@@ -1253,11 +1497,11 @@ async function readServices(composeDir) {
|
|
|
1253
1497
|
function climb(dir) {
|
|
1254
1498
|
const folders = [dir];
|
|
1255
1499
|
let current = dir;
|
|
1256
|
-
while (!
|
|
1257
|
-
current =
|
|
1500
|
+
while (!existsSync3(join7(current, ".git")) && dirname4(current) !== current) {
|
|
1501
|
+
current = dirname4(current);
|
|
1258
1502
|
folders.push(current);
|
|
1259
1503
|
}
|
|
1260
|
-
return
|
|
1504
|
+
return existsSync3(join7(current, ".git")) ? folders : [dir];
|
|
1261
1505
|
}
|
|
1262
1506
|
function containerPath(service, dir) {
|
|
1263
1507
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1268,7 +1512,7 @@ function containerPath(service, dir) {
|
|
|
1268
1512
|
if (deepest === undefined)
|
|
1269
1513
|
return;
|
|
1270
1514
|
const inside = relative(deepest.source, dir);
|
|
1271
|
-
return inside === "" ? deepest.target :
|
|
1515
|
+
return inside === "" ? deepest.target : join7(deepest.target, inside);
|
|
1272
1516
|
}
|
|
1273
1517
|
var noticed = new Set;
|
|
1274
1518
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1288,7 +1532,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1288
1532
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1289
1533
|
return;
|
|
1290
1534
|
}
|
|
1291
|
-
if (Bun.which("docker", { PATH:
|
|
1535
|
+
if (Bun.which("docker", { PATH: process16.env.PATH ?? "" }) === null) {
|
|
1292
1536
|
if (service !== undefined)
|
|
1293
1537
|
fail(`--in ${service}: docker not found`);
|
|
1294
1538
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1340,7 +1584,7 @@ class Stack {
|
|
|
1340
1584
|
}
|
|
1341
1585
|
static async running(composeDir) {
|
|
1342
1586
|
try {
|
|
1343
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1587
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process16.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1344
1588
|
if (ran.code !== 0)
|
|
1345
1589
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1346
1590
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1372,14 +1616,14 @@ function placeSettings(values) {
|
|
|
1372
1616
|
}
|
|
1373
1617
|
|
|
1374
1618
|
// src/fix.ts
|
|
1375
|
-
import { existsSync as
|
|
1619
|
+
import { existsSync as existsSync4, statSync as statSync2 } from "fs";
|
|
1376
1620
|
import { rename, writeFile as writeFile2 } from "fs/promises";
|
|
1377
|
-
import { join as
|
|
1378
|
-
import
|
|
1621
|
+
import { join as join11 } from "path";
|
|
1622
|
+
import process18 from "process";
|
|
1379
1623
|
|
|
1380
1624
|
// src/changes.ts
|
|
1381
1625
|
import { stat as stat2 } from "fs/promises";
|
|
1382
|
-
import { join as
|
|
1626
|
+
import { join as join8 } from "path";
|
|
1383
1627
|
var {$ } = globalThis.Bun;
|
|
1384
1628
|
async function dirtyFiles(dir) {
|
|
1385
1629
|
const listed = await $`git ls-files -z --modified --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
@@ -1388,7 +1632,7 @@ async function dirtyFiles(dir) {
|
|
|
1388
1632
|
const files = new Map;
|
|
1389
1633
|
for (const path of listed.stdout.toString().split("\x00").filter(Boolean)) {
|
|
1390
1634
|
try {
|
|
1391
|
-
const { size, mtimeMs } = await stat2(
|
|
1635
|
+
const { size, mtimeMs } = await stat2(join8(dir, path));
|
|
1392
1636
|
files.set(path, `${size}:${mtimeMs}`);
|
|
1393
1637
|
} catch {
|
|
1394
1638
|
files.set(path, "");
|
|
@@ -1433,7 +1677,7 @@ ${body}`;
|
|
|
1433
1677
|
|
|
1434
1678
|
// src/steps.ts
|
|
1435
1679
|
import { readdir as readdir2 } from "fs/promises";
|
|
1436
|
-
import { join as
|
|
1680
|
+
import { join as join9 } from "path";
|
|
1437
1681
|
var STEP_NAMES = ["check", "typecheck", "lint", "test"];
|
|
1438
1682
|
var TARGET2 = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
|
|
1439
1683
|
var JUSTFILES = ["justfile", "Justfile", ".justfile"];
|
|
@@ -1445,7 +1689,7 @@ var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
|
|
|
1445
1689
|
var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "var", "tmp", "coverage"]);
|
|
1446
1690
|
async function readFirst(dir, files) {
|
|
1447
1691
|
for (const file of files) {
|
|
1448
|
-
const handle = Bun.file(
|
|
1692
|
+
const handle = Bun.file(join9(dir, file));
|
|
1449
1693
|
if (await handle.exists())
|
|
1450
1694
|
return { file, text: await handle.text() };
|
|
1451
1695
|
}
|
|
@@ -1453,7 +1697,7 @@ async function readFirst(dir, files) {
|
|
|
1453
1697
|
}
|
|
1454
1698
|
async function read(dir, ...files) {
|
|
1455
1699
|
for (const file of files) {
|
|
1456
|
-
const handle = Bun.file(
|
|
1700
|
+
const handle = Bun.file(join9(dir, file));
|
|
1457
1701
|
if (await handle.exists())
|
|
1458
1702
|
return handle.text();
|
|
1459
1703
|
}
|
|
@@ -1513,7 +1757,7 @@ async function candidates(dir, bin) {
|
|
|
1513
1757
|
}
|
|
1514
1758
|
async function firstFile(dir, names) {
|
|
1515
1759
|
for (const name of names) {
|
|
1516
|
-
if (await Bun.file(
|
|
1760
|
+
if (await Bun.file(join9(dir, name)).exists())
|
|
1517
1761
|
return name;
|
|
1518
1762
|
}
|
|
1519
1763
|
return;
|
|
@@ -1540,9 +1784,9 @@ async function discoverProjects(dir) {
|
|
|
1540
1784
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
1541
1785
|
if (!entry.isDirectory() || entry.name.startsWith(".") || SKIPPED.has(entry.name))
|
|
1542
1786
|
continue;
|
|
1543
|
-
const steps = await discover(
|
|
1787
|
+
const steps = await discover(join9(dir, entry.name));
|
|
1544
1788
|
if (steps.length > 0)
|
|
1545
|
-
projects.push({ name: entry.name, dir:
|
|
1789
|
+
projects.push({ name: entry.name, dir: join9(dir, entry.name), steps });
|
|
1546
1790
|
}
|
|
1547
1791
|
return projects;
|
|
1548
1792
|
}
|
|
@@ -1584,8 +1828,8 @@ function pick(steps, only, noun = "step") {
|
|
|
1584
1828
|
|
|
1585
1829
|
// src/run.ts
|
|
1586
1830
|
import { mkdir as mkdir2, readdir as readdir3, stat as stat3, writeFile } from "fs/promises";
|
|
1587
|
-
import { basename as basename2, join as
|
|
1588
|
-
import
|
|
1831
|
+
import { basename as basename2, join as join10 } from "path";
|
|
1832
|
+
import process17 from "process";
|
|
1589
1833
|
|
|
1590
1834
|
// src/e2e.ts
|
|
1591
1835
|
var E2E_NOISE = [
|
|
@@ -2220,7 +2464,7 @@ var runPrefix = (cwd) => `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-`;
|
|
|
2220
2464
|
async function logDirectory(cwd) {
|
|
2221
2465
|
const root = await privateLogDirectory("check");
|
|
2222
2466
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
2223
|
-
const path =
|
|
2467
|
+
const path = join10(root, `${runPrefix(cwd)}${Date.now().toString(36)}-${process17.pid}`);
|
|
2224
2468
|
await mkdir2(path, { mode: 448 });
|
|
2225
2469
|
return path;
|
|
2226
2470
|
}
|
|
@@ -2231,7 +2475,7 @@ async function lastFailed(cwd) {
|
|
|
2231
2475
|
for (const name of await readdir3(root)) {
|
|
2232
2476
|
if (!name.startsWith(prefix))
|
|
2233
2477
|
continue;
|
|
2234
|
-
const file =
|
|
2478
|
+
const file = join10(root, name, RESULTS_FILE);
|
|
2235
2479
|
try {
|
|
2236
2480
|
const { mtimeMs } = await stat3(file);
|
|
2237
2481
|
if (latest === undefined || mtimeMs > latest.time)
|
|
@@ -2246,7 +2490,7 @@ async function lastFailed(cwd) {
|
|
|
2246
2490
|
async function saveLog(output) {
|
|
2247
2491
|
const root = await privateLogDirectory("errs");
|
|
2248
2492
|
await sweepLogs(root);
|
|
2249
|
-
const path =
|
|
2493
|
+
const path = join10(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process17.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
2250
2494
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
2251
2495
|
return path;
|
|
2252
2496
|
}
|
|
@@ -2254,7 +2498,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
2254
2498
|
const started = Date.now();
|
|
2255
2499
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
2256
2500
|
cwd,
|
|
2257
|
-
env: { ...
|
|
2501
|
+
env: { ...process17.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
2258
2502
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
2259
2503
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
2260
2504
|
});
|
|
@@ -2270,14 +2514,17 @@ function outcomeJson(name, command, logFile, outcome, service) {
|
|
|
2270
2514
|
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) } };
|
|
2271
2515
|
}
|
|
2272
2516
|
function printOutcome(name, width, command, logFile, outcome) {
|
|
2517
|
+
const colors = paint(process17.stdout);
|
|
2518
|
+
const path = role("path", process17.stdout);
|
|
2519
|
+
const took = colors.dim(formatDuration(outcome.ms));
|
|
2273
2520
|
if (outcome.ok) {
|
|
2274
|
-
console.log(
|
|
2521
|
+
console.log(`${colors.bold(colors.green("ok "))} ${name.padEnd(width)} ${took} ${path(logFile)}`);
|
|
2275
2522
|
return;
|
|
2276
2523
|
}
|
|
2277
|
-
const label = outcome.timedOut === true ? "TIME " : "FAIL ";
|
|
2278
|
-
console.log(`${label} ${name.padEnd(width)} ${
|
|
2524
|
+
const label = outcome.timedOut === true ? colors.bold(colors.yellow("TIME ")) : colors.bold(colors.red("FAIL "));
|
|
2525
|
+
console.log(`${label} ${name.padEnd(width)} ${took} ${colors.dim(command)} ${path(logFile)}`);
|
|
2279
2526
|
if (outcome.timedOut === true)
|
|
2280
|
-
console.log(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`);
|
|
2527
|
+
console.log(colors.yellow(` timed out after ${formatDuration(outcome.ms)}, the step and what it started were ended`));
|
|
2281
2528
|
console.log(failureExcerpt(outcome.output).split(`
|
|
2282
2529
|
`).map((line) => ` ${line}`.trimEnd()).join(`
|
|
2283
2530
|
`));
|
|
@@ -2299,8 +2546,8 @@ var RUFF_CONFIGS = ["ruff.toml", ".ruff.toml"];
|
|
|
2299
2546
|
var RUFF_SECTION = /^\[tool\.ruff/m;
|
|
2300
2547
|
var MAX_CHANGED = 30;
|
|
2301
2548
|
async function replaceFile(path, content) {
|
|
2302
|
-
const temporary = `${path}.${
|
|
2303
|
-
await writeFile2(temporary, content, { mode:
|
|
2549
|
+
const temporary = `${path}.${process18.pid}.tmp`;
|
|
2550
|
+
await writeFile2(temporary, content, { mode: statSync2(path).mode & 511 });
|
|
2304
2551
|
await rename(temporary, path);
|
|
2305
2552
|
}
|
|
2306
2553
|
async function projectFixers(dir) {
|
|
@@ -2318,9 +2565,9 @@ async function toolFixers(dir) {
|
|
|
2318
2565
|
const ruff = await firstFile(dir, RUFF_CONFIGS) !== undefined || RUFF_SECTION.test(await read(dir, "pyproject.toml") ?? "");
|
|
2319
2566
|
if (makefile !== undefined) {
|
|
2320
2567
|
fixers.push({ name: "makefile", command: "declare every target .PHONY", source: makefile, write: async (cwd) => {
|
|
2321
|
-
const path =
|
|
2568
|
+
const path = join11(cwd, makefile);
|
|
2322
2569
|
const current = await Bun.file(path).text();
|
|
2323
|
-
const { content, targets } = declarePhony(current, (name) =>
|
|
2570
|
+
const { content, targets } = declarePhony(current, (name) => existsSync4(join11(cwd, name)));
|
|
2324
2571
|
if (content !== current)
|
|
2325
2572
|
await replaceFile(path, content);
|
|
2326
2573
|
return `.PHONY: ${targets.join(" ")}`;
|
|
@@ -2328,9 +2575,9 @@ async function toolFixers(dir) {
|
|
|
2328
2575
|
}
|
|
2329
2576
|
if (justfile !== undefined)
|
|
2330
2577
|
fixers.push({ name: "justfile", command: `just --justfile ${justfile} --fmt`, source: justfile, requires: "just" });
|
|
2331
|
-
if (await Bun.file(
|
|
2578
|
+
if (await Bun.file(join11(dir, "go.mod")).exists())
|
|
2332
2579
|
fixers.push({ name: "go", command: "go fmt ./... && go mod tidy", source: "go.mod", requires: "go" });
|
|
2333
|
-
if (await Bun.file(
|
|
2580
|
+
if (await Bun.file(join11(dir, "Cargo.toml")).exists())
|
|
2334
2581
|
fixers.push({ name: "rust", command: "cargo fmt", source: "Cargo.toml", requires: "cargo" });
|
|
2335
2582
|
if (ruff)
|
|
2336
2583
|
fixers.push({ name: "python", command: "ruff check --fix . && ruff format .", source: "ruff", requires: "ruff" });
|
|
@@ -2371,14 +2618,14 @@ function printChanged(changed) {
|
|
|
2371
2618
|
if (changed.length > MAX_CHANGED)
|
|
2372
2619
|
console.log(` and ${changed.length - MAX_CHANGED} more`);
|
|
2373
2620
|
}
|
|
2374
|
-
async function fix(args, cwd =
|
|
2621
|
+
async function fix(args, cwd = process18.cwd()) {
|
|
2375
2622
|
const parsed = parse(args, fixUsage, fixOptions, { replaces: "running each fixer and formatter by hand, or docker compose exec <service> bun run lint:fix", examples: ["fix", ["fix --list", "the fixers it would run"]] });
|
|
2376
2623
|
return runFixers(parsed.values, cwd);
|
|
2377
2624
|
}
|
|
2378
2625
|
async function runFixers(values, cwd) {
|
|
2379
2626
|
const parsed = { values };
|
|
2380
2627
|
const settings = placeSettings(values);
|
|
2381
|
-
if (
|
|
2628
|
+
if (process18.env[RUNNING] !== undefined)
|
|
2382
2629
|
fail("a fixer called fix again, which would recurse: give its script another command");
|
|
2383
2630
|
const found = await fixers(cwd);
|
|
2384
2631
|
if (found.length === 0)
|
|
@@ -2412,11 +2659,11 @@ async function runFixers(values, cwd) {
|
|
|
2412
2659
|
break;
|
|
2413
2660
|
if (missing(fixer)) {
|
|
2414
2661
|
if (!json)
|
|
2415
|
-
console.log(
|
|
2662
|
+
console.log(`${paint(process18.stdout).yellow("skip ")} ${fixer.name.padEnd(width)} ${fixer.requires} is not installed`);
|
|
2416
2663
|
ran.push({ name: fixer.name, command: fixer.command, skipped: `${fixer.requires} is not installed` });
|
|
2417
2664
|
continue;
|
|
2418
2665
|
}
|
|
2419
|
-
const logFile =
|
|
2666
|
+
const logFile = join11(directory, `fix-${fixer.name.replaceAll(":", "-")}.log`);
|
|
2420
2667
|
const placement = placements.get(fixer);
|
|
2421
2668
|
const down = placement === undefined ? undefined : await stack.problem(placement);
|
|
2422
2669
|
const outcome = down === undefined ? await runFixer(fixer, placement, cwd, logFile, runSettings) : await refusedStep(down, logFile);
|
|
@@ -2445,8 +2692,8 @@ async function runFixers(values, cwd) {
|
|
|
2445
2692
|
}
|
|
2446
2693
|
|
|
2447
2694
|
// src/narrow.ts
|
|
2448
|
-
import { existsSync as
|
|
2449
|
-
import { basename as basename3, dirname as
|
|
2695
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2696
|
+
import { basename as basename3, dirname as dirname5, extname, join as join12 } from "path";
|
|
2450
2697
|
var {$: $2 } = globalThis.Bun;
|
|
2451
2698
|
var LINTERS = /^(?:keslint|eslint|oxlint)\b/;
|
|
2452
2699
|
var LINTABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".svelte"]);
|
|
@@ -2458,17 +2705,17 @@ async function changedPaths(dir) {
|
|
|
2458
2705
|
const untracked = await $2`git ls-files -z --others --exclude-standard`.cwd(dir).quiet().nothrow();
|
|
2459
2706
|
if (tracked.exitCode !== 0 || untracked.exitCode !== 0)
|
|
2460
2707
|
return;
|
|
2461
|
-
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" &&
|
|
2708
|
+
return [...new Set([...tracked.stdout.toString().split("\x00"), ...untracked.stdout.toString().split("\x00")])].filter((path) => path !== "" && existsSync5(join12(dir, path)));
|
|
2462
2709
|
}
|
|
2463
2710
|
function siblingTests(path, exists) {
|
|
2464
2711
|
const extension = extname(path);
|
|
2465
2712
|
const name = basename3(path, extension);
|
|
2466
|
-
const dir =
|
|
2467
|
-
const folders = [dir,
|
|
2713
|
+
const dir = dirname5(path);
|
|
2714
|
+
const folders = [dir, join12(dir, "tests"), join12(dir, "..", "tests"), join12(dir, "__tests__")];
|
|
2468
2715
|
const found = new Set;
|
|
2469
2716
|
for (const folder of folders) {
|
|
2470
2717
|
for (const kind of ["test", "spec"]) {
|
|
2471
|
-
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) =>
|
|
2718
|
+
for (const candidate of [`${name}.${kind}${extension}`, `${name}.${kind}.ts`].map((file) => join12(folder, file))) {
|
|
2472
2719
|
if (exists(candidate))
|
|
2473
2720
|
found.add(candidate);
|
|
2474
2721
|
}
|
|
@@ -2492,7 +2739,7 @@ async function narrow2(step, dir, changed) {
|
|
|
2492
2739
|
if (TEST_FILE.test(path)) {
|
|
2493
2740
|
tests.add(path);
|
|
2494
2741
|
} else {
|
|
2495
|
-
for (const test of siblingTests(path, (candidate) =>
|
|
2742
|
+
for (const test of siblingTests(path, (candidate) => existsSync5(join12(dir, candidate)))) {
|
|
2496
2743
|
tests.add(test);
|
|
2497
2744
|
}
|
|
2498
2745
|
}
|
|
@@ -2559,7 +2806,14 @@ async function narrowed(steps) {
|
|
|
2559
2806
|
function launch(step) {
|
|
2560
2807
|
return step.placement === undefined ? step.command : shellIn(step.placement, step.command);
|
|
2561
2808
|
}
|
|
2562
|
-
|
|
2809
|
+
function summaryLine(outcomes) {
|
|
2810
|
+
const colors = paint(process19.stdout);
|
|
2811
|
+
const failed = outcomes.filter((outcome) => !outcome.ok).length;
|
|
2812
|
+
const passed = outcomes.length - failed;
|
|
2813
|
+
const parts = [colors.green(`${passed} passed`), ...failed === 0 ? [] : [colors.red(`${failed} failed`)], colors.dim(formatDuration(outcomes.reduce((sum, outcome) => sum + outcome.ms, 0)))];
|
|
2814
|
+
return parts.join(colors.dim(" \xB7 "));
|
|
2815
|
+
}
|
|
2816
|
+
async function check(args, cwd = process19.cwd()) {
|
|
2563
2817
|
const parsed = parse(args, usage2, options, { replaces: "chaining docker compose exec <service> bun run check | tail, lint and test by hand, or bun run check && bun run lint && bun run test read through tail", examples: ["check", ["check --only lint,test", "two of the steps"], ["check --in app", "every step inside the app service"]] });
|
|
2564
2818
|
const settings = placeSettings(parsed.values);
|
|
2565
2819
|
if (parsed.values.fix === true) {
|
|
@@ -2570,7 +2824,7 @@ async function check(args, cwd = process15.cwd()) {
|
|
|
2570
2824
|
return runFixers(parsed.values, cwd);
|
|
2571
2825
|
}
|
|
2572
2826
|
const timeoutMs = parsed.values.timeout === undefined ? undefined : duration(parsed.values.timeout, "timeout", 0);
|
|
2573
|
-
if (parsed.values.slot === true && Bun.which("slot", { PATH:
|
|
2827
|
+
if (parsed.values.slot === true && Bun.which("slot", { PATH: process19.env.PATH ?? "" }) === null)
|
|
2574
2828
|
fail("--slot needs the slot bin: bun install -g @kaynooo/cli-wait");
|
|
2575
2829
|
const projects = await discoverProjects(cwd);
|
|
2576
2830
|
const found = projects.flatMap((project) => project.steps.map((step) => ({ ...step, project })));
|
|
@@ -2600,9 +2854,12 @@ async function check(args, cwd = process15.cwd()) {
|
|
|
2600
2854
|
const stack = new Stack;
|
|
2601
2855
|
const width = Math.max(...steps.map((step) => step.label.length));
|
|
2602
2856
|
const outcomes = [];
|
|
2857
|
+
const heading = json ? "" : header("check", `${basename4(cwd)} \xB7 ${steps.length} ${steps.length === 1 ? "step" : "steps"}`, process19.stdout);
|
|
2858
|
+
if (heading !== "")
|
|
2859
|
+
console.log(heading);
|
|
2603
2860
|
try {
|
|
2604
2861
|
for (const step of steps) {
|
|
2605
|
-
const logFile =
|
|
2862
|
+
const logFile = join13(directory, `${step.label.replaceAll("/", "-")}.log`);
|
|
2606
2863
|
const down = step.placement === undefined ? undefined : await stack.problem(step.placement);
|
|
2607
2864
|
const command = parsed.values.slot === true ? slotted(launch(step)) : launch(step);
|
|
2608
2865
|
const outcome = down === undefined ? await runStep(command, step.dir, logFile, { ...timeoutMs === undefined ? {} : { timeoutMs }, held }) : await refusedStep(down, logFile);
|
|
@@ -2615,9 +2872,11 @@ async function check(args, cwd = process15.cwd()) {
|
|
|
2615
2872
|
} finally {
|
|
2616
2873
|
held.release();
|
|
2617
2874
|
}
|
|
2618
|
-
await writeFile3(
|
|
2875
|
+
await writeFile3(join13(directory, RESULTS_FILE), JSON.stringify(outcomes.map(({ name, ok }) => ({ name, ok }))), { mode: 384 });
|
|
2619
2876
|
if (json)
|
|
2620
2877
|
printJson(outcomes);
|
|
2878
|
+
else if (heading !== "")
|
|
2879
|
+
console.log(summaryLine(outcomes));
|
|
2621
2880
|
if (held.signal !== undefined)
|
|
2622
2881
|
return exitCodeOf(null, held.signal);
|
|
2623
2882
|
if (outcomes.some((outcome) => outcome.timedOut === true))
|
|
@@ -2626,4 +2885,4 @@ async function check(args, cwd = process15.cwd()) {
|
|
|
2626
2885
|
}
|
|
2627
2886
|
|
|
2628
2887
|
// src/cli.ts
|
|
2629
|
-
|
|
2888
|
+
process20.exitCode = await runMain({ name: "check", version, run: async (args) => check(args) });
|