@kaynooo/cli-workspace 0.10.0 → 0.10.2

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/sweep-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/sweep-cli.ts
5
- import process18 from "process";
5
+ import process19 from "process";
6
6
 
7
7
  // ../kit/src/advisory.ts
8
8
  var SEVERITIES = ["low", "moderate", "high", "critical"];
@@ -32,6 +32,7 @@ function y(e, t) {
32
32
  n = new Intl.NumberFormat(e, t), i.set(o, n);
33
33
  return n;
34
34
  }
35
+
35
36
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
36
37
  var N = new Map;
37
38
  var Nt = /\s+\S*$/;
@@ -49,6 +50,7 @@ function ko(t, e, r = "...") {
49
50
  }
50
51
  var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
51
52
  var z = new Map;
53
+
52
54
  // ../kit/src/mode.ts
53
55
  import process2 from "process";
54
56
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -97,7 +99,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
97
99
  return false;
98
100
  return r?.isTTY === true;
99
101
  }
100
- function f2(r, e = []) {
102
+ function f(r, e = []) {
101
103
  let l = "", n = "";
102
104
  for (let t = 0, i = e.length;t < i; t++)
103
105
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
@@ -107,7 +109,7 @@ function f2(r, e = []) {
107
109
  if (Array.isArray(a)) {
108
110
  let s = g.get(i);
109
111
  if (s === undefined)
110
- s = f2(r, [...e, a]), g.set(i, s);
112
+ s = f(r, [...e, a]), g.set(i, s);
111
113
  return s;
112
114
  }
113
115
  if (typeof a === "function")
@@ -116,20 +118,20 @@ function f2(r, e = []) {
116
118
  if (u === undefined) {
117
119
  if (g.size >= 64)
118
120
  g.clear();
119
- u = f2(r, [...e, a(...s)]), g.set(y, u);
121
+ u = f(r, [...e, a(...s)]), g.set(y, u);
120
122
  }
121
123
  return u;
122
124
  };
123
125
  throw Error(`Unknown style: ${String(i)}`);
124
126
  } });
125
127
  }
126
- function Fe2(r = {}) {
127
- return f2(r);
128
+ function Fe(r = {}) {
129
+ return f(r);
128
130
  }
129
- var o2 = Fe2();
131
+ var o = Fe();
130
132
 
131
133
  // ../kit/src/theme.ts
132
- import { existsSync as existsSync3, readFileSync, statSync } from "fs";
134
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
133
135
  import { homedir as homedir2 } from "os";
134
136
  import { join as join3, resolve as resolve2 } from "path";
135
137
  import process5 from "process";
@@ -150,7 +152,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
150
152
  }
151
153
 
152
154
  // ../kit/src/user-config.ts
153
- import { existsSync as existsSync2 } from "fs";
155
+ import { existsSync as existsSync2, readFileSync } from "fs";
154
156
  import { homedir } from "os";
155
157
  import { join as join2 } from "path";
156
158
  import process4 from "process";
@@ -168,6 +170,21 @@ function userConfigReadPath(bin, legacy = [], where = {}) {
168
170
  const base = configBase(where);
169
171
  return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
170
172
  }
173
+ function readUserConfig(bin, where = {}, legacy = []) {
174
+ const path = userConfigReadPath(bin, legacy, where);
175
+ if (!existsSync2(path))
176
+ return {};
177
+ try {
178
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
179
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
180
+ } catch {
181
+ return {};
182
+ }
183
+ }
184
+ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
185
+ const value = readUserConfig(bin, where, legacy)[key];
186
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
187
+ }
171
188
 
172
189
  // ../kit/src/theme.ts
173
190
  var ENDS = new Map;
@@ -234,7 +251,7 @@ function readThemeFile(path, warn) {
234
251
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
235
252
  return;
236
253
  }
237
- const parsed = JSON.parse(readFileSync(path, "utf8"));
254
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
238
255
  if (isRecord(parsed))
239
256
  return parsed;
240
257
  warn(`${path} is not a JSON object, theme ignored`);
@@ -356,7 +373,7 @@ function takesControlCodes(stream, env = process6.env) {
356
373
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
357
374
  }
358
375
  function paint(stream, env = process6.env) {
359
- return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
376
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
360
377
  }
361
378
  function marked(mark, text, stream, detail, env = process6.env) {
362
379
  const colors = paint(stream, env);
@@ -404,7 +421,7 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
404
421
  console.log(line);
405
422
  }
