@kaynooo/cli-workspace 0.10.2 → 0.11.1
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/audit-cli.js +286 -46
- package/dist/cli.js +399 -102
- package/dist/repos-cli.js +159 -44
- package/dist/sweep-cli.js +217 -45
- package/package.json +2 -2
package/dist/sweep-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/sweep-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -517,7 +517,7 @@ function printJson(value) {
|
|
|
517
517
|
|
|
518
518
|
// ../kit/src/help.ts
|
|
519
519
|
import process8 from "process";
|
|
520
|
-
var OPTIONAL =
|
|
520
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
521
521
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
522
522
|
var FULL_STOP = /\.$/;
|
|
523
523
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
@@ -556,29 +556,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
556
556
|
return [];
|
|
557
557
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
558
558
|
}
|
|
559
|
+
var MAX_INLINE_CHOICES = 24;
|
|
559
560
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
560
561
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
561
562
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
562
|
-
const
|
|
563
|
+
const choices = option.choices?.join("|");
|
|
564
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
565
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
563
566
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
564
567
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
565
|
-
|
|
568
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
569
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
566
570
|
});
|
|
567
571
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
568
572
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
569
573
|
}
|
|
570
574
|
|
|
571
575
|
// ../kit/src/text.ts
|
|
572
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
573
576
|
function distance(a, b) {
|
|
574
|
-
|
|
575
|
-
|
|
577
|
+
const left = [...a];
|
|
578
|
+
const right = [...b];
|
|
579
|
+
let before = [];
|
|
580
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
581
|
+
for (const [i, x] of left.entries()) {
|
|
576
582
|
const current = [i + 1];
|
|
577
|
-
for (const [j,
|
|
578
|
-
|
|
583
|
+
for (const [j, y] of right.entries()) {
|
|
584
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
585
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
586
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
587
|
+
current.push(cost);
|
|
588
|
+
}
|
|
589
|
+
before = previous;
|
|
579
590
|
previous = current;
|
|
580
591
|
}
|
|
581
|
-
return previous[
|
|
592
|
+
return previous[right.length] ?? 0;
|
|
582
593
|
}
|
|
583
594
|
function closest(name, names) {
|
|
584
595
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -645,7 +656,7 @@ class Completing {
|
|
|
645
656
|
}
|
|
646
657
|
var completion = { active: false };
|
|
647
658
|
var OUTPUT_OPTIONS = {
|
|
648
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
659
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
649
660
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
650
661
|
};
|
|
651
662
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -980,13 +991,91 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
980
991
|
// ../kit/src/cli.ts
|
|
981
992
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
982
993
|
import { dirname as dirname3, join as join5 } from "path";
|
|
983
|
-
import
|
|
994
|
+
import process15 from "process";
|
|
995
|
+
|
|
996
|
+
// ../kit/src/completions.ts
|
|
997
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
998
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
999
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1000
|
+
set -l current (commandline -ct)
|
|
1001
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1002
|
+
if test "$line" = __files__
|
|
1003
|
+
__fish_complete_path $current
|
|
1004
|
+
else
|
|
1005
|
+
echo $line
|
|
1006
|
+
end
|
|
1007
|
+
end
|
|
1008
|
+
end`;
|
|
1009
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1010
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1011
|
+
local -a lines
|
|
1012
|
+
COMPREPLY=()
|
|
1013
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1014
|
+
for line in "\${lines[@]}"; do
|
|
1015
|
+
if [[ $line == __files__ ]]; then
|
|
1016
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1017
|
+
else
|
|
1018
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1019
|
+
fi
|
|
1020
|
+
done
|
|
1021
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1022
|
+
}`;
|
|
1023
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1024
|
+
local line
|
|
1025
|
+
local -a described plain
|
|
1026
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1027
|
+
if [[ $line == __files__ ]]; then
|
|
1028
|
+
_files
|
|
1029
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1030
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1031
|
+
else
|
|
1032
|
+
plain+=("$line")
|
|
1033
|
+
fi
|
|
1034
|
+
done
|
|
1035
|
+
(( \${#described} )) && _describe -V value described
|
|
1036
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1037
|
+
return 0
|
|
1038
|
+
}`;
|
|
1039
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1040
|
+
if (shell === "fish")
|
|
1041
|
+
return `${header}
|
|
1042
|
+
${FISH_FUNCTION}
|
|
1043
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1044
|
+
`).join("")}`;
|
|
1045
|
+
if (shell === "bash")
|
|
1046
|
+
return `${header}
|
|
1047
|
+
${BASH_FUNCTION}
|
|
1048
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1049
|
+
`;
|
|
1050
|
+
return `${header}
|
|
1051
|
+
${ZSH_FUNCTION}
|
|
1052
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1053
|
+
`;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// ../kit/src/notify.ts
|
|
1057
|
+
import process13 from "process";
|
|
1058
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1059
|
+
var CANCELLED = 130;
|
|
1060
|
+
function base64(text) {
|
|
1061
|
+
return Buffer.from(text).toString("base64");
|
|
1062
|
+
}
|
|
1063
|
+
function notification(title, body, env = process13.env) {
|
|
1064
|
+
const id = `kit${process13.pid}`;
|
|
1065
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1066
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1067
|
+
}
|
|
1068
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1069
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1070
|
+
return;
|
|
1071
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1072
|
+
}
|
|
984
1073
|
|
|
985
1074
|
// ../kit/src/usage.ts
|
|
986
1075
|
import { appendFileSync, mkdirSync } from "fs";
|
|
987
1076
|
import { homedir as homedir3 } from "os";
|
|
988
1077
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
989
|
-
import
|
|
1078
|
+
import process14 from "process";
|
|
990
1079
|
|
|
991
1080
|
// ../kit/src/logs.ts
|
|
992
1081
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1000,14 +1089,14 @@ var usageError;
|
|
|
1000
1089
|
function noteUsageError(message) {
|
|
1001
1090
|
usageError = message;
|
|
1002
1091
|
}
|
|
1003
|
-
function stateHome(env =
|
|
1092
|
+
function stateHome(env = process14.env) {
|
|
1004
1093
|
const dir = env.XDG_STATE_HOME;
|
|
1005
1094
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1006
1095
|
}
|
|
1007
|
-
function usagePath(env =
|
|
1096
|
+
function usagePath(env = process14.env) {
|
|
1008
1097
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1009
1098
|
}
|
|
1010
|
-
function usageRecorded(env =
|
|
1099
|
+
function usageRecorded(env = process14.env) {
|
|
1011
1100
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1012
1101
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1013
1102
|
}
|
|
@@ -1021,7 +1110,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1021
1110
|
usageError = undefined;
|
|
1022
1111
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1023
1112
|
}
|
|
1024
|
-
function recordUsage(entry, env =
|
|
1113
|
+
function recordUsage(entry, env = process14.env) {
|
|
1025
1114
|
if (!usageRecorded(env))
|
|
1026
1115
|
return;
|
|
1027
1116
|
try {
|
|
@@ -1037,7 +1126,11 @@ var LEVEL_OPTIONS = {
|
|
|
1037
1126
|
...OUTPUT_OPTIONS,
|
|
1038
1127
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1039
1128
|
};
|
|
1040
|
-
var TOP_OPTIONS = {
|
|
1129
|
+
var TOP_OPTIONS = {
|
|
1130
|
+
...LEVEL_OPTIONS,
|
|
1131
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1132
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1133
|
+
};
|
|
1041
1134
|
async function commandRows(all, colors) {
|
|
1042
1135
|
const commands = shown(all);
|
|
1043
1136
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1111,8 +1204,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1111
1204
|
`);
|
|
1112
1205
|
}
|
|
1113
1206
|
function printError(prefix, message, hint, cause) {
|
|
1114
|
-
const colors = paint(
|
|
1115
|
-
const styled = takesControlCodes(
|
|
1207
|
+
const colors = paint(process15.stderr);
|
|
1208
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1116
1209
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1117
1210
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1118
1211
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1155,11 +1248,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1155
1248
|
}
|
|
1156
1249
|
}
|
|
1157
1250
|
if (name === undefined && level.path.length > 1) {
|
|
1158
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1251
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1159
1252
|
return 2;
|
|
1160
1253
|
}
|
|
1161
1254
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1162
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1255
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1163
1256
|
return 0;
|
|
1164
1257
|
}
|
|
1165
1258
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1270,6 +1363,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1270
1363
|
}
|
|
1271
1364
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1272
1365
|
}
|
|
1366
|
+
var COMPLETIONS = "--completions";
|
|
1367
|
+
function flagValue([flag = "", ...rest]) {
|
|
1368
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1369
|
+
}
|
|
1370
|
+
function printCompletionScript(name, args) {
|
|
1371
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1372
|
+
if (shell === undefined || args.length !== 1) {
|
|
1373
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1374
|
+
return 2;
|
|
1375
|
+
}
|
|
1376
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1377
|
+
return 0;
|
|
1378
|
+
}
|
|
1273
1379
|
async function printCandidates(found) {
|
|
1274
1380
|
for (const line of await found)
|
|
1275
1381
|
console.log(line);
|
|
@@ -1294,10 +1400,15 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1294
1400
|
const version = cli.version ?? packageVersion();
|
|
1295
1401
|
if (argv[0] === COMPLETE)
|
|
1296
1402
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1403
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1404
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1405
|
+
const started = performance.now();
|
|
1297
1406
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1407
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1408
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1298
1409
|
if (cli.usage !== false) {
|
|
1299
1410
|
try {
|
|
1300
|
-
recordUsage(usageEntry(cli.name,
|
|
1411
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1301
1412
|
} catch {}
|
|
1302
1413
|
}
|
|
1303
1414
|
return code;
|
|
@@ -1320,16 +1431,20 @@ function commandPath(scope, argv) {
|
|
|
1320
1431
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1321
1432
|
if (argv[0] === COMPLETE)
|
|
1322
1433
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1434
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1435
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1323
1436
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1324
1437
|
console.log(version ?? packageVersion());
|
|
1325
1438
|
return 0;
|
|
1326
1439
|
}
|
|
1327
1440
|
let code;
|
|
1441
|
+
const started = performance.now();
|
|
1328
1442
|
try {
|
|
1329
1443
|
code = await run(argv);
|
|
1330
1444
|
} catch (error) {
|
|
1331
1445
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1332
1446
|
}
|
|
1447
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1333
1448
|
if (usage !== false) {
|
|
1334
1449
|
try {
|
|
1335
1450
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1369,7 +1484,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1369
1484
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1370
1485
|
}
|
|
1371
1486
|
// ../kit/src/watch.ts
|
|
1372
|
-
import
|
|
1487
|
+
import process16 from "process";
|
|
1373
1488
|
import { format } from "util";
|
|
1374
1489
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1375
1490
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1391,7 +1506,7 @@ function withoutWatch(args) {
|
|
|
1391
1506
|
}
|
|
1392
1507
|
return rest;
|
|
1393
1508
|
}
|
|
1394
|
-
async function watching(value, step, stream =
|
|
1509
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1395
1510
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1396
1511
|
if (!takesControlCodes(stream))
|
|
1397
1512
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1399,12 +1514,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1399
1514
|
for (let round = 0;round < rounds; round++) {
|
|
1400
1515
|
const held = [];
|
|
1401
1516
|
const { log, info } = console;
|
|
1402
|
-
const write =
|
|
1517
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1403
1518
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1404
1519
|
`);
|
|
1405
1520
|
console.log = hold;
|
|
1406
1521
|
console.info = hold;
|
|
1407
|
-
|
|
1522
|
+
process16.stdout.write = (text) => {
|
|
1408
1523
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1409
1524
|
return true;
|
|
1410
1525
|
};
|
|
@@ -1413,7 +1528,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1413
1528
|
} finally {
|
|
1414
1529
|
console.log = log;
|
|
1415
1530
|
console.info = info;
|
|
1416
|
-
|
|
1531
|
+
process16.stdout.write = write;
|
|
1417
1532
|
}
|
|
1418
1533
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1419
1534
|
await sleep(interval);
|
|
@@ -1423,7 +1538,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1423
1538
|
// ../kit/src/workspace-root.ts
|
|
1424
1539
|
import { homedir as homedir4 } from "os";
|
|
1425
1540
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1426
|
-
import
|
|
1541
|
+
import process17 from "process";
|
|
1427
1542
|
function expandHome(path, home) {
|
|
1428
1543
|
if (path === "~")
|
|
1429
1544
|
return home;
|
|
@@ -1433,7 +1548,7 @@ function configured(env, home) {
|
|
|
1433
1548
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1434
1549
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1435
1550
|
}
|
|
1436
|
-
function workspaceRoot({ given, env =
|
|
1551
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1437
1552
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1438
1553
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1439
1554
|
}
|
|
@@ -1443,7 +1558,21 @@ import { homedir as homedir6 } from "os";
|
|
|
1443
1558
|
import { relative } from "path";
|
|
1444
1559
|
|
|
1445
1560
|
// ../kit/src/prompt.ts
|
|
1446
|
-
import
|
|
1561
|
+
import process20 from "process";
|
|
1562
|
+
|
|
1563
|
+
// ../kit/src/job.ts
|
|
1564
|
+
import process19 from "process";
|
|
1565
|
+
function stopJob() {
|
|
1566
|
+
process19.kill(0, "SIGTSTP");
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
// ../kit/src/picker/line.ts
|
|
1570
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1571
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1572
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1573
|
+
function isEditKey(key) {
|
|
1574
|
+
return EDIT_KEYS.has(key);
|
|
1575
|
+
}
|
|
1447
1576
|
|
|
1448
1577
|
// ../kit/src/picker/score.ts
|
|
1449
1578
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1475,10 +1604,29 @@ var KEYS = {
|
|
|
1475
1604
|
"\n": "enter",
|
|
1476
1605
|
"\x03": "cancel",
|
|
1477
1606
|
"\x1B": "cancel",
|
|
1607
|
+
"\x1B[D": "left",
|
|
1608
|
+
"\x1BOD": "left",
|
|
1609
|
+
"\x1B[C": "right",
|
|
1610
|
+
"\x1BOC": "right",
|
|
1611
|
+
"\x1B[1;5D": "wordleft",
|
|
1612
|
+
"\x1B[1;3D": "wordleft",
|
|
1613
|
+
"\x1Bb": "wordleft",
|
|
1614
|
+
"\x1B[1;5C": "wordright",
|
|
1615
|
+
"\x1B[1;3C": "wordright",
|
|
1616
|
+
"\x1Bf": "wordright",
|
|
1617
|
+
"\x01": "linestart",
|
|
1618
|
+
"\x05": "lineend",
|
|
1478
1619
|
"\x7F": "erase",
|
|
1479
|
-
"\
|
|
1620
|
+
"\x1B[3~": "delete",
|
|
1621
|
+
"\b": "killword",
|
|
1622
|
+
"\x1B\x7F": "killword",
|
|
1623
|
+
"\x1B[3;5~": "killnext",
|
|
1624
|
+
"\x1Bd": "killnext",
|
|
1480
1625
|
"\x15": "clear",
|
|
1626
|
+
"\v": "killend",
|
|
1481
1627
|
"\x17": "word",
|
|
1628
|
+
"\x19": "yank",
|
|
1629
|
+
"\x1A": "suspend",
|
|
1482
1630
|
"\t": "tab",
|
|
1483
1631
|
"\x1F": "help",
|
|
1484
1632
|
"\x1BOP": "help",
|
|
@@ -1508,10 +1656,21 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1508
1656
|
});
|
|
1509
1657
|
}
|
|
1510
1658
|
|
|
1659
|
+
// ../kit/src/redraw.ts
|
|
1660
|
+
var SYNC_START = "\x1B[?2026h";
|
|
1661
|
+
var SYNC_END = "\x1B[?2026l";
|
|
1662
|
+
function overwrite(lines, columns) {
|
|
1663
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1664
|
+
`);
|
|
1665
|
+
}
|
|
1666
|
+
function rowsTaken(lines, columns) {
|
|
1667
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1511
1670
|
// ../kit/src/prompt.ts
|
|
1512
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "
|
|
1671
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1513
1672
|
function readKeys(input, paste = { active: false }) {
|
|
1514
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
1673
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1515
1674
|
}
|
|
1516
1675
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1517
1676
|
let answered = fallback;
|
|
@@ -1535,7 +1694,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1535
1694
|
function answer(colors, question, state, picked) {
|
|
1536
1695
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1537
1696
|
}
|
|
1538
|
-
async function ask(question, { hint, terminal =
|
|
1697
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
1539
1698
|
const { stdin, stderr } = terminal;
|
|
1540
1699
|
if (!isInteractive(terminal))
|
|
1541
1700
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -1545,12 +1704,22 @@ async function ask(question, { hint, terminal = process18 }, render, press) {
|
|
|
1545
1704
|
const columns = () => stderr.columns || 80;
|
|
1546
1705
|
const draw = (state, last = false) => {
|
|
1547
1706
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1548
|
-
|
|
1549
|
-
|
|
1707
|
+
const rows = rowsTaken(frame, columns());
|
|
1708
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1550
1709
|
current = state;
|
|
1551
1710
|
};
|
|
1552
1711
|
const redraw = () => draw(current);
|
|
1553
1712
|
const paste = { active: false };
|
|
1713
|
+
const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
|
|
1714
|
+
const suspend = () => {
|
|
1715
|
+
if (stop === undefined)
|
|
1716
|
+
return;
|
|
1717
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1718
|
+
stdin.setRawMode(false);
|
|
1719
|
+
stop();
|
|
1720
|
+
stdin.setRawMode(true);
|
|
1721
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1722
|
+
};
|
|
1554
1723
|
try {
|
|
1555
1724
|
stderr.on?.("resize", redraw);
|
|
1556
1725
|
stdin.setRawMode(true);
|
|
@@ -1560,6 +1729,10 @@ async function ask(question, { hint, terminal = process18 }, render, press) {
|
|
|
1560
1729
|
return await new Promise((resolve) => {
|
|
1561
1730
|
function onData(data) {
|
|
1562
1731
|
for (const key of readKeys(data.toString(), paste)) {
|
|
1732
|
+
if (key === "suspend") {
|
|
1733
|
+
suspend();
|
|
1734
|
+
continue;
|
|
1735
|
+
}
|
|
1563
1736
|
const pressed = press(key);
|
|
1564
1737
|
if (pressed !== undefined) {
|
|
1565
1738
|
settle(pressed);
|
|
@@ -1675,9 +1848,10 @@ async function sizeOf(folder) {
|
|
|
1675
1848
|
}
|
|
1676
1849
|
|
|
1677
1850
|
// src/sweep-scan.ts
|
|
1678
|
-
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
|
|
1851
|
+
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target", "vendor", ".venv", "__pycache__", ".gradle"]);
|
|
1852
|
+
var NEEDS_BESIDE = { target: ["Cargo.toml"], vendor: ["composer.json", "composer.lock"] };
|
|
1679
1853
|
var MAX_DEPTH = 3;
|
|
1680
|
-
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
|
|
1854
|
+
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit", "__pycache__", ".gradle"]);
|
|
1681
1855
|
var GLOBAL_CACHES = [".bun/install/cache", ".npm/_cacache", ".cache/pip", ".cache/uv", ".cache/ms-playwright", ".cache/puppeteer", ".cache/go-build", ".cache/typescript", ".cargo/registry"];
|
|
1682
1856
|
function isCachePath(path, home = homedir5()) {
|
|
1683
1857
|
return GLOBAL_CACHES.some((cache) => join8(home, cache) === path) || basename(path) === ".cache" && basename(dirname5(path)) === "node_modules";
|
|
@@ -1722,7 +1896,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
1722
1896
|
}
|
|
1723
1897
|
continue;
|
|
1724
1898
|
}
|
|
1725
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name
|
|
1899
|
+
if (FOLDER_NAMES.has(entry.name) && (NEEDS_BESIDE[entry.name]?.some((file) => existsSync4(join8(dir, file))) ?? true)) {
|
|
1726
1900
|
if (entry.isSymbolicLink()) {
|
|
1727
1901
|
found.skipped.push({ path, reason: "symlink" });
|
|
1728
1902
|
} else if (entry.isDirectory()) {
|
|
@@ -1909,7 +2083,7 @@ async function applyAll(entries, done) {
|
|
|
1909
2083
|
// src/sweep.ts
|
|
1910
2084
|
var LARGE = 100 * 1024 ** 2;
|
|
1911
2085
|
var BIG = 1024 ** 3;
|
|
1912
|
-
var USAGE = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, target beside a Cargo.toml), the caches (.nuxt, .next, .turbo, .svelte-kit and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (the configured workspace, ~/Workspace by default, ${MAX_DEPTH} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
|
|
2086
|
+
var USAGE = `sweep [options] [root]: lists the regenerable folders (node_modules, .output, dist, build, .venv, target beside a Cargo.toml, vendor beside a composer.json or composer.lock), the caches (.nuxt, .next, .turbo, .svelte-kit, __pycache__, .gradle and node_modules/.cache per project; ~/.bun/install/cache, ~/.npm/_cacache, ~/.cache/{pip,uv,ms-playwright,puppeteer,go-build,typescript} and ~/.cargo/registry, exact paths only, listed only when no root is given or with --only caches) and the .worktrees/* and .claude/worktrees/* entries under root (the configured workspace, ~/Workspace by default, ${MAX_DEPTH} levels down), largest first with the age of the repo's last commit; --only worktrees, folders or caches keeps one kind
|
|
1913
2087
|
|
|
1914
2088
|
Dry unless --apply, which deletes after a confirm showing the total (read from the terminal; off one, pass --yes). A folder is deleted for good, not trashed. Never touched: a symlink, a folder git tracks files in, a build folder git does not ignore. A worktree is removed with git worktree remove, never forced, and only when it is clean and every commit of its branch is on another branch or a remote; the others stay listed as kept and count for nothing in the total. With --docker the Docker usage comes after the list, left to dclean.`;
|
|
1915
2089
|
var EXITS = [[0, "it listed, or removed every entry it was allowed to"], [1, "a removal failed or the confirm was declined"], [2, "a usage error, a missing root, or --apply off a terminal without --yes"]];
|
|
@@ -1919,7 +2093,7 @@ var OPTIONS = {
|
|
|
1919
2093
|
yes: { type: "boolean", short: "y", description: "with --apply, skip the confirm" },
|
|
1920
2094
|
older: { type: "string", description: "only the entries whose repo last committed longer ago than this (30d, 12h)" },
|
|
1921
2095
|
min: { type: "string", description: "only the entries of at least this size (500K, 10M, 1G)" },
|
|
1922
|
-
only: { type: "string",
|
|
2096
|
+
only: { type: "string", choices: Object.keys(ONLY_KINDS), description: "leave the other kinds out (.nuxt, .next, .turbo, .svelte-kit, __pycache__ and .gradle are caches; the global caches are listed with no root or with caches)" },
|
|
1923
2097
|
docker: { type: "boolean", description: "add the docker system df output, which alone takes about ten seconds" },
|
|
1924
2098
|
json: jsonOption("{root, entries: [{path, kind (folder, worktree or cache), bytes, committedAt, action (remove or keep), reason}], skipped: [{path, reason}], reclaimable, docker, removed?}")
|
|
1925
2099
|
};
|
|
@@ -1940,8 +2114,6 @@ async function sweep(args) {
|
|
|
1940
2114
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1941
2115
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1942
2116
|
fail(`${root} is not a folder`);
|
|
1943
|
-
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
1944
|
-
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
1945
2117
|
const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0);
|
|
1946
2118
|
const minBytes = values.min === undefined ? 0 : parseSize(values.min);
|
|
1947
2119
|
if (minBytes === undefined)
|
|
@@ -2012,4 +2184,4 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2012
2184
|
}
|
|
2013
2185
|
|
|
2014
2186
|
// src/sweep-cli.ts
|
|
2015
|
-
|
|
2187
|
+
process21.exitCode = await runMain({ name: "sweep", run: sweep });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.1",
|
|
5
5
|
"description": "ws, repos, sweep, audit: the repositories of the workspace that need attention, the folders worth reclaiming and their known vulnerabilities.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"audit": "$npm_execpath src/audit-cli.ts"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@kaynooo/cli-kit": "0.
|
|
37
|
+
"@kaynooo/cli-kit": "0.41.0"
|
|
38
38
|
}
|
|
39
39
|
}
|