@kaynooo/cli-doctor 0.7.0 → 0.9.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 +9 -2
- package/dist/cli-bin.js +574 -88
- package/dist/cli.js +571 -87
- 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 process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process7 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process5 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 process4 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,21 +295,38 @@ function le(i = {}) {
|
|
|
274
295
|
}
|
|
275
296
|
var t = le();
|
|
276
297
|
|
|
298
|
+
// ../kit/src/user-config.ts
|
|
299
|
+
import { homedir } from "os";
|
|
300
|
+
import { join } from "path";
|
|
301
|
+
import process3 from "process";
|
|
302
|
+
function configBase(where = {}) {
|
|
303
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
304
|
+
return xdg !== undefined && xdg !== "" ? xdg : join(where.home ?? homedir(), ".config");
|
|
305
|
+
}
|
|
306
|
+
function userConfigPath(bin, where = {}) {
|
|
307
|
+
return join(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ../kit/src/theme.ts
|
|
311
|
+
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"]);
|
|
312
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
313
|
+
var warned = new Set;
|
|
314
|
+
|
|
277
315
|
// ../kit/src/style.ts
|
|
278
|
-
function takesControlCodes(stream, env =
|
|
279
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
316
|
+
function takesControlCodes(stream, env = process4.env) {
|
|
317
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
280
318
|
}
|
|
281
|
-
function paint(stream, env =
|
|
319
|
+
function paint(stream, env = process4.env) {
|
|
282
320
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
283
321
|
}
|
|
284
|
-
var
|
|
285
|
-
passed:
|
|
286
|
-
failed:
|
|
287
|
-
running:
|
|
288
|
-
queued:
|
|
289
|
-
skipped:
|
|
322
|
+
var STATUS_WORDS = {
|
|
323
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
324
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
325
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
326
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
327
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
290
328
|
};
|
|
291
|
-
var STATUS_OF = new Map(Object.entries(
|
|
329
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
292
330
|
|
|
293
331
|
// ../kit/src/format.ts
|
|
294
332
|
function upTo(text, separator) {
|
|
@@ -303,15 +341,18 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
303
341
|
function textWidth(text) {
|
|
304
342
|
return Bun.stringWidth(text);
|
|
305
343
|
}
|
|
306
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
344
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process5.stdout, env = process5.env } = {}) {
|
|
307
345
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
346
|
+
if (outputMode(stream, env) === "agent")
|
|
347
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
348
|
+
`);
|
|
308
349
|
const widths = [];
|
|
309
350
|
for (const row of cells) {
|
|
310
351
|
for (const [index, cell] of row.entries())
|
|
311
352
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
312
353
|
}
|
|
313
354
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
314
|
-
const colors = paint(
|
|
355
|
+
const colors = paint(stream);
|
|
315
356
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
316
357
|
const width = widths[index] ?? 0;
|
|
317
358
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -319,7 +360,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
319
360
|
return `${gap}${cell}`;
|
|
320
361
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
321
362
|
}).join(" ").trimEnd());
|
|
322
|
-
|
|
363
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
364
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
323
365
|
`);
|
|
324
366
|
}
|
|
325
367
|
function narrow(rows, widths, limit) {
|
|
@@ -338,32 +380,35 @@ function narrow(rows, widths, limit) {
|
|
|
338
380
|
}
|
|
339
381
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
340
382
|
}
|
|
383
|
+
function jsonText(value, replacer, { stream = process5.stdout, env = process5.env } = {}) {
|
|
384
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
385
|
+
}
|
|
341
386
|
function printJson(value) {
|
|
342
|
-
console.log(
|
|
387
|
+
console.log(jsonText(value));
|
|
343
388
|
}
|
|
344
389
|
|
|
345
390
|
// ../kit/src/help.ts
|
|
346
|
-
import
|
|
391
|
+
import process6 from "process";
|
|
347
392
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
348
393
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
349
394
|
var FULL_STOP = /\.$/;
|
|
350
|
-
function usageLine(usage, colors = paint(
|
|
395
|
+
function usageLine(usage, colors = paint(process6.stdout)) {
|
|
351
396
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
352
397
|
}
|
|
353
|
-
function helpText(usage, options, colors = paint(
|
|
398
|
+
function helpText(usage, options, colors = paint(process6.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
354
399
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
355
400
|
`);
|
|
356
401
|
}
|
|
357
|
-
function exitRows(exits, colors = paint(
|
|
402
|
+
function exitRows(exits, colors = paint(process6.stdout)) {
|
|
358
403
|
if (exits.length === 0)
|
|
359
404
|
return [];
|
|
360
405
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
361
406
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
362
407
|
}
|
|
363
|
-
function replacesRows(replaces, colors = paint(
|
|
364
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
408
|
+
function replacesRows(replaces, colors = paint(process6.stdout)) {
|
|
409
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
365
410
|
}
|
|
366
|
-
function wantsHelpJson(env =
|
|
411
|
+
function wantsHelpJson(env = process6.env) {
|
|
367
412
|
return env.KIT_HELP === "json";
|
|
368
413
|
}
|
|
369
414
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -382,12 +427,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
382
427
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
383
428
|
};
|
|
384
429
|
}
|
|
385
|
-
function exampleRows(examples, colors = paint(
|
|
386
|
-
if (examples.length === 0)
|
|
430
|
+
function exampleRows(examples, colors = paint(process6.stdout)) {
|
|
431
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
387
432
|
return [];
|
|
388
433
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
389
434
|
}
|
|
390
|
-
function optionRows(options, colors = paint(
|
|
435
|
+
function optionRows(options, colors = paint(process6.stdout)) {
|
|
391
436
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
392
437
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
393
438
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -446,6 +491,10 @@ class Exit extends Error {
|
|
|
446
491
|
this.hint = hint;
|
|
447
492
|
}
|
|
448
493
|
}
|
|
494
|
+
function fail(message, code = 2, hint) {
|
|
495
|
+
throw new Exit(message, code, hint);
|
|
496
|
+
}
|
|
497
|
+
|
|
449
498
|
class UsageError extends Exit {
|
|
450
499
|
constructor(message, hint) {
|
|
451
500
|
super(message, 2, hint);
|
|
@@ -476,7 +525,7 @@ var OUTPUT_OPTIONS = {
|
|
|
476
525
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
477
526
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
478
527
|
};
|
|
479
|
-
function applyOutput(color, plain, env =
|
|
528
|
+
function applyOutput(color, plain, env = process7.env) {
|
|
480
529
|
const when = plain === true ? "never" : color ?? "auto";
|
|
481
530
|
if (when === "auto")
|
|
482
531
|
return;
|
|
@@ -647,7 +696,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
647
696
|
}
|
|
648
697
|
// ../kit/src/process.ts
|
|
649
698
|
import { constants } from "os";
|
|
650
|
-
import
|
|
699
|
+
import process8 from "process";
|
|
651
700
|
var KILL_GRACE_MS = 2000;
|
|
652
701
|
function exitCodeOf(code, signal) {
|
|
653
702
|
if (code !== null)
|
|
@@ -667,7 +716,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
667
716
|
return;
|
|
668
717
|
try {
|
|
669
718
|
if (grouped)
|
|
670
|
-
|
|
719
|
+
process8.kill(-proc.pid, killing);
|
|
671
720
|
else
|
|
672
721
|
proc.kill(killing);
|
|
673
722
|
} catch {}
|
|
@@ -742,14 +791,14 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
742
791
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
743
792
|
// ../kit/src/cli.ts
|
|
744
793
|
import { readFileSync, realpathSync } from "fs";
|
|
745
|
-
import { dirname as dirname2, join as
|
|
746
|
-
import
|
|
794
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
795
|
+
import process10 from "process";
|
|
747
796
|
|
|
748
797
|
// ../kit/src/usage.ts
|
|
749
798
|
import { appendFileSync, mkdirSync } from "fs";
|
|
750
|
-
import { homedir } from "os";
|
|
751
|
-
import { dirname, isAbsolute, join } from "path";
|
|
752
|
-
import
|
|
799
|
+
import { homedir as homedir2 } from "os";
|
|
800
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
801
|
+
import process9 from "process";
|
|
753
802
|
|
|
754
803
|
// ../kit/src/logs.ts
|
|
755
804
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -763,14 +812,14 @@ var usageError;
|
|
|
763
812
|
function noteUsageError(message) {
|
|
764
813
|
usageError = message;
|
|
765
814
|
}
|
|
766
|
-
function stateHome(env =
|
|
815
|
+
function stateHome(env = process9.env) {
|
|
767
816
|
const dir = env.XDG_STATE_HOME;
|
|
768
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
817
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
|
|
769
818
|
}
|
|
770
|
-
function usagePath(env =
|
|
771
|
-
return
|
|
819
|
+
function usagePath(env = process9.env) {
|
|
820
|
+
return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
772
821
|
}
|
|
773
|
-
function usageRecorded(env =
|
|
822
|
+
function usageRecorded(env = process9.env) {
|
|
774
823
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
775
824
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
776
825
|
}
|
|
@@ -784,7 +833,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
784
833
|
usageError = undefined;
|
|
785
834
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
786
835
|
}
|
|
787
|
-
function recordUsage(entry, env =
|
|
836
|
+
function recordUsage(entry, env = process9.env) {
|
|
788
837
|
if (!usageRecorded(env))
|
|
789
838
|
return;
|
|
790
839
|
try {
|
|
@@ -923,8 +972,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
923
972
|
`);
|
|
924
973
|
}
|
|
925
974
|
function printError(prefix, message, hint, cause) {
|
|
926
|
-
const colors = paint(
|
|
927
|
-
const styled = takesControlCodes(
|
|
975
|
+
const colors = paint(process10.stderr);
|
|
976
|
+
const styled = takesControlCodes(process10.stderr);
|
|
928
977
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
929
978
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
930
979
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -967,11 +1016,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
967
1016
|
}
|
|
968
1017
|
}
|
|
969
1018
|
if (name === undefined && level.path.length > 1) {
|
|
970
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1019
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process10.stderr));
|
|
971
1020
|
return 2;
|
|
972
1021
|
}
|
|
973
1022
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
974
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1023
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process10.stdout));
|
|
975
1024
|
return 0;
|
|
976
1025
|
}
|
|
977
1026
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1090,7 +1139,7 @@ async function printCandidates(found) {
|
|
|
1090
1139
|
function packageVersion(entry = Bun.main) {
|
|
1091
1140
|
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
1092
1141
|
try {
|
|
1093
|
-
const { version } = JSON.parse(readFileSync(
|
|
1142
|
+
const { version } = JSON.parse(readFileSync(join3(dir, "package.json"), "utf8"));
|
|
1094
1143
|
if (typeof version === "string")
|
|
1095
1144
|
return version;
|
|
1096
1145
|
} catch {}
|
|
@@ -1098,7 +1147,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1098
1147
|
return "0.0.0";
|
|
1099
1148
|
}
|
|
1100
1149
|
}
|
|
1101
|
-
async function runCli(cli, argv =
|
|
1150
|
+
async function runCli(cli, argv = process10.argv.slice(2)) {
|
|
1102
1151
|
const version = cli.version ?? packageVersion();
|
|
1103
1152
|
if (argv[0] === COMPLETE)
|
|
1104
1153
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1125,7 +1174,7 @@ function commandPath(scope, argv) {
|
|
|
1125
1174
|
}
|
|
1126
1175
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1127
1176
|
}
|
|
1128
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1177
|
+
async function runMain({ name, version, run, redact, usage }, argv = process10.argv.slice(2)) {
|
|
1129
1178
|
if (argv[0] === COMPLETE)
|
|
1130
1179
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1131
1180
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1151,17 +1200,97 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
1151
1200
|
var {Glob } = globalThis.Bun;
|
|
1152
1201
|
var SESSION_FILES = new Glob("*.json");
|
|
1153
1202
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1203
|
+
// ../kit/src/workspace-root.ts
|
|
1204
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
1205
|
+
import { homedir as homedir3 } from "os";
|
|
1206
|
+
import { dirname as dirname3, join as join4, resolve } from "path";
|
|
1207
|
+
import process11 from "process";
|
|
1208
|
+
function expandHome(path, home) {
|
|
1209
|
+
if (path === "~")
|
|
1210
|
+
return home;
|
|
1211
|
+
return path.startsWith("~/") ? join4(home, path.slice(2)) : path;
|
|
1212
|
+
}
|
|
1213
|
+
function configured(env, home) {
|
|
1214
|
+
const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
|
|
1215
|
+
if (!existsSync(path))
|
|
1216
|
+
return;
|
|
1217
|
+
try {
|
|
1218
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
1219
|
+
const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
|
|
1220
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1221
|
+
} catch {
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
function workspaceRoot({ given, env = process11.env, home = homedir3() } = {}) {
|
|
1226
|
+
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1227
|
+
return resolve(expandHome(given ?? fromEnv ?? configured(env, home) ?? join4(home, "Workspace"), home));
|
|
1228
|
+
}
|
|
1229
|
+
function workspaceChosen({ env = process11.env, home = homedir3() } = {}) {
|
|
1230
|
+
return (env.KAYNOOO_WORKSPACE ?? "") !== "" || configured(env, home) !== undefined;
|
|
1231
|
+
}
|
|
1232
|
+
function saveWorkspace(folder, { env = process11.env, home = homedir3() } = {}) {
|
|
1233
|
+
const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
|
|
1234
|
+
let current = {};
|
|
1235
|
+
if (existsSync(path)) {
|
|
1236
|
+
try {
|
|
1237
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
1238
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
1239
|
+
return false;
|
|
1240
|
+
current = parsed;
|
|
1241
|
+
} catch {
|
|
1242
|
+
return false;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
mkdirSync2(dirname3(path), { recursive: true });
|
|
1246
|
+
writeFileSync(path, `${JSON.stringify({ ...current, workspace: folder }, undefined, 2)}
|
|
1247
|
+
`);
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1154
1250
|
// src/doctor.ts
|
|
1155
|
-
import
|
|
1251
|
+
import process17 from "process";
|
|
1156
1252
|
|
|
1157
1253
|
// src/checks.ts
|
|
1158
|
-
import { existsSync as
|
|
1159
|
-
import { basename, join as
|
|
1254
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
|
|
1255
|
+
import { basename, join as join6 } from "path";
|
|
1256
|
+
|
|
1257
|
+
// src/catalog.ts
|
|
1258
|
+
var HOOKS_REQUIRES = "@kaynooo/cli-guard";
|
|
1259
|
+
var ABOUT = {
|
|
1260
|
+
"@kaynooo/cli-base": "run a command at a ref in a throwaway worktree, and prove a test fails before a change",
|
|
1261
|
+
"@kaynooo/cli-changelog": "release notes from conventional commits, published as a Forgejo release",
|
|
1262
|
+
"@kaynooo/cli-check": "the repo's check, lint and test steps, its fixers, error lines from logs and a recipe picker",
|
|
1263
|
+
"@kaynooo/cli-code": "source read by spans, TODO comments and the files worth splitting",
|
|
1264
|
+
"@kaynooo/cli-db": "read-only SQL against Postgres, MySQL and MariaDB, credentials never shown",
|
|
1265
|
+
"@kaynooo/cli-dev": "passwords, JWTs, timestamps, UUIDs, base64 and file hashes",
|
|
1266
|
+
"@kaynooo/cli-docker": "docker compose on the stack found here, service health, shells and Symfony commands",
|
|
1267
|
+
"@kaynooo/cli-doctor": "this install check, and the list of every bin",
|
|
1268
|
+
"@kaynooo/cli-edit": "replace text in files, writing nothing unless every match count is right",
|
|
1269
|
+
"@kaynooo/cli-env": ".env files listed and edited with secrets masked, and a secrets filter for pipes",
|
|
1270
|
+
"@kaynooo/cli-forgejo": "Forgejo CI runs, logs, releases and issue checklists",
|
|
1271
|
+
"@kaynooo/cli-git": "repository state in one line, commits of exact paths, a branch picker",
|
|
1272
|
+
"@kaynooo/cli-gitlab": "GitLab pipelines and their failed tests",
|
|
1273
|
+
"@kaynooo/cli-guard": "the safety rules a Claude Code Bash call is held to",
|
|
1274
|
+
"@kaynooo/cli-out": "shortens a noisy command's output, keeping the errors",
|
|
1275
|
+
"@kaynooo/cli-pick": "a fuzzy selector for pipes",
|
|
1276
|
+
"@kaynooo/cli-pkg": "vets npm packages before they are added, and bumps a lib in its consumers",
|
|
1277
|
+
"@kaynooo/cli-probe": "a site's HTTP version, redirects, timings and TLS",
|
|
1278
|
+
"@kaynooo/cli-proc": "what a process is, who listens on a port, leftover dev processes",
|
|
1279
|
+
"@kaynooo/cli-stack": "a stable port per service name, and a compose release audit",
|
|
1280
|
+
"@kaynooo/cli-view": "markdown, source and git diffs in the colours of the other bins",
|
|
1281
|
+
"@kaynooo/cli-wait": "wait for a line, a port, a URL or a process; a machine-wide slot for heavy jobs",
|
|
1282
|
+
"@kaynooo/cli-workspace": "the repositories under a root needing attention, reclaimable folders and known vulnerabilities"
|
|
1283
|
+
};
|
|
1284
|
+
var NEEDS = {
|
|
1285
|
+
"@kaynooo/cli-forgejo": [{ bin: "tea", why: "ft goes through it", how: "https://gitea.com/gitea/tea/releases" }],
|
|
1286
|
+
"@kaynooo/cli-gitlab": [{ bin: "glab", why: "gl goes through it", how: "https://gitlab.com/gitlab-org/cli" }],
|
|
1287
|
+
"@kaynooo/cli-docker": [{ bin: "docker", why: "dc, dlog, dx and sf run docker compose", how: "https://docs.docker.com/engine/install/" }]
|
|
1288
|
+
};
|
|
1160
1289
|
|
|
1161
1290
|
// src/completions.ts
|
|
1162
|
-
import { existsSync, mkdirSync as
|
|
1163
|
-
import { join as
|
|
1164
|
-
import
|
|
1291
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync3, rmSync } from "fs";
|
|
1292
|
+
import { join as join5 } from "path";
|
|
1293
|
+
import process13 from "process";
|
|
1165
1294
|
var MARKER = "# Generated by `cli completions fish`";
|
|
1166
1295
|
var FISH_FILE = /\.fish$/;
|
|
1167
1296
|
var FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-* bin offers for the word being typed'
|
|
@@ -1195,8 +1324,8 @@ ${BASH_FUNCTION}
|
|
|
1195
1324
|
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1196
1325
|
`;
|
|
1197
1326
|
}
|
|
1198
|
-
function completionDir(home, env =
|
|
1199
|
-
return
|
|
1327
|
+
function completionDir(home, env = process13.env) {
|
|
1328
|
+
return join5(env.XDG_CACHE_HOME ?? join5(home, ".cache"), "fish", "kaynooo-cli");
|
|
1200
1329
|
}
|
|
1201
1330
|
function installedBins(host) {
|
|
1202
1331
|
return Object.values(TOOLS).flat().filter((bin) => host.which(bin) !== null);
|
|
@@ -1209,15 +1338,15 @@ complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
|
1209
1338
|
}
|
|
1210
1339
|
async function installCompletions(host, dir) {
|
|
1211
1340
|
const bins = installedBins(host);
|
|
1212
|
-
|
|
1213
|
-
const removed = readdirSync(dir).filter((name) => FISH_FILE.test(name) && !bins.includes(name.replace(FISH_FILE, "")) &&
|
|
1341
|
+
mkdirSync3(dir, { recursive: true });
|
|
1342
|
+
const removed = readdirSync(dir).filter((name) => FISH_FILE.test(name) && !bins.includes(name.replace(FISH_FILE, "")) && readFileSync3(join5(dir, name), "utf8").startsWith(MARKER));
|
|
1214
1343
|
for (const name of removed)
|
|
1215
|
-
rmSync(
|
|
1216
|
-
await Promise.all(bins.map(async (bin) => Bun.write(
|
|
1344
|
+
rmSync(join5(dir, name));
|
|
1345
|
+
await Promise.all(bins.map(async (bin) => Bun.write(join5(dir, `${bin}.fish`), completionFile(bin))));
|
|
1217
1346
|
return { written: bins, removed: removed.map((name) => name.replace(FISH_FILE, "")) };
|
|
1218
1347
|
}
|
|
1219
1348
|
function missingCompletions(host, dir) {
|
|
1220
|
-
return installedBins(host).filter((bin) => !
|
|
1349
|
+
return installedBins(host).filter((bin) => !existsSync2(join5(dir, `${bin}.fish`)));
|
|
1221
1350
|
}
|
|
1222
1351
|
|
|
1223
1352
|
// src/checks.ts
|
|
@@ -1261,7 +1390,7 @@ function readJsonText(text) {
|
|
|
1261
1390
|
}
|
|
1262
1391
|
}
|
|
1263
1392
|
function readJson(path) {
|
|
1264
|
-
return
|
|
1393
|
+
return existsSync3(path) ? readJsonText(readFileSync4(path, "utf8")) : undefined;
|
|
1265
1394
|
}
|
|
1266
1395
|
function firstLine(text) {
|
|
1267
1396
|
const trimmed = text.trim();
|
|
@@ -1270,12 +1399,15 @@ function firstLine(text) {
|
|
|
1270
1399
|
return end === -1 ? trimmed : trimmed.slice(0, end);
|
|
1271
1400
|
}
|
|
1272
1401
|
function installed(host, name) {
|
|
1273
|
-
return readJson(
|
|
1402
|
+
return readJson(join6(host.globalModules, name, "package.json"));
|
|
1403
|
+
}
|
|
1404
|
+
function isInstalled(host, name) {
|
|
1405
|
+
return installed(host, name)?.version !== undefined;
|
|
1274
1406
|
}
|
|
1275
1407
|
function ownBin(host, name, bin) {
|
|
1276
1408
|
const declared = installed(host, name)?.bin;
|
|
1277
1409
|
const file = typeof declared === "string" ? declared : declared?.[bin];
|
|
1278
|
-
return file === undefined ? undefined :
|
|
1410
|
+
return file === undefined ? undefined : join6(host.globalModules, name, file);
|
|
1279
1411
|
}
|
|
1280
1412
|
async function checkTool(host, name, bins) {
|
|
1281
1413
|
const check = name.slice(name.indexOf("/") + 1);
|
|
@@ -1290,7 +1422,7 @@ async function checkTool(host, name, bins) {
|
|
|
1290
1422
|
if (latest !== "" && Bun.semver.order(version, latest) < 0)
|
|
1291
1423
|
return { check, ok: false, detail: `${version}, ${latest} released${off.length > 0 ? `, ${off.join(", ")} not on the PATH` : ""}`, fix: `bun install -g ${name}@${latest}` };
|
|
1292
1424
|
if (off.length > 0)
|
|
1293
|
-
return { check, ok: false, detail: `${version}, ${off.join(", ")} not on the PATH`, fix: `add ${
|
|
1425
|
+
return { check, ok: false, detail: `${version}, ${off.join(", ")} not on the PATH`, fix: `add ${join6(host.globalModules, "..", "..", "..", "bin")} to the PATH` };
|
|
1294
1426
|
if (latest === "")
|
|
1295
1427
|
return { check, ok: true, detail: `${version}, the registry did not answer: ${firstLine(info.stderr) || answered || "no version"}` };
|
|
1296
1428
|
return { check, ok: true, detail: version };
|
|
@@ -1310,10 +1442,16 @@ async function checkTea(host) {
|
|
|
1310
1442
|
return { check: "tea", ok: false, detail: `${forge} did not answer: ${firstLine(version.stderr || version.stdout)}`, fix: `tea login edit ${login.name} --token <token>, or check the network` };
|
|
1311
1443
|
return { check: "tea", ok: true, detail: `logged in to ${forge} as ${login.name}, Forgejo ${served}` };
|
|
1312
1444
|
}
|
|
1313
|
-
function
|
|
1314
|
-
const settings = readJson(
|
|
1445
|
+
function hooksWiring(host) {
|
|
1446
|
+
const settings = readJson(join6(host.home, ".claude", "settings.json")) ?? {};
|
|
1315
1447
|
const plugin = settings.enabledPlugins?.[PLUGIN] === true;
|
|
1316
|
-
const mod = (settings.env?.CLAUDE_CODE_PLUGIN_DIRS ?? "").split(":").map((dir) => dir.replace(LEADING_TILDE, host.home)).find((dir) => basename(dir) === "cli" &&
|
|
1448
|
+
const mod = (settings.env?.CLAUDE_CODE_PLUGIN_DIRS ?? "").split(":").map((dir) => dir.replace(LEADING_TILDE, host.home)).find((dir) => basename(dir) === "cli" && existsSync3(join6(dir, "hooks", "hooks.json")));
|
|
1449
|
+
return { plugin, mod };
|
|
1450
|
+
}
|
|
1451
|
+
function checkHooks(host) {
|
|
1452
|
+
const { plugin, mod } = hooksWiring(host);
|
|
1453
|
+
if ((plugin || mod !== undefined) && !isInstalled(host, HOOKS_REQUIRES))
|
|
1454
|
+
return { check: "hooks", ok: false, detail: `wired, but ${HOOKS_REQUIRES} is not installed, so every hook finds no guard`, fix: `bun install -g ${HOOKS_REQUIRES}` };
|
|
1317
1455
|
if (plugin && mod !== undefined)
|
|
1318
1456
|
return { check: "hooks", ok: false, detail: `both the ${PLUGIN} plugin and the mod in ${mod} run guard, so every call is checked twice`, fix: `claude plugin disable ${PLUGIN}` };
|
|
1319
1457
|
if (plugin)
|
|
@@ -1338,21 +1476,39 @@ function checkCompletions(host) {
|
|
|
1338
1476
|
return { check: "completions", ok: false, detail: `no fish completion in ${dir} for ${missing.join(", ")}`, fix: "cli completions fish --install" };
|
|
1339
1477
|
return { check: "completions", ok: true, detail: dir };
|
|
1340
1478
|
}
|
|
1479
|
+
function checkNeeds(host) {
|
|
1480
|
+
const missing = Object.entries(NEEDS).flatMap(([name, needs]) => isInstalled(host, name) ? needs.filter((need) => need.bin !== "tea" && host.which(need.bin) === null) : []);
|
|
1481
|
+
if (missing.length > 0)
|
|
1482
|
+
return { check: "needs", ok: false, detail: `missing ${missing.map((need) => `${need.bin} (${need.why})`).join(", ")}`, fix: `install ${missing.map((need) => `${need.bin}: ${need.how}`).join("; ")}` };
|
|
1483
|
+
return { check: "needs", ok: true, detail: "every tool the installed packages need is on the PATH" };
|
|
1484
|
+
}
|
|
1341
1485
|
var toolCheck = (name) => name.slice(name.indexOf("/") + 1);
|
|
1342
|
-
var OTHER_CHECKS = ["tea", "hooks", "bun", "completions"];
|
|
1486
|
+
var OTHER_CHECKS = ["tea", "hooks", "needs", "bun", "completions", "workspace"];
|
|
1487
|
+
var FORGEJO = "@kaynooo/cli-forgejo";
|
|
1488
|
+
var WORKSPACE = "@kaynooo/cli-workspace";
|
|
1489
|
+
function checkWorkspace(host, env = process.env) {
|
|
1490
|
+
const folder = workspaceRoot({ home: host.home, env });
|
|
1491
|
+
if (existsSync3(folder))
|
|
1492
|
+
return { check: "workspace", ok: true, detail: folder };
|
|
1493
|
+
return { check: "workspace", ok: false, detail: `${folder} does not exist`, fix: `mkdir -p ${folder}, or set "workspace" in ~/.config/kaynooo-cli/config.json to your folder` };
|
|
1494
|
+
}
|
|
1343
1495
|
var CHECK_NAMES = [...Object.keys(TOOLS).map(toolCheck), ...OTHER_CHECKS];
|
|
1344
1496
|
async function runChecks(host, only = []) {
|
|
1345
1497
|
const wanted = (check) => only.length === 0 || only.includes(check);
|
|
1346
|
-
const entries = Object.entries(TOOLS).filter(([name]) => wanted(toolCheck(name)));
|
|
1498
|
+
const entries = Object.entries(TOOLS).filter(([name]) => only.length === 0 ? isInstalled(host, name) : wanted(toolCheck(name)));
|
|
1499
|
+
const { plugin, mod } = hooksWiring(host);
|
|
1500
|
+
const hooks = only.length > 0 || plugin || mod !== undefined || isInstalled(host, HOOKS_REQUIRES);
|
|
1347
1501
|
const tools = [];
|
|
1348
1502
|
for (let at = 0;at < entries.length; at += INFO_AT_ONCE)
|
|
1349
1503
|
tools.push(...await Promise.all(entries.slice(at, at + INFO_AT_ONCE).map(async ([name, bins]) => checkTool(host, name, bins))));
|
|
1350
1504
|
return [
|
|
1351
1505
|
...tools,
|
|
1352
|
-
...wanted("tea") ? [await checkTea(host)] : [],
|
|
1353
|
-
...wanted("hooks") ? [checkHooks(host)] : [],
|
|
1506
|
+
...wanted("tea") && (only.length > 0 || isInstalled(host, FORGEJO)) ? [await checkTea(host)] : [],
|
|
1507
|
+
...wanted("hooks") && hooks ? [checkHooks(host)] : [],
|
|
1508
|
+
...wanted("needs") ? [checkNeeds(host)] : [],
|
|
1354
1509
|
...wanted("bun") ? [checkBun(host)] : [],
|
|
1355
|
-
...wanted("completions") ? [checkCompletions(host)] : []
|
|
1510
|
+
...wanted("completions") ? [checkCompletions(host)] : [],
|
|
1511
|
+
...wanted("workspace") && (only.length > 0 || isInstalled(host, WORKSPACE) || isInstalled(host, "@kaynooo/cli-pkg")) ? [checkWorkspace(host)] : []
|
|
1356
1512
|
];
|
|
1357
1513
|
}
|
|
1358
1514
|
|
|
@@ -1394,19 +1550,19 @@ async function applyFixes(host, steps, dry) {
|
|
|
1394
1550
|
}
|
|
1395
1551
|
|
|
1396
1552
|
// src/host.ts
|
|
1397
|
-
import { homedir as
|
|
1398
|
-
import { join as
|
|
1399
|
-
import
|
|
1553
|
+
import { homedir as homedir4 } from "os";
|
|
1554
|
+
import { join as join7 } from "path";
|
|
1555
|
+
import process14 from "process";
|
|
1400
1556
|
var RUN_TIMEOUT_MS = 20000;
|
|
1401
1557
|
function hostHere() {
|
|
1402
|
-
const home =
|
|
1558
|
+
const home = homedir4();
|
|
1403
1559
|
return {
|
|
1404
1560
|
home,
|
|
1405
|
-
globalModules:
|
|
1561
|
+
globalModules: join7(process14.env.BUN_INSTALL ?? join7(home, ".bun"), "install", "global", "node_modules"),
|
|
1406
1562
|
bunVersion: Bun.version,
|
|
1407
1563
|
which: (bin) => Bun.which(bin),
|
|
1408
1564
|
run: async (argv, env) => {
|
|
1409
|
-
const ran = await runCommand(argv, { timeoutMs: RUN_TIMEOUT_MS, ...env === undefined ? {} : { env: { ...
|
|
1565
|
+
const ran = await runCommand(argv, { timeoutMs: RUN_TIMEOUT_MS, ...env === undefined ? {} : { env: { ...process14.env, ...env } } });
|
|
1410
1566
|
if (ran.timedOut)
|
|
1411
1567
|
return { code: 1, stdout: "", stderr: `timed out after ${RUN_TIMEOUT_MS / 1000}s` };
|
|
1412
1568
|
const of = (stream) => Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === stream).map((chunk) => chunk.data)).toString();
|
|
@@ -1415,11 +1571,325 @@ function hostHere() {
|
|
|
1415
1571
|
};
|
|
1416
1572
|
}
|
|
1417
1573
|
|
|
1574
|
+
// src/install.ts
|
|
1575
|
+
import process16 from "process";
|
|
1576
|
+
|
|
1577
|
+
// ../kit/src/prompt.ts
|
|
1578
|
+
import process15 from "process";
|
|
1579
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|[\s\S]/giu;
|
|
1580
|
+
var CONTROL = /^[\x00-\x1F\x7F]/;
|
|
1581
|
+
var WORDS = /\s+/;
|
|
1582
|
+
var MAX_ROWS = 10;
|
|
1583
|
+
var KEYS = { "\x1B[A": "up", "\x1BOA": "up", "\x1B[B": "down", "\x1BOB": "down", "\r": "enter", "\n": "enter", "\x03": "cancel", "\x1B": "cancel", "\x7F": "erase", "\b": "erase" };
|
|
1584
|
+
function readKeys(input) {
|
|
1585
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => KEYS[sequence] ?? (CONTROL.test(sequence) ? [] : [{ text: sequence }]));
|
|
1586
|
+
}
|
|
1587
|
+
function flip(checked, value) {
|
|
1588
|
+
const next = new Set(checked);
|
|
1589
|
+
if (!next.delete(value))
|
|
1590
|
+
next.add(value);
|
|
1591
|
+
return next;
|
|
1592
|
+
}
|
|
1593
|
+
async function checklist(question, choices, { initial = new Set, min = 0, toggle = flip, ...settings } = {}) {
|
|
1594
|
+
const list = new List(choices, 0);
|
|
1595
|
+
let checked = initial;
|
|
1596
|
+
let invalid;
|
|
1597
|
+
const accepted = await ask(question, settings, (colors, state, rows) => state === "asking" ? [asking(colors, question, list.query, "type to filter, space toggles, enter accepts"), ...list.rows(colors, rows, (choice) => checked.has(choice.value) ? `${colors.cyan("\u25C9")} ` : `${colors.dim("\u25EF")} `), ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]] : [answer(colors, question, state, choices.filter((choice) => checked.has(choice.value)).map((choice) => choice.label).join(", ") || "none")], (key) => {
|
|
1598
|
+
if (key === "cancel")
|
|
1599
|
+
return key;
|
|
1600
|
+
invalid = undefined;
|
|
1601
|
+
if (key === "enter") {
|
|
1602
|
+
invalid = checked.size < min ? `pick at least ${min}` : undefined;
|
|
1603
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1604
|
+
}
|
|
1605
|
+
const current = list.current();
|
|
1606
|
+
if (typeof key === "object" && key.text === " ") {
|
|
1607
|
+
if (current !== undefined)
|
|
1608
|
+
checked = toggle(checked, current.value);
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
list.press(key);
|
|
1612
|
+
return;
|
|
1613
|
+
});
|
|
1614
|
+
return accepted ? checked : undefined;
|
|
1615
|
+
}
|
|
1616
|
+
async function input2(question, { default: fallback, mask = false, validate, ...settings } = {}) {
|
|
1617
|
+
let value = "";
|
|
1618
|
+
let invalid;
|
|
1619
|
+
const taken = () => value === "" ? fallback ?? "" : value;
|
|
1620
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1621
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1622
|
+
if (state !== "asking")
|
|
1623
|
+
return [answer(colors, question, state, shown())];
|
|
1624
|
+
const characters = [...shown()];
|
|
1625
|
+
const room = Math.max(columns - question.length - 5, 1);
|
|
1626
|
+
const tail = characters.length > room ? `\u2026${characters.slice(1 - room).join("")}` : shown();
|
|
1627
|
+
const typed = value === "" ? colors.dim(tail) : tail;
|
|
1628
|
+
return [`${colors.cyan("?")} ${question} ${typed}${colors.dim("\u2588")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]];
|
|
1629
|
+
}, (key) => {
|
|
1630
|
+
if (key === "cancel")
|
|
1631
|
+
return "cancel";
|
|
1632
|
+
invalid = undefined;
|
|
1633
|
+
if (key === "enter") {
|
|
1634
|
+
invalid = validate?.(taken());
|
|
1635
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1636
|
+
}
|
|
1637
|
+
if (key === "erase")
|
|
1638
|
+
value = [...value].slice(0, -1).join("");
|
|
1639
|
+
else if (typeof key === "object")
|
|
1640
|
+
value += key.text;
|
|
1641
|
+
return;
|
|
1642
|
+
});
|
|
1643
|
+
return accepted ? taken() : undefined;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
class List {
|
|
1647
|
+
choices;
|
|
1648
|
+
query = "";
|
|
1649
|
+
matches;
|
|
1650
|
+
cursor;
|
|
1651
|
+
top = 0;
|
|
1652
|
+
width;
|
|
1653
|
+
constructor(choices, initial) {
|
|
1654
|
+
this.choices = choices;
|
|
1655
|
+
this.matches = choices;
|
|
1656
|
+
this.cursor = Math.min(Math.max(initial, 0), choices.length - 1);
|
|
1657
|
+
this.width = Math.max(0, ...choices.map((choice) => choice.label.length));
|
|
1658
|
+
}
|
|
1659
|
+
current() {
|
|
1660
|
+
return this.matches[this.cursor];
|
|
1661
|
+
}
|
|
1662
|
+
press(key) {
|
|
1663
|
+
if (key === "up" || key === "down") {
|
|
1664
|
+
if (this.matches.length > 0)
|
|
1665
|
+
this.cursor = (this.cursor + (key === "up" ? this.matches.length - 1 : 1)) % this.matches.length;
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
if (key === "erase")
|
|
1669
|
+
this.filter([...this.query].slice(0, -1).join(""));
|
|
1670
|
+
else if (typeof key === "object")
|
|
1671
|
+
this.filter(this.query + key.text);
|
|
1672
|
+
}
|
|
1673
|
+
filter(query) {
|
|
1674
|
+
const words = query.toLowerCase().split(WORDS).filter((word) => word !== "");
|
|
1675
|
+
const current = this.current();
|
|
1676
|
+
this.query = query;
|
|
1677
|
+
this.matches = this.choices.filter(({ label, hint }) => words.every((word) => `${label} ${hint}`.toLowerCase().includes(word)));
|
|
1678
|
+
this.cursor = current === undefined ? 0 : Math.max(this.matches.indexOf(current), 0);
|
|
1679
|
+
this.top = 0;
|
|
1680
|
+
}
|
|
1681
|
+
rows(colors, { columns, rows }, marker) {
|
|
1682
|
+
if (this.matches.length === 0)
|
|
1683
|
+
return [colors.dim(" no match")];
|
|
1684
|
+
const height = Math.max(1, Math.min(MAX_ROWS, rows - 3, this.matches.length));
|
|
1685
|
+
this.top = Math.min(Math.max(this.top, this.cursor - height + 1), this.cursor);
|
|
1686
|
+
const shown = this.matches.slice(this.top, this.top + height).map((choice, index) => {
|
|
1687
|
+
const here = this.top + index === this.cursor;
|
|
1688
|
+
const mark = marker(choice);
|
|
1689
|
+
const head = `${here ? "\u276F" : " "} ${mark}`;
|
|
1690
|
+
const label = choice.label.padEnd(this.width);
|
|
1691
|
+
const room = columns - 5 - (mark === "" ? 0 : 2) - this.width;
|
|
1692
|
+
return `${here ? colors.cyan(head) : head}${here ? colors.cyan(label) : label} ${colors.dim(truncate(choice.hint, Math.max(room, 0)))}`;
|
|
1693
|
+
});
|
|
1694
|
+
const below = this.matches.length - this.top - height;
|
|
1695
|
+
return [...this.top > 0 ? [colors.dim(` \u2026 ${this.top} more`)] : [], ...shown, ...below > 0 ? [colors.dim(` \u2026 ${below} more`)] : []];
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function asking(colors, question, typed, keys) {
|
|
1699
|
+
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
1700
|
+
}
|
|
1701
|
+
function answer(colors, question, state, picked) {
|
|
1702
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1703
|
+
}
|
|
1704
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1705
|
+
const { stdin, stderr } = terminal;
|
|
1706
|
+
if (!isInteractive(terminal))
|
|
1707
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1708
|
+
const colors = paint(stderr);
|
|
1709
|
+
let drawn = 0;
|
|
1710
|
+
let outcome;
|
|
1711
|
+
const draw = (state) => {
|
|
1712
|
+
const frame = render(colors, state, { columns: stderr.columns || 80, rows: stderr.rows || 24 });
|
|
1713
|
+
stderr.write(`${drawn > 1 ? `\x1B[${drawn - 1}A` : ""}\r\x1B[0J${frame.join(`
|
|
1714
|
+
`)}`);
|
|
1715
|
+
drawn = frame.length;
|
|
1716
|
+
};
|
|
1717
|
+
try {
|
|
1718
|
+
stdin.setRawMode(true);
|
|
1719
|
+
stdin.resume();
|
|
1720
|
+
stderr.write("\x1B[?25l");
|
|
1721
|
+
draw("asking");
|
|
1722
|
+
return await new Promise((resolve) => {
|
|
1723
|
+
function onData(data) {
|
|
1724
|
+
for (const key of readKeys(data.toString())) {
|
|
1725
|
+
const pressed = press(key);
|
|
1726
|
+
if (pressed !== undefined) {
|
|
1727
|
+
settle(pressed);
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
draw("asking");
|
|
1732
|
+
}
|
|
1733
|
+
function onEnd() {
|
|
1734
|
+
settle("cancel");
|
|
1735
|
+
}
|
|
1736
|
+
function settle(settled) {
|
|
1737
|
+
outcome = settled;
|
|
1738
|
+
stdin.off("data", onData);
|
|
1739
|
+
stdin.off("end", onEnd);
|
|
1740
|
+
resolve(settled === "enter");
|
|
1741
|
+
}
|
|
1742
|
+
stdin.on("data", onData);
|
|
1743
|
+
stdin.on("end", onEnd);
|
|
1744
|
+
});
|
|
1745
|
+
} finally {
|
|
1746
|
+
draw(outcome ?? "cancel");
|
|
1747
|
+
stderr.write(`
|
|
1748
|
+
\x1B[?25h`);
|
|
1749
|
+
stdin.setRawMode(false);
|
|
1750
|
+
stdin.pause();
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/install.ts
|
|
1755
|
+
var HOOKS = "hooks";
|
|
1756
|
+
var PLUGIN_INSTALL = ["claude", "plugin", "install", "cli-hooks", "--marketplace", `https://${FORGE}/kaynooo/cli.git`];
|
|
1757
|
+
var CLI_PREFIX = /^cli-/;
|
|
1758
|
+
var shortName = (name) => name.slice(name.indexOf("/") + 1).replace(CLI_PREFIX, "");
|
|
1759
|
+
function candidates2(host) {
|
|
1760
|
+
const packages = Object.entries(TOOLS).filter(([name]) => !isInstalled(host, name)).map(([name, bins]) => {
|
|
1761
|
+
const needs = (NEEDS[name] ?? []).map((need) => need.bin);
|
|
1762
|
+
return { id: name, names: [shortName(name), name, `cli-${shortName(name)}`, ...bins], label: shortName(name), hint: `${bins.join(" ")}: ${ABOUT[name] ?? ""}${needs.length === 0 ? "" : `, needs ${needs.join(", ")}`}`, packages: [name] };
|
|
1763
|
+
});
|
|
1764
|
+
const { plugin, mod } = hooksWiring(host);
|
|
1765
|
+
if (plugin || mod !== undefined)
|
|
1766
|
+
return packages;
|
|
1767
|
+
return [...packages, { id: HOOKS, names: [HOOKS, "plugin", "cli-hooks"], label: "hooks", hint: `the Claude Code plugin running guard on every tool call, needs ${HOOKS_REQUIRES}`, packages: isInstalled(host, HOOKS_REQUIRES) ? [] : [HOOKS_REQUIRES] }];
|
|
1768
|
+
}
|
|
1769
|
+
function choose(pool, names) {
|
|
1770
|
+
const chosen = new Set;
|
|
1771
|
+
for (const name of names) {
|
|
1772
|
+
if (name === "all") {
|
|
1773
|
+
for (const each of pool)
|
|
1774
|
+
chosen.add(each);
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
const found = pool.find((each) => each.names.includes(name));
|
|
1778
|
+
if (found !== undefined)
|
|
1779
|
+
chosen.add(found);
|
|
1780
|
+
}
|
|
1781
|
+
return [...chosen];
|
|
1782
|
+
}
|
|
1783
|
+
function plan(host, picked, force) {
|
|
1784
|
+
const blocked = [];
|
|
1785
|
+
const warnings = [];
|
|
1786
|
+
const packages = [];
|
|
1787
|
+
for (const name of new Set(picked.flatMap((each) => each.packages))) {
|
|
1788
|
+
const lacking = (NEEDS[name] ?? []).filter((need) => host.which(need.bin) === null);
|
|
1789
|
+
if (lacking.length > 0 && !force) {
|
|
1790
|
+
for (const need of lacking)
|
|
1791
|
+
blocked.push({ package: shortName(name), need: need.bin, why: need.why, how: need.how });
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
for (const need of lacking)
|
|
1795
|
+
warnings.push({ package: shortName(name), need: need.bin, why: need.why });
|
|
1796
|
+
packages.push(name);
|
|
1797
|
+
}
|
|
1798
|
+
const guardBlocked = blocked.some((each) => `@kaynooo/cli-${each.package}` === HOOKS_REQUIRES);
|
|
1799
|
+
return { packages, plugin: picked.some((each) => each.id === HOOKS) && !guardBlocked, blocked, warnings };
|
|
1800
|
+
}
|
|
1801
|
+
function checksFor(packages, plugin) {
|
|
1802
|
+
return [...packages.map((name) => name.slice(name.indexOf("/") + 1)), ...plugin ? ["hooks"] : [], "needs", "completions", ...packages.includes("@kaynooo/cli-forgejo") ? ["tea"] : []];
|
|
1803
|
+
}
|
|
1804
|
+
async function ask2(pool) {
|
|
1805
|
+
if (!isInteractive())
|
|
1806
|
+
badUsage("name what to install, or all: doctor --install forgejo check hooks (doctor --install --list shows the choices)");
|
|
1807
|
+
const choices = pool.map((each) => ({ value: each, label: each.label, hint: each.hint }));
|
|
1808
|
+
const picked = await checklist("install which?", choices, { hint: "name them instead: doctor --install forgejo check" });
|
|
1809
|
+
return picked === undefined ? [] : [...picked];
|
|
1810
|
+
}
|
|
1811
|
+
async function askWorkspace(host) {
|
|
1812
|
+
if (!isInteractive() || workspaceChosen({ home: host.home }))
|
|
1813
|
+
return;
|
|
1814
|
+
const folder = await input2("folder holding your repositories (repos, sweep and pkg bump look there)", { default: "~/Workspace" });
|
|
1815
|
+
if (folder !== undefined && folder !== "" && !saveWorkspace(folder, { home: host.home }))
|
|
1816
|
+
console.error(`could not write the workspace into ${userConfigPath("config", { home: host.home })}: it does not parse, fix it by hand`);
|
|
1817
|
+
}
|
|
1818
|
+
async function install(host, options, recheck) {
|
|
1819
|
+
const pool = candidates2(host);
|
|
1820
|
+
const { dim, green, red, yellow } = paint(process16.stdout);
|
|
1821
|
+
if (options.list) {
|
|
1822
|
+
for (const each of pool)
|
|
1823
|
+
console.log(`${each.label.padEnd(12)} ${dim(each.hint)}`);
|
|
1824
|
+
if (pool.length === 0)
|
|
1825
|
+
console.log("everything is installed");
|
|
1826
|
+
return 0;
|
|
1827
|
+
}
|
|
1828
|
+
if (pool.length === 0) {
|
|
1829
|
+
console.log("everything is installed");
|
|
1830
|
+
return 0;
|
|
1831
|
+
}
|
|
1832
|
+
const unknown = options.names.filter((name) => name !== "all" && !Object.values(candidatesAll(host)).some((each) => each.names.includes(name)));
|
|
1833
|
+
if (unknown.length > 0)
|
|
1834
|
+
badUsage(`nothing to install is named ${unknown.join(", ")}: doctor --install --list`);
|
|
1835
|
+
const picked = options.names.length === 0 ? await ask2(pool) : choose(pool, options.names);
|
|
1836
|
+
const skipped = options.names.filter((name) => name !== "all" && !pool.some((each) => each.names.includes(name)));
|
|
1837
|
+
for (const name of skipped)
|
|
1838
|
+
console.log(`${dim("already")} ${name} is installed`);
|
|
1839
|
+
if (picked.length === 0) {
|
|
1840
|
+
if (skipped.length === 0)
|
|
1841
|
+
console.log("nothing picked");
|
|
1842
|
+
return 0;
|
|
1843
|
+
}
|
|
1844
|
+
const planned = plan(host, picked, options.force);
|
|
1845
|
+
for (const each of planned.blocked)
|
|
1846
|
+
console.log(`${red("blocked")} ${each.package} needs ${each.need} (${each.why}): ${each.how}; --force installs it anyway`);
|
|
1847
|
+
for (const each of planned.warnings)
|
|
1848
|
+
console.log(`${yellow("warn ")} ${each.package}: ${each.need} is missing, ${each.why}`);
|
|
1849
|
+
if (planned.packages.length === 0 && !planned.plugin)
|
|
1850
|
+
return 1;
|
|
1851
|
+
if (!options.dryRun && planned.packages.some((name) => name === "@kaynooo/cli-workspace" || name === "@kaynooo/cli-pkg"))
|
|
1852
|
+
await askWorkspace(host);
|
|
1853
|
+
const command = ["bun", "install", "-g", ...planned.packages];
|
|
1854
|
+
if (planned.packages.length > 0)
|
|
1855
|
+
console.log(`${options.dryRun ? dim("would ") : green("install")} ${command.join(" ")}`);
|
|
1856
|
+
if (planned.plugin)
|
|
1857
|
+
console.log(`${options.dryRun ? dim("would ") : green("install")} ${PLUGIN_INSTALL.join(" ")}`);
|
|
1858
|
+
if (options.dryRun)
|
|
1859
|
+
return planned.blocked.length > 0 ? 1 : 0;
|
|
1860
|
+
if (planned.packages.length > 0) {
|
|
1861
|
+
const ran = await host.run(command);
|
|
1862
|
+
if (ran.code !== 0) {
|
|
1863
|
+
console.error(`${red("failed")} bun install -g: exit ${ran.code}: ${firstLine(ran.stderr || ran.stdout)}`);
|
|
1864
|
+
return 1;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
if (planned.plugin) {
|
|
1868
|
+
if (host.which("claude") === null) {
|
|
1869
|
+
console.log(`${dim("not run")} claude is not on the PATH: ${PLUGIN_INSTALL.join(" ")}`);
|
|
1870
|
+
} else {
|
|
1871
|
+
const ran = await host.run(PLUGIN_INSTALL);
|
|
1872
|
+
if (ran.code !== 0)
|
|
1873
|
+
console.error(`${red("failed")} ${PLUGIN_INSTALL.join(" ")}: exit ${ran.code}: ${firstLine(ran.stderr || ran.stdout)}`);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
console.log(`
|
|
1877
|
+
after the install:`);
|
|
1878
|
+
const code = await recheck(checksFor(planned.packages, planned.plugin));
|
|
1879
|
+
return planned.blocked.length > 0 ? 1 : code;
|
|
1880
|
+
}
|
|
1881
|
+
function candidatesAll(host) {
|
|
1882
|
+
const open = candidates2(host);
|
|
1883
|
+
const done = Object.entries(TOOLS).filter(([name]) => isInstalled(host, name)).map(([name, bins]) => ({ id: name, names: [shortName(name), name, `cli-${shortName(name)}`, ...bins], label: shortName(name), hint: "", packages: [name] }));
|
|
1884
|
+
return [...open, ...done];
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1418
1887
|
// src/doctor.ts
|
|
1419
|
-
var USAGE = `doctor [--only <check>] [--quiet] [--fix [--dry-run]] [--json]: checks this host's @kaynooo/cli-* install, one line per check, the command that fixes a failing one beside it
|
|
1888
|
+
var USAGE = `doctor [--only <check>] [--quiet] [--fix | --install [<name>...|all]] [--list] [--dry-run] [--force] [--json]: checks this host's @kaynooo/cli-* install, one line per check, the command that fixes a failing one beside it, and installs the packages it picks
|
|
1420
1889
|
|
|
1421
|
-
Each @kaynooo/cli-* package installed globally with its bins on the PATH and no older than the registry's latest; tea logged in to git.kaynooo.fr and reaching it; the Claude Code hooks wired through the cli-hooks plugin or the cli mod, not both; Bun at least the version the tools ask for; fish completions for every bin.
|
|
1890
|
+
Each @kaynooo/cli-* package installed globally with its bins on the PATH and no older than the registry's latest; tea logged in to git.kaynooo.fr and reaching it when ft is installed; the system tools the installed packages need (glab, docker); the Claude Code hooks wired through the cli-hooks plugin or the cli mod, not both, with guard installed; Bun at least the version the tools ask for; fish completions for every bin. A package not installed is no failure, the last line counts them.
|
|
1422
1891
|
--fix runs the printed fix: lines it may (global installs of the packages, the completions, the hooks plugin), the installs in one call, then checks again; a line that installs a system package or only describes a step is printed as not run. --dry-run shows what --fix would run.
|
|
1892
|
+
--install adds packages: the names given (a package such as forgejo, one of its bins such as ft, hooks for the Claude Code plugin, or all), else a checklist on a terminal. Each is checked against what it needs first: a missing required tool (tea for ft, glab for gl, docker for dc) leaves that package out unless --force, and hooks brings guard along. doctor never installs a system package. Then it checks and fixes what it installed. --list prints the choices, --dry-run what would be installed.
|
|
1423
1893
|
--quiet prints only the failing checks, nothing when all pass. --only limits the run to the checks named, e.g. --only tea --only bun.`;
|
|
1424
1894
|
var EXITS = [[0, "every check passes (after --fix, the ones it fixed too)"], [1, "a check fails"], [2, "a usage error"]];
|
|
1425
1895
|
var INSTALL2 = "bun install -g ";
|
|
@@ -1428,12 +1898,15 @@ var OPTIONS = {
|
|
|
1428
1898
|
only: { type: "string", multiple: true, choices: CHECK_NAMES, description: "run only this check (a package such as cli-forgejo, tea, hooks, bun or completions), repeatable" },
|
|
1429
1899
|
quiet: { type: "boolean", short: "q", description: "print only the failing checks" },
|
|
1430
1900
|
fix: { type: "boolean", description: "run the fix: lines doctor may run, then check again" },
|
|
1431
|
-
"dry-run": { type: "boolean", description: "with --fix, show what would run without running it (alone, it implies --fix)" }
|
|
1901
|
+
"dry-run": { type: "boolean", description: "with --fix or --install, show what would run without running it (alone, it implies --fix)" },
|
|
1902
|
+
install: { type: "boolean", description: "install the packages named, or picked from a checklist: forgejo, ft, hooks, all" },
|
|
1903
|
+
list: { type: "boolean", description: "with --install, print the choices" },
|
|
1904
|
+
force: { type: "boolean", description: "with --install, install a package even though a tool it requires is missing" }
|
|
1432
1905
|
};
|
|
1433
1906
|
function print(results) {
|
|
1434
1907
|
if (results.length === 0)
|
|
1435
1908
|
return;
|
|
1436
|
-
const { green, red, dim } = paint(
|
|
1909
|
+
const { green, red, dim } = paint(process17.stdout);
|
|
1437
1910
|
const width = Math.max(...results.map((result) => result.check.length));
|
|
1438
1911
|
for (const { check, ok, detail, fix } of results)
|
|
1439
1912
|
console.log(`${ok ? green("ok ") : red("FAIL")} ${check.padEnd(width)} ${detail}${fix === undefined ? "" : ` ${dim("fix:")} ${fix}`}`);
|
|
@@ -1443,14 +1916,21 @@ function print(results) {
|
|
|
1443
1916
|
${dim("fix them all:")} ${INSTALL2}${installs.join(" ")}`);
|
|
1444
1917
|
}
|
|
1445
1918
|
function printOutcomes(outcomes, log) {
|
|
1446
|
-
const { green, red, dim } = paint(
|
|
1919
|
+
const { green, red, dim } = paint(process17.stdout);
|
|
1447
1920
|
const marks = { ran: green("ran "), failed: red("failed "), "dry-run": dim("would "), "not run": dim("not run") };
|
|
1448
1921
|
for (const { command, status, detail } of outcomes)
|
|
1449
1922
|
log(`${marks[status]} ${command}${detail === undefined ? "" : ` ${dim(detail)}`}`);
|
|
1450
1923
|
}
|
|
1451
1924
|
async function main(args, host = hostHere()) {
|
|
1452
|
-
const { values } = parse(args, USAGE, OPTIONS, { positionals: [], exits: EXITS, replaces: "checking each bin's version, tea's login and the hooks by hand", examples: ["doctor", ["doctor --json", "the checks for a script"], ["doctor -q", "silent unless something fails"], ["doctor --fix --dry-run", "what --fix would run"]] });
|
|
1925
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[name...]"], exits: EXITS, replaces: "checking each bin's version, tea's login and the hooks by hand", examples: ["doctor", ["doctor --json", "the checks for a script"], ["doctor -q", "silent unless something fails"], ["doctor --fix --dry-run", "what --fix would run"], ["doctor --install", "pick the packages to add"], ["doctor --install forgejo check hooks", "three named ones"], ["doctor --install all --dry-run", "what installing everything would run"]] });
|
|
1453
1926
|
const only = values.only ?? [];
|
|
1927
|
+
if (values.install !== true && (positionals.length > 0 || values.list === true || values.force === true))
|
|
1928
|
+
badUsage("names, --list and --force go with --install");
|
|
1929
|
+
if (values.install === true) {
|
|
1930
|
+
if (values.fix === true || only.length > 0 || values.json === true || values.quiet === true)
|
|
1931
|
+
badUsage("--install does not combine with --fix, --only, --json or --quiet");
|
|
1932
|
+
return install(host, { names: positionals, list: values.list === true, dryRun: values["dry-run"] === true, force: values.force === true }, async (checks) => main(["--fix", ...checks.flatMap((check) => ["--only", check])], host));
|
|
1933
|
+
}
|
|
1454
1934
|
const dry = values["dry-run"] === true;
|
|
1455
1935
|
const json = values.json === true;
|
|
1456
1936
|
let results = await runChecks(host, only);
|
|
@@ -1473,8 +1953,12 @@ after the fixes:`);
|
|
|
1473
1953
|
printJson(shown);
|
|
1474
1954
|
else
|
|
1475
1955
|
print(shown);
|
|
1956
|
+
const absent = Object.keys(TOOLS).filter((name) => !isInstalled(host, name)).length;
|
|
1957
|
+
if (!json && only.length === 0 && absent > 0)
|
|
1958
|
+
console.log(`
|
|
1959
|
+
${paint(process17.stdout).dim(`${absent} packages not installed: doctor --install`)}`);
|
|
1476
1960
|
return results.every((result) => result.ok) ? 0 : 1;
|
|
1477
1961
|
}
|
|
1478
1962
|
|
|
1479
1963
|
// src/cli.ts
|
|
1480
|
-
|
|
1964
|
+
process18.exitCode = await runMain({ name: "doctor", run: async (args) => main(args) });
|