@kaynooo/cli-workspace 0.10.1 → 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 +340 -77
- package/dist/cli.js +456 -137
- package/dist/repos-cli.js +210 -72
- package/dist/sweep-cli.js +271 -77
- 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,24 +517,20 @@ 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)) {
|
|
524
524
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
525
525
|
}
|
|
526
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
527
|
-
return [usageLine(usage, colors),
|
|
526
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
527
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
528
528
|
`);
|
|
529
529
|
}
|
|
530
530
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
531
531
|
if (exits.length === 0)
|
|
532
532
|
return [];
|
|
533
|
-
|
|
534
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
535
|
-
}
|
|
536
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
537
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
533
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
538
534
|
}
|
|
539
535
|
function wantsHelpJson(env = process8.env) {
|
|
540
536
|
return env.KIT_HELP === "json";
|
|
@@ -560,29 +556,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
560
556
|
return [];
|
|
561
557
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
562
558
|
}
|
|
559
|
+
var MAX_INLINE_CHOICES = 24;
|
|
563
560
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
564
561
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
565
562
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
566
|
-
const
|
|
563
|
+
const choices = option.choices?.join("|");
|
|
564
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
565
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
567
566
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
568
567
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
569
|
-
|
|
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 };
|
|
570
570
|
});
|
|
571
571
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
572
572
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
573
573
|
}
|
|
574
574
|
|
|
575
575
|
// ../kit/src/text.ts
|
|
576
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
577
576
|
function distance(a, b) {
|
|
578
|
-
|
|
579
|
-
|
|
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()) {
|
|
580
582
|
const current = [i + 1];
|
|
581
|
-
for (const [j,
|
|
582
|
-
|
|
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;
|
|
583
590
|
previous = current;
|
|
584
591
|
}
|
|
585
|
-
return previous[
|
|
592
|
+
return previous[right.length] ?? 0;
|
|
586
593
|
}
|
|
587
594
|
function closest(name, names) {
|
|
588
595
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -649,7 +656,7 @@ class Completing {
|
|
|
649
656
|
}
|
|
650
657
|
var completion = { active: false };
|
|
651
658
|
var OUTPUT_OPTIONS = {
|
|
652
|
-
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" },
|
|
653
660
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
654
661
|
};
|
|
655
662
|
function applyOutput(color, plain, env = process9.env) {
|
|
@@ -821,9 +828,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
821
828
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
822
829
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
823
830
|
}
|
|
831
|
+
// ../kit/src/argv.ts
|
|
832
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
833
|
+
import { resolve as resolve3 } from "path";
|
|
834
|
+
import process10 from "process";
|
|
835
|
+
function commandLine() {
|
|
836
|
+
try {
|
|
837
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
838
|
+
} catch {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function realPath(word) {
|
|
843
|
+
try {
|
|
844
|
+
return realpathSync(resolve3(word));
|
|
845
|
+
} catch {
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
850
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
851
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
852
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
853
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
854
|
+
}
|
|
824
855
|
// ../kit/src/process.ts
|
|
825
856
|
import { constants } from "os";
|
|
826
|
-
import
|
|
857
|
+
import process11 from "process";
|
|
827
858
|
var KILL_GRACE_MS = 2000;
|
|
828
859
|
function exitCodeOf(code, signal) {
|
|
829
860
|
if (code !== null)
|
|
@@ -843,7 +874,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
843
874
|
return;
|
|
844
875
|
try {
|
|
845
876
|
if (grouped)
|
|
846
|
-
|
|
877
|
+
process11.kill(-proc.pid, killing);
|
|
847
878
|
else
|
|
848
879
|
proc.kill(killing);
|
|
849
880
|
} catch {}
|
|
@@ -918,10 +949,10 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
918
949
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
919
950
|
|
|
920
951
|
// ../kit/src/tool.ts
|
|
921
|
-
import
|
|
952
|
+
import process12 from "process";
|
|
922
953
|
function cwdGone() {
|
|
923
954
|
try {
|
|
924
|
-
|
|
955
|
+
process12.cwd();
|
|
925
956
|
return false;
|
|
926
957
|
} catch {
|
|
927
958
|
return true;
|
|
@@ -943,7 +974,7 @@ function spawnFailure(command, error) {
|
|
|
943
974
|
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
944
975
|
let ran;
|
|
945
976
|
try {
|
|
946
|
-
ran = await runCommand(argv, { env:
|
|
977
|
+
ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
947
978
|
} catch (error) {
|
|
948
979
|
throw spawnFailure(label, error);
|
|
949
980
|
}
|
|
@@ -958,15 +989,93 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
958
989
|
return { code: ran.code, ...streams };
|
|
959
990
|
}
|
|
960
991
|
// ../kit/src/cli.ts
|
|
961
|
-
import { readFileSync as
|
|
992
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
962
993
|
import { dirname as dirname3, join as join5 } from "path";
|
|
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
|
|
963
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
|
+
}
|
|
964
1073
|
|
|
965
1074
|
// ../kit/src/usage.ts
|
|
966
1075
|
import { appendFileSync, mkdirSync } from "fs";
|
|
967
1076
|
import { homedir as homedir3 } from "os";
|
|
968
1077
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
969
|
-
import
|
|
1078
|
+
import process14 from "process";
|
|
970
1079
|
|
|
971
1080
|
// ../kit/src/logs.ts
|
|
972
1081
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -980,14 +1089,14 @@ var usageError;
|
|
|
980
1089
|
function noteUsageError(message) {
|
|
981
1090
|
usageError = message;
|
|
982
1091
|
}
|
|
983
|
-
function stateHome(env =
|
|
1092
|
+
function stateHome(env = process14.env) {
|
|
984
1093
|
const dir = env.XDG_STATE_HOME;
|
|
985
1094
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
986
1095
|
}
|
|
987
|
-
function usagePath(env =
|
|
1096
|
+
function usagePath(env = process14.env) {
|
|
988
1097
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
989
1098
|
}
|
|
990
|
-
function usageRecorded(env =
|
|
1099
|
+
function usageRecorded(env = process14.env) {
|
|
991
1100
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
992
1101
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
993
1102
|
}
|
|
@@ -1001,7 +1110,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1001
1110
|
usageError = undefined;
|
|
1002
1111
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1003
1112
|
}
|
|
1004
|
-
function recordUsage(entry, env =
|
|
1113
|
+
function recordUsage(entry, env = process14.env) {
|
|
1005
1114
|
if (!usageRecorded(env))
|
|
1006
1115
|
return;
|
|
1007
1116
|
try {
|
|
@@ -1017,7 +1126,11 @@ var LEVEL_OPTIONS = {
|
|
|
1017
1126
|
...OUTPUT_OPTIONS,
|
|
1018
1127
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1019
1128
|
};
|
|
1020
|
-
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
|
+
};
|
|
1021
1134
|
async function commandRows(all, colors) {
|
|
1022
1135
|
const commands = shown(all);
|
|
1023
1136
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1078,7 +1191,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1078
1191
|
header(colors, summary),
|
|
1079
1192
|
"",
|
|
1080
1193
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1081
|
-
...replacesRows(replaces, colors),
|
|
1082
1194
|
"",
|
|
1083
1195
|
...await commandRows(commands, colors),
|
|
1084
1196
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -1092,8 +1204,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1092
1204
|
`);
|
|
1093
1205
|
}
|
|
1094
1206
|
function printError(prefix, message, hint, cause) {
|
|
1095
|
-
const colors = paint(
|
|
1096
|
-
const styled = takesControlCodes(
|
|
1207
|
+
const colors = paint(process15.stderr);
|
|
1208
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1097
1209
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1098
1210
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1099
1211
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1136,11 +1248,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1136
1248
|
}
|
|
1137
1249
|
}
|
|
1138
1250
|
if (name === undefined && level.path.length > 1) {
|
|
1139
|
-
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));
|
|
1140
1252
|
return 2;
|
|
1141
1253
|
}
|
|
1142
1254
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1143
|
-
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));
|
|
1144
1256
|
return 0;
|
|
1145
1257
|
}
|
|
1146
1258
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1196,24 +1308,24 @@ function candidateLine(candidate) {
|
|
|
1196
1308
|
}
|
|
1197
1309
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1198
1310
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1199
|
-
|
|
1311
|
+
const typed = [];
|
|
1200
1312
|
let at = 0;
|
|
1201
1313
|
while (at < before.length) {
|
|
1202
1314
|
const word = before[at];
|
|
1203
1315
|
if (word === "--") {
|
|
1204
|
-
|
|
1316
|
+
typed.push(...before.slice(at + 1));
|
|
1205
1317
|
break;
|
|
1206
1318
|
}
|
|
1207
1319
|
if (!word.startsWith("-"))
|
|
1208
|
-
|
|
1320
|
+
typed.push(word);
|
|
1209
1321
|
else if (takesValue(word))
|
|
1210
1322
|
at++;
|
|
1211
1323
|
at++;
|
|
1212
1324
|
}
|
|
1213
1325
|
const last = positionals.at(-1);
|
|
1214
|
-
if (
|
|
1215
|
-
return positionals[
|
|
1216
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1326
|
+
if (typed.length < positionals.length)
|
|
1327
|
+
return { name: positionals[typed.length], typed };
|
|
1328
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1217
1329
|
}
|
|
1218
1330
|
async function leafCandidates(run, words) {
|
|
1219
1331
|
const completing = await completingOf(run);
|
|
@@ -1221,12 +1333,12 @@ async function leafCandidates(run, words) {
|
|
|
1221
1333
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1222
1334
|
const flag = words.at(-2);
|
|
1223
1335
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1336
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1224
1337
|
if (option?.type === "string") {
|
|
1225
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1338
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1226
1339
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1227
1340
|
}
|
|
1228
|
-
const
|
|
1229
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1341
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1230
1342
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1231
1343
|
}
|
|
1232
1344
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1251,15 +1363,32 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1251
1363
|
}
|
|
1252
1364
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1253
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
|
+
}
|
|
1254
1379
|
async function printCandidates(found) {
|
|
1255
1380
|
for (const line of await found)
|
|
1256
1381
|
console.log(line);
|
|
1257
1382
|
return 0;
|
|
1258
1383
|
}
|
|
1259
1384
|
function packageVersion(entry = Bun.main) {
|
|
1260
|
-
|
|
1385
|
+
let resolved = entry;
|
|
1386
|
+
try {
|
|
1387
|
+
resolved = realpathSync2(entry);
|
|
1388
|
+
} catch {}
|
|
1389
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1261
1390
|
try {
|
|
1262
|
-
const { version } = JSON.parse(
|
|
1391
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1263
1392
|
if (typeof version === "string")
|
|
1264
1393
|
return version;
|
|
1265
1394
|
} catch {}
|
|
@@ -1267,14 +1396,19 @@ function packageVersion(entry = Bun.main) {
|
|
|
1267
1396
|
return "0.0.0";
|
|
1268
1397
|
}
|
|
1269
1398
|
}
|
|
1270
|
-
async function runCli(cli, argv =
|
|
1399
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1271
1400
|
const version = cli.version ?? packageVersion();
|
|
1272
1401
|
if (argv[0] === COMPLETE)
|
|
1273
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();
|
|
1274
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);
|
|
1275
1409
|
if (cli.usage !== false) {
|
|
1276
1410
|
try {
|
|
1277
|
-
recordUsage(usageEntry(cli.name,
|
|
1411
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1278
1412
|
} catch {}
|
|
1279
1413
|
}
|
|
1280
1414
|
return code;
|
|
@@ -1294,19 +1428,23 @@ function commandPath(scope, argv) {
|
|
|
1294
1428
|
}
|
|
1295
1429
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1296
1430
|
}
|
|
1297
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1431
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1298
1432
|
if (argv[0] === COMPLETE)
|
|
1299
1433
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1434
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1435
|
+
return printCompletionScript(name, flagValue(argv));
|
|
1300
1436
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1301
1437
|
console.log(version ?? packageVersion());
|
|
1302
1438
|
return 0;
|
|
1303
1439
|
}
|
|
1304
1440
|
let code;
|
|
1441
|
+
const started = performance.now();
|
|
1305
1442
|
try {
|
|
1306
1443
|
code = await run(argv);
|
|
1307
1444
|
} catch (error) {
|
|
1308
1445
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1309
1446
|
}
|
|
1447
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1310
1448
|
if (usage !== false) {
|
|
1311
1449
|
try {
|
|
1312
1450
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1346,7 +1484,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1346
1484
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1347
1485
|
}
|
|
1348
1486
|
// ../kit/src/watch.ts
|
|
1349
|
-
import
|
|
1487
|
+
import process16 from "process";
|
|
1350
1488
|
import { format } from "util";
|
|
1351
1489
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1352
1490
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1368,7 +1506,7 @@ function withoutWatch(args) {
|
|
|
1368
1506
|
}
|
|
1369
1507
|
return rest;
|
|
1370
1508
|
}
|
|
1371
|
-
async function watching(value, step, stream =
|
|
1509
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1372
1510
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1373
1511
|
if (!takesControlCodes(stream))
|
|
1374
1512
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1376,12 +1514,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1376
1514
|
for (let round = 0;round < rounds; round++) {
|
|
1377
1515
|
const held = [];
|
|
1378
1516
|
const { log, info } = console;
|
|
1379
|
-
const write =
|
|
1517
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1380
1518
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1381
1519
|
`);
|
|
1382
1520
|
console.log = hold;
|
|
1383
1521
|
console.info = hold;
|
|
1384
|
-
|
|
1522
|
+
process16.stdout.write = (text) => {
|
|
1385
1523
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1386
1524
|
return true;
|
|
1387
1525
|
};
|
|
@@ -1390,7 +1528,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1390
1528
|
} finally {
|
|
1391
1529
|
console.log = log;
|
|
1392
1530
|
console.info = info;
|
|
1393
|
-
|
|
1531
|
+
process16.stdout.write = write;
|
|
1394
1532
|
}
|
|
1395
1533
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1396
1534
|
await sleep(interval);
|
|
@@ -1399,8 +1537,8 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1399
1537
|
}
|
|
1400
1538
|
// ../kit/src/workspace-root.ts
|
|
1401
1539
|
import { homedir as homedir4 } from "os";
|
|
1402
|
-
import { dirname as dirname4, join as join6, resolve as
|
|
1403
|
-
import
|
|
1540
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1541
|
+
import process17 from "process";
|
|
1404
1542
|
function expandHome(path, home) {
|
|
1405
1543
|
if (path === "~")
|
|
1406
1544
|
return home;
|
|
@@ -1410,9 +1548,9 @@ function configured(env, home) {
|
|
|
1410
1548
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1411
1549
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1412
1550
|
}
|
|
1413
|
-
function workspaceRoot({ given, env =
|
|
1551
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1414
1552
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1415
|
-
return
|
|
1553
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1416
1554
|
}
|
|
1417
1555
|
// src/sweep.ts
|
|
1418
1556
|
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
@@ -1420,7 +1558,21 @@ import { homedir as homedir6 } from "os";
|
|
|
1420
1558
|
import { relative } from "path";
|
|
1421
1559
|
|
|
1422
1560
|
// ../kit/src/prompt.ts
|
|
1423
|
-
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
|
+
}
|
|
1424
1576
|
|
|
1425
1577
|
// ../kit/src/picker/score.ts
|
|
1426
1578
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1452,10 +1604,29 @@ var KEYS = {
|
|
|
1452
1604
|
"\n": "enter",
|
|
1453
1605
|
"\x03": "cancel",
|
|
1454
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",
|
|
1455
1619
|
"\x7F": "erase",
|
|
1456
|
-
"\
|
|
1620
|
+
"\x1B[3~": "delete",
|
|
1621
|
+
"\b": "killword",
|
|
1622
|
+
"\x1B\x7F": "killword",
|
|
1623
|
+
"\x1B[3;5~": "killnext",
|
|
1624
|
+
"\x1Bd": "killnext",
|
|
1457
1625
|
"\x15": "clear",
|
|
1626
|
+
"\v": "killend",
|
|
1458
1627
|
"\x17": "word",
|
|
1628
|
+
"\x19": "yank",
|
|
1629
|
+
"\x1A": "suspend",
|
|
1459
1630
|
"\t": "tab",
|
|
1460
1631
|
"\x1F": "help",
|
|
1461
1632
|
"\x1BOP": "help",
|
|
@@ -1485,10 +1656,21 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1485
1656
|
});
|
|
1486
1657
|
}
|
|
1487
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
|
+
|
|
1488
1670
|
// ../kit/src/prompt.ts
|
|
1489
|
-
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"]);
|
|
1490
1672
|
function readKeys(input, paste = { active: false }) {
|
|
1491
|
-
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));
|
|
1492
1674
|
}
|
|
1493
1675
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1494
1676
|
let answered = fallback;
|
|
@@ -1512,7 +1694,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1512
1694
|
function answer(colors, question, state, picked) {
|
|
1513
1695
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1514
1696
|
}
|
|
1515
|
-
async function ask(question, { hint, terminal =
|
|
1697
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
1516
1698
|
const { stdin, stderr } = terminal;
|
|
1517
1699
|
if (!isInteractive(terminal))
|
|
1518
1700
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -1522,12 +1704,22 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
|
1522
1704
|
const columns = () => stderr.columns || 80;
|
|
1523
1705
|
const draw = (state, last = false) => {
|
|
1524
1706
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1525
|
-
|
|
1526
|
-
|
|
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}`);
|
|
1527
1709
|
current = state;
|
|
1528
1710
|
};
|
|
1529
1711
|
const redraw = () => draw(current);
|
|
1530
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
|
+
};
|
|
1531
1723
|
try {
|
|
1532
1724
|
stderr.on?.("resize", redraw);
|
|
1533
1725
|
stdin.setRawMode(true);
|
|
@@ -1537,6 +1729,10 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
|
1537
1729
|
return await new Promise((resolve) => {
|
|
1538
1730
|
function onData(data) {
|
|
1539
1731
|
for (const key of readKeys(data.toString(), paste)) {
|
|
1732
|
+
if (key === "suspend") {
|
|
1733
|
+
suspend();
|
|
1734
|
+
continue;
|
|
1735
|
+
}
|
|
1540
1736
|
const pressed = press(key);
|
|
1541
1737
|
if (pressed !== undefined) {
|
|
1542
1738
|
settle(pressed);
|
|
@@ -1652,9 +1848,10 @@ async function sizeOf(folder) {
|
|
|
1652
1848
|
}
|
|
1653
1849
|
|
|
1654
1850
|
// src/sweep-scan.ts
|
|
1655
|
-
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"] };
|
|
1656
1853
|
var MAX_DEPTH = 3;
|
|
1657
|
-
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"]);
|
|
1658
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"];
|
|
1659
1856
|
function isCachePath(path, home = homedir5()) {
|
|
1660
1857
|
return GLOBAL_CACHES.some((cache) => join8(home, cache) === path) || basename(path) === ".cache" && basename(dirname5(path)) === "node_modules";
|
|
@@ -1699,7 +1896,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
1699
1896
|
}
|
|
1700
1897
|
continue;
|
|
1701
1898
|
}
|
|
1702
|
-
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)) {
|
|
1703
1900
|
if (entry.isSymbolicLink()) {
|
|
1704
1901
|
found.skipped.push({ path, reason: "symlink" });
|
|
1705
1902
|
} else if (entry.isDirectory()) {
|
|
@@ -1886,18 +2083,17 @@ async function applyAll(entries, done) {
|
|
|
1886
2083
|
// src/sweep.ts
|
|
1887
2084
|
var LARGE = 100 * 1024 ** 2;
|
|
1888
2085
|
var BIG = 1024 ** 3;
|
|
1889
|
-
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
|
|
1890
|
-
|
|
1891
|
-
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.
|
|
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
|
|
1892
2087
|
|
|
1893
|
-
|
|
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.`;
|
|
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"]];
|
|
1894
2090
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
1895
2091
|
var OPTIONS = {
|
|
1896
2092
|
apply: { type: "boolean", description: "delete what is listed as removable, after the confirm" },
|
|
1897
2093
|
yes: { type: "boolean", short: "y", description: "with --apply, skip the confirm" },
|
|
1898
2094
|
older: { type: "string", description: "only the entries whose repo last committed longer ago than this (30d, 12h)" },
|
|
1899
2095
|
min: { type: "string", description: "only the entries of at least this size (500K, 10M, 1G)" },
|
|
1900
|
-
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)" },
|
|
1901
2097
|
docker: { type: "boolean", description: "add the docker system df output, which alone takes about ten seconds" },
|
|
1902
2098
|
json: jsonOption("{root, entries: [{path, kind (folder, worktree or cache), bytes, committedAt, action (remove or keep), reason}], skipped: [{path, reason}], reclaimable, docker, removed?}")
|
|
1903
2099
|
};
|
|
@@ -1912,14 +2108,12 @@ async function dockerUsage() {
|
|
|
1912
2108
|
}
|
|
1913
2109
|
}
|
|
1914
2110
|
async function sweep(args) {
|
|
1915
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["sweep", "sweep ~/Workspace --older 30d --min 100M --apply", "sweep --only worktrees --apply"] });
|
|
2111
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["sweep", "sweep ~/Workspace --older 30d --min 100M --apply", "sweep --only worktrees --apply"] });
|
|
1916
2112
|
if (positionals.length > 1)
|
|
1917
2113
|
badUsage("give one root");
|
|
1918
2114
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1919
2115
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1920
2116
|
fail(`${root} is not a folder`);
|
|
1921
|
-
if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
|
|
1922
|
-
badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
|
|
1923
2117
|
const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0);
|
|
1924
2118
|
const minBytes = values.min === undefined ? 0 : parseSize(values.min);
|
|
1925
2119
|
if (minBytes === undefined)
|
|
@@ -1990,4 +2184,4 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
1990
2184
|
}
|
|
1991
2185
|
|
|
1992
2186
|
// src/sweep-cli.ts
|
|
1993
|
-
|
|
2187
|
+
process21.exitCode = await runMain({ name: "sweep", run: sweep });
|