406
423
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
407
- function tt2(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
424
+ function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
408
425
  let e = r === "si" ? 1000 : 1024;
409
426
  if (Math.abs(i) < e)
410
427
  return `${i} B`;
@@ -506,18 +523,14 @@ var FULL_STOP = /\.$/;
506
523
  function usageLine(usage, colors = paint(process8.stdout)) {
507
524
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
508
525
  }
509
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
510
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
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(`
511
528
  `);
512
529
  }
513
530
  function exitRows(exits, colors = paint(process8.stdout)) {
514
531
  if (exits.length === 0)
515
532
  return [];
516
- const width = Math.max(...exits.map(([code]) => String(code).length));
517
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
518
- }
519
- function replacesRows(replaces, colors = paint(process8.stdout)) {
520
- 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(", ")}`];
521
534
  }
522
535
  function wantsHelpJson(env = process8.env) {
523
536
  return env.KIT_HELP === "json";
@@ -804,9 +817,33 @@ function nearestOption(message, options, allowNegative) {
804
817
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
805
818
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
806
819
  }
820
+ // ../kit/src/argv.ts
821
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
822
+ import { resolve as resolve3 } from "path";
823
+ import process10 from "process";
824
+ function commandLine() {
825
+ try {
826
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
827
+ } catch {
828
+ return;
829
+ }
830
+ }
831
+ function realPath(word) {
832
+ try {
833
+ return realpathSync(resolve3(word));
834
+ } catch {
835
+ return;
836
+ }
837
+ }
838
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
839
+ const target = script === undefined ? undefined : realPath(script) ?? script;
840
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
841
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
842
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
843
+ }
807
844
  // ../kit/src/process.ts
808
845
  import { constants } from "os";
809
- import process10 from "process";
846
+ import process11 from "process";
810
847
  var KILL_GRACE_MS = 2000;
811
848
  function exitCodeOf(code, signal) {
812
849
  if (code !== null)
@@ -826,7 +863,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
826
863
  return;
827
864
  try {
828
865
  if (grouped)
829
- process10.kill(-proc.pid, killing);
866
+ process11.kill(-proc.pid, killing);
830
867
  else
831
868
  proc.kill(killing);
832
869
  } catch {}
@@ -901,10 +938,10 @@ var RESET_STYLE = `${ESC}[0m`;
901
938
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
902
939
 
903
940
  // ../kit/src/tool.ts
904
- import process11 from "process";
941
+ import process12 from "process";
905
942
  function cwdGone() {
906
943
  try {
907
- process11.cwd();
944
+ process12.cwd();
908
945
  return false;
909
946
  } catch {
910
947
  return true;
@@ -926,7 +963,7 @@ function spawnFailure(command, error) {
926
963
  async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
927
964
  let ran;
928
965
  try {
929
- ran = await runCommand(argv, { env: process11.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
966
+ ran = await runCommand(argv, { env: process12.env, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
930
967
  } catch (error) {
931
968
  throw spawnFailure(label, error);
932
969
  }
@@ -941,15 +978,15 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
941
978
  return { code: ran.code, ...streams };
942
979
  }
943
980
  // ../kit/src/cli.ts
944
- import { readFileSync as readFileSync2, realpathSync } from "fs";
981
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
945
982
  import { dirname as dirname3, join as join5 } from "path";
946
- import process13 from "process";
983
+ import process14 from "process";
947
984
 
948
985
  // ../kit/src/usage.ts
949
986
  import { appendFileSync, mkdirSync } from "fs";
950
987
  import { homedir as homedir3 } from "os";
951
988
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
952
- import process12 from "process";
989
+ import process13 from "process";
953
990
 
954
991
  // ../kit/src/logs.ts
955
992
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -963,14 +1000,14 @@ var usageError;
963
1000
  function noteUsageError(message) {
964
1001
  usageError = message;
965
1002
  }
966
- function stateHome(env = process12.env) {
1003
+ function stateHome(env = process13.env) {
967
1004
  const dir = env.XDG_STATE_HOME;
968
1005
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
969
1006
  }
970
- function usagePath(env = process12.env) {
1007
+ function usagePath(env = process13.env) {
971
1008
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
972
1009
  }
973
- function usageRecorded(env = process12.env) {
1010
+ function usageRecorded(env = process13.env) {
974
1011
  const off = env.KAYNOOO_CLI_NO_USAGE;
975
1012
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
976
1013
  }
@@ -984,7 +1021,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
984
1021
  usageError = undefined;
985
1022
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
986
1023
  }
987
- function recordUsage(entry, env = process12.env) {
1024
+ function recordUsage(entry, env = process13.env) {
988
1025
  if (!usageRecorded(env))
989
1026
  return;
990
1027
  try {
@@ -1061,7 +1098,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1061
1098
  header(colors, summary),
1062
1099
  "",
1063
1100
  usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
1064
- ...replacesRows(replaces, colors),
1065
1101
  "",
1066
1102
  ...await commandRows(commands, colors),
1067
1103
  ...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
@@ -1075,8 +1111,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1075
1111
  `);
