@kaynooo/cli-base 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +286 -81
- package/dist/proof-cli.js +284 -79
- package/package.json +2 -2
package/dist/proof-cli.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/proof-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 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
13
|
// ../kit/src/mode.ts
|
|
14
14
|
import process2 from "process";
|
|
@@ -29,7 +29,7 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
|
-
import
|
|
32
|
+
import process6 from "process";
|
|
33
33
|
|
|
34
34
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
35
35
|
function x(s) {
|
|
@@ -293,17 +293,220 @@ function le(i = {}) {
|
|
|
293
293
|
var t = le();
|
|
294
294
|
|
|
295
295
|
// ../kit/src/theme.ts
|
|
296
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
297
|
+
import { homedir as homedir2 } from "os";
|
|
298
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
299
|
+
import process5 from "process";
|
|
300
|
+
|
|
301
|
+
// ../kit/src/config.ts
|
|
302
|
+
import { existsSync } from "fs";
|
|
303
|
+
import { dirname, join, resolve } from "path";
|
|
304
|
+
import process3 from "process";
|
|
305
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
306
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
307
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
308
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
309
|
+
if (found !== undefined)
|
|
310
|
+
return found;
|
|
311
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ../kit/src/user-config.ts
|
|
317
|
+
import { homedir } from "os";
|
|
318
|
+
import { join as join2 } from "path";
|
|
319
|
+
import process4 from "process";
|
|
320
|
+
function configBase(where = {}) {
|
|
321
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
322
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
323
|
+
}
|
|
324
|
+
function userConfigPath(bin, where = {}) {
|
|
325
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ../kit/src/theme.ts
|
|
329
|
+
var DEFAULT = {
|
|
330
|
+
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" },
|
|
331
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
|
|
332
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
333
|
+
bins: {}
|
|
334
|
+
};
|
|
335
|
+
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" };
|
|
336
|
+
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" };
|
|
337
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
|
|
338
|
+
var PRESETS = {
|
|
339
|
+
default: {},
|
|
340
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
341
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
342
|
+
ascii: { glyphs: ASCII }
|
|
343
|
+
};
|
|
296
344
|
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"]);
|
|
345
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
346
|
+
var CONTROL = /\p{Cc}/u;
|
|
297
347
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
348
|
+
var SPACES = /\s+/;
|
|
349
|
+
function isColorSpec(spec) {
|
|
350
|
+
if (typeof spec === "number")
|
|
351
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
352
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
353
|
+
}
|
|
354
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
355
|
+
function cubeLevel(channel) {
|
|
356
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
357
|
+
}
|
|
358
|
+
function nearest256(hex) {
|
|
359
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
360
|
+
const levels = rgb.map(cubeLevel);
|
|
361
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
362
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
363
|
+
const greyValue = 8 + grey * 10;
|
|
364
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
365
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
366
|
+
}
|
|
367
|
+
function hasTrueColor(env) {
|
|
368
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
369
|
+
}
|
|
370
|
+
function tinted(colors, spec, env = process5.env) {
|
|
371
|
+
if (typeof spec === "number")
|
|
372
|
+
return colors.ansi256(spec);
|
|
373
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
374
|
+
if (HEX.test(token))
|
|
375
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
376
|
+
return chain[token] ?? chain;
|
|
377
|
+
}, colors);
|
|
378
|
+
}
|
|
379
|
+
function isRecord(value) {
|
|
380
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
381
|
+
}
|
|
382
|
+
function readThemeFile(path, warn) {
|
|
383
|
+
try {
|
|
384
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
385
|
+
if (stat === undefined)
|
|
386
|
+
return;
|
|
387
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
388
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
392
|
+
if (isRecord(parsed))
|
|
393
|
+
return parsed;
|
|
394
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
function applyPreset(theme, name, warn, where) {
|
|
401
|
+
if (name === undefined)
|
|
402
|
+
return;
|
|
403
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
404
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const preset = PRESETS[name];
|
|
408
|
+
Object.assign(theme.colors, preset.colors);
|
|
409
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
410
|
+
if (preset.accents !== undefined)
|
|
411
|
+
theme.accents = [...preset.accents];
|
|
412
|
+
return name;
|
|
413
|
+
}
|
|
414
|
+
function applyFile(theme, file, where, warn) {
|
|
415
|
+
if (isRecord(file.colors)) {
|
|
416
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
417
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
418
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
419
|
+
else if (!isColorSpec(value))
|
|
420
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
421
|
+
else
|
|
422
|
+
theme.colors[key] = value;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (isRecord(file.glyphs)) {
|
|
426
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
427
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
428
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
429
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
430
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
431
|
+
else
|
|
432
|
+
theme.glyphs[key] = value;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
436
|
+
theme.accents = [...file.accents];
|
|
437
|
+
else if (file.accents !== undefined)
|
|
438
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
439
|
+
if (isRecord(file.bins)) {
|
|
440
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
441
|
+
if (isColorSpec(value))
|
|
442
|
+
theme.bins[bin] = value;
|
|
443
|
+
else
|
|
444
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function endsWalk(home) {
|
|
449
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
450
|
+
}
|
|
298
451
|
var warned = new Set;
|
|
452
|
+
function warnOnce(message) {
|
|
453
|
+
if (warned.has(message))
|
|
454
|
+
return;
|
|
455
|
+
warned.add(message);
|
|
456
|
+
console.error(`warning: theme ${message}`);
|
|
457
|
+
}
|
|
458
|
+
function isPath(chosen) {
|
|
459
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
460
|
+
}
|
|
461
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
462
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
463
|
+
const sources = [];
|
|
464
|
+
const chosen = env.KIT_THEME ?? "";
|
|
465
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
466
|
+
if (isPath(chosen))
|
|
467
|
+
wanted.push(resolve2(from, chosen));
|
|
468
|
+
const files = [];
|
|
469
|
+
for (const path of wanted) {
|
|
470
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
471
|
+
if (path !== undefined && file !== undefined)
|
|
472
|
+
files.push({ path, file });
|
|
473
|
+
}
|
|
474
|
+
let preset = "default";
|
|
475
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
476
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
477
|
+
} else {
|
|
478
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
479
|
+
if (named !== undefined)
|
|
480
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
481
|
+
}
|
|
482
|
+
for (const { path, file } of files) {
|
|
483
|
+
applyFile(theme, file, path, warn);
|
|
484
|
+
sources.push(path);
|
|
485
|
+
}
|
|
486
|
+
return { theme, sources, preset };
|
|
487
|
+
}
|
|
488
|
+
var current;
|
|
489
|
+
var currentKey = "";
|
|
490
|
+
function activeTheme() {
|
|
491
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
492
|
+
if (current === undefined || key !== currentKey) {
|
|
493
|
+
current = loadTheme();
|
|
494
|
+
currentKey = key;
|
|
495
|
+
}
|
|
496
|
+
return current;
|
|
497
|
+
}
|
|
299
498
|
|
|
300
499
|
// ../kit/src/style.ts
|
|
301
|
-
function takesControlCodes(stream, env =
|
|
500
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
302
501
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
303
502
|
}
|
|
304
|
-
function paint(stream, env =
|
|
503
|
+
function paint(stream, env = process6.env) {
|
|
305
504
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
306
505
|
}
|
|
506
|
+
function role(name, stream, env = process6.env) {
|
|
507
|
+
const colors = paint(stream, env);
|
|
508
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
509
|
+
}
|
|
307
510
|
var STATUS_WORDS = {
|
|
308
511
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
309
512
|
failed: ["failed", "failure", "error", "errored"],
|
|
@@ -319,7 +522,7 @@ function upTo(text, separator) {
|
|
|
319
522
|
return end === -1 ? text : text.slice(0, end);
|
|
320
523
|
}
|
|
321
524
|
var ESCAPE = String.fromCharCode(27);
|
|
322
|
-
function jsonText(value, replacer, { stream =
|
|
525
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
323
526
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
324
527
|
}
|
|
325
528
|
function printJson(value) {
|
|
@@ -327,27 +530,27 @@ function printJson(value) {
|
|
|
327
530
|
}
|
|
328
531
|
|
|
329
532
|
// ../kit/src/help.ts
|
|
330
|
-
import
|
|
533
|
+
import process8 from "process";
|
|
331
534
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
332
535
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
333
536
|
var FULL_STOP = /\.$/;
|
|
334
|
-
function usageLine(usage, colors = paint(
|
|
537
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
335
538
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
336
539
|
}
|
|
337
|
-
function helpText(usage, options, colors = paint(
|
|
540
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
338
541
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
339
542
|
`);
|
|
340
543
|
}
|
|
341
|
-
function exitRows(exits, colors = paint(
|
|
544
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
342
545
|
if (exits.length === 0)
|
|
343
546
|
return [];
|
|
344
547
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
345
548
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
346
549
|
}
|
|
347
|
-
function replacesRows(replaces, colors = paint(
|
|
550
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
348
551
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
349
552
|
}
|
|
350
|
-
function wantsHelpJson(env =
|
|
553
|
+
function wantsHelpJson(env = process8.env) {
|
|
351
554
|
return env.KIT_HELP === "json";
|
|
352
555
|
}
|
|
353
556
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -366,12 +569,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
366
569
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
367
570
|
};
|
|
368
571
|
}
|
|
369
|
-
function exampleRows(examples, colors = paint(
|
|
572
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
370
573
|
if (examples.length === 0 || outputMode() === "agent")
|
|
371
574
|
return [];
|
|
372
575
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
373
576
|
}
|
|
374
|
-
function optionRows(options, colors = paint(
|
|
577
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
375
578
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
376
579
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
377
580
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -461,7 +664,7 @@ var OUTPUT_OPTIONS = {
|
|
|
461
664
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
462
665
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
463
666
|
};
|
|
464
|
-
function applyOutput(color, plain, env =
|
|
667
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
465
668
|
const when = plain === true ? "never" : color ?? "auto";
|
|
466
669
|
if (when === "auto")
|
|
467
670
|
return;
|
|
@@ -632,7 +835,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
632
835
|
}
|
|
633
836
|
// ../kit/src/process.ts
|
|
634
837
|
import { constants } from "os";
|
|
635
|
-
import
|
|
838
|
+
import process10 from "process";
|
|
636
839
|
var KILL_GRACE_MS = 2000;
|
|
637
840
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
638
841
|
function exitCodeOf(code, signal) {
|
|
@@ -654,7 +857,7 @@ function holdSignals(cleanup) {
|
|
|
654
857
|
},
|
|
655
858
|
release: () => {
|
|
656
859
|
for (const signal of SIGNALS)
|
|
657
|
-
|
|
860
|
+
process10.off(signal, onSignal);
|
|
658
861
|
}
|
|
659
862
|
};
|
|
660
863
|
function onSignal(signal) {
|
|
@@ -667,10 +870,10 @@ function holdSignals(cleanup) {
|
|
|
667
870
|
return;
|
|
668
871
|
held.release();
|
|
669
872
|
cleanup(signal);
|
|
670
|
-
|
|
873
|
+
process10.kill(process10.pid, signal);
|
|
671
874
|
}
|
|
672
875
|
for (const signal of SIGNALS)
|
|
673
|
-
|
|
876
|
+
process10.on(signal, onSignal);
|
|
674
877
|
return held;
|
|
675
878
|
}
|
|
676
879
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -684,7 +887,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
684
887
|
return;
|
|
685
888
|
try {
|
|
686
889
|
if (grouped)
|
|
687
|
-
|
|
890
|
+
process10.kill(-proc.pid, killing);
|
|
688
891
|
else
|
|
689
892
|
proc.kill(killing);
|
|
690
893
|
} catch {}
|
|
@@ -758,15 +961,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
758
961
|
var RESET_STYLE = `${ESC}[0m`;
|
|
759
962
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
760
963
|
// ../kit/src/cli.ts
|
|
761
|
-
import { readFileSync, realpathSync } from "fs";
|
|
762
|
-
import { dirname as
|
|
763
|
-
import
|
|
964
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
965
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
966
|
+
import process12 from "process";
|
|
764
967
|
|
|
765
968
|
// ../kit/src/usage.ts
|
|
766
969
|
import { appendFileSync, mkdirSync } from "fs";
|
|
767
|
-
import { homedir } from "os";
|
|
768
|
-
import { dirname, isAbsolute, join } from "path";
|
|
769
|
-
import
|
|
970
|
+
import { homedir as homedir3 } from "os";
|
|
971
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
972
|
+
import process11 from "process";
|
|
770
973
|
|
|
771
974
|
// ../kit/src/logs.ts
|
|
772
975
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -780,14 +983,14 @@ var usageError;
|
|
|
780
983
|
function noteUsageError(message) {
|
|
781
984
|
usageError = message;
|
|
782
985
|
}
|
|
783
|
-
function stateHome(env =
|
|
986
|
+
function stateHome(env = process11.env) {
|
|
784
987
|
const dir = env.XDG_STATE_HOME;
|
|
785
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
988
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
786
989
|
}
|
|
787
|
-
function usagePath(env =
|
|
788
|
-
return
|
|
990
|
+
function usagePath(env = process11.env) {
|
|
991
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
789
992
|
}
|
|
790
|
-
function usageRecorded(env =
|
|
993
|
+
function usageRecorded(env = process11.env) {
|
|
791
994
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
792
995
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
793
996
|
}
|
|
@@ -801,12 +1004,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
801
1004
|
usageError = undefined;
|
|
802
1005
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
803
1006
|
}
|
|
804
|
-
function recordUsage(entry, env =
|
|
1007
|
+
function recordUsage(entry, env = process11.env) {
|
|
805
1008
|
if (!usageRecorded(env))
|
|
806
1009
|
return;
|
|
807
1010
|
try {
|
|
808
1011
|
const path = usagePath(env);
|
|
809
|
-
mkdirSync(
|
|
1012
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
810
1013
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
811
1014
|
`, { mode: 384 });
|
|
812
1015
|
} catch {}
|
|
@@ -892,8 +1095,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
892
1095
|
`);
|
|
893
1096
|
}
|
|
894
1097
|
function printError(prefix, message, hint, cause) {
|
|
895
|
-
const colors = paint(
|
|
896
|
-
const styled = takesControlCodes(
|
|
1098
|
+
const colors = paint(process12.stderr);
|
|
1099
|
+
const styled = takesControlCodes(process12.stderr);
|
|
897
1100
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
898
1101
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
899
1102
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -936,11 +1139,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
936
1139
|
}
|
|
937
1140
|
}
|
|
938
1141
|
if (name === undefined && level.path.length > 1) {
|
|
939
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1142
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
|
|
940
1143
|
return 2;
|
|
941
1144
|
}
|
|
942
1145
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
943
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1146
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
|
|
944
1147
|
return 0;
|
|
945
1148
|
}
|
|
946
1149
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1057,17 +1260,17 @@ async function printCandidates(found) {
|
|
|
1057
1260
|
return 0;
|
|
1058
1261
|
}
|
|
1059
1262
|
function packageVersion(entry = Bun.main) {
|
|
1060
|
-
for (let dir =
|
|
1263
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1061
1264
|
try {
|
|
1062
|
-
const { version } = JSON.parse(
|
|
1265
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1063
1266
|
if (typeof version === "string")
|
|
1064
1267
|
return version;
|
|
1065
1268
|
} catch {}
|
|
1066
|
-
if (
|
|
1269
|
+
if (dirname3(dir) === dir)
|
|
1067
1270
|
return "0.0.0";
|
|
1068
1271
|
}
|
|
1069
1272
|
}
|
|
1070
|
-
async function runCli(cli, argv =
|
|
1273
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
1071
1274
|
const version = cli.version ?? packageVersion();
|
|
1072
1275
|
if (argv[0] === COMPLETE)
|
|
1073
1276
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1094,7 +1297,7 @@ function commandPath(scope, argv) {
|
|
|
1094
1297
|
}
|
|
1095
1298
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1096
1299
|
}
|
|
1097
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1300
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
1098
1301
|
if (argv[0] === COMPLETE)
|
|
1099
1302
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1100
1303
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1114,6 +1317,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
|
|
|
1114
1317
|
}
|
|
1115
1318
|
return code;
|
|
1116
1319
|
}
|
|
1320
|
+
// ../kit/src/folders.ts
|
|
1321
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1117
1322
|
// ../kit/src/secrets.ts
|
|
1118
1323
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1119
1324
|
// ../kit/src/sessions.ts
|
|
@@ -1121,13 +1326,13 @@ var {Glob } = globalThis.Bun;
|
|
|
1121
1326
|
var SESSION_FILES = new Glob("*.json");
|
|
1122
1327
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1123
1328
|
// src/proof.ts
|
|
1124
|
-
import
|
|
1329
|
+
import process15 from "process";
|
|
1125
1330
|
|
|
1126
1331
|
// src/worktree.ts
|
|
1127
|
-
import { cpSync, existsSync, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
|
|
1332
|
+
import { cpSync, existsSync as existsSync3, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync2, rmSync, symlinkSync, unlinkSync } from "fs";
|
|
1128
1333
|
import { tmpdir } from "os";
|
|
1129
|
-
import { basename, dirname as
|
|
1130
|
-
import
|
|
1334
|
+
import { basename, dirname as dirname4, isAbsolute as isAbsolute2, join as join6, relative, resolve as resolve3, sep } from "path";
|
|
1335
|
+
import process14 from "process";
|
|
1131
1336
|
var WHITESPACE = /\s/;
|
|
1132
1337
|
var ORIGIN_PREFIX = /^origin\//;
|
|
1133
1338
|
var ENV_FILE = /^\.env(?:\..+)?$/;
|
|
@@ -1175,21 +1380,21 @@ async function defaultProofRef(root) {
|
|
|
1175
1380
|
function keptPaths(root, cwd, paths) {
|
|
1176
1381
|
const realRoot = realpathSync2(root);
|
|
1177
1382
|
return paths.map((path) => {
|
|
1178
|
-
const absolute =
|
|
1179
|
-
if (!
|
|
1383
|
+
const absolute = resolve3(cwd, path);
|
|
1384
|
+
if (!existsSync3(dirname4(absolute)))
|
|
1180
1385
|
fail(`--keep ${path}: no such file`);
|
|
1181
|
-
const inRepo = relative(realRoot,
|
|
1386
|
+
const inRepo = relative(realRoot, join6(realpathSync2(dirname4(absolute)), basename(absolute)));
|
|
1182
1387
|
if (inRepo === "" || inRepo === ".." || inRepo.startsWith(PARENT) || isAbsolute2(inRepo))
|
|
1183
1388
|
fail(`--keep ${path} is outside the repository`);
|
|
1184
|
-
if (!
|
|
1389
|
+
if (!existsSync3(absolute))
|
|
1185
1390
|
fail(`--keep ${path}: no such file`);
|
|
1186
1391
|
return inRepo;
|
|
1187
1392
|
});
|
|
1188
1393
|
}
|
|
1189
1394
|
function checkNoSymlink(dir, path) {
|
|
1190
1395
|
let current = dir;
|
|
1191
|
-
for (const part of
|
|
1192
|
-
current =
|
|
1396
|
+
for (const part of dirname4(path).split(sep)) {
|
|
1397
|
+
current = join6(current, part);
|
|
1193
1398
|
if (lstatSync(current, { throwIfNoEntry: false })?.isSymbolicLink() === true)
|
|
1194
1399
|
fail(`--keep ${path} goes through the symlink ${relative(dir, current)} of the ref, which would write outside the worktree`);
|
|
1195
1400
|
}
|
|
@@ -1205,10 +1410,10 @@ async function linkedEntries(root) {
|
|
|
1205
1410
|
}).map((entry) => entry.replace(TRAILING_SLASH, ""));
|
|
1206
1411
|
}
|
|
1207
1412
|
async function addWorktree(root, sha) {
|
|
1208
|
-
const dir =
|
|
1413
|
+
const dir = join6(mkdtempSync(join6(tmpdir(), "base-")), basename(root));
|
|
1209
1414
|
const ran = await git2(["worktree", "add", "--detach", dir, sha], root);
|
|
1210
1415
|
if (ran.code !== 0) {
|
|
1211
|
-
rmSync(
|
|
1416
|
+
rmSync(dirname4(dir), { recursive: true, force: true });
|
|
1212
1417
|
fail(`git worktree add failed:
|
|
1213
1418
|
${ran.text.trim()}`);
|
|
1214
1419
|
}
|
|
@@ -1217,41 +1422,41 @@ ${ran.text.trim()}`);
|
|
|
1217
1422
|
function copyKept(root, dir, paths) {
|
|
1218
1423
|
for (const path of paths) {
|
|
1219
1424
|
checkNoSymlink(dir, path);
|
|
1220
|
-
const target =
|
|
1425
|
+
const target = join6(dir, path);
|
|
1221
1426
|
rmSync(target, { recursive: true, force: true });
|
|
1222
|
-
mkdirSync2(
|
|
1223
|
-
cpSync(
|
|
1427
|
+
mkdirSync2(dirname4(target), { recursive: true });
|
|
1428
|
+
cpSync(join6(root, path), target, { recursive: true });
|
|
1224
1429
|
}
|
|
1225
1430
|
}
|
|
1226
1431
|
function linkEntries(root, dir, entries) {
|
|
1227
1432
|
const links = [];
|
|
1228
1433
|
for (const entry of entries) {
|
|
1229
|
-
const link =
|
|
1230
|
-
if (
|
|
1434
|
+
const link = join6(dir, entry);
|
|
1435
|
+
if (existsSync3(link))
|
|
1231
1436
|
continue;
|
|
1232
|
-
mkdirSync2(
|
|
1437
|
+
mkdirSync2(dirname4(link), { recursive: true });
|
|
1233
1438
|
if (basename(entry) === "node_modules" && hasWorkspaceLinks(root, entry)) {
|
|
1234
1439
|
links.push(...linkModules(root, dir, entry));
|
|
1235
1440
|
continue;
|
|
1236
1441
|
}
|
|
1237
|
-
symlinkSync(
|
|
1442
|
+
symlinkSync(join6(root, entry), link);
|
|
1238
1443
|
links.push(link);
|
|
1239
1444
|
}
|
|
1240
1445
|
return links;
|
|
1241
1446
|
}
|
|
1242
1447
|
function moduleLinks(root, folder) {
|
|
1243
1448
|
const found = [];
|
|
1244
|
-
for (const entry of readdirSync(
|
|
1449
|
+
for (const entry of readdirSync(join6(root, folder), { withFileTypes: true })) {
|
|
1245
1450
|
if (entry.isSymbolicLink())
|
|
1246
|
-
found.push({ path:
|
|
1451
|
+
found.push({ path: join6(folder, entry.name), name: entry.name });
|
|
1247
1452
|
else if (entry.isDirectory() && entry.name.startsWith("@"))
|
|
1248
|
-
found.push(...moduleLinks(root,
|
|
1453
|
+
found.push(...moduleLinks(root, join6(folder, entry.name)));
|
|
1249
1454
|
}
|
|
1250
1455
|
return found;
|
|
1251
1456
|
}
|
|
1252
1457
|
function workspaceTarget(root, path) {
|
|
1253
1458
|
try {
|
|
1254
|
-
const inRepo = relative(realpathSync2(root), realpathSync2(
|
|
1459
|
+
const inRepo = relative(realpathSync2(root), realpathSync2(join6(root, path)));
|
|
1255
1460
|
return inRepo === "" || inRepo.startsWith(PARENT) || inRepo.split(sep).includes("node_modules") ? undefined : inRepo;
|
|
1256
1461
|
} catch {
|
|
1257
1462
|
return;
|
|
@@ -1262,16 +1467,16 @@ function hasWorkspaceLinks(root, folder) {
|
|
|
1262
1467
|
}
|
|
1263
1468
|
function linkModules(root, dir, folder) {
|
|
1264
1469
|
const links = [];
|
|
1265
|
-
mkdirSync2(
|
|
1266
|
-
for (const entry of readdirSync(
|
|
1267
|
-
const path =
|
|
1268
|
-
const link =
|
|
1470
|
+
mkdirSync2(join6(dir, folder), { recursive: true });
|
|
1471
|
+
for (const entry of readdirSync(join6(root, folder), { withFileTypes: true })) {
|
|
1472
|
+
const path = join6(folder, entry.name);
|
|
1473
|
+
const link = join6(dir, path);
|
|
1269
1474
|
if (entry.isDirectory() && entry.name.startsWith("@")) {
|
|
1270
1475
|
links.push(...linkModules(root, dir, path));
|
|
1271
1476
|
continue;
|
|
1272
1477
|
}
|
|
1273
1478
|
const workspace = entry.isSymbolicLink() ? workspaceTarget(root, path) : undefined;
|
|
1274
|
-
symlinkSync(workspace === undefined ?
|
|
1479
|
+
symlinkSync(workspace === undefined ? join6(root, path) : join6(dir, workspace), link);
|
|
1275
1480
|
links.push(link);
|
|
1276
1481
|
}
|
|
1277
1482
|
return links;
|
|
@@ -1281,9 +1486,9 @@ async function sweepStale(root) {
|
|
|
1281
1486
|
for (const name of readdirSync(tmpdir())) {
|
|
1282
1487
|
if (!BASE_DIR.test(name))
|
|
1283
1488
|
continue;
|
|
1284
|
-
const path =
|
|
1489
|
+
const path = join6(tmpdir(), name);
|
|
1285
1490
|
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
1286
|
-
if (stat?.isDirectory() === true && stat.uid ===
|
|
1491
|
+
if (stat?.isDirectory() === true && stat.uid === process14.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
|
|
1287
1492
|
rmSync(path, { recursive: true, force: true });
|
|
1288
1493
|
}
|
|
1289
1494
|
await git2(["worktree", "prune"], root);
|
|
@@ -1294,7 +1499,7 @@ async function removeWorktree(root, dir, links) {
|
|
|
1294
1499
|
unlinkSync(link);
|
|
1295
1500
|
}
|
|
1296
1501
|
await git2(["worktree", "remove", "--force", dir], root);
|
|
1297
|
-
rmSync(
|
|
1502
|
+
rmSync(dirname4(dir), { recursive: true, force: true });
|
|
1298
1503
|
await git2(["worktree", "prune"], root);
|
|
1299
1504
|
}
|
|
1300
1505
|
function shellCommand(given) {
|
|
@@ -1342,8 +1547,8 @@ async function inWorktree(options, body) {
|
|
|
1342
1547
|
try {
|
|
1343
1548
|
copyKept(root, dir, kept);
|
|
1344
1549
|
links = link ? linkEntries(root, dir, await linkedEntries(root)) : [];
|
|
1345
|
-
const runDir =
|
|
1346
|
-
if (!
|
|
1550
|
+
const runDir = join6(dir, prefix);
|
|
1551
|
+
if (!existsSync3(runDir))
|
|
1347
1552
|
fail(`${prefix} does not exist at ${ref}`);
|
|
1348
1553
|
return await body(runDir, signals);
|
|
1349
1554
|
} finally {
|
|
@@ -1403,7 +1608,7 @@ ${USAGE}`);
|
|
|
1403
1608
|
if (runsInContainer(given))
|
|
1404
1609
|
fail("a container of the compose project mounts the main checkout, not the temporary worktree, so the command would not run at the ref: run the tool on the host, or check the ref out by hand");
|
|
1405
1610
|
const command = shellCommand(given);
|
|
1406
|
-
const cwd =
|
|
1611
|
+
const cwd = process15.cwd();
|
|
1407
1612
|
const { root, prefix } = await checkout(cwd);
|
|
1408
1613
|
const runs = wholeNumber(parsed.values.runs, "runs", 1, 1);
|
|
1409
1614
|
const ref = parsed.values.ref ?? await defaultProofRef(root);
|
|
@@ -1438,7 +1643,7 @@ ${folded(run.output)}`}`);
|
|
|
1438
1643
|
printJson({ outcome, proved, ref, sha, before: { code: before.code, output: before.output }, now: { code: now.code, output: now.output }, runs: nowRuns.map((run) => ({ code: run.code })) });
|
|
1439
1644
|
return proved ? 0 : 1;
|
|
1440
1645
|
}
|
|
1441
|
-
console.log(message);
|
|
1646
|
+
console.log(role(proved ? "ok" : "problem", process15.stdout)(message));
|
|
1442
1647
|
if (runs > 1)
|
|
1443
1648
|
console.log(`now: ${codes.map((code, i) => `run ${i + 1} ${code === 0 ? "passed" : `failed (exit ${code})`}`).join(", ")}`);
|
|
1444
1649
|
const shown = side === "before" ? before : now;
|
|
@@ -1449,4 +1654,4 @@ ${folded(shown.output)}`);
|
|
|
1449
1654
|
}
|
|
1450
1655
|
|
|
1451
1656
|
// src/proof-cli.ts
|
|
1452
|
-
|
|
1657
|
+
process16.exitCode = await runMain({ name: "proof", run: proof });
|