@kaynooo/cli-code 0.10.0 → 0.12.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 +144 -71
- package/dist/hotspots-cli.js +133 -60
- package/dist/peek-cli.js +136 -64
- package/dist/todo-scan-cli.js +129 -57
- package/package.json +2 -2
package/dist/peek-cli.js
CHANGED
|
@@ -2,16 +2,36 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/peek-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process15 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
|
+
|
|
13
|
+
// ../kit/src/mode.ts
|
|
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
|
+
}
|
|
12
30
|
|
|
13
31
|
// ../kit/src/style.ts
|
|
14
|
-
import
|
|
32
|
+
import { resolve as resolve3 } from "path";
|
|
33
|
+
import process6 from "process";
|
|
34
|
+
import { pathToFileURL } from "url";
|
|
15
35
|
|
|
16
36
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
37
|
function x(s) {
|
|
@@ -278,13 +298,13 @@ var t = le();
|
|
|
278
298
|
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
279
299
|
import { homedir as homedir2 } from "os";
|
|
280
300
|
import { join as join3, resolve as resolve2 } from "path";
|
|
281
|
-
import
|
|
301
|
+
import process5 from "process";
|
|
282
302
|
|
|
283
303
|
// ../kit/src/config.ts
|
|
284
304
|
import { existsSync } from "fs";
|
|
285
305
|
import { dirname, join, resolve } from "path";
|
|
286
|
-
import
|
|
287
|
-
function findUp(names, from =
|
|
306
|
+
import process3 from "process";
|
|
307
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
288
308
|
const wanted = typeof names === "string" ? [names] : names;
|
|
289
309
|
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
290
310
|
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
@@ -298,9 +318,9 @@ function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
|
298
318
|
// ../kit/src/user-config.ts
|
|
299
319
|
import { homedir } from "os";
|
|
300
320
|
import { join as join2 } from "path";
|
|
301
|
-
import
|
|
321
|
+
import process4 from "process";
|
|
302
322
|
function configBase(where = {}) {
|
|
303
|
-
const xdg = where.xdg ?? (where.home === undefined ?
|
|
323
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
304
324
|
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
305
325
|
}
|
|
306
326
|
function userConfigPath(bin, where = {}) {
|
|
@@ -310,13 +330,13 @@ function userConfigPath(bin, where = {}) {
|
|
|
310
330
|
// ../kit/src/theme.ts
|
|
311
331
|
var DEFAULT = {
|
|
312
332
|
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" },
|
|
313
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
333
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
|
|
314
334
|
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
315
335
|
bins: {}
|
|
316
336
|
};
|
|
317
337
|
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" };
|
|
318
338
|
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" };
|
|
319
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
339
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
|
|
320
340
|
var PRESETS = {
|
|
321
341
|
default: {},
|
|
322
342
|
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
@@ -333,10 +353,30 @@ function isColorSpec(spec) {
|
|
|
333
353
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
334
354
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
335
355
|
}
|
|
336
|
-
|
|
356
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
357
|
+
function cubeLevel(channel) {
|
|
358
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
359
|
+
}
|
|
360
|
+
function nearest256(hex) {
|
|
361
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
362
|
+
const levels = rgb.map(cubeLevel);
|
|
363
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
364
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
365
|
+
const greyValue = 8 + grey * 10;
|
|
366
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
367
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
368
|
+
}
|
|
369
|
+
function hasTrueColor(env) {
|
|
370
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
371
|
+
}
|
|
372
|
+
function tinted(colors, spec, env = process5.env) {
|
|
337
373
|
if (typeof spec === "number")
|
|
338
374
|
return colors.ansi256(spec);
|
|
339
|
-
return spec.trim().split(SPACES).reduce((chain, token) =>
|
|
375
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
376
|
+
if (HEX.test(token))
|
|
377
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
378
|
+
return chain[token] ?? chain;
|
|
379
|
+
}, colors);
|
|
340
380
|
}
|
|
341
381
|
function isRecord(value) {
|
|
342
382
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -420,7 +460,7 @@ function warnOnce(message) {
|
|
|
420
460
|
function isPath(chosen) {
|
|
421
461
|
return chosen.includes("/") || chosen.endsWith(".json");
|
|
422
462
|
}
|
|
423
|
-
function loadTheme({ env =
|
|
463
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
424
464
|
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
425
465
|
const sources = [];
|
|
426
466
|
const chosen = env.KIT_THEME ?? "";
|
|
@@ -450,7 +490,7 @@ function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(
|
|
|
450
490
|
var current;
|
|
451
491
|
var currentKey = "";
|
|
452
492
|
function activeTheme() {
|
|
453
|
-
const key = `${
|
|
493
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
454
494
|
if (current === undefined || key !== currentKey) {
|
|
455
495
|
current = loadTheme();
|
|
456
496
|
currentKey = key;
|
|
@@ -460,36 +500,62 @@ function activeTheme() {
|
|
|
460
500
|
|
|
461
501
|
// ../kit/src/style.ts
|
|
462
502
|
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
463
|
-
function takesControlCodes(stream, env =
|
|
464
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
503
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
504
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
465
505
|
}
|
|
466
|
-
function paint(stream, env =
|
|
506
|
+
function paint(stream, env = process6.env) {
|
|
467
507
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
468
508
|
}
|
|
469
|
-
function marked(mark, text, stream, detail, env =
|
|
509
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
470
510
|
const colors = paint(stream, env);
|
|
471
511
|
let head = MARK_WORDS[mark];
|
|
472
512
|
if (takesControlCodes(stream, env)) {
|
|
473
513
|
const { theme } = activeTheme();
|
|
474
|
-
head = tinted(colors.bold, theme.colors[mark])(theme.glyphs[mark]);
|
|
514
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
475
515
|
}
|
|
476
516
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
477
517
|
}
|
|
478
518
|
function warn(text, detail) {
|
|
479
|
-
console.error(marked("warn", text,
|
|
519
|
+
console.error(marked("warn", text, process6.stderr, detail));
|
|
480
520
|
}
|
|
481
|
-
function role(name, stream, env =
|
|
521
|
+
function role(name, stream, env = process6.env) {
|
|
482
522
|
const colors = paint(stream, env);
|
|
483
|
-
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
|
|
523
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
484
524
|
}
|
|
485
525
|
var STATUS_WORDS = {
|
|
486
526
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
487
527
|
failed: ["failed", "failure", "error", "errored"],
|
|
488
|
-
running: ["running", "in_progress", "started"],
|
|
528
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
489
529
|
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
490
530
|
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
491
531
|
};
|
|
492
532
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
533
|
+
function header(bin, context, stream, env = process6.env) {
|
|
534
|
+
if (!takesControlCodes(stream, env))
|
|
535
|
+
return "";
|
|
536
|
+
const colors = paint(stream, env);
|
|
537
|
+
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
538
|
+
const { theme } = activeTheme();
|
|
539
|
+
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
540
|
+
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
541
|
+
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
542
|
+
}
|
|
543
|
+
function link(text, url, stream, env = process6.env) {
|
|
544
|
+
if (takesControlCodes(stream, env))
|
|
545
|
+
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
|
|
546
|
+
return text === url ? text : `${text} (${url})`;
|
|
547
|
+
}
|
|
548
|
+
function printHeader(bin, context, stream = process6.stdout, env = process6.env) {
|
|
549
|
+
const line = header(bin, context, stream, env);
|
|
550
|
+
if (line !== "")
|
|
551
|
+
console.log(line);
|
|
552
|
+
}
|
|
553
|
+
function hyperlink(text, url, stream, env = process6.env) {
|
|
554
|
+
return takesControlCodes(stream, env) ? link(text, url, stream, env) : text;
|
|
555
|
+
}
|
|
556
|
+
function fileLink(text, path, stream, from = process6.cwd(), env = process6.env) {
|
|
557
|
+
return hyperlink(text, pathToFileURL(resolve3(from, path)).href, stream, env);
|
|
558
|
+
}
|
|
493
559
|
|
|
494
560
|
// ../kit/src/format.ts
|
|
495
561
|
function upTo(text, separator) {
|
|
@@ -504,8 +570,11 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
504
570
|
function textWidth(text) {
|
|
505
571
|
return Bun.stringWidth(text);
|
|
506
572
|
}
|
|
507
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream =
|
|
573
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
508
574
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
575
|
+
if (outputMode(stream, env) === "agent")
|
|
576
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
577
|
+
`);
|
|
509
578
|
const widths = [];
|
|
510
579
|
for (const row of cells) {
|
|
511
580
|
for (const [index, cell] of row.entries())
|
|
@@ -540,32 +609,35 @@ function narrow(rows, widths, limit) {
|
|
|
540
609
|
}
|
|
541
610
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
542
611
|
}
|
|
612
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
613
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
614
|
+
}
|
|
543
615
|
function printJson(value) {
|
|
544
|
-
console.log(
|
|
616
|
+
console.log(jsonText(value));
|
|
545
617
|
}
|
|
546
618
|
|
|
547
619
|
// ../kit/src/help.ts
|
|
548
|
-
import
|
|
620
|
+
import process8 from "process";
|
|
549
621
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
550
622
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
551
623
|
var FULL_STOP = /\.$/;
|
|
552
|
-
function usageLine(usage, colors = paint(
|
|
624
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
553
625
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
554
626
|
}
|
|
555
|
-
function helpText(usage, options, colors = paint(
|
|
627
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
556
628
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
557
629
|
`);
|
|
558
630
|
}
|
|
559
|
-
function exitRows(exits, colors = paint(
|
|
631
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
560
632
|
if (exits.length === 0)
|
|
561
633
|
return [];
|
|
562
634
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
563
635
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
564
636
|
}
|
|
565
|
-
function replacesRows(replaces, colors = paint(
|
|
566
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
637
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
638
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
567
639
|
}
|
|
568
|
-
function wantsHelpJson(env =
|
|
640
|
+
function wantsHelpJson(env = process8.env) {
|
|
569
641
|
return env.KIT_HELP === "json";
|
|
570
642
|
}
|
|
571
643
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -584,12 +656,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
584
656
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
585
657
|
};
|
|
586
658
|
}
|
|
587
|
-
function exampleRows(examples, colors = paint(
|
|
588
|
-
if (examples.length === 0)
|
|
659
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
660
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
589
661
|
return [];
|
|
590
662
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
591
663
|
}
|
|
592
|
-
function optionRows(options, colors = paint(
|
|
664
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
593
665
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
594
666
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
595
667
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -652,7 +724,6 @@ var DASHES = /^-+/;
|
|
|
652
724
|
function jsonOption(holds) {
|
|
653
725
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
654
726
|
}
|
|
655
|
-
|
|
656
727
|
class Exit extends Error {
|
|
657
728
|
code;
|
|
658
729
|
hint;
|
|
@@ -696,7 +767,7 @@ var OUTPUT_OPTIONS = {
|
|
|
696
767
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
697
768
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
698
769
|
};
|
|
699
|
-
function applyOutput(color, plain, env =
|
|
770
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
700
771
|
const when = plain === true ? "never" : color ?? "auto";
|
|
701
772
|
if (when === "auto")
|
|
702
773
|
return;
|
|
@@ -867,7 +938,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
867
938
|
}
|
|
868
939
|
// ../kit/src/process.ts
|
|
869
940
|
import { constants } from "os";
|
|
870
|
-
import
|
|
941
|
+
import process10 from "process";
|
|
871
942
|
var KILL_GRACE_MS = 2000;
|
|
872
943
|
function exitCodeOf(code, signal) {
|
|
873
944
|
if (code !== null)
|
|
@@ -887,7 +958,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
887
958
|
return;
|
|
888
959
|
try {
|
|
889
960
|
if (grouped)
|
|
890
|
-
|
|
961
|
+
process10.kill(-proc.pid, killing);
|
|
891
962
|
else
|
|
892
963
|
proc.kill(killing);
|
|
893
964
|
} catch {}
|
|
@@ -963,13 +1034,13 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
|
963
1034
|
// ../kit/src/cli.ts
|
|
964
1035
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
965
1036
|
import { dirname as dirname3, join as join5 } from "path";
|
|
966
|
-
import
|
|
1037
|
+
import process12 from "process";
|
|
967
1038
|
|
|
968
1039
|
// ../kit/src/usage.ts
|
|
969
1040
|
import { appendFileSync, mkdirSync } from "fs";
|
|
970
1041
|
import { homedir as homedir3 } from "os";
|
|
971
1042
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
972
|
-
import
|
|
1043
|
+
import process11 from "process";
|
|
973
1044
|
|
|
974
1045
|
// ../kit/src/logs.ts
|
|
975
1046
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -983,14 +1054,14 @@ var usageError;
|
|
|
983
1054
|
function noteUsageError(message) {
|
|
984
1055
|
usageError = message;
|
|
985
1056
|
}
|
|
986
|
-
function stateHome(env =
|
|
1057
|
+
function stateHome(env = process11.env) {
|
|
987
1058
|
const dir = env.XDG_STATE_HOME;
|
|
988
1059
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
989
1060
|
}
|
|
990
|
-
function usagePath(env =
|
|
1061
|
+
function usagePath(env = process11.env) {
|
|
991
1062
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
992
1063
|
}
|
|
993
|
-
function usageRecorded(env =
|
|
1064
|
+
function usageRecorded(env = process11.env) {
|
|
994
1065
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
995
1066
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
996
1067
|
}
|
|
@@ -1004,7 +1075,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1004
1075
|
usageError = undefined;
|
|
1005
1076
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1006
1077
|
}
|
|
1007
|
-
function recordUsage(entry, env =
|
|
1078
|
+
function recordUsage(entry, env = process11.env) {
|
|
1008
1079
|
if (!usageRecorded(env))
|
|
1009
1080
|
return;
|
|
1010
1081
|
try {
|
|
@@ -1095,8 +1166,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1095
1166
|
`);
|
|
1096
1167
|
}
|
|
1097
1168
|
function printError(prefix, message, hint, cause) {
|
|
1098
|
-
const colors = paint(
|
|
1099
|
-
const styled = takesControlCodes(
|
|
1169
|
+
const colors = paint(process12.stderr);
|
|
1170
|
+
const styled = takesControlCodes(process12.stderr);
|
|
1100
1171
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1101
1172
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1102
1173
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1139,11 +1210,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1139
1210
|
}
|
|
1140
1211
|
}
|
|
1141
1212
|
if (name === undefined && level.path.length > 1) {
|
|
1142
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1213
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
|
|
1143
1214
|
return 2;
|
|
1144
1215
|
}
|
|
1145
1216
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1146
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1217
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
|
|
1147
1218
|
return 0;
|
|
1148
1219
|
}
|
|
1149
1220
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1270,7 +1341,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1270
1341
|
return "0.0.0";
|
|
1271
1342
|
}
|
|
1272
1343
|
}
|
|
1273
|
-
async function runCli(cli, argv =
|
|
1344
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
1274
1345
|
const version = cli.version ?? packageVersion();
|
|
1275
1346
|
if (argv[0] === COMPLETE)
|
|
1276
1347
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1297,7 +1368,7 @@ function commandPath(scope, argv) {
|
|
|
1297
1368
|
}
|
|
1298
1369
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1299
1370
|
}
|
|
1300
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1371
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
1301
1372
|
if (argv[0] === COMPLETE)
|
|
1302
1373
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1303
1374
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1317,6 +1388,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process11.a
|
|
|
1317
1388
|
}
|
|
1318
1389
|
return code;
|
|
1319
1390
|
}
|
|
1391
|
+
// ../kit/src/folders.ts
|
|
1392
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1320
1393
|
// ../kit/src/limit.ts
|
|
1321
1394
|
function limitOptions(fallback) {
|
|
1322
1395
|
return {
|
|
@@ -1346,15 +1419,14 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1346
1419
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1347
1420
|
// src/peek.ts
|
|
1348
1421
|
import { realpathSync as realpathSync2 } from "fs";
|
|
1349
|
-
import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as
|
|
1350
|
-
import
|
|
1422
|
+
import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve4, sep } from "path";
|
|
1423
|
+
import process14 from "process";
|
|
1351
1424
|
|
|
1352
1425
|
// src/files.ts
|
|
1353
1426
|
import { existsSync as existsSync3, readdirSync, statSync as statSync2 } from "fs";
|
|
1354
1427
|
import { join as join6, relative } from "path";
|
|
1355
1428
|
var MAX_BYTES = 2000000;
|
|
1356
1429
|
var SNIFF_BYTES = 8000;
|
|
1357
|
-
var SKIPPED = new Set(["node_modules", "dist", "build", "vendor", "target", "coverage"]);
|
|
1358
1430
|
function walk(dir, found) {
|
|
1359
1431
|
let entries;
|
|
1360
1432
|
try {
|
|
@@ -1363,7 +1435,7 @@ function walk(dir, found) {
|
|
|
1363
1435
|
return found;
|
|
1364
1436
|
}
|
|
1365
1437
|
for (const entry of entries) {
|
|
1366
|
-
if (entry.name.startsWith(".") ||
|
|
1438
|
+
if (entry.name.startsWith(".") || SKIPPED_FOLDERS.has(entry.name))
|
|
1367
1439
|
continue;
|
|
1368
1440
|
if (entry.isDirectory())
|
|
1369
1441
|
walk(join6(dir, entry.name), found);
|
|
@@ -1596,13 +1668,13 @@ function cut(text) {
|
|
|
1596
1668
|
return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
|
|
1597
1669
|
}
|
|
1598
1670
|
async function readableRoot() {
|
|
1599
|
-
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd:
|
|
1600
|
-
return realpathSync2(ran.code === 0 ? ran.text.trim() :
|
|
1671
|
+
const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process14.cwd() });
|
|
1672
|
+
return realpathSync2(ran.code === 0 ? ran.text.trim() : process14.cwd());
|
|
1601
1673
|
}
|
|
1602
1674
|
async function isOutside(path) {
|
|
1603
1675
|
let real;
|
|
1604
1676
|
try {
|
|
1605
|
-
real = realpathSync2(
|
|
1677
|
+
real = realpathSync2(resolve4(process14.cwd(), path));
|
|
1606
1678
|
} catch {
|
|
1607
1679
|
return false;
|
|
1608
1680
|
}
|
|
@@ -1616,7 +1688,7 @@ async function checkInside(path) {
|
|
|
1616
1688
|
async function pipedSpans(text, context) {
|
|
1617
1689
|
const spans = [];
|
|
1618
1690
|
for (const [path, numbers] of locations(text)) {
|
|
1619
|
-
const source = await isOutside(path) ? undefined : await readText(
|
|
1691
|
+
const source = await isOutside(path) ? undefined : await readText(resolve4(process14.cwd(), path));
|
|
1620
1692
|
if (source !== undefined)
|
|
1621
1693
|
spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
|
|
1622
1694
|
`).length, numbers, context));
|
|
@@ -1625,7 +1697,7 @@ async function pipedSpans(text, context) {
|
|
|
1625
1697
|
}
|
|
1626
1698
|
async function textOf(path) {
|
|
1627
1699
|
await checkInside(path);
|
|
1628
|
-
const text = await readText(
|
|
1700
|
+
const text = await readText(resolve4(process14.cwd(), path));
|
|
1629
1701
|
if (text === undefined)
|
|
1630
1702
|
fail(`cannot read ${path} (missing, binary or too large)`, 1);
|
|
1631
1703
|
return text;
|
|
@@ -1683,8 +1755,8 @@ async function spanOf(target) {
|
|
|
1683
1755
|
async function* sources(paths) {
|
|
1684
1756
|
for (const path of paths)
|
|
1685
1757
|
await checkInside(path);
|
|
1686
|
-
for (const path of await listFiles(paths,
|
|
1687
|
-
const text = await readText(join7(
|
|
1758
|
+
for (const path of await listFiles(paths, process14.cwd())) {
|
|
1759
|
+
const text = await readText(join7(process14.cwd(), path));
|
|
1688
1760
|
if (text !== undefined)
|
|
1689
1761
|
yield { path, text };
|
|
1690
1762
|
}
|
|
@@ -1784,4 +1856,4 @@ async function peek(args) {
|
|
|
1784
1856
|
}
|
|
1785
1857
|
|
|
1786
1858
|
// src/peek-cli.ts
|
|
1787
|
-
|
|
1859
|
+
process15.exitCode = await runMain({ name: "peek", run: peek });
|