1076
1112
  }
1077
1113
  function printError(prefix, message, hint, cause) {
1078
- const colors = paint(process13.stderr);
1079
- const styled = takesControlCodes(process13.stderr);
1114
+ const colors = paint(process14.stderr);
1115
+ const styled = takesControlCodes(process14.stderr);
1080
1116
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1081
1117
  const under = (label, text, tint) => text === undefined ? "" : `
1082
1118
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1119,11 +1155,11 @@ async function dispatch(level, typed, { version, redact }) {
1119
1155
  }
1120
1156
  }
1121
1157
  if (name === undefined && level.path.length > 1) {
1122
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
1158
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1123
1159
  return 2;
1124
1160
  }
1125
1161
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1126
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
1162
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1127
1163
  return 0;
1128
1164
  }
1129
1165
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1179,24 +1215,24 @@ function candidateLine(candidate) {
1179
1215
  }
1180
1216
  function positionalBeingTyped(before, { options, positionals }) {
1181
1217
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1182
- let index = 0;
1218
+ const typed = [];
1183
1219
  let at = 0;
1184
1220
  while (at < before.length) {
1185
1221
  const word = before[at];
1186
1222
  if (word === "--") {
1187
- index += before.length - at - 1;
1223
+ typed.push(...before.slice(at + 1));
1188
1224
  break;
1189
1225
  }
1190
1226
  if (!word.startsWith("-"))
1191
- index++;
1227
+ typed.push(word);
1192
1228
  else if (takesValue(word))
1193
1229
  at++;
1194
1230
  at++;
1195
1231
  }
1196
1232
  const last = positionals.at(-1);
1197
- if (index < positionals.length)
1198
- return positionals[index];
1199
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1233
+ if (typed.length < positionals.length)
1234
+ return { name: positionals[typed.length], typed };
1235
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1200
1236
  }
1201
1237
  async function leafCandidates(run, words) {
1202
1238
  const completing = await completingOf(run);
@@ -1204,12 +1240,12 @@ async function leafCandidates(run, words) {
1204
1240
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1205
1241
  const flag = words.at(-2);
1206
1242
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1243
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1207
1244
  if (option?.type === "string") {
1208
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1245
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1209
1246
  return values === undefined ? [FILES] : values.map(candidateLine);
1210
1247
  }
1211
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1212
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1248
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1213
1249
  return values === undefined ? [FILES] : values.map(candidateLine);
1214
1250
  }
1215
1251
  async function candidates(scope, defaultCommand, words, before = []) {
@@ -1240,9 +1276,13 @@ async function printCandidates(found) {
1240
1276
  return 0;
1241
1277
  }
1242
1278
  function packageVersion(entry = Bun.main) {
1243
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1279
+ let resolved = entry;
1280
+ try {
1281
+ resolved = realpathSync2(entry);
1282
+ } catch {}
1283
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1244
1284
  try {
1245
- const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1285
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1246
1286
  if (typeof version === "string")
1247
1287
  return version;
1248
1288
  } catch {}
@@ -1250,7 +1290,7 @@ function packageVersion(entry = Bun.main) {
1250
1290
  return "0.0.0";
1251
1291
  }
1252
1292
  }
1253
- async function runCli(cli, argv = process13.argv.slice(2)) {
1293
+ async function runCli(cli, argv = scriptArgs()) {
1254
1294
  const version = cli.version ?? packageVersion();
1255
1295
  if (argv[0] === COMPLETE)
1256
1296
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
@@ -1277,7 +1317,7 @@ function commandPath(scope, argv) {
1277
1317
  }
1278
1318
  return path.length === 0 ? undefined : path.join(" ");
1279
1319
  }
1280
- async function runMain({ name, version, run, redact, usage }, argv = process13.argv.slice(2)) {
1320
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1281
1321
  if (argv[0] === COMPLETE)
1282
1322
  return printCandidates(leafCandidates(run, argv.slice(1)));
1283
1323
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1329,7 +1369,7 @@ function parseSize(text, bareUnit = 1) {
1329
1369
  return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
1330
1370
  }
1331
1371
  // ../kit/src/watch.ts
1332
- import process14 from "process";
1372
+ import process15 from "process";
1333
1373
  import { format } from "util";
1334
1374
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1335
1375
  var DEFAULT_SECONDS = 2;
@@ -1351,7 +1391,7 @@ function withoutWatch(args) {
1351
1391
  }
1352
1392
  return rest;
1353
1393
  }
1354
- async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1394
+ async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1355
1395
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1356
1396
  if (!takesControlCodes(stream))
1357
1397
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1359,12 +1399,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1359
1399
  for (let round = 0;round < rounds; round++) {
1360
1400
  const held = [];
1361
1401
  const { log, info } = console;
1362
- const write = process14.stdout.write.bind(process14.stdout);
1402
+ const write = process15.stdout.write.bind(process15.stdout);
1363
1403
  const hold = (...parts) => void held.push(`${format(...parts)}
1364
1404
  `);
1365
1405
  console.log = hold;
1366
1406
  console.info = hold;
1367
- process14.stdout.write = (text) => {
1407
+ process15.stdout.write = (text) => {
1368
1408
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1369
1409
  return true;
1370
1410
  };
@@ -1373,7 +1413,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1373
1413
  } finally {
1374
1414
  console.log = log;
1375
1415
  console.info = info;
1376
- process14.stdout.write = write;
1416
+ process15.stdout.write = write;
1377
1417
  }
1378
1418
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1379
1419
  await sleep(interval);
@@ -1381,38 +1421,29 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1381
1421
  return code;
1382
1422
  }
1383
1423
  // ../kit/src/workspace-root.ts
1384
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1385
1424
  import { homedir as homedir4 } from "os";
1386
- import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
1387
- import process15 from "process";
1425
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1426
+ import process16 from "process";
1388
1427
  function expandHome(path, home) {
1389
1428
  if (path === "~")
1390
1429
  return home;
1391
1430
  return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1392
1431
  }
1393
1432
  function configured(env, home) {
1394
- const path = userConfigPath("config", { home, xdg: env.XDG_CONFIG_HOME });
1395
- if (!existsSync4(path))
1396
- return;
1397
- try {
1398
- const parsed = JSON.parse(readFileSync3(path, "utf8"));
1399
- const folder = typeof parsed === "object" && parsed !== null ? parsed.workspace : undefined;
1400
- return typeof folder === "string" && folder !== "" ? folder : undefined;
1401
- } catch {
1402
- return;
1403
- }
1433
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1434
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1404
1435
  }
1405
- function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
1436
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1406
1437
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1407
- return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1438
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1408
1439
  }
1409
1440
  // src/sweep.ts
1410
- import { existsSync as existsSync7, statSync as statSync2 } from "fs";
1441
+ import { existsSync as existsSync6, statSync as statSync2 } from "fs";
1411
1442
  import { homedir as homedir6 } from "os";
1412
1443
  import { relative } from "path";
1413
1444
 
1414
1445
  // ../kit/src/prompt.ts
1415
- import process17 from "process";
1446
+ import process18 from "process";
1416
1447
 
1417
1448
  // ../kit/src/picker/score.ts
1418
1449
  var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
@@ -1422,7 +1453,9 @@ var NONE = Number.NEGATIVE_INFINITY;
1422
1453
  var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1423
1454
  var PASTE_START = "\x1B[200~";
1424
1455
  var PASTE_END = "\x1B[201~";
1425
- var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1456
+ var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1457
+ var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1458
+ var WHEEL_LINES = 3;
1426
1459
  var KEYS = {
1427
1460
  "\x1B[A": "up",
1428
1461
  "\x1BOA": "up",
@@ -1451,9 +1484,15 @@ var KEYS = {
1451
1484
  "\x1BOP": "help",
1452
1485
  "\x1B[11~": "help"
1453
1486
  };
1487
+ function repeat(value, count) {
1488
+ return Array.from({ length: count }).fill(value);
1489
+ }
1454
1490
  function parseKeys(input, paste = { active: false }, ctrls = []) {
1455
1491
  const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1456
1492
  return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1493
+ const wheel = MOUSE.exec(sequence)?.[1];
1494
+ if (wheel !== undefined)
1495
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1457
1496
  const named = codes.get(sequence);
1458
1497
  const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1459
1498
  if (sequence === PASTE_START || sequence === PASTE_END) {
@@ -1496,21 +1535,18 @@ function asking(colors, question, typed, keys) {
1496
1535
  function answer(colors, question, state, picked) {
1497
1536
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1498
1537
  }
1499
- async function ask(question, { hint, terminal = process17 }, render, press) {
1538
+ async function ask(question, { hint, terminal = process18 }, render, press) {
1500
1539
  const { stdin, stderr } = terminal;
1501
1540
  if (!isInteractive(terminal))
1502
1541
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
1503
1542
  const colors = paint(stderr);
1504
- let drawn = [];
1505
1543
  let current = "asking";
1506
1544
  let outcome;
1507
1545
  const columns = () => stderr.columns || 80;
1508
- const draw = (state) => {
1546
+ const draw = (state, last = false) => {
1509
1547
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1510
- const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
1511
- stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
1512
- `)}`);
1513
- drawn = frame;
1548
+ stderr.write(`\r\x1B[0J${frame.join(`
1549
+ `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
1514
1550
  current = state;
1515
1551
  };
1516
1552
  const redraw = () => draw(current);
@@ -1546,7 +1582,7 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
1546
1582
  });
