@kaynooo/cli-workspace 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit-cli.js +203 -44
- package/dist/cli.js +315 -97
- package/dist/repos-cli.js +75 -41
- package/dist/sweep-cli.js +134 -41
- 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));
|
|
@@ -980,13 +991,31 @@ 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/notify.ts
|
|
997
|
+
import process13 from "process";
|
|
998
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
999
|
+
var CANCELLED = 130;
|
|
1000
|
+
function base64(text) {
|
|
1001
|
+
return Buffer.from(text).toString("base64");
|
|
1002
|
+
}
|
|
1003
|
+
function notification(title, body, env = process13.env) {
|
|
1004
|
+
const id = `kit${process13.pid}`;
|
|
1005
|
+
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\\`];
|
|
1006
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1007
|
+
}
|
|
1008
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1009
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1010
|
+
return;
|
|
1011
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1012
|
+
}
|
|
984
1013
|
|
|
985
1014
|
// ../kit/src/usage.ts
|
|
986
1015
|
import { appendFileSync, mkdirSync } from "fs";
|
|
987
1016
|
import { homedir as homedir3 } from "os";
|
|
988
1017
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
989
|
-
import
|
|
1018
|
+
import process14 from "process";
|
|
990
1019
|
|
|
991
1020
|
// ../kit/src/logs.ts
|
|
992
1021
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -1000,14 +1029,14 @@ var usageError;
|
|
|
1000
1029
|
function noteUsageError(message) {
|
|
1001
1030
|
usageError = message;
|
|
1002
1031
|
}
|
|
1003
|
-
function stateHome(env =
|
|
1032
|
+
function stateHome(env = process14.env) {
|
|
1004
1033
|
const dir = env.XDG_STATE_HOME;
|
|
1005
1034
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1006
1035
|
}
|
|
1007
|
-
function usagePath(env =
|
|
1036
|
+
function usagePath(env = process14.env) {
|
|
1008
1037
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1009
1038
|
}
|
|
1010
|
-
function usageRecorded(env =
|
|
1039
|
+
function usageRecorded(env = process14.env) {
|
|
1011
1040
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1012
1041
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1013
1042
|
}
|
|
@@ -1021,7 +1050,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1021
1050
|
usageError = undefined;
|
|
1022
1051
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1023
1052
|
}
|
|
1024
|
-
function recordUsage(entry, env =
|
|
1053
|
+
function recordUsage(entry, env = process14.env) {
|
|
1025
1054
|
if (!usageRecorded(env))
|
|
1026
1055
|
return;
|
|
1027
1056
|
try {
|
|
@@ -1111,8 +1140,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1111
1140
|
`);
|
|
1112
1141
|
}
|
|
1113
1142
|
function printError(prefix, message, hint, cause) {
|
|
1114
|
-
const colors = paint(
|
|
1115
|
-
const styled = takesControlCodes(
|
|
1143
|
+
const colors = paint(process15.stderr);
|
|
1144
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1116
1145
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1117
1146
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1118
1147
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1155,11 +1184,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1155
1184
|
}
|
|
1156
1185
|
}
|
|
1157
1186
|
if (name === undefined && level.path.length > 1) {
|
|
1158
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1187
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1159
1188
|
return 2;
|
|
1160
1189
|
}
|
|
1161
1190
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1162
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1191
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1163
1192
|
return 0;
|
|
1164
1193
|
}
|
|
1165
1194
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1294,10 +1323,13 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1294
1323
|
const version = cli.version ?? packageVersion();
|
|
1295
1324
|
if (argv[0] === COMPLETE)
|
|
1296
1325
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1326
|
+
const started = performance.now();
|
|
1297
1327
|
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 });
|
|
1328
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1329
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1298
1330
|
if (cli.usage !== false) {
|
|
1299
1331
|
try {
|
|
1300
|
-
recordUsage(usageEntry(cli.name,
|
|
1332
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1301
1333
|
} catch {}
|
|
1302
1334
|
}
|
|
1303
1335
|
return code;
|
|
@@ -1325,11 +1357,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1325
1357
|
return 0;
|
|
1326
1358
|
}
|
|
1327
1359
|
let code;
|
|
1360
|
+
const started = performance.now();
|
|
1328
1361
|
try {
|
|
1329
1362
|
code = await run(argv);
|
|
1330
1363
|
} catch (error) {
|
|
1331
1364
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1332
1365
|
}
|
|
1366
|
+
notifyEnd(name, code, performance.now() - started);
|
|
1333
1367
|
if (usage !== false) {
|
|
1334
1368
|
try {
|
|
1335
1369
|
recordUsage(usageEntry(name, undefined, argv, code));
|
|
@@ -1369,7 +1403,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1369
1403
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1370
1404
|
}
|
|
1371
1405
|
// ../kit/src/watch.ts
|
|
1372
|
-
import
|
|
1406
|
+
import process16 from "process";
|
|
1373
1407
|
import { format } from "util";
|
|
1374
1408
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1375
1409
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1391,7 +1425,7 @@ function withoutWatch(args) {
|
|
|
1391
1425
|
}
|
|
1392
1426
|
return rest;
|
|
1393
1427
|
}
|
|
1394
|
-
async function watching(value, step, stream =
|
|
1428
|
+
async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1395
1429
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1396
1430
|
if (!takesControlCodes(stream))
|
|
1397
1431
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1399,12 +1433,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1399
1433
|
for (let round = 0;round < rounds; round++) {
|
|
1400
1434
|
const held = [];
|
|
1401
1435
|
const { log, info } = console;
|
|
1402
|
-
const write =
|
|
1436
|
+
const write = process16.stdout.write.bind(process16.stdout);
|
|
1403
1437
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1404
1438
|
`);
|
|
1405
1439
|
console.log = hold;
|
|
1406
1440
|
console.info = hold;
|
|
1407
|
-
|
|
1441
|
+
process16.stdout.write = (text) => {
|
|
1408
1442
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1409
1443
|
return true;
|
|
1410
1444
|
};
|
|
@@ -1413,7 +1447,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1413
1447
|
} finally {
|
|
1414
1448
|
console.log = log;
|
|
1415
1449
|
console.info = info;
|
|
1416
|
-
|
|
1450
|
+
process16.stdout.write = write;
|
|
1417
1451
|
}
|
|
1418
1452
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1419
1453
|
await sleep(interval);
|
|
@@ -1423,7 +1457,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
|
|
|
1423
1457
|
// ../kit/src/workspace-root.ts
|
|
1424
1458
|
import { homedir as homedir4 } from "os";
|
|
1425
1459
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1426
|
-
import
|
|
1460
|
+
import process17 from "process";
|
|
1427
1461
|
function expandHome(path, home) {
|
|
1428
1462
|
if (path === "~")
|
|
1429
1463
|
return home;
|
|
@@ -1433,7 +1467,7 @@ function configured(env, home) {
|
|
|
1433
1467
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1434
1468
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1435
1469
|
}
|
|
1436
|
-
function workspaceRoot({ given, env =
|
|
1470
|
+
function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
|
|
1437
1471
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1438
1472
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1439
1473
|
}
|
|
@@ -1443,7 +1477,21 @@ import { homedir as homedir6 } from "os";
|
|
|
1443
1477
|
import { relative } from "path";
|
|
1444
1478
|
|
|
1445
1479
|
// ../kit/src/prompt.ts
|
|
1446
|
-
import
|
|
1480
|
+
import process20 from "process";
|
|
1481
|
+
|
|
1482
|
+
// ../kit/src/job.ts
|
|
1483
|
+
import process19 from "process";
|
|
1484
|
+
function stopJob() {
|
|
1485
|
+
process19.kill(0, "SIGTSTP");
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
// ../kit/src/picker/line.ts
|
|
1489
|
+
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1490
|
+
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1491
|
+
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1492
|
+
function isEditKey(key) {
|
|
1493
|
+
return EDIT_KEYS.has(key);
|
|
1494
|
+
}
|
|
1447
1495
|
|
|
1448
1496
|
// ../kit/src/picker/score.ts
|
|
1449
1497
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1475,10 +1523,29 @@ var KEYS = {
|
|
|
1475
1523
|
"\n": "enter",
|
|
1476
1524
|
"\x03": "cancel",
|
|
1477
1525
|
"\x1B": "cancel",
|
|
1526
|
+
"\x1B[D": "left",
|
|
1527
|
+
"\x1BOD": "left",
|
|
1528
|
+
"\x1B[C": "right",
|
|
1529
|
+
"\x1BOC": "right",
|
|
1530
|
+
"\x1B[1;5D": "wordleft",
|
|
1531
|
+
"\x1B[1;3D": "wordleft",
|
|
1532
|
+
"\x1Bb": "wordleft",
|
|
1533
|
+
"\x1B[1;5C": "wordright",
|
|
1534
|
+
"\x1B[1;3C": "wordright",
|
|
1535
|
+
"\x1Bf": "wordright",
|
|
1536
|
+
"\x01": "linestart",
|
|
1537
|
+
"\x05": "lineend",
|
|
1478
1538
|
"\x7F": "erase",
|
|
1479
|
-
"\
|
|
1539
|
+
"\x1B[3~": "delete",
|
|
1540
|
+
"\b": "killword",
|
|
1541
|
+
"\x1B\x7F": "killword",
|
|
1542
|
+
"\x1B[3;5~": "killnext",
|
|
1543
|
+
"\x1Bd": "killnext",
|
|
1480
1544
|
"\x15": "clear",
|
|
1545
|
+
"\v": "killend",
|
|
1481
1546
|
"\x17": "word",
|
|
1547
|
+
"\x19": "yank",
|
|
1548
|
+
"\x1A": "suspend",
|
|
1482
1549
|
"\t": "tab",
|
|
1483
1550
|
"\x1F": "help",
|
|
1484
1551
|
"\x1BOP": "help",
|
|
@@ -1508,10 +1575,21 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1508
1575
|
});
|
|
1509
1576
|
}
|
|
1510
1577
|
|
|
1578
|
+
// ../kit/src/redraw.ts
|
|
1579
|
+
var SYNC_START = "\x1B[?2026h";
|
|
1580
|
+
var SYNC_END = "\x1B[?2026l";
|
|
1581
|
+
function overwrite(lines, columns) {
|
|
1582
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1583
|
+
`);
|
|
1584
|
+
}
|
|
1585
|
+
function rowsTaken(lines, columns) {
|
|
1586
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1511
1589
|
// ../kit/src/prompt.ts
|
|
1512
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "
|
|
1590
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1513
1591
|
function readKeys(input, paste = { active: false }) {
|
|
1514
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
1592
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1515
1593
|
}
|
|
1516
1594
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1517
1595
|
let answered = fallback;
|
|
@@ -1535,7 +1613,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1535
1613
|
function answer(colors, question, state, picked) {
|
|
1536
1614
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1537
1615
|
}
|
|
1538
|
-
async function ask(question, { hint, terminal =
|
|
1616
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
1539
1617
|
const { stdin, stderr } = terminal;
|
|
1540
1618
|
if (!isInteractive(terminal))
|
|
1541
1619
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -1545,12 +1623,22 @@ async function ask(question, { hint, terminal = process18 }, render, press) {
|
|
|
1545
1623
|
const columns = () => stderr.columns || 80;
|
|
1546
1624
|
const draw = (state, last = false) => {
|
|
1547
1625
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1548
|
-
|
|
1549
|
-
|
|
1626
|
+
const rows = rowsTaken(frame, columns());
|
|
1627
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1550
1628
|
current = state;
|
|
1551
1629
|
};
|
|
1552
1630
|
const redraw = () => draw(current);
|
|
1553
1631
|
const paste = { active: false };
|
|
1632
|
+
const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
|
|
1633
|
+
const suspend = () => {
|
|
1634
|
+
if (stop === undefined)
|
|
1635
|
+
return;
|
|
1636
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1637
|
+
stdin.setRawMode(false);
|
|
1638
|
+
stop();
|
|
1639
|
+
stdin.setRawMode(true);
|
|
1640
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1641
|
+
};
|
|
1554
1642
|
try {
|
|
1555
1643
|
stderr.on?.("resize", redraw);
|
|
1556
1644
|
stdin.setRawMode(true);
|
|
@@ -1560,6 +1648,10 @@ async function ask(question, { hint, terminal = process18 }, render, press) {
|
|
|
1560
1648
|
return await new Promise((resolve) => {
|
|
1561
1649
|
function onData(data) {
|
|
1562
1650
|
for (const key of readKeys(data.toString(), paste)) {
|
|
1651
|
+
if (key === "suspend") {
|
|
1652
|
+
suspend();
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1563
1655
|
const pressed = press(key);
|
|
1564
1656
|
if (pressed !== undefined) {
|
|
1565
1657
|
settle(pressed);
|
|
@@ -1675,9 +1767,10 @@ async function sizeOf(folder) {
|
|
|
1675
1767
|
}
|
|
1676
1768
|
|
|
1677
1769
|
// src/sweep-scan.ts
|
|
1678
|
-
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target"]);
|
|
1770
|
+
var FOLDER_NAMES = new Set(["node_modules", ".nuxt", ".next", ".output", "dist", "build", ".turbo", ".svelte-kit", "target", "vendor", ".venv", "__pycache__", ".gradle"]);
|
|
1771
|
+
var NEEDS_BESIDE = { target: ["Cargo.toml"], vendor: ["composer.json", "composer.lock"] };
|
|
1679
1772
|
var MAX_DEPTH = 3;
|
|
1680
|
-
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit"]);
|
|
1773
|
+
var PROJECT_CACHE_NAMES = new Set([".turbo", ".nuxt", ".next", ".svelte-kit", "__pycache__", ".gradle"]);
|
|
1681
1774
|
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
1775
|
function isCachePath(path, home = homedir5()) {
|
|
1683
1776
|
return GLOBAL_CACHES.some((cache) => join8(home, cache) === path) || basename(path) === ".cache" && basename(dirname5(path)) === "node_modules";
|
|
@@ -1722,7 +1815,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
|
|
|
1722
1815
|
}
|
|
1723
1816
|
continue;
|
|
1724
1817
|
}
|
|
1725
|
-
if (FOLDER_NAMES.has(entry.name) && (entry.name
|
|
1818
|
+
if (FOLDER_NAMES.has(entry.name) && (NEEDS_BESIDE[entry.name]?.some((file) => existsSync4(join8(dir, file))) ?? true)) {
|
|
1726
1819
|
if (entry.isSymbolicLink()) {
|
|
1727
1820
|
found.skipped.push({ path, reason: "symlink" });
|
|
1728
1821
|
} else if (entry.isDirectory()) {
|
|
@@ -1909,7 +2002,7 @@ async function applyAll(entries, done) {
|
|
|
1909
2002
|
// src/sweep.ts
|
|
1910
2003
|
var LARGE = 100 * 1024 ** 2;
|
|
1911
2004
|
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
|
|
2005
|
+
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
2006
|
|
|
1914
2007
|
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
2008
|
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 +2012,7 @@ var OPTIONS = {
|
|
|
1919
2012
|
yes: { type: "boolean", short: "y", description: "with --apply, skip the confirm" },
|
|
1920
2013
|
older: { type: "string", description: "only the entries whose repo last committed longer ago than this (30d, 12h)" },
|
|
1921
2014
|
min: { type: "string", description: "only the entries of at least this size (500K, 10M, 1G)" },
|
|
1922
|
-
only: { type: "string", description: "worktrees, folders or caches: leave the other kinds out (.nuxt, .next, .turbo
|
|
2015
|
+
only: { type: "string", description: "worktrees, folders or caches: 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
2016
|
docker: { type: "boolean", description: "add the docker system df output, which alone takes about ten seconds" },
|
|
1924
2017
|
json: jsonOption("{root, entries: [{path, kind (folder, worktree or cache), bytes, committedAt, action (remove or keep), reason}], skipped: [{path, reason}], reclaimable, docker, removed?}")
|
|
1925
2018
|
};
|
|
@@ -2012,4 +2105,4 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2012
2105
|
}
|
|
2013
2106
|
|
|
2014
2107
|
// src/sweep-cli.ts
|
|
2015
|
-
|
|
2108
|
+
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.0",
|
|
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.40.0"
|
|
38
38
|
}
|
|
39
39
|
}
|