1547
1583
  } finally {
1548
1584
  stderr.off?.("resize", redraw);
1549
- draw(outcome ?? "cancel");
1585
+ draw(outcome ?? "cancel", true);
1550
1586
  stderr.write(`
1551
1587
  \x1B[?25h\x1B[?2004l`);
1552
1588
  stdin.setRawMode(false);
@@ -1555,12 +1591,12 @@ async function ask(question, { hint, terminal = process17 }, render, press) {
1555
1591
  }
1556
1592
 
1557
1593
  // src/apply.ts
1558
- import { existsSync as existsSync6 } from "fs";
1594
+ import { existsSync as existsSync5 } from "fs";
1559
1595
  import { lstat as lstat3, rm } from "fs/promises";
1560
1596
  import { basename as basename2, join as join9 } from "path";
1561
1597
 
1562
1598
  // src/sweep-scan.ts
1563
- import { existsSync as existsSync5 } from "fs";
1599
+ import { existsSync as existsSync4 } from "fs";
1564
1600
  import { lstat as lstat2, readdir as readdir2, realpath } from "fs/promises";
1565
1601
  import { homedir as homedir5 } from "os";
1566
1602
  import { basename, dirname as dirname5, join as join8 } from "path";
@@ -1686,7 +1722,7 @@ async function findCandidates(root, home = homedir5(), withGlobal = true) {
1686
1722
  }
1687
1723
  continue;
1688
1724
  }
1689
- if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync5(join8(dir, "Cargo.toml")))) {
1725
+ if (FOLDER_NAMES.has(entry.name) && (entry.name !== "target" || existsSync4(join8(dir, "Cargo.toml")))) {
1690
1726
  if (entry.isSymbolicLink()) {
1691
1727
  found.skipped.push({ path, reason: "symlink" });
1692
1728
  } else if (entry.isDirectory()) {
@@ -1772,7 +1808,7 @@ async function judgeFolder(path, kind, inside) {
1772
1808
  const located = await toplevelOf(parent);
1773
1809
  if (located === "failed")
1774
1810
  return { skip: "git failed" };
1775
- if (existsSync5(join8(path, ".git")))
1811
+ if (existsSync4(join8(path, ".git")))
1776
1812
  return { skip: "holds a git repository" };
1777
1813
  if (located === "none")
1778
1814
  return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
@@ -1840,7 +1876,7 @@ async function removeFolder(entry) {
1840
1876
  const stat = await lstat3(entry.path);
1841
1877
  if (stat.isSymbolicLink() || !stat.isDirectory() || !(FOLDER_NAMES.has(basename2(entry.path)) || entry.kind === "cache" && isCachePath(entry.path)))
1842
1878
  return { path: entry.path, removed: false, error: "no longer a plain folder" };
1843
- if (existsSync6(join9(entry.path, ".git")))
1879
+ if (existsSync5(join9(entry.path, ".git")))
1844
1880
  return { path: entry.path, removed: false, error: "holds a git repository" };
1845
1881
  await rm(entry.path, { recursive: true, force: true });
1846
1882
  return { path: entry.path, removed: true };
@@ -1875,9 +1911,8 @@ var LARGE = 100 * 1024 ** 2;
1875
1911
  var BIG = 1024 ** 3;
1876
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
1877
1913
 
1878
- 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.
1879
-
1880
- Exits 0 when it listed, or removed every entry it was allowed to, 1 when a removal failed or the confirm was declined, 2 on a usage error, a missing root, or --apply off a terminal without --yes.`;
1914
+ 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
+ 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"]];
1881
1916
  var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
1882
1917
  var OPTIONS = {
1883
1918
  apply: { type: "boolean", description: "delete what is listed as removable, after the confirm" },
@@ -1899,11 +1934,11 @@ async function dockerUsage() {
1899
1934
  }
1900
1935
  }
1901
1936
  async function sweep(args) {
1902
- 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"] });
1937
+ 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"] });
1903
1938
  if (positionals.length > 1)
1904
1939
  badUsage("give one root");
1905
1940
  const root = workspaceRoot({ given: positionals[0] });
1906
- if (!existsSync7(root) || !statSync2(root).isDirectory())
1941
+ if (!existsSync6(root) || !statSync2(root).isDirectory())
1907
1942
  fail(`${root} is not a folder`);
1908
1943
  if (values.only !== undefined && !Object.hasOwn(ONLY_KINDS, values.only))
1909
1944
  badUsage(`--only takes worktrees, folders or caches, not ${values.only}`);
@@ -1923,7 +1958,7 @@ async function sweep(args) {
1923
1958
  if (values.apply === true && removable.length > 0 && values.yes !== true) {
1924
1959
  if (!json)
1925
1960
  print(root, entries, skipped.length, reclaimable, now);
1926
- const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${tt2(reclaimable)})?`, { default: false, hint: "pass --yes to skip the confirm" });
1961
+ const agreed = await confirm(`Delete ${removable.length} ${removable.length === 1 ? "entry" : "entries"} (${tt(reclaimable)})?`, { default: false, hint: "pass --yes to skip the confirm" });
1927
1962
  if (agreed !== true) {
1928
1963
  if (json)
1929
1964
  fail("nothing deleted: the confirm was declined", 1, "pass --yes to skip the confirm");
@@ -1943,7 +1978,7 @@ async function sweep(args) {
1943
1978
  console.log("dry run, pass --apply to delete");
1944
1979
  } else {
1945
1980
  const bytes = new Map(removable.map((entry) => [entry.path, entry.bytes]));
1946
- note(`freed ${tt2(outcomes.reduce((sum, outcome) => sum + (outcome.removed ? bytes.get(outcome.path) ?? 0 : 0), 0))}`);
1981
+ note(`freed ${tt(outcomes.reduce((sum, outcome) => sum + (outcome.removed ? bytes.get(outcome.path) ?? 0 : 0), 0))}`);
1947
1982
  }
1948
1983
  if (docker !== undefined)
1949
1984
  console.log(`
@@ -1968,13 +2003,13 @@ function print(root, entries, skipped, reclaimable, now) {
1968
2003
  const path = role("path", process.stdout);
1969
2004
  const sized = (bytes) => {
1970
2005
  if (bytes >= BIG)
1971
- return colors.red(tt2(bytes));
1972
- return bytes >= LARGE ? colors.yellow(tt2(bytes)) : tt2(bytes);
2006
+ return colors.red(tt(bytes));
2007
+ return bytes >= LARGE ? colors.yellow(tt(bytes)) : tt(bytes);
1973
2008
  };
1974
2009
  console.log(table([["size", "age", "what", "path", "note"], ...entries.map((entry) => [sized(entry.bytes), entry.committedAt === undefined ? colors.dim("-") : colors.dim(formatAge(entry.committedAt, now)), entry.kind, path(relative(root, entry.path)), entry.action === "keep" ? colors.dim(`kept: ${entry.reason}`) : ""])], { header: true, align: ["right", "right", "left", "left", "left"] }));
1975
2010
  console.log(`
1976
- ${tt2(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
2011
+ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (symlinks, tracked or not ignored by git)`}`);
1977
2012
  }
1978
2013
 
1979
2014
  // src/sweep-cli.ts
1980
- process18.exitCode = await runMain({ name: "sweep", run: sweep });
2015
+ process19.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.10.0",
4
+ "version": "0.10.2",
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.36.0"
37
+ "@kaynooo/cli-kit": "0.38.3"
38
38
  }
39
39
  }