@kaynooo/cli-workspace 0.11.1 → 0.14.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/README.md +25 -25
- package/dist/cli.js +1152 -492
- package/package.json +9 -15
- package/dist/audit-cli.js +0 -1927
- package/dist/repos-cli.js +0 -1797
- package/dist/sweep-cli.js +0 -2187
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
import process24 from "process";
|
|
6
|
-
|
|
7
|
-
// ../kit/src/advisory.ts
|
|
8
|
-
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
9
|
-
function severityRank(severity) {
|
|
10
|
-
return SEVERITIES.indexOf(severity);
|
|
11
|
-
}
|
|
12
|
-
function isIgnored(advisory, ignore) {
|
|
13
|
-
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
14
|
-
}
|
|
15
|
-
// ../kit/src/args.ts
|
|
16
|
-
import process9 from "process";
|
|
17
|
-
import { parseArgs } from "util";
|
|
18
|
-
|
|
19
|
-
// ../kit/src/format.ts
|
|
20
|
-
import process7 from "process";
|
|
21
|
-
|
|
22
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
|
|
23
|
-
var r = new Map;
|
|
24
|
-
var i = new Map;
|
|
25
|
-
var l = new Map;
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-n6z2kk96.js
|
|
26
16
|
function a(e, t, o) {
|
|
27
17
|
return JSON.stringify([e ?? null, t ?? null, o]);
|
|
28
18
|
}
|
|
@@ -32,12 +22,15 @@ function y(e, t) {
|
|
|
32
22
|
n = new Intl.NumberFormat(e, t), i.set(o, n);
|
|
33
23
|
return n;
|
|
34
24
|
}
|
|
25
|
+
var r, i, l;
|
|
26
|
+
var init_chunk_n6z2kk96 = __esm(() => {
|
|
27
|
+
r = new Map;
|
|
28
|
+
i = new Map;
|
|
29
|
+
l = new Map;
|
|
30
|
+
});
|
|
35
31
|
|
|
36
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.
|
|
37
|
-
|
|
38
|
-
var Nt = /\s+\S*$/;
|
|
39
|
-
var Y = /\s/;
|
|
40
|
-
function ko(t, e, r = "...") {
|
|
32
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
33
|
+
function Ao(t, e, r = "...") {
|
|
41
34
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
42
35
|
if (t.length <= e)
|
|
43
36
|
return t;
|
|
@@ -48,13 +41,22 @@ function ko(t, e, r = "...") {
|
|
|
48
41
|
c = c.trimEnd();
|
|
49
42
|
return s ? (c + n).slice(0, l) : c + n;
|
|
50
43
|
}
|
|
51
|
-
var
|
|
52
|
-
var
|
|
44
|
+
var N, Nt, Y, be, W;
|
|
45
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
46
|
+
N = new Map;
|
|
47
|
+
Nt = /\s+\S*$/;
|
|
48
|
+
Y = /\s/;
|
|
49
|
+
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));
|
|
50
|
+
W = new Map;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
54
|
+
var init_text = __esm(() => {
|
|
55
|
+
init_chunk_rkhsft4a();
|
|
56
|
+
});
|
|
53
57
|
|
|
54
58
|
// ../kit/src/mode.ts
|
|
55
59
|
import process2 from "process";
|
|
56
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
57
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
58
60
|
function isSet(value) {
|
|
59
61
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
60
62
|
}
|
|
@@ -71,12 +73,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
71
73
|
function isInteractive(streams = process2) {
|
|
72
74
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
73
75
|
}
|
|
76
|
+
var MODES, AGENT_VARIABLES;
|
|
77
|
+
var init_mode = __esm(() => {
|
|
78
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
79
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
80
|
+
});
|
|
74
81
|
|
|
75
|
-
//
|
|
76
|
-
import process6 from "process";
|
|
77
|
-
|
|
78
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
79
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
82
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
80
83
|
function b(r) {
|
|
81
84
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
82
85
|
if (!G2.test(e))
|
|
@@ -87,11 +90,6 @@ function b(r) {
|
|
|
87
90
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
88
91
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
89
92
|
}
|
|
90
|
-
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
91
|
-
let [l, n, c] = b(r);
|
|
92
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
93
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
94
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
95
93
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
96
94
|
if (e.FORCE_COLOR !== undefined)
|
|
97
95
|
return h.has(e.FORCE_COLOR);
|
|
@@ -105,7 +103,7 @@ function f(r, e = []) {
|
|
|
105
103
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
106
104
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
107
105
|
return new Proxy(c, { get(t, i) {
|
|
108
|
-
let a =
|
|
106
|
+
let a = B[i];
|
|
109
107
|
if (Array.isArray(a)) {
|
|
110
108
|
let s = g.get(i);
|
|
111
109
|
if (s === undefined)
|
|
@@ -128,13 +126,21 @@ function f(r, e = []) {
|
|
|
128
126
|
function Fe(r = {}) {
|
|
129
127
|
return f(r);
|
|
130
128
|
}
|
|
131
|
-
var
|
|
129
|
+
var G2, B, h, o;
|
|
130
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
131
|
+
G2 = /^[a-f0-9]+$/i;
|
|
132
|
+
B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
133
|
+
let [l, n, c] = b(r);
|
|
134
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
135
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
136
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
137
|
+
o = Fe();
|
|
138
|
+
});
|
|
132
139
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
import process5 from "process";
|
|
140
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
141
|
+
var init_colors = __esm(() => {
|
|
142
|
+
init_chunk_x450vn3m();
|
|
143
|
+
});
|
|
138
144
|
|
|
139
145
|
// ../kit/src/config.ts
|
|
140
146
|
import { existsSync } from "fs";
|
|
@@ -150,15 +156,21 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
150
156
|
return;
|
|
151
157
|
}
|
|
152
158
|
}
|
|
159
|
+
var init_config = __esm(() => {
|
|
160
|
+
init_args();
|
|
161
|
+
});
|
|
153
162
|
|
|
154
163
|
// ../kit/src/user-config.ts
|
|
155
164
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
156
165
|
import { homedir } from "os";
|
|
157
|
-
import { join as join2 } from "path";
|
|
166
|
+
import { isAbsolute, join as join2 } from "path";
|
|
158
167
|
import process4 from "process";
|
|
168
|
+
function xdgFolder(value, fallback) {
|
|
169
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
170
|
+
}
|
|
159
171
|
function configBase(where = {}) {
|
|
160
172
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
161
|
-
return xdg
|
|
173
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
162
174
|
}
|
|
163
175
|
function userConfigPath(bin, where = {}) {
|
|
164
176
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -185,36 +197,49 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
|
185
197
|
const value = readUserConfig(bin, where, legacy)[key];
|
|
186
198
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
187
199
|
}
|
|
200
|
+
var init_user_config = () => {};
|
|
188
201
|
|
|
189
202
|
// ../kit/src/theme.ts
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
203
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
204
|
+
import { homedir as homedir2 } from "os";
|
|
205
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
206
|
+
import process5 from "process";
|
|
207
|
+
function toLinear(channel) {
|
|
208
|
+
const value = channel / 255;
|
|
209
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
210
|
+
}
|
|
211
|
+
function toOklab(hex) {
|
|
212
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
213
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
214
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
215
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
216
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
217
|
+
}
|
|
218
|
+
function fromOklab([lightness, a, b]) {
|
|
219
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
220
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
221
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
222
|
+
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
223
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
224
|
+
}
|
|
225
|
+
function gradientAt(theme, ratio) {
|
|
226
|
+
if (theme.gradient === undefined)
|
|
227
|
+
return;
|
|
228
|
+
const key = theme.gradient.join();
|
|
229
|
+
let ends = ENDS.get(key);
|
|
230
|
+
if (ends === undefined) {
|
|
231
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
232
|
+
ENDS.set(key, ends);
|
|
233
|
+
}
|
|
234
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
235
|
+
const [from, to] = ends;
|
|
236
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
237
|
+
}
|
|
212
238
|
function isColorSpec(spec) {
|
|
213
239
|
if (typeof spec === "number")
|
|
214
240
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
215
241
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
216
242
|
}
|
|
217
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
218
243
|
function cubeLevel(channel) {
|
|
219
244
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
220
245
|
}
|
|
@@ -239,6 +264,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
239
264
|
return chain[token] ?? chain;
|
|
240
265
|
}, colors);
|
|
241
266
|
}
|
|
267
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
268
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
269
|
+
}
|
|
242
270
|
function isRecord(value) {
|
|
243
271
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
244
272
|
}
|
|
@@ -319,7 +347,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
319
347
|
function endsWalk(home) {
|
|
320
348
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
321
349
|
}
|
|
322
|
-
var warned = new Set;
|
|
323
350
|
function warnOnce(message) {
|
|
324
351
|
if (warned.has(message))
|
|
325
352
|
return;
|
|
@@ -356,8 +383,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
356
383
|
}
|
|
357
384
|
return { theme, sources, preset };
|
|
358
385
|
}
|
|
359
|
-
var current;
|
|
360
|
-
var currentKey = "";
|
|
361
386
|
function activeTheme() {
|
|
362
387
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
363
388
|
if (current === undefined || key !== currentKey) {
|
|
@@ -366,9 +391,38 @@ function activeTheme() {
|
|
|
366
391
|
}
|
|
367
392
|
return current;
|
|
368
393
|
}
|
|
394
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
395
|
+
var init_theme = __esm(() => {
|
|
396
|
+
init_config();
|
|
397
|
+
init_user_config();
|
|
398
|
+
ENDS = new Map;
|
|
399
|
+
DEFAULT = {
|
|
400
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
401
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
402
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
403
|
+
bins: {},
|
|
404
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
405
|
+
};
|
|
406
|
+
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
407
|
+
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
408
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
409
|
+
PRESETS = {
|
|
410
|
+
default: {},
|
|
411
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
412
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
413
|
+
ascii: { glyphs: ASCII }
|
|
414
|
+
};
|
|
415
|
+
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
416
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
417
|
+
CONTROL = /\p{Cc}/u;
|
|
418
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
419
|
+
SPACES = /\s+/;
|
|
420
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
421
|
+
warned = new Set;
|
|
422
|
+
});
|
|
369
423
|
|
|
370
424
|
// ../kit/src/style.ts
|
|
371
|
-
|
|
425
|
+
import process6 from "process";
|
|
372
426
|
function takesControlCodes(stream, env = process6.env) {
|
|
373
427
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
374
428
|
}
|
|
@@ -397,14 +451,6 @@ function role(name, stream, env = process6.env) {
|
|
|
397
451
|
const colors = paint(stream, env);
|
|
398
452
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
399
453
|
}
|
|
400
|
-
var STATUS_WORDS = {
|
|
401
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
402
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
403
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
404
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
405
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
406
|
-
};
|
|
407
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
408
454
|
function header(bin, context, stream, env = process6.env) {
|
|
409
455
|
if (!takesControlCodes(stream, env))
|
|
410
456
|
return "";
|
|
@@ -420,7 +466,23 @@ function printHeader(bin, context, stream = process6.stdout, env = process6.env)
|
|
|
420
466
|
if (line !== "")
|
|
421
467
|
console.log(line);
|
|
422
468
|
}
|
|
423
|
-
|
|
469
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
470
|
+
var init_style = __esm(() => {
|
|
471
|
+
init_colors();
|
|
472
|
+
init_mode();
|
|
473
|
+
init_theme();
|
|
474
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
475
|
+
STATUS_WORDS = {
|
|
476
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
477
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
478
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
479
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
480
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
481
|
+
};
|
|
482
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-knqbxp56.js
|
|
424
486
|
function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
425
487
|
let e = r === "si" ? 1000 : 1024;
|
|
426
488
|
if (Math.abs(i) < e)
|
|
@@ -431,9 +493,17 @@ function tt(i, { units: r = "iec", dp: t = 1, locale: n } = {}) {
|
|
|
431
493
|
while (Math.round(Math.abs(i) * a) / a >= e && o < s.length - 1);
|
|
432
494
|
return `${n ? y(n, { minimumFractionDigits: t, maximumFractionDigits: t }).format(i) : i.toFixed(t)} ${s[o]}`;
|
|
433
495
|
}
|
|
496
|
+
var init_chunk_knqbxp56 = __esm(() => {
|
|
497
|
+
init_chunk_n6z2kk96();
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/format/index.js
|
|
501
|
+
var init_format = __esm(() => {
|
|
502
|
+
init_chunk_knqbxp56();
|
|
503
|
+
});
|
|
434
504
|
|
|
435
505
|
// ../kit/src/format.ts
|
|
436
|
-
|
|
506
|
+
import process7 from "process";
|
|
437
507
|
function formatSeconds(total) {
|
|
438
508
|
let rest = Math.max(0, Math.round(total));
|
|
439
509
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -450,6 +520,9 @@ function formatSeconds(total) {
|
|
|
450
520
|
function formatDuration(ms) {
|
|
451
521
|
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
452
522
|
}
|
|
523
|
+
function formatElapsed(ms) {
|
|
524
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
525
|
+
}
|
|
453
526
|
function upTo(text, separator) {
|
|
454
527
|
const end = text.indexOf(separator);
|
|
455
528
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -462,10 +535,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
462
535
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
463
536
|
}
|
|
464
537
|
function truncate(text, width) {
|
|
465
|
-
return
|
|
538
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
466
539
|
}
|
|
467
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
468
|
-
var ESCAPE = String.fromCharCode(27);
|
|
469
540
|
function textWidth(text) {
|
|
470
541
|
return Bun.stringWidth(text);
|
|
471
542
|
}
|
|
@@ -514,14 +585,41 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
514
585
|
function printJson(value) {
|
|
515
586
|
console.log(jsonText(value));
|
|
516
587
|
}
|
|
588
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
589
|
+
var init_format2 = __esm(() => {
|
|
590
|
+
init_text();
|
|
591
|
+
init_mode();
|
|
592
|
+
init_style();
|
|
593
|
+
init_format();
|
|
594
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
595
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
596
|
+
ESCAPE = String.fromCharCode(27);
|
|
597
|
+
});
|
|
517
598
|
|
|
518
599
|
// ../kit/src/help.ts
|
|
519
600
|
import process8 from "process";
|
|
520
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
521
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
522
|
-
var FULL_STOP = /\.$/;
|
|
523
601
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
524
|
-
|
|
602
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
603
|
+
`);
|
|
604
|
+
const blank = lines.indexOf("");
|
|
605
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
606
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
607
|
+
const colon = synopses[0].indexOf(": ");
|
|
608
|
+
const inline = synopses[0].slice(colon + 2);
|
|
609
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
610
|
+
if (colon !== -1)
|
|
611
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
612
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
613
|
+
`)}`;
|
|
614
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
615
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
616
|
+
return [head, ...lead, ...rest].join(`
|
|
617
|
+
`);
|
|
618
|
+
}
|
|
619
|
+
function prose(line, colors) {
|
|
620
|
+
if (colors.cyan("x") === "x")
|
|
621
|
+
return line;
|
|
622
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
525
623
|
}
|
|
526
624
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
527
625
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -556,7 +654,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
556
654
|
return [];
|
|
557
655
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
558
656
|
}
|
|
559
|
-
var MAX_INLINE_CHOICES = 24;
|
|
560
657
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
561
658
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
562
659
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -571,6 +668,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
571
668
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
572
669
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
573
670
|
}
|
|
671
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
672
|
+
var init_help = __esm(() => {
|
|
673
|
+
init_mode();
|
|
674
|
+
init_style();
|
|
675
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
676
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
677
|
+
FULL_STOP = /\.$/;
|
|
678
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
679
|
+
});
|
|
574
680
|
|
|
575
681
|
// ../kit/src/text.ts
|
|
576
682
|
function distance(a, b) {
|
|
@@ -598,9 +704,9 @@ function closest(name, names) {
|
|
|
598
704
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
599
705
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
600
706
|
}
|
|
707
|
+
var init_text2 = () => {};
|
|
708
|
+
|
|
601
709
|
// ../kit/src/input.ts
|
|
602
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
603
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
604
710
|
function duration(value, name, fallback, unit = "s") {
|
|
605
711
|
if (value === undefined)
|
|
606
712
|
return fallback;
|
|
@@ -610,40 +716,26 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
610
716
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
611
717
|
return ms;
|
|
612
718
|
}
|
|
719
|
+
var DURATION, UNIT_MS;
|
|
720
|
+
var init_input = __esm(() => {
|
|
721
|
+
init_args();
|
|
722
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
723
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
724
|
+
});
|
|
613
725
|
|
|
614
726
|
// ../kit/src/args.ts
|
|
615
|
-
|
|
727
|
+
import process9 from "process";
|
|
728
|
+
import { parseArgs } from "util";
|
|
616
729
|
function jsonOption(holds) {
|
|
617
730
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
618
731
|
}
|
|
619
|
-
class Exit extends Error {
|
|
620
|
-
code;
|
|
621
|
-
hint;
|
|
622
|
-
constructor(message, code, hint) {
|
|
623
|
-
super(message);
|
|
624
|
-
this.code = code;
|
|
625
|
-
this.hint = hint;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
732
|
function fail(message, code = 2, hint) {
|
|
629
733
|
throw new Exit(message, code, hint);
|
|
630
734
|
}
|
|
631
|
-
|
|
632
|
-
class UsageError extends Exit {
|
|
633
|
-
constructor(message, hint) {
|
|
634
|
-
super(message, 2, hint);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
735
|
function badUsage(message) {
|
|
638
736
|
throw new UsageError(message);
|
|
639
737
|
}
|
|
640
738
|
|
|
641
|
-
class HelpShown extends Exit {
|
|
642
|
-
constructor() {
|
|
643
|
-
super("help shown", 0);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
|
|
647
739
|
class Completing {
|
|
648
740
|
options;
|
|
649
741
|
positionals;
|
|
@@ -654,11 +746,6 @@ class Completing {
|
|
|
654
746
|
this.candidates = candidates;
|
|
655
747
|
}
|
|
656
748
|
}
|
|
657
|
-
var completion = { active: false };
|
|
658
|
-
var OUTPUT_OPTIONS = {
|
|
659
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
660
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
661
|
-
};
|
|
662
749
|
function applyOutput(color, plain, env = process9.env) {
|
|
663
750
|
const when = plain === true ? "never" : color ?? "auto";
|
|
664
751
|
if (when === "auto")
|
|
@@ -812,7 +899,6 @@ function parseError(error) {
|
|
|
812
899
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
813
900
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
814
901
|
}
|
|
815
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
816
902
|
function nearestOption(message, options, allowNegative) {
|
|
817
903
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
818
904
|
if (typed === undefined)
|
|
@@ -828,6 +914,303 @@ function nearestOption(message, options, allowNegative) {
|
|
|
828
914
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
829
915
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
830
916
|
}
|
|
917
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
918
|
+
var init_args = __esm(() => {
|
|
919
|
+
init_format2();
|
|
920
|
+
init_help();
|
|
921
|
+
init_text2();
|
|
922
|
+
init_help();
|
|
923
|
+
init_input();
|
|
924
|
+
DASHES = /^-+/;
|
|
925
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
926
|
+
Exit = class Exit extends Error {
|
|
927
|
+
code;
|
|
928
|
+
hint;
|
|
929
|
+
[EXIT] = true;
|
|
930
|
+
constructor(message, code, hint) {
|
|
931
|
+
super(message);
|
|
932
|
+
this.code = code;
|
|
933
|
+
this.hint = hint;
|
|
934
|
+
}
|
|
935
|
+
static [Symbol.hasInstance](value) {
|
|
936
|
+
if (this !== Exit)
|
|
937
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
938
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
UsageError = class UsageError extends Exit {
|
|
942
|
+
constructor(message, hint) {
|
|
943
|
+
super(message, 2, hint);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
HelpShown = class HelpShown extends Exit {
|
|
947
|
+
constructor() {
|
|
948
|
+
super("help shown", 0);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
completion = { active: false };
|
|
952
|
+
OUTPUT_OPTIONS = {
|
|
953
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
954
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
955
|
+
};
|
|
956
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
// ../kit/src/folders.ts
|
|
960
|
+
var SKIPPED_FOLDERS;
|
|
961
|
+
var init_folders = __esm(() => {
|
|
962
|
+
init_user_config();
|
|
963
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
// ../kit/src/answers.ts
|
|
967
|
+
var init_answers = __esm(() => {
|
|
968
|
+
init_folders();
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
// ../kit/src/job.ts
|
|
972
|
+
import process24 from "process";
|
|
973
|
+
function stopJob() {
|
|
974
|
+
process24.kill(0, "SIGTSTP");
|
|
975
|
+
}
|
|
976
|
+
var init_job = () => {};
|
|
977
|
+
|
|
978
|
+
// ../kit/src/picker/line.ts
|
|
979
|
+
function isEditKey(key) {
|
|
980
|
+
return EDIT_KEYS.has(key);
|
|
981
|
+
}
|
|
982
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS;
|
|
983
|
+
var init_line = __esm(() => {
|
|
984
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
985
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
986
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
// ../kit/src/picker/score.ts
|
|
990
|
+
var BOUNDARY_AFTER, NONE;
|
|
991
|
+
var init_score = __esm(() => {
|
|
992
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
993
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
// ../kit/src/picker/state.ts
|
|
997
|
+
function repeat(value, count) {
|
|
998
|
+
return Array.from({ length: count }).fill(value);
|
|
999
|
+
}
|
|
1000
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1001
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1002
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1003
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1004
|
+
if (wheel !== undefined)
|
|
1005
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1006
|
+
const named = codes.get(sequence);
|
|
1007
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1008
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1009
|
+
paste.active = sequence === PASTE_START;
|
|
1010
|
+
return [];
|
|
1011
|
+
}
|
|
1012
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1013
|
+
`))
|
|
1014
|
+
return [];
|
|
1015
|
+
if (key !== undefined)
|
|
1016
|
+
return [key];
|
|
1017
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
1021
|
+
var init_state = __esm(() => {
|
|
1022
|
+
init_text2();
|
|
1023
|
+
init_line();
|
|
1024
|
+
init_score();
|
|
1025
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1026
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1027
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1028
|
+
KEYS = {
|
|
1029
|
+
"\x1B[A": "up",
|
|
1030
|
+
"\x1BOA": "up",
|
|
1031
|
+
"\x10": "up",
|
|
1032
|
+
"\x1B[B": "down",
|
|
1033
|
+
"\x1BOB": "down",
|
|
1034
|
+
"\x0E": "down",
|
|
1035
|
+
"\x1B[5~": "pageup",
|
|
1036
|
+
"\x1B[6~": "pagedown",
|
|
1037
|
+
"\x1B[H": "home",
|
|
1038
|
+
"\x1B[1~": "home",
|
|
1039
|
+
"\x1BOH": "home",
|
|
1040
|
+
"\x1B[F": "end",
|
|
1041
|
+
"\x1B[4~": "end",
|
|
1042
|
+
"\x1BOF": "end",
|
|
1043
|
+
"\r": "enter",
|
|
1044
|
+
"\n": "enter",
|
|
1045
|
+
"\x03": "cancel",
|
|
1046
|
+
"\x1B": "cancel",
|
|
1047
|
+
"\x1B[D": "left",
|
|
1048
|
+
"\x1BOD": "left",
|
|
1049
|
+
"\x1B[C": "right",
|
|
1050
|
+
"\x1BOC": "right",
|
|
1051
|
+
"\x1B[1;5D": "wordleft",
|
|
1052
|
+
"\x1B[1;3D": "wordleft",
|
|
1053
|
+
"\x1Bb": "wordleft",
|
|
1054
|
+
"\x1B[1;5C": "wordright",
|
|
1055
|
+
"\x1B[1;3C": "wordright",
|
|
1056
|
+
"\x1Bf": "wordright",
|
|
1057
|
+
"\x01": "linestart",
|
|
1058
|
+
"\x05": "lineend",
|
|
1059
|
+
"\x7F": "erase",
|
|
1060
|
+
"\x1B[3~": "delete",
|
|
1061
|
+
"\b": "killword",
|
|
1062
|
+
"\x1B\x7F": "killword",
|
|
1063
|
+
"\x1B[3;5~": "killnext",
|
|
1064
|
+
"\x1Bd": "killnext",
|
|
1065
|
+
"\x15": "clear",
|
|
1066
|
+
"\v": "killend",
|
|
1067
|
+
"\x17": "word",
|
|
1068
|
+
"\x19": "yank",
|
|
1069
|
+
"\x1A": "suspend",
|
|
1070
|
+
"\t": "tab",
|
|
1071
|
+
"\x1F": "help",
|
|
1072
|
+
"\x1BOP": "help",
|
|
1073
|
+
"\x1B[11~": "help"
|
|
1074
|
+
};
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
// ../kit/src/redraw.ts
|
|
1078
|
+
function overwrite(lines, columns) {
|
|
1079
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1080
|
+
`);
|
|
1081
|
+
}
|
|
1082
|
+
function rowsTaken(lines, columns) {
|
|
1083
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1084
|
+
}
|
|
1085
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1086
|
+
var init_redraw = __esm(() => {
|
|
1087
|
+
init_format2();
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
// ../kit/src/prompt.ts
|
|
1091
|
+
import process25 from "process";
|
|
1092
|
+
function readKeys(input, paste = { active: false }) {
|
|
1093
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1094
|
+
}
|
|
1095
|
+
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1096
|
+
let answered = fallback;
|
|
1097
|
+
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
1098
|
+
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
1099
|
+
if (key === "cancel")
|
|
1100
|
+
return "cancel";
|
|
1101
|
+
if (key === "enter")
|
|
1102
|
+
return answered === undefined ? undefined : "enter";
|
|
1103
|
+
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
1104
|
+
if (letter !== "y" && letter !== "n")
|
|
1105
|
+
return;
|
|
1106
|
+
answered = letter === "y";
|
|
1107
|
+
return "enter";
|
|
1108
|
+
});
|
|
1109
|
+
return accepted ? answered : undefined;
|
|
1110
|
+
}
|
|
1111
|
+
function asking(colors, question, typed, keys) {
|
|
1112
|
+
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
1113
|
+
}
|
|
1114
|
+
function answer(colors, question, state, picked) {
|
|
1115
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1116
|
+
}
|
|
1117
|
+
async function ask(question, { hint, terminal = process25 }, render, press) {
|
|
1118
|
+
const { stdin, stderr } = terminal;
|
|
1119
|
+
if (!isInteractive(terminal))
|
|
1120
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1121
|
+
const colors = paint(stderr);
|
|
1122
|
+
let current = "asking";
|
|
1123
|
+
let outcome;
|
|
1124
|
+
const columns = () => stderr.columns || 80;
|
|
1125
|
+
const draw = (state, last = false) => {
|
|
1126
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1127
|
+
const rows = rowsTaken(frame, columns());
|
|
1128
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1129
|
+
current = state;
|
|
1130
|
+
};
|
|
1131
|
+
const redraw = () => draw(current);
|
|
1132
|
+
const paste = { active: false };
|
|
1133
|
+
const stop = terminal.stop ?? (terminal === process25 ? stopJob : undefined);
|
|
1134
|
+
const suspend = () => {
|
|
1135
|
+
if (stop === undefined)
|
|
1136
|
+
return;
|
|
1137
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1138
|
+
stdin.setRawMode(false);
|
|
1139
|
+
stop();
|
|
1140
|
+
stdin.setRawMode(true);
|
|
1141
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1142
|
+
};
|
|
1143
|
+
try {
|
|
1144
|
+
stderr.on?.("resize", redraw);
|
|
1145
|
+
stdin.setRawMode(true);
|
|
1146
|
+
stdin.resume();
|
|
1147
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1148
|
+
draw("asking");
|
|
1149
|
+
return await new Promise((resolve) => {
|
|
1150
|
+
function onData(data) {
|
|
1151
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1152
|
+
if (key === "suspend") {
|
|
1153
|
+
suspend();
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
const pressed = press(key);
|
|
1157
|
+
if (pressed !== undefined) {
|
|
1158
|
+
settle(pressed);
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
draw("asking");
|
|
1163
|
+
}
|
|
1164
|
+
function onEnd() {
|
|
1165
|
+
settle("cancel");
|
|
1166
|
+
}
|
|
1167
|
+
function settle(settled) {
|
|
1168
|
+
outcome = settled;
|
|
1169
|
+
stdin.off("data", onData);
|
|
1170
|
+
stdin.off("end", onEnd);
|
|
1171
|
+
resolve(settled === "enter");
|
|
1172
|
+
}
|
|
1173
|
+
stdin.on("data", onData);
|
|
1174
|
+
stdin.on("end", onEnd);
|
|
1175
|
+
});
|
|
1176
|
+
} finally {
|
|
1177
|
+
stderr.off?.("resize", redraw);
|
|
1178
|
+
draw(outcome ?? "cancel", true);
|
|
1179
|
+
stderr.write(`
|
|
1180
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1181
|
+
stdin.setRawMode(false);
|
|
1182
|
+
stdin.pause();
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
var PROMPT_KEYS;
|
|
1186
|
+
var init_prompt = __esm(() => {
|
|
1187
|
+
init_answers();
|
|
1188
|
+
init_args();
|
|
1189
|
+
init_format2();
|
|
1190
|
+
init_job();
|
|
1191
|
+
init_mode();
|
|
1192
|
+
init_line();
|
|
1193
|
+
init_state();
|
|
1194
|
+
init_redraw();
|
|
1195
|
+
init_style();
|
|
1196
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
// src/cli.ts
|
|
1200
|
+
import process26 from "process";
|
|
1201
|
+
|
|
1202
|
+
// ../kit/src/advisory.ts
|
|
1203
|
+
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
1204
|
+
function severityRank(severity) {
|
|
1205
|
+
return SEVERITIES.indexOf(severity);
|
|
1206
|
+
}
|
|
1207
|
+
function isIgnored(advisory, ignore) {
|
|
1208
|
+
return ignore.includes(advisory.ghsa ?? "") || ignore.includes(String(advisory.id));
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// ../kit/src/index.ts
|
|
1212
|
+
init_args();
|
|
1213
|
+
|
|
831
1214
|
// ../kit/src/argv.ts
|
|
832
1215
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
833
1216
|
import { resolve as resolve3 } from "path";
|
|
@@ -852,10 +1235,26 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
852
1235
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
853
1236
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
854
1237
|
}
|
|
1238
|
+
// ../kit/src/chart.ts
|
|
1239
|
+
init_format2();
|
|
1240
|
+
init_mode();
|
|
1241
|
+
init_style();
|
|
1242
|
+
init_theme();
|
|
1243
|
+
// ../kit/src/ci.ts
|
|
1244
|
+
init_args();
|
|
1245
|
+
init_format2();
|
|
1246
|
+
|
|
1247
|
+
// ../kit/src/progress.ts
|
|
1248
|
+
init_format2();
|
|
1249
|
+
import process12 from "process";
|
|
1250
|
+
|
|
855
1251
|
// ../kit/src/process.ts
|
|
1252
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
856
1253
|
import { constants } from "os";
|
|
857
1254
|
import process11 from "process";
|
|
858
1255
|
var KILL_GRACE_MS = 2000;
|
|
1256
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1257
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
859
1258
|
function exitCodeOf(code, signal) {
|
|
860
1259
|
if (code !== null)
|
|
861
1260
|
return code;
|
|
@@ -863,10 +1262,57 @@ function exitCodeOf(code, signal) {
|
|
|
863
1262
|
return 128 + signal;
|
|
864
1263
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
865
1264
|
}
|
|
866
|
-
|
|
1265
|
+
function groupsOf(pid) {
|
|
1266
|
+
try {
|
|
1267
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
1268
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1269
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
1270
|
+
} catch {
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
function heardTheTerminal(child) {
|
|
1275
|
+
if (child.pid === undefined)
|
|
1276
|
+
return false;
|
|
1277
|
+
const own = groupsOf("self");
|
|
1278
|
+
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
1279
|
+
}
|
|
1280
|
+
function holdSignals(cleanup) {
|
|
1281
|
+
let received;
|
|
1282
|
+
let child;
|
|
1283
|
+
const held = {
|
|
1284
|
+
get signal() {
|
|
1285
|
+
return received;
|
|
1286
|
+
},
|
|
1287
|
+
forward: (to) => {
|
|
1288
|
+
child = to;
|
|
1289
|
+
},
|
|
1290
|
+
release: () => {
|
|
1291
|
+
for (const signal of SIGNALS)
|
|
1292
|
+
process11.off(signal, onSignal);
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
function onSignal(signal) {
|
|
1296
|
+
received = signal;
|
|
1297
|
+
if (child !== undefined) {
|
|
1298
|
+
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1299
|
+
child.kill(signal);
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
if (cleanup === undefined)
|
|
1303
|
+
return;
|
|
1304
|
+
held.release();
|
|
1305
|
+
cleanup(signal);
|
|
1306
|
+
process11.kill(process11.pid, signal);
|
|
1307
|
+
}
|
|
1308
|
+
for (const signal of SIGNALS)
|
|
1309
|
+
process11.on(signal, onSignal);
|
|
1310
|
+
return held;
|
|
1311
|
+
}
|
|
1312
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
867
1313
|
const chunks = [];
|
|
868
1314
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
869
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1315
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
870
1316
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
871
1317
|
const timers = [];
|
|
872
1318
|
const killGroup = (killing) => {
|
|
@@ -906,12 +1352,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
906
1352
|
stop();
|
|
907
1353
|
continue;
|
|
908
1354
|
}
|
|
1355
|
+
if (state.truncated)
|
|
1356
|
+
continue;
|
|
1357
|
+
let kept = data;
|
|
909
1358
|
if (state.kept + data.length > maxBytes) {
|
|
1359
|
+
let cut = maxBytes - state.kept;
|
|
1360
|
+
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1361
|
+
cut--;
|
|
1362
|
+
kept = data.subarray(0, cut);
|
|
910
1363
|
state.truncated = true;
|
|
911
|
-
continue;
|
|
912
1364
|
}
|
|
913
|
-
state.kept +=
|
|
914
|
-
|
|
1365
|
+
state.kept += kept.length;
|
|
1366
|
+
if (kept.length > 0)
|
|
1367
|
+
chunks.push({ stream: name, data: kept });
|
|
915
1368
|
}
|
|
916
1369
|
};
|
|
917
1370
|
try {
|
|
@@ -928,6 +1381,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
928
1381
|
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
929
1382
|
let output;
|
|
930
1383
|
let text;
|
|
1384
|
+
let stdout;
|
|
931
1385
|
return {
|
|
932
1386
|
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
933
1387
|
chunks,
|
|
@@ -938,21 +1392,241 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
938
1392
|
},
|
|
939
1393
|
get text() {
|
|
940
1394
|
return text ??= (output ??= joined()).toString();
|
|
1395
|
+
},
|
|
1396
|
+
get stdout() {
|
|
1397
|
+
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// ../kit/src/progress.ts
|
|
1403
|
+
init_style();
|
|
1404
|
+
init_theme();
|
|
1405
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1406
|
+
var FRAME_MS = 200;
|
|
1407
|
+
var BAR_WIDTH = 20;
|
|
1408
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
1409
|
+
var ESC = String.fromCharCode(27);
|
|
1410
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1411
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1412
|
+
var CTRL_C = 3;
|
|
1413
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1414
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1415
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
1416
|
+
if (!takesControlCodes(stream, env))
|
|
1417
|
+
return { redraw: () => {
|
|
1418
|
+
return;
|
|
1419
|
+
}, print: (text) => void stream.write(`${text}
|
|
1420
|
+
`), stop: () => {
|
|
1421
|
+
return;
|
|
1422
|
+
}, pause: () => () => {
|
|
1423
|
+
return;
|
|
1424
|
+
} };
|
|
1425
|
+
const write = stream.write.bind(stream);
|
|
1426
|
+
let frame = 0;
|
|
1427
|
+
let drawn = false;
|
|
1428
|
+
let paused = false;
|
|
1429
|
+
let stopped = false;
|
|
1430
|
+
const columns = () => {
|
|
1431
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
1432
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
1433
|
+
};
|
|
1434
|
+
const clear = () => {
|
|
1435
|
+
if (drawn)
|
|
1436
|
+
write(CLEAR_BELOW);
|
|
1437
|
+
drawn = false;
|
|
1438
|
+
};
|
|
1439
|
+
const draw = () => {
|
|
1440
|
+
if (paused)
|
|
1441
|
+
return;
|
|
1442
|
+
const width = columns() - 1;
|
|
1443
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1444
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
1445
|
+
if (lines.length === 0) {
|
|
1446
|
+
clear();
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
1450
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1451
|
+
drawn = true;
|
|
1452
|
+
};
|
|
1453
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1454
|
+
stream.on?.("resize", draw);
|
|
1455
|
+
let restore = interceptOutput(clear);
|
|
1456
|
+
let release = swallowInput();
|
|
1457
|
+
const onExit = () => {
|
|
1458
|
+
clear();
|
|
1459
|
+
release();
|
|
1460
|
+
};
|
|
1461
|
+
const signals = holdSignals(stop);
|
|
1462
|
+
function stop() {
|
|
1463
|
+
stopped = true;
|
|
1464
|
+
clearInterval(timer);
|
|
1465
|
+
stream.off?.("resize", draw);
|
|
1466
|
+
clear();
|
|
1467
|
+
restore();
|
|
1468
|
+
release();
|
|
1469
|
+
process12.off("exit", onExit);
|
|
1470
|
+
signals.release();
|
|
1471
|
+
}
|
|
1472
|
+
function pause() {
|
|
1473
|
+
if (paused || stopped)
|
|
1474
|
+
return () => {
|
|
1475
|
+
return;
|
|
1476
|
+
};
|
|
1477
|
+
paused = true;
|
|
1478
|
+
clearInterval(timer);
|
|
1479
|
+
stream.off?.("resize", draw);
|
|
1480
|
+
clear();
|
|
1481
|
+
restore();
|
|
1482
|
+
release();
|
|
1483
|
+
return () => {
|
|
1484
|
+
if (!paused || stopped)
|
|
1485
|
+
return;
|
|
1486
|
+
paused = false;
|
|
1487
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1488
|
+
timer.unref();
|
|
1489
|
+
stream.on?.("resize", draw);
|
|
1490
|
+
restore = interceptOutput(clear);
|
|
1491
|
+
release = swallowInput();
|
|
1492
|
+
draw();
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
timer.unref();
|
|
1496
|
+
process12.on("exit", onExit);
|
|
1497
|
+
return {
|
|
1498
|
+
redraw: draw,
|
|
1499
|
+
print: (text) => {
|
|
1500
|
+
clear();
|
|
1501
|
+
write(`${text}
|
|
1502
|
+
`);
|
|
1503
|
+
draw();
|
|
1504
|
+
},
|
|
1505
|
+
stop,
|
|
1506
|
+
pause
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1510
|
+
const colors = paint(stream, env);
|
|
1511
|
+
const write = stream.write.bind(stream);
|
|
1512
|
+
const begun = performance.now();
|
|
1513
|
+
let started = begun;
|
|
1514
|
+
let current;
|
|
1515
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1516
|
+
const end = (line) => {
|
|
1517
|
+
region.stop();
|
|
1518
|
+
write(`${line}
|
|
1519
|
+
`);
|
|
1520
|
+
};
|
|
1521
|
+
return {
|
|
1522
|
+
update: (progress) => {
|
|
1523
|
+
const step = current?.step;
|
|
1524
|
+
current = progress;
|
|
1525
|
+
if (progress.step !== step) {
|
|
1526
|
+
started = performance.now();
|
|
1527
|
+
region.redraw();
|
|
1528
|
+
}
|
|
1529
|
+
},
|
|
1530
|
+
stop: region.stop,
|
|
1531
|
+
pause: region.pause,
|
|
1532
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1533
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1537
|
+
const { theme } = activeTheme();
|
|
1538
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1539
|
+
if (total !== undefined && total > 0) {
|
|
1540
|
+
const counted = Math.min(done ?? 0, total);
|
|
1541
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1542
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1543
|
+
}
|
|
1544
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1545
|
+
return parts;
|
|
1546
|
+
}
|
|
1547
|
+
function plain(text) {
|
|
1548
|
+
return text;
|
|
1549
|
+
}
|
|
1550
|
+
function tintedParts(parts, colors) {
|
|
1551
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1552
|
+
}
|
|
1553
|
+
function cutToWidth(line, width) {
|
|
1554
|
+
if (Bun.stringWidth(line) <= width)
|
|
1555
|
+
return line;
|
|
1556
|
+
let room = width;
|
|
1557
|
+
let kept = "";
|
|
1558
|
+
let index = 0;
|
|
1559
|
+
let linked = false;
|
|
1560
|
+
while (index < line.length) {
|
|
1561
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1562
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1563
|
+
if (escape !== null) {
|
|
1564
|
+
kept += escape[0];
|
|
1565
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1566
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1570
|
+
const columns = Bun.stringWidth(char);
|
|
1571
|
+
if (columns > room)
|
|
1572
|
+
break;
|
|
1573
|
+
kept += char;
|
|
1574
|
+
room -= columns;
|
|
1575
|
+
index += char.length;
|
|
1576
|
+
}
|
|
1577
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1578
|
+
}
|
|
1579
|
+
function swallowInput() {
|
|
1580
|
+
const input = process12.stdin;
|
|
1581
|
+
if (!input.isTTY)
|
|
1582
|
+
return () => {
|
|
1583
|
+
return;
|
|
1584
|
+
};
|
|
1585
|
+
const onData = (data) => {
|
|
1586
|
+
if (data.includes(CTRL_C))
|
|
1587
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1588
|
+
};
|
|
1589
|
+
input.setRawMode(true);
|
|
1590
|
+
input.on("data", onData);
|
|
1591
|
+
input.resume();
|
|
1592
|
+
let released = false;
|
|
1593
|
+
return () => {
|
|
1594
|
+
if (released)
|
|
1595
|
+
return;
|
|
1596
|
+
released = true;
|
|
1597
|
+
input.off("data", onData);
|
|
1598
|
+
input.pause();
|
|
1599
|
+
input.setRawMode(false);
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function interceptOutput(clear) {
|
|
1603
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1604
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1605
|
+
const original = Reflect.get(target, name);
|
|
1606
|
+
const wrapper = (...args) => {
|
|
1607
|
+
clear();
|
|
1608
|
+
return original.apply(target, args);
|
|
1609
|
+
};
|
|
1610
|
+
Reflect.set(target, name, wrapper);
|
|
1611
|
+
return { target, name, original, wrapper };
|
|
1612
|
+
});
|
|
1613
|
+
return () => {
|
|
1614
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1615
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1616
|
+
Reflect.set(target, name, original);
|
|
941
1617
|
}
|
|
942
1618
|
};
|
|
943
1619
|
}
|
|
944
1620
|
|
|
945
|
-
// ../kit/src/
|
|
946
|
-
|
|
947
|
-
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
948
|
-
var RESET_STYLE = `${ESC}[0m`;
|
|
949
|
-
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1621
|
+
// ../kit/src/ci.ts
|
|
1622
|
+
init_style();
|
|
950
1623
|
|
|
951
1624
|
// ../kit/src/tool.ts
|
|
952
|
-
|
|
1625
|
+
init_format2();
|
|
1626
|
+
import process13 from "process";
|
|
953
1627
|
function cwdGone() {
|
|
954
1628
|
try {
|
|
955
|
-
|
|
1629
|
+
process13.cwd();
|
|
956
1630
|
return false;
|
|
957
1631
|
} catch {
|
|
958
1632
|
return true;
|
|
@@ -971,10 +1645,10 @@ function spawnFailure(command, error) {
|
|
|
971
1645
|
const missing = !gone && error?.code === "ENOENT";
|
|
972
1646
|
return new SpawnError(`${command}: ${error instanceof Error ? error.message : String(error)}${gone ? " (the working directory was removed)" : ""}`, missing);
|
|
973
1647
|
}
|
|
974
|
-
async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
1648
|
+
async function runTool(label, argv, { timeoutMs, cwd, onStart, env } = {}) {
|
|
975
1649
|
let ran;
|
|
976
1650
|
try {
|
|
977
|
-
ran = await runCommand(argv, { env:
|
|
1651
|
+
ran = await runCommand(argv, { env: { ...process13.env, ...env }, ...timeoutMs === undefined ? {} : { timeoutMs }, ...cwd === undefined ? {} : { cwd }, ...onStart === undefined ? {} : { onStart } });
|
|
978
1652
|
} catch (error) {
|
|
979
1653
|
throw spawnFailure(label, error);
|
|
980
1654
|
}
|
|
@@ -989,9 +1663,49 @@ async function runTool(label, argv, { timeoutMs, cwd, onStart } = {}) {
|
|
|
989
1663
|
return { code: ran.code, ...streams };
|
|
990
1664
|
}
|
|
991
1665
|
// ../kit/src/cli.ts
|
|
992
|
-
|
|
1666
|
+
init_args();
|
|
1667
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
993
1668
|
import { dirname as dirname3, join as join5 } from "path";
|
|
994
|
-
import
|
|
1669
|
+
import process17 from "process";
|
|
1670
|
+
|
|
1671
|
+
// ../kit/src/askpass.ts
|
|
1672
|
+
import process14 from "process";
|
|
1673
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1674
|
+
async function askpassClient(argv) {
|
|
1675
|
+
const socketPath = process14.env[SOCKET_VARIABLE];
|
|
1676
|
+
if (socketPath === undefined)
|
|
1677
|
+
return;
|
|
1678
|
+
const request = { prompt: argv[0] ?? "", ...process14.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1679
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1680
|
+
let received = "";
|
|
1681
|
+
try {
|
|
1682
|
+
await Bun.connect({
|
|
1683
|
+
unix: socketPath,
|
|
1684
|
+
socket: {
|
|
1685
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1686
|
+
`),
|
|
1687
|
+
data: (_, chunk) => {
|
|
1688
|
+
received += chunk.toString();
|
|
1689
|
+
},
|
|
1690
|
+
close: () => resolve(received),
|
|
1691
|
+
error: () => resolve("")
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
} catch {
|
|
1695
|
+
return 1;
|
|
1696
|
+
}
|
|
1697
|
+
const reply = await promise;
|
|
1698
|
+
if (reply === "")
|
|
1699
|
+
return 1;
|
|
1700
|
+
const { answer } = JSON.parse(reply);
|
|
1701
|
+
if (request.notice === true)
|
|
1702
|
+
return 0;
|
|
1703
|
+
if (answer === undefined)
|
|
1704
|
+
return 1;
|
|
1705
|
+
process14.stdout.write(`${answer}
|
|
1706
|
+
`);
|
|
1707
|
+
return 0;
|
|
1708
|
+
}
|
|
995
1709
|
|
|
996
1710
|
// ../kit/src/completions.ts
|
|
997
1711
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1054,34 +1768,42 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1054
1768
|
}
|
|
1055
1769
|
|
|
1056
1770
|
// ../kit/src/notify.ts
|
|
1057
|
-
|
|
1771
|
+
init_format2();
|
|
1772
|
+
init_mode();
|
|
1773
|
+
import process15 from "process";
|
|
1058
1774
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1059
1775
|
var CANCELLED = 130;
|
|
1060
1776
|
function base64(text) {
|
|
1061
1777
|
return Buffer.from(text).toString("base64");
|
|
1062
1778
|
}
|
|
1063
|
-
function notification(title, body, env =
|
|
1064
|
-
const id = `kit${
|
|
1779
|
+
function notification(title, body, env = process15.env) {
|
|
1780
|
+
const id = `kit${process15.pid}`;
|
|
1065
1781
|
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
1782
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1067
1783
|
}
|
|
1068
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1784
|
+
function notifyEnd(command, code, ms, { stream = process15.stderr, env = process15.env } = {}) {
|
|
1069
1785
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1070
1786
|
return;
|
|
1071
1787
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1072
1788
|
}
|
|
1073
1789
|
|
|
1790
|
+
// ../kit/src/cli.ts
|
|
1791
|
+
init_style();
|
|
1792
|
+
init_text2();
|
|
1793
|
+
|
|
1074
1794
|
// ../kit/src/usage.ts
|
|
1075
1795
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1076
1796
|
import { homedir as homedir3 } from "os";
|
|
1077
|
-
import { dirname as dirname2,
|
|
1078
|
-
import
|
|
1797
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
1798
|
+
import process16 from "process";
|
|
1079
1799
|
|
|
1080
1800
|
// ../kit/src/logs.ts
|
|
1801
|
+
init_user_config();
|
|
1081
1802
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1082
1803
|
var CLI_FOLDER = "kaynooo-cli";
|
|
1083
1804
|
|
|
1084
1805
|
// ../kit/src/usage.ts
|
|
1806
|
+
init_user_config();
|
|
1085
1807
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1086
1808
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1087
1809
|
var LONGEST_NAME = 40;
|
|
@@ -1089,14 +1811,13 @@ var usageError;
|
|
|
1089
1811
|
function noteUsageError(message) {
|
|
1090
1812
|
usageError = message;
|
|
1091
1813
|
}
|
|
1092
|
-
function stateHome(env =
|
|
1093
|
-
|
|
1094
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1814
|
+
function stateHome(env = process16.env) {
|
|
1815
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
1095
1816
|
}
|
|
1096
|
-
function usagePath(env =
|
|
1817
|
+
function usagePath(env = process16.env) {
|
|
1097
1818
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1098
1819
|
}
|
|
1099
|
-
function usageRecorded(env =
|
|
1820
|
+
function usageRecorded(env = process16.env) {
|
|
1100
1821
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1101
1822
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1102
1823
|
}
|
|
@@ -1105,12 +1826,12 @@ function flagNames(argv) {
|
|
|
1105
1826
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1106
1827
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1107
1828
|
}
|
|
1108
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1829
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1109
1830
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1110
1831
|
usageError = undefined;
|
|
1111
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1832
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1112
1833
|
}
|
|
1113
|
-
function recordUsage(entry, env =
|
|
1834
|
+
function recordUsage(entry, env = process16.env) {
|
|
1114
1835
|
if (!usageRecorded(env))
|
|
1115
1836
|
return;
|
|
1116
1837
|
try {
|
|
@@ -1165,6 +1886,10 @@ function takeOutputFlags(argv) {
|
|
|
1165
1886
|
async function resolveSummary(summary) {
|
|
1166
1887
|
return typeof summary === "string" ? summary : summary();
|
|
1167
1888
|
}
|
|
1889
|
+
function lookup({ commands, aliases }, word) {
|
|
1890
|
+
const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
|
|
1891
|
+
return Object.hasOwn(commands, name) ? commands[name] : undefined;
|
|
1892
|
+
}
|
|
1168
1893
|
function scopeOf(commands, extra, aliases) {
|
|
1169
1894
|
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1170
1895
|
}
|
|
@@ -1204,8 +1929,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1204
1929
|
`);
|
|
1205
1930
|
}
|
|
1206
1931
|
function printError(prefix, message, hint, cause) {
|
|
1207
|
-
const colors = paint(
|
|
1208
|
-
const styled = takesControlCodes(
|
|
1932
|
+
const colors = paint(process17.stderr);
|
|
1933
|
+
const styled = takesControlCodes(process17.stderr);
|
|
1209
1934
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1210
1935
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1211
1936
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1248,23 +1973,23 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1248
1973
|
}
|
|
1249
1974
|
}
|
|
1250
1975
|
if (name === undefined && level.path.length > 1) {
|
|
1251
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1976
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stderr));
|
|
1252
1977
|
return 2;
|
|
1253
1978
|
}
|
|
1254
1979
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1255
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1980
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process17.stdout));
|
|
1256
1981
|
return 0;
|
|
1257
1982
|
}
|
|
1258
1983
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
1259
1984
|
console.log(version);
|
|
1260
1985
|
return 0;
|
|
1261
1986
|
}
|
|
1262
|
-
let command = level
|
|
1987
|
+
let command = lookup(level, name);
|
|
1263
1988
|
let rest = args;
|
|
1264
1989
|
let ran = name;
|
|
1265
1990
|
if (command === undefined && level.lazy.length > 0) {
|
|
1266
1991
|
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1267
|
-
command = level
|
|
1992
|
+
command = lookup(level, name);
|
|
1268
1993
|
}
|
|
1269
1994
|
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1270
1995
|
command = level.commands[level.defaultCommand];
|
|
@@ -1344,18 +2069,19 @@ async function leafCandidates(run, words) {
|
|
|
1344
2069
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1345
2070
|
const [word = "", ...rest] = words;
|
|
1346
2071
|
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1347
|
-
let { commands
|
|
1348
|
-
let command =
|
|
2072
|
+
let { commands } = scope;
|
|
2073
|
+
let command = lookup(scope, word);
|
|
1349
2074
|
if (listing || command === undefined) {
|
|
1350
|
-
|
|
1351
|
-
|
|
2075
|
+
const expanded = await expand(scope, [...before, ...words]);
|
|
2076
|
+
commands = expanded.commands;
|
|
2077
|
+
command = lookup(expanded, word);
|
|
1352
2078
|
}
|
|
1353
2079
|
if (listing) {
|
|
1354
2080
|
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1355
2081
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1356
2082
|
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
1357
2083
|
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
1358
|
-
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line)
|
|
2084
|
+
return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
|
|
1359
2085
|
}
|
|
1360
2086
|
if (command === undefined) {
|
|
1361
2087
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
@@ -1388,7 +2114,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1388
2114
|
} catch {}
|
|
1389
2115
|
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1390
2116
|
try {
|
|
1391
|
-
const { version } = JSON.parse(
|
|
2117
|
+
const { version } = JSON.parse(readFileSync5(join5(dir, "package.json"), "utf8"));
|
|
1392
2118
|
if (typeof version === "string")
|
|
1393
2119
|
return version;
|
|
1394
2120
|
} catch {}
|
|
@@ -1398,6 +2124,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1398
2124
|
}
|
|
1399
2125
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1400
2126
|
const version = cli.version ?? packageVersion();
|
|
2127
|
+
const answered = await askpassClient(argv);
|
|
2128
|
+
if (answered !== undefined)
|
|
2129
|
+
return answered;
|
|
1401
2130
|
if (argv[0] === COMPLETE)
|
|
1402
2131
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1403
2132
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1408,7 +2137,7 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1408
2137
|
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1409
2138
|
if (cli.usage !== false) {
|
|
1410
2139
|
try {
|
|
1411
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
2140
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1412
2141
|
} catch {}
|
|
1413
2142
|
}
|
|
1414
2143
|
return code;
|
|
@@ -1417,8 +2146,7 @@ function commandPath(scope, argv) {
|
|
|
1417
2146
|
const path = [];
|
|
1418
2147
|
let level = scope;
|
|
1419
2148
|
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1420
|
-
const
|
|
1421
|
-
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
2149
|
+
const command = lookup(level, word);
|
|
1422
2150
|
if (command === undefined)
|
|
1423
2151
|
break;
|
|
1424
2152
|
path.push(word);
|
|
@@ -1428,63 +2156,77 @@ function commandPath(scope, argv) {
|
|
|
1428
2156
|
}
|
|
1429
2157
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1430
2158
|
}
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1451
|
-
} catch {}
|
|
1452
|
-
}
|
|
1453
|
-
return code;
|
|
1454
|
-
}
|
|
1455
|
-
// ../kit/src/folders.ts
|
|
1456
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
2159
|
+
|
|
2160
|
+
// ../kit/src/index.ts
|
|
2161
|
+
init_config();
|
|
2162
|
+
|
|
2163
|
+
// ../kit/src/excerpt.ts
|
|
2164
|
+
init_text2();
|
|
2165
|
+
|
|
2166
|
+
// ../kit/src/index.ts
|
|
2167
|
+
init_folders();
|
|
2168
|
+
init_format2();
|
|
2169
|
+
|
|
2170
|
+
// ../kit/src/git.ts
|
|
2171
|
+
init_args();
|
|
2172
|
+
// ../kit/src/limit.ts
|
|
2173
|
+
init_args();
|
|
2174
|
+
|
|
2175
|
+
// ../kit/src/index.ts
|
|
2176
|
+
init_mode();
|
|
2177
|
+
|
|
1457
2178
|
// ../kit/src/pool.ts
|
|
1458
|
-
async function pool(items, limit, task) {
|
|
2179
|
+
async function pool(items, limit, task, onDone) {
|
|
1459
2180
|
const results = Array.from({ length: items.length });
|
|
1460
2181
|
let next = 0;
|
|
2182
|
+
let done = 0;
|
|
1461
2183
|
async function worker() {
|
|
1462
2184
|
while (next < items.length) {
|
|
1463
2185
|
const index = next++;
|
|
1464
2186
|
results[index] = await task(items[index]);
|
|
2187
|
+
onDone?.(++done, items.length);
|
|
1465
2188
|
}
|
|
1466
2189
|
}
|
|
1467
2190
|
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
1468
2191
|
return results;
|
|
1469
2192
|
}
|
|
2193
|
+
// ../kit/src/report.ts
|
|
2194
|
+
init_style();
|
|
2195
|
+
init_text2();
|
|
1470
2196
|
// ../kit/src/secrets.ts
|
|
1471
2197
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2198
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1472
2199
|
// ../kit/src/sessions.ts
|
|
1473
2200
|
var {Glob } = globalThis.Bun;
|
|
1474
2201
|
var SESSION_FILES = new Glob("*.json");
|
|
1475
2202
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1476
2203
|
// ../kit/src/size.ts
|
|
1477
|
-
var SIZE = /^(\d+(?:\.\d+)?)\s*([kmgt]
|
|
2204
|
+
var SIZE = /^(\d+(?:\.\d+)?)\s*(?:([kmgt])i?b?|(b))?$/i;
|
|
1478
2205
|
var POWERS = { "": 0, k: 1, m: 2, g: 3, t: 4 };
|
|
1479
2206
|
function parseSize(text, bareUnit = 1) {
|
|
1480
2207
|
const match = SIZE.exec(text.trim());
|
|
1481
2208
|
if (match === null)
|
|
1482
2209
|
return;
|
|
1483
|
-
const suffix = match[2]
|
|
1484
|
-
|
|
2210
|
+
const suffix = match[2]?.toLowerCase();
|
|
2211
|
+
let unit = bareUnit;
|
|
2212
|
+
if (match[3] !== undefined)
|
|
2213
|
+
unit = 1;
|
|
2214
|
+
else if (suffix !== undefined)
|
|
2215
|
+
unit = 1024 ** POWERS[suffix];
|
|
2216
|
+
return Math.round(Number(match[1]) * unit);
|
|
1485
2217
|
}
|
|
2218
|
+
|
|
2219
|
+
// ../kit/src/index.ts
|
|
2220
|
+
init_style();
|
|
2221
|
+
init_text2();
|
|
2222
|
+
init_theme();
|
|
2223
|
+
init_user_config();
|
|
2224
|
+
|
|
1486
2225
|
// ../kit/src/watch.ts
|
|
1487
|
-
|
|
2226
|
+
init_args();
|
|
2227
|
+
init_input();
|
|
2228
|
+
init_style();
|
|
2229
|
+
import process18 from "process";
|
|
1488
2230
|
import { format } from "util";
|
|
1489
2231
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1490
2232
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1506,7 +2248,7 @@ function withoutWatch(args) {
|
|
|
1506
2248
|
}
|
|
1507
2249
|
return rest;
|
|
1508
2250
|
}
|
|
1509
|
-
async function watching(value, step, stream =
|
|
2251
|
+
async function watching(value, step, stream = process18.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1510
2252
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1511
2253
|
if (!takesControlCodes(stream))
|
|
1512
2254
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1514,12 +2256,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1514
2256
|
for (let round = 0;round < rounds; round++) {
|
|
1515
2257
|
const held = [];
|
|
1516
2258
|
const { log, info } = console;
|
|
1517
|
-
const write =
|
|
2259
|
+
const write = process18.stdout.write.bind(process18.stdout);
|
|
1518
2260
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1519
2261
|
`);
|
|
1520
2262
|
console.log = hold;
|
|
1521
2263
|
console.info = hold;
|
|
1522
|
-
|
|
2264
|
+
process18.stdout.write = (text) => {
|
|
1523
2265
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1524
2266
|
return true;
|
|
1525
2267
|
};
|
|
@@ -1528,7 +2270,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1528
2270
|
} finally {
|
|
1529
2271
|
console.log = log;
|
|
1530
2272
|
console.info = info;
|
|
1531
|
-
|
|
2273
|
+
process18.stdout.write = write;
|
|
1532
2274
|
}
|
|
1533
2275
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1534
2276
|
await sleep(interval);
|
|
@@ -1536,9 +2278,10 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1536
2278
|
return code;
|
|
1537
2279
|
}
|
|
1538
2280
|
// ../kit/src/workspace-root.ts
|
|
2281
|
+
init_user_config();
|
|
1539
2282
|
import { homedir as homedir4 } from "os";
|
|
1540
2283
|
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1541
|
-
import
|
|
2284
|
+
import process19 from "process";
|
|
1542
2285
|
function expandHome(path, home) {
|
|
1543
2286
|
if (path === "~")
|
|
1544
2287
|
return home;
|
|
@@ -1548,22 +2291,22 @@ function configured(env, home) {
|
|
|
1548
2291
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1549
2292
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1550
2293
|
}
|
|
1551
|
-
function workspaceRoot({ given, env =
|
|
2294
|
+
function workspaceRoot({ given, env = process19.env, home = homedir4() } = {}) {
|
|
1552
2295
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1553
2296
|
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1554
2297
|
}
|
|
1555
2298
|
// src/audit.ts
|
|
1556
|
-
import { existsSync as existsSync6, readdirSync, readFileSync as
|
|
2299
|
+
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync8, statSync as statSync2 } from "fs";
|
|
1557
2300
|
import { readdir } from "fs/promises";
|
|
1558
2301
|
import { join as join9, relative, resolve as resolve5 } from "path";
|
|
1559
|
-
import
|
|
2302
|
+
import process21 from "process";
|
|
1560
2303
|
|
|
1561
2304
|
// src/osv.ts
|
|
1562
|
-
import { existsSync as existsSync5, readFileSync as
|
|
2305
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
|
|
1563
2306
|
import { join as join8 } from "path";
|
|
1564
2307
|
|
|
1565
2308
|
// src/report.ts
|
|
1566
|
-
import { existsSync as existsSync4, readFileSync as
|
|
2309
|
+
import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
|
|
1567
2310
|
import { join as join7 } from "path";
|
|
1568
2311
|
var UPPER_BOUND = /<\s*(\d[\w.+-]*)/;
|
|
1569
2312
|
var DEPENDENCY_KINDS = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"];
|
|
@@ -1647,7 +2390,7 @@ function reachedFrom(graph, direct, targets) {
|
|
|
1647
2390
|
}
|
|
1648
2391
|
function readManifest(path) {
|
|
1649
2392
|
try {
|
|
1650
|
-
return existsSync4(path) ? JSON.parse(
|
|
2393
|
+
return existsSync4(path) ? JSON.parse(readFileSync6(path, "utf8")) : {};
|
|
1651
2394
|
} catch {
|
|
1652
2395
|
return {};
|
|
1653
2396
|
}
|
|
@@ -1768,7 +2511,7 @@ async function osvFindings(locked, ecosystem, direct, level, ignore, fetcher = f
|
|
|
1768
2511
|
}
|
|
1769
2512
|
function manifestNames(dir) {
|
|
1770
2513
|
try {
|
|
1771
|
-
const manifest = JSON.parse(
|
|
2514
|
+
const manifest = JSON.parse(readFileSync7(join8(dir, "composer.json"), "utf8"));
|
|
1772
2515
|
return new Set([...Object.keys(manifest.require ?? {}), ...Object.keys(manifest["require-dev"] ?? {})]);
|
|
1773
2516
|
} catch {
|
|
1774
2517
|
return new Set;
|
|
@@ -1777,7 +2520,7 @@ function manifestNames(dir) {
|
|
|
1777
2520
|
async function osvAudit(dir, level, ignore, fetcher = fetch) {
|
|
1778
2521
|
const all = { findings: [], below: 0 };
|
|
1779
2522
|
for (const each of ECOSYSTEMS.filter((each) => existsSync5(join8(dir, each.lockfile)))) {
|
|
1780
|
-
const done = await osvFindings(each.parse(
|
|
2523
|
+
const done = await osvFindings(each.parse(readFileSync7(join8(dir, each.lockfile), "utf8")), each.osv, each.lockfile === "composer.lock" ? manifestNames(dir) : new Set, level, ignore, fetcher);
|
|
1781
2524
|
all.findings.push(...done.findings);
|
|
1782
2525
|
all.below += done.below;
|
|
1783
2526
|
}
|
|
@@ -1785,12 +2528,11 @@ async function osvAudit(dir, level, ignore, fetcher = fetch) {
|
|
|
1785
2528
|
}
|
|
1786
2529
|
|
|
1787
2530
|
// src/audit.ts
|
|
1788
|
-
var USAGE = `audit [options] [root]: the known vulnerabilities of the Bun, Composer, Cargo and uv repositories under root (the current folder by default), one table per repository
|
|
2531
|
+
var USAGE = `ws audit [options] [root]: the known vulnerabilities of the Bun, Composer, Cargo and uv repositories under root (the current folder by default), one table per repository
|
|
1789
2532
|
|
|
1790
|
-
Each package with an advisory is one row: its worst severity,
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
Reach for it to sweep many repositories at once; \`pkg audit\` vets the one repository in a folder (package age, install scripts, licences) as well as its advisories, and shares --level, --prod and --ignore.`;
|
|
2533
|
+
Each package with an advisory is one row: its worst severity, advisory count, prod or dev, direct or via the direct dependencies leading to it, and the version that fixes every advisory at once.
|
|
2534
|
+
It reaches the network: \`bun audit --json\` for a bun.lock, osv.dev for a composer.lock, Cargo.lock or uv.lock; the walk goes three levels deep and stops at a lockfile.
|
|
2535
|
+
To sweep many repositories at once; \`pkg audit\` vets the one repository in depth.`;
|
|
1794
2536
|
var EXITS = [[0, "no repository has an advisory at the level asked"], [1, "one has"], [2, "a repository's audit failed, no lockfile sits under root, a usage error or a root that is no folder"]];
|
|
1795
2537
|
var OPTIONS = {
|
|
1796
2538
|
level: { type: "string", choices: SEVERITIES, default: "moderate", description: "only the advisories at least this severe: low, moderate, high or critical" },
|
|
@@ -1861,8 +2603,8 @@ async function bunAudited(path, shown, level, ignore) {
|
|
|
1861
2603
|
runCommand(["bun", "audit", "--json"], { cwd: path, timeoutMs: AUDIT_MS }),
|
|
1862
2604
|
runCommand(["bun", "audit", "--json", "--prod"], { cwd: path, timeoutMs: AUDIT_MS })
|
|
1863
2605
|
]);
|
|
1864
|
-
const audit = parseAudit(
|
|
1865
|
-
const reached = parseAudit(
|
|
2606
|
+
const audit = parseAudit(all.stdout);
|
|
2607
|
+
const reached = parseAudit(production.stdout);
|
|
1866
2608
|
if (audit === undefined || reached === undefined)
|
|
1867
2609
|
return { repo: shown, path, findings: [], below: 0, warnings: [], error: failure(audit === undefined ? all : production) };
|
|
1868
2610
|
const reaching = new Set(Object.keys(reached));
|
|
@@ -1873,7 +2615,7 @@ async function bunAudited(path, shown, level, ignore) {
|
|
|
1873
2615
|
}
|
|
1874
2616
|
function lockText(path) {
|
|
1875
2617
|
try {
|
|
1876
|
-
return
|
|
2618
|
+
return readFileSync8(join9(path, "bun.lock"), "utf8");
|
|
1877
2619
|
} catch {
|
|
1878
2620
|
return "";
|
|
1879
2621
|
}
|
|
@@ -1885,15 +2627,12 @@ function originOf(found) {
|
|
|
1885
2627
|
return "via";
|
|
1886
2628
|
return `via ${found.via.slice(0, VIA_SHOWN).join(", ")}${found.via.length > VIA_SHOWN ? ` +${found.via.length - VIA_SHOWN}` : ""}`;
|
|
1887
2629
|
}
|
|
1888
|
-
function stdoutOf(ran) {
|
|
1889
|
-
return Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
1890
|
-
}
|
|
1891
2630
|
function failure(ran) {
|
|
1892
2631
|
return ran.timedOut ? `timed out after ${AUDIT_MS / 1000}s` : ran.text.trim().split(`
|
|
1893
2632
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1894
2633
|
}
|
|
1895
2634
|
function tint(severity) {
|
|
1896
|
-
const colors = paint(
|
|
2635
|
+
const colors = paint(process21.stdout);
|
|
1897
2636
|
if (severity === "critical" || severity === "high")
|
|
1898
2637
|
return colors.red;
|
|
1899
2638
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1909,15 +2648,23 @@ function rows(findings) {
|
|
|
1909
2648
|
]);
|
|
1910
2649
|
}
|
|
1911
2650
|
async function audit(args) {
|
|
1912
|
-
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["audit", "audit ~/Workspace --level high --prod"] });
|
|
2651
|
+
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a bun audit run in each repository and a read of every advisory to find what is worth fixing", examples: ["ws audit", "ws audit ~/Workspace --level high --prod"] });
|
|
1913
2652
|
const root = resolve5(positionals[0] ?? ".");
|
|
1914
2653
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1915
2654
|
fail(`no folder ${root}`);
|
|
1916
2655
|
const level = oneOf(values.level, "level", SEVERITIES);
|
|
1917
|
-
const
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2656
|
+
const progress = progressLine();
|
|
2657
|
+
let audits;
|
|
2658
|
+
try {
|
|
2659
|
+
progress.update({ step: "finding the repositories" });
|
|
2660
|
+
const paths = await findRepos(root);
|
|
2661
|
+
if (paths.length === 0)
|
|
2662
|
+
fail(`no bun.lock, composer.lock, Cargo.lock or uv.lock under ${root}`);
|
|
2663
|
+
progress.update({ step: "auditing", done: 0, total: paths.length, unit: "repositories" });
|
|
2664
|
+
audits = await pool(paths, configuredNumber("audit", "concurrency", CONCURRENCY), async (path) => audited(path, relative(root, path) || ".", level, values.ignore ?? []), (done, total) => progress.update({ step: "auditing", done, total, unit: "repositories" }));
|
|
2665
|
+
} finally {
|
|
2666
|
+
progress.stop();
|
|
2667
|
+
}
|
|
1921
2668
|
const kept = audits.map((each) => ({ ...each, findings: values.prod === true ? each.findings.filter((found) => found.scope === "prod") : each.findings }));
|
|
1922
2669
|
if (values.json === true)
|
|
1923
2670
|
printJson(kept);
|
|
@@ -1928,8 +2675,8 @@ async function audit(args) {
|
|
|
1928
2675
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1929
2676
|
}
|
|
1930
2677
|
function show(audits, total) {
|
|
1931
|
-
const label = role("label",
|
|
1932
|
-
const path = role("path",
|
|
2678
|
+
const label = role("label", process21.stdout);
|
|
2679
|
+
const path = role("path", process21.stdout);
|
|
1933
2680
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1934
2681
|
if (flagged.length === 0) {
|
|
1935
2682
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1951,13 +2698,13 @@ function show(audits, total) {
|
|
|
1951
2698
|
// src/repos.ts
|
|
1952
2699
|
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1953
2700
|
import { basename as basename2, relative as relative2 } from "path";
|
|
1954
|
-
import
|
|
2701
|
+
import process23 from "process";
|
|
1955
2702
|
|
|
1956
2703
|
// src/repos-scan.ts
|
|
1957
2704
|
import { existsSync as existsSync7 } from "fs";
|
|
1958
2705
|
import { readdir as readdir2 } from "fs/promises";
|
|
1959
2706
|
import { basename, join as join10 } from "path";
|
|
1960
|
-
import
|
|
2707
|
+
import process22 from "process";
|
|
1961
2708
|
var MAX_DEPTH2 = 3;
|
|
1962
2709
|
var CONCURRENCY2 = 8;
|
|
1963
2710
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -2004,8 +2751,8 @@ async function findRepos2(root, skip) {
|
|
|
2004
2751
|
}
|
|
2005
2752
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
2006
2753
|
try {
|
|
2007
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
2008
|
-
return ran.code === 0 && !ran.timedOut ? ran.
|
|
2754
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process22.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
2755
|
+
return ran.code === 0 && !ran.timedOut ? ran.stdout.trim() : undefined;
|
|
2009
2756
|
} catch {
|
|
2010
2757
|
return;
|
|
2011
2758
|
}
|
|
@@ -2081,7 +2828,7 @@ function firstLine(text) {
|
|
|
2081
2828
|
}
|
|
2082
2829
|
async function fastForward(path) {
|
|
2083
2830
|
try {
|
|
2084
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
2831
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process22.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
2085
2832
|
if (ran.timedOut)
|
|
2086
2833
|
return "timed out";
|
|
2087
2834
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -2091,17 +2838,14 @@ async function fastForward(path) {
|
|
|
2091
2838
|
}
|
|
2092
2839
|
|
|
2093
2840
|
// src/repos.ts
|
|
2094
|
-
var USAGE2 = `repos [options] [root]: the git repositories under root (the configured workspace
|
|
2841
|
+
var USAGE2 = `ws repos [options] [root]: the git repositories under root (the configured workspace by default) that need attention: dirty files, commits not pushed, an upstream ahead, commits since the latest tag
|
|
2095
2842
|
|
|
2096
|
-
A repository with
|
|
2097
|
-
|
|
2098
|
-
Ahead and behind are those of the last fetch unless --fetch refreshes the upstreams first, which reaches the remote.
|
|
2099
|
-
--pull fetches, then fast-forwards the repositories listed that are clean, on a branch and only behind their upstream, and touches nothing else: a dirty, ahead, diverged or detached one is reported as skipped. A repository pulled is listed again as it now stands.
|
|
2100
|
-
--path prints only the paths of the repositories listed, one per line, for xargs -d '\\n'.`;
|
|
2843
|
+
A clean repository, or one with only unreleased commits, is left out unless --all or --only unreleased. The walk goes ${MAX_DEPTH2} levels deep and skips the names in "skip" of \`~/.config/kaynooo-cli/repos.json\`; ahead and behind are those of the last fetch unless --fetch reaches the remote.
|
|
2844
|
+
--pull fetches, then fast-forwards only the repositories listed that are clean, on a branch and only behind their upstream; the others are reported as skipped.`;
|
|
2101
2845
|
var EXITS2 = [[0, "it listed the repositories, including when none needs attention"], [1, "a fast-forward --pull attempted failed"], [2, "a usage error, an unreadable config or a root that is no folder"]];
|
|
2102
2846
|
var OPTIONS2 = {
|
|
2103
2847
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
2104
|
-
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
2848
|
+
only: { type: "string", multiple: true, choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind, repeatable" },
|
|
2105
2849
|
watch: watchOption("the repositories"),
|
|
2106
2850
|
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
2107
2851
|
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
@@ -2124,7 +2868,7 @@ function releasedCell(repo) {
|
|
|
2124
2868
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
2125
2869
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
2126
2870
|
}
|
|
2127
|
-
function syncCell(repo, stream =
|
|
2871
|
+
function syncCell(repo, stream = process23.stdout) {
|
|
2128
2872
|
const colors = paint(stream);
|
|
2129
2873
|
const ahead = repo.ahead ?? 0;
|
|
2130
2874
|
const behind = repo.behind ?? 0;
|
|
@@ -2135,7 +2879,7 @@ function syncCell(repo, stream = process21.stdout) {
|
|
|
2135
2879
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
2136
2880
|
}
|
|
2137
2881
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
2138
|
-
function branchCell(repo, stream =
|
|
2882
|
+
function branchCell(repo, stream = process23.stdout) {
|
|
2139
2883
|
const colors = paint(stream);
|
|
2140
2884
|
if (repo.unreadable)
|
|
2141
2885
|
return colors.red("? (unreadable)");
|
|
@@ -2144,8 +2888,8 @@ function branchCell(repo, stream = process21.stdout) {
|
|
|
2144
2888
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
2145
2889
|
}
|
|
2146
2890
|
function row(repo, shown) {
|
|
2147
|
-
const colors = paint(
|
|
2148
|
-
const tint = role("path",
|
|
2891
|
+
const colors = paint(process23.stdout);
|
|
2892
|
+
const tint = role("path", process23.stdout);
|
|
2149
2893
|
const unreleased = releasedCell(repo);
|
|
2150
2894
|
return [
|
|
2151
2895
|
tint(shown),
|
|
@@ -2156,19 +2900,31 @@ function row(repo, shown) {
|
|
|
2156
2900
|
unreleased === "-" ? colors.dim("-") : colors.cyan(unreleased)
|
|
2157
2901
|
];
|
|
2158
2902
|
}
|
|
2159
|
-
async function repos(args) {
|
|
2160
|
-
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
2903
|
+
async function repos(args, watched = false) {
|
|
2904
|
+
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["ws repos", "ws repos ~/Workspace --only unreleased --fetch", ["ws repos --only behind --pull", "fast-forward what is behind and clean"], ["ws repos --only dirty --path", "the paths, for xargs"]] });
|
|
2161
2905
|
if (values.watch !== undefined)
|
|
2162
|
-
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
2906
|
+
return watching(values.watch, async () => repos(withoutWatch(args), true));
|
|
2163
2907
|
const root = workspaceRoot({ given: positionals[0] });
|
|
2164
2908
|
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
2165
2909
|
fail(`no folder ${root}`);
|
|
2166
|
-
const only = values.only;
|
|
2167
|
-
const
|
|
2168
|
-
const
|
|
2910
|
+
const only = values.only ?? [];
|
|
2911
|
+
const progress = watched ? undefined : progressLine();
|
|
2912
|
+
const fetching = values.fetch === true || values.pull === true;
|
|
2913
|
+
const step = fetching ? "fetching" : "reading";
|
|
2914
|
+
let states;
|
|
2915
|
+
try {
|
|
2916
|
+
progress?.update({ step: "finding the repositories" });
|
|
2917
|
+
const paths = await findRepos2(root, await skipped());
|
|
2918
|
+
progress?.update({ step, done: 0, total: paths.length, unit: "repositories" });
|
|
2919
|
+
states = await pool(paths, configuredNumber("repos", "concurrency", CONCURRENCY2), async (path) => inspect(path, fetching), (done, total) => progress?.update({ step, done, total, unit: "repositories" }));
|
|
2920
|
+
} finally {
|
|
2921
|
+
progress?.stop();
|
|
2922
|
+
}
|
|
2169
2923
|
const keeps = (repo) => {
|
|
2170
2924
|
const reasons = reasonsOf(repo);
|
|
2171
|
-
|
|
2925
|
+
if (only.length > 0)
|
|
2926
|
+
return reasons.some((reason) => only.includes(reason));
|
|
2927
|
+
return values.all === true || reasons.some((reason) => reason !== "unreleased") || repo.unreadable;
|
|
2172
2928
|
};
|
|
2173
2929
|
let failedPulls = 0;
|
|
2174
2930
|
if (values.pull === true) {
|
|
@@ -2179,12 +2935,12 @@ async function repos(args) {
|
|
|
2179
2935
|
const blocker = pullBlocker(repo);
|
|
2180
2936
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
2181
2937
|
if (blocker !== undefined) {
|
|
2182
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2938
|
+
log(marked("note", `${repo.name} skipped`, process23.stdout, blocker));
|
|
2183
2939
|
} else if (refused !== undefined) {
|
|
2184
2940
|
failedPulls++;
|
|
2185
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2941
|
+
log(marked("problem", `${repo.name} not pulled`, process23.stdout, refused));
|
|
2186
2942
|
} else {
|
|
2187
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2943
|
+
log(marked("ok", `${repo.name} pulled`, process23.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
2188
2944
|
states[index] = await inspect(repo.path, false);
|
|
2189
2945
|
}
|
|
2190
2946
|
}
|
|
@@ -2199,7 +2955,7 @@ async function repos(args) {
|
|
|
2199
2955
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
2200
2956
|
return failedPulls > 0 ? 1 : 0;
|
|
2201
2957
|
}
|
|
2202
|
-
const label = role("label",
|
|
2958
|
+
const label = role("label", process23.stdout);
|
|
2203
2959
|
printHeader("repos", `${basename2(root)} \xB7 ${states.length} ${states.length === 1 ? "repository" : "repositories"}`);
|
|
2204
2960
|
if (kept.length === 0) {
|
|
2205
2961
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
@@ -2218,212 +2974,7 @@ async function repos(args) {
|
|
|
2218
2974
|
import { existsSync as existsSync11, statSync as statSync4 } from "fs";
|
|
2219
2975
|
import { homedir as homedir6 } from "os";
|
|
2220
2976
|
import { relative as relative3 } from "path";
|
|
2221
|
-
|
|
2222
|
-
// ../kit/src/prompt.ts
|
|
2223
|
-
import process23 from "process";
|
|
2224
|
-
|
|
2225
|
-
// ../kit/src/job.ts
|
|
2226
|
-
import process22 from "process";
|
|
2227
|
-
function stopJob() {
|
|
2228
|
-
process22.kill(0, "SIGTSTP");
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
// ../kit/src/picker/line.ts
|
|
2232
|
-
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2233
|
-
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2234
|
-
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2235
|
-
function isEditKey(key) {
|
|
2236
|
-
return EDIT_KEYS.has(key);
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2239
|
-
// ../kit/src/picker/score.ts
|
|
2240
|
-
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2241
|
-
var NONE = Number.NEGATIVE_INFINITY;
|
|
2242
|
-
|
|
2243
|
-
// ../kit/src/picker/state.ts
|
|
2244
|
-
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2245
|
-
var PASTE_START = "\x1B[200~";
|
|
2246
|
-
var PASTE_END = "\x1B[201~";
|
|
2247
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2248
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
2249
|
-
var WHEEL_LINES = 3;
|
|
2250
|
-
var KEYS = {
|
|
2251
|
-
"\x1B[A": "up",
|
|
2252
|
-
"\x1BOA": "up",
|
|
2253
|
-
"\x10": "up",
|
|
2254
|
-
"\x1B[B": "down",
|
|
2255
|
-
"\x1BOB": "down",
|
|
2256
|
-
"\x0E": "down",
|
|
2257
|
-
"\x1B[5~": "pageup",
|
|
2258
|
-
"\x1B[6~": "pagedown",
|
|
2259
|
-
"\x1B[H": "home",
|
|
2260
|
-
"\x1B[1~": "home",
|
|
2261
|
-
"\x1BOH": "home",
|
|
2262
|
-
"\x1B[F": "end",
|
|
2263
|
-
"\x1B[4~": "end",
|
|
2264
|
-
"\x1BOF": "end",
|
|
2265
|
-
"\r": "enter",
|
|
2266
|
-
"\n": "enter",
|
|
2267
|
-
"\x03": "cancel",
|
|
2268
|
-
"\x1B": "cancel",
|
|
2269
|
-
"\x1B[D": "left",
|
|
2270
|
-
"\x1BOD": "left",
|
|
2271
|
-
"\x1B[C": "right",
|
|
2272
|
-
"\x1BOC": "right",
|
|
2273
|
-
"\x1B[1;5D": "wordleft",
|
|
2274
|
-
"\x1B[1;3D": "wordleft",
|
|
2275
|
-
"\x1Bb": "wordleft",
|
|
2276
|
-
"\x1B[1;5C": "wordright",
|
|
2277
|
-
"\x1B[1;3C": "wordright",
|
|
2278
|
-
"\x1Bf": "wordright",
|
|
2279
|
-
"\x01": "linestart",
|
|
2280
|
-
"\x05": "lineend",
|
|
2281
|
-
"\x7F": "erase",
|
|
2282
|
-
"\x1B[3~": "delete",
|
|
2283
|
-
"\b": "killword",
|
|
2284
|
-
"\x1B\x7F": "killword",
|
|
2285
|
-
"\x1B[3;5~": "killnext",
|
|
2286
|
-
"\x1Bd": "killnext",
|
|
2287
|
-
"\x15": "clear",
|
|
2288
|
-
"\v": "killend",
|
|
2289
|
-
"\x17": "word",
|
|
2290
|
-
"\x19": "yank",
|
|
2291
|
-
"\x1A": "suspend",
|
|
2292
|
-
"\t": "tab",
|
|
2293
|
-
"\x1F": "help",
|
|
2294
|
-
"\x1BOP": "help",
|
|
2295
|
-
"\x1B[11~": "help"
|
|
2296
|
-
};
|
|
2297
|
-
function repeat(value, count) {
|
|
2298
|
-
return Array.from({ length: count }).fill(value);
|
|
2299
|
-
}
|
|
2300
|
-
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2301
|
-
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2302
|
-
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2303
|
-
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2304
|
-
if (wheel !== undefined)
|
|
2305
|
-
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
2306
|
-
const named = codes.get(sequence);
|
|
2307
|
-
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2308
|
-
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2309
|
-
paste.active = sequence === PASTE_START;
|
|
2310
|
-
return [];
|
|
2311
|
-
}
|
|
2312
|
-
if (paste.active && (sequence === "\r" || sequence === `
|
|
2313
|
-
`))
|
|
2314
|
-
return [];
|
|
2315
|
-
if (key !== undefined)
|
|
2316
|
-
return [key];
|
|
2317
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
// ../kit/src/redraw.ts
|
|
2322
|
-
var SYNC_START = "\x1B[?2026h";
|
|
2323
|
-
var SYNC_END = "\x1B[?2026l";
|
|
2324
|
-
function overwrite(lines, columns) {
|
|
2325
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2326
|
-
`);
|
|
2327
|
-
}
|
|
2328
|
-
function rowsTaken(lines, columns) {
|
|
2329
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
// ../kit/src/prompt.ts
|
|
2333
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2334
|
-
function readKeys(input, paste = { active: false }) {
|
|
2335
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2336
|
-
}
|
|
2337
|
-
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2338
|
-
let answered = fallback;
|
|
2339
|
-
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
2340
|
-
const accepted = await ask(question, settings, (colors, state) => [state === "asking" ? asking(colors, question, "", choices) : answer(colors, question, state, answered ? "yes" : "no")], (key) => {
|
|
2341
|
-
if (key === "cancel")
|
|
2342
|
-
return "cancel";
|
|
2343
|
-
if (key === "enter")
|
|
2344
|
-
return answered === undefined ? undefined : "enter";
|
|
2345
|
-
const letter = typeof key === "object" ? key.text.toLowerCase() : "";
|
|
2346
|
-
if (letter !== "y" && letter !== "n")
|
|
2347
|
-
return;
|
|
2348
|
-
answered = letter === "y";
|
|
2349
|
-
return "enter";
|
|
2350
|
-
});
|
|
2351
|
-
return accepted ? answered : undefined;
|
|
2352
|
-
}
|
|
2353
|
-
function asking(colors, question, typed, keys) {
|
|
2354
|
-
return `${colors.cyan("?")} ${question} ${typed === "" ? colors.dim(`(${keys})`) : typed}`;
|
|
2355
|
-
}
|
|
2356
|
-
function answer(colors, question, state, picked) {
|
|
2357
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2358
|
-
}
|
|
2359
|
-
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2360
|
-
const { stdin, stderr } = terminal;
|
|
2361
|
-
if (!isInteractive(terminal))
|
|
2362
|
-
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2363
|
-
const colors = paint(stderr);
|
|
2364
|
-
let current = "asking";
|
|
2365
|
-
let outcome;
|
|
2366
|
-
const columns = () => stderr.columns || 80;
|
|
2367
|
-
const draw = (state, last = false) => {
|
|
2368
|
-
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2369
|
-
const rows = rowsTaken(frame, columns());
|
|
2370
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2371
|
-
current = state;
|
|
2372
|
-
};
|
|
2373
|
-
const redraw = () => draw(current);
|
|
2374
|
-
const paste = { active: false };
|
|
2375
|
-
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2376
|
-
const suspend = () => {
|
|
2377
|
-
if (stop === undefined)
|
|
2378
|
-
return;
|
|
2379
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2380
|
-
stdin.setRawMode(false);
|
|
2381
|
-
stop();
|
|
2382
|
-
stdin.setRawMode(true);
|
|
2383
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2384
|
-
};
|
|
2385
|
-
try {
|
|
2386
|
-
stderr.on?.("resize", redraw);
|
|
2387
|
-
stdin.setRawMode(true);
|
|
2388
|
-
stdin.resume();
|
|
2389
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2390
|
-
draw("asking");
|
|
2391
|
-
return await new Promise((resolve) => {
|
|
2392
|
-
function onData(data) {
|
|
2393
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
2394
|
-
if (key === "suspend") {
|
|
2395
|
-
suspend();
|
|
2396
|
-
continue;
|
|
2397
|
-
}
|
|
2398
|
-
const pressed = press(key);
|
|
2399
|
-
if (pressed !== undefined) {
|
|
2400
|
-
settle(pressed);
|
|
2401
|
-
return;
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
draw("asking");
|
|
2405
|
-
}
|
|
2406
|
-
function onEnd() {
|
|
2407
|
-
settle("cancel");
|
|
2408
|
-
}
|
|
2409
|
-
function settle(settled) {
|
|
2410
|
-
outcome = settled;
|
|
2411
|
-
stdin.off("data", onData);
|
|
2412
|
-
stdin.off("end", onEnd);
|
|
2413
|
-
resolve(settled === "enter");
|
|
2414
|
-
}
|
|
2415
|
-
stdin.on("data", onData);
|
|
2416
|
-
stdin.on("end", onEnd);
|
|
2417
|
-
});
|
|
2418
|
-
} finally {
|
|
2419
|
-
stderr.off?.("resize", redraw);
|
|
2420
|
-
draw(outcome ?? "cancel", true);
|
|
2421
|
-
stderr.write(`
|
|
2422
|
-
\x1B[?25h\x1B[?2004l`);
|
|
2423
|
-
stdin.setRawMode(false);
|
|
2424
|
-
stdin.pause();
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2977
|
+
init_prompt();
|
|
2427
2978
|
|
|
2428
2979
|
// src/apply.ts
|
|
2429
2980
|
import { existsSync as existsSync10 } from "fs";
|
|
@@ -2441,7 +2992,8 @@ import { lstat, readdir as readdir3 } from "fs/promises";
|
|
|
2441
2992
|
import { join as join11 } from "path";
|
|
2442
2993
|
var FS_LIMIT = 32;
|
|
2443
2994
|
var FIND_MS = 60000;
|
|
2444
|
-
var FIND_LINE = /^(\d+) (\S+) (\d+)$/gm;
|
|
2995
|
+
var FIND_LINE = /^(\w) (\d+) (\S+) (\d+) (\d+)$/gm;
|
|
2996
|
+
var OWN_UID = process.getuid?.() ?? -1;
|
|
2445
2997
|
var waiting = [];
|
|
2446
2998
|
var running = 0;
|
|
2447
2999
|
async function gated(call) {
|
|
@@ -2455,9 +3007,10 @@ async function gated(call) {
|
|
|
2455
3007
|
waiting.shift()?.();
|
|
2456
3008
|
}
|
|
2457
3009
|
}
|
|
2458
|
-
async function
|
|
3010
|
+
async function walk(folder, uid) {
|
|
2459
3011
|
const seen = new Set;
|
|
2460
3012
|
let total = 0;
|
|
3013
|
+
let foreign = 0;
|
|
2461
3014
|
const visit = async (dir) => {
|
|
2462
3015
|
let entries;
|
|
2463
3016
|
try {
|
|
@@ -2467,10 +3020,12 @@ async function walkSize(folder) {
|
|
|
2467
3020
|
}
|
|
2468
3021
|
await Promise.all(entries.map(async (entry) => {
|
|
2469
3022
|
const path = join11(dir, entry.name);
|
|
2470
|
-
if (entry.isDirectory())
|
|
2471
|
-
return visit(path);
|
|
2472
3023
|
try {
|
|
2473
3024
|
const stat = await gated(async () => lstat(path));
|
|
3025
|
+
if (stat.uid !== uid)
|
|
3026
|
+
foreign++;
|
|
3027
|
+
if (entry.isDirectory())
|
|
3028
|
+
return await visit(path);
|
|
2474
3029
|
if (stat.nlink > 1) {
|
|
2475
3030
|
const key = `${stat.dev}:${stat.ino}`;
|
|
2476
3031
|
if (seen.has(key))
|
|
@@ -2481,18 +3036,27 @@ async function walkSize(folder) {
|
|
|
2481
3036
|
} catch {}
|
|
2482
3037
|
}));
|
|
2483
3038
|
};
|
|
3039
|
+
try {
|
|
3040
|
+
if ((await lstat(folder)).uid !== uid)
|
|
3041
|
+
foreign++;
|
|
3042
|
+
} catch {}
|
|
2484
3043
|
await visit(folder);
|
|
2485
|
-
return total;
|
|
3044
|
+
return { bytes: total, foreign };
|
|
2486
3045
|
}
|
|
2487
|
-
async function findSize(folder) {
|
|
3046
|
+
async function findSize(folder, uid) {
|
|
2488
3047
|
try {
|
|
2489
|
-
const ran = await runCommand(["find", "-P", folder, "
|
|
3048
|
+
const ran = await runCommand(["find", "-P", folder, "-printf", "%y %n %D:%i %s %U\\n"], { timeoutMs: FIND_MS });
|
|
2490
3049
|
const lines = [...ran.text.matchAll(FIND_LINE)];
|
|
2491
3050
|
if (ran.timedOut || ran.code !== 0 && lines.length === 0)
|
|
2492
3051
|
return;
|
|
2493
3052
|
const seen = new Set;
|
|
2494
3053
|
let total = 0;
|
|
2495
|
-
|
|
3054
|
+
let foreign = 0;
|
|
3055
|
+
for (const [, type, links, id, bytes, owner] of lines) {
|
|
3056
|
+
if (Number(owner) !== uid)
|
|
3057
|
+
foreign++;
|
|
3058
|
+
if (type !== "f" && type !== "l")
|
|
3059
|
+
continue;
|
|
2496
3060
|
if (Number(links) > 1) {
|
|
2497
3061
|
if (seen.has(id))
|
|
2498
3062
|
continue;
|
|
@@ -2500,13 +3064,13 @@ async function findSize(folder) {
|
|
|
2500
3064
|
}
|
|
2501
3065
|
total += Number(bytes);
|
|
2502
3066
|
}
|
|
2503
|
-
return total;
|
|
3067
|
+
return { bytes: total, foreign };
|
|
2504
3068
|
} catch {
|
|
2505
3069
|
return;
|
|
2506
3070
|
}
|
|
2507
3071
|
}
|
|
2508
|
-
async function
|
|
2509
|
-
return await findSize(folder) ?? await
|
|
3072
|
+
async function measure(folder, uid = OWN_UID) {
|
|
3073
|
+
return await findSize(folder, uid) ?? await walk(folder, uid);
|
|
2510
3074
|
}
|
|
2511
3075
|
|
|
2512
3076
|
// src/sweep-scan.ts
|
|
@@ -2647,13 +3211,13 @@ async function judgeFolder(path, kind, inside) {
|
|
|
2647
3211
|
if (existsSync9(join12(path, ".git")))
|
|
2648
3212
|
return { skip: "holds a git repository" };
|
|
2649
3213
|
if (located === "none")
|
|
2650
|
-
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside } } : { skip: "not in a git repository" };
|
|
3214
|
+
return name === "node_modules" || inside !== undefined ? { entry: { path, kind, committedAt: undefined, action: "remove", inside, project: dirname5(inside ?? path) } } : { skip: "not in a git repository" };
|
|
2651
3215
|
const tracked = await gitIn(parent, ["ls-files", "--", name]);
|
|
2652
3216
|
if (tracked.code !== 0 || tracked.stdout !== "")
|
|
2653
3217
|
return { skip: "tracked by git" };
|
|
2654
3218
|
if (name !== "node_modules" && inside === undefined && (await gitIn(parent, ["check-ignore", "-q", "--", name])).code !== 0)
|
|
2655
3219
|
return { skip: "not ignored by git" };
|
|
2656
|
-
return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside } };
|
|
3220
|
+
return { entry: { path, kind, committedAt: await lastCommitOf(located.top), action: "remove", inside, project: located.top } };
|
|
2657
3221
|
}
|
|
2658
3222
|
async function judgeWorktree(path) {
|
|
2659
3223
|
const located = await toplevelOf(dirname5(path));
|
|
@@ -2685,23 +3249,26 @@ async function judgeWorktree(path) {
|
|
|
2685
3249
|
if (unique.stdout !== "")
|
|
2686
3250
|
return keep(`${unique.stdout.split(`
|
|
2687
3251
|
`).length} commits on no other branch or remote`);
|
|
2688
|
-
return { entry: { path, kind: "worktree", committedAt, action: "remove", repo: top } };
|
|
3252
|
+
return { entry: { path, kind: "worktree", committedAt, action: "remove", repo: top, project: path } };
|
|
2689
3253
|
}
|
|
2690
3254
|
async function judge(candidate) {
|
|
2691
3255
|
if (candidate.global === true)
|
|
2692
3256
|
return { entry: { path: candidate.path, kind: candidate.kind, committedAt: undefined, action: "remove" } };
|
|
2693
3257
|
return candidate.kind === "worktree" ? judgeWorktree(candidate.path) : judgeFolder(candidate.path, candidate.kind, candidate.inside);
|
|
2694
3258
|
}
|
|
2695
|
-
async function inspect2({ candidates, skipped }) {
|
|
3259
|
+
async function inspect2({ candidates, skipped }, onDone, uid) {
|
|
2696
3260
|
const entries = [];
|
|
2697
3261
|
const rejected = [...skipped];
|
|
2698
3262
|
await pool(candidates, 8, async (candidate) => {
|
|
2699
3263
|
const verdict = await judge(candidate);
|
|
2700
|
-
if ("skip" in verdict)
|
|
3264
|
+
if ("skip" in verdict) {
|
|
2701
3265
|
rejected.push({ path: candidate.path, reason: verdict.skip });
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
3266
|
+
return;
|
|
3267
|
+
}
|
|
3268
|
+
const { bytes, foreign } = await measure(candidate.path, uid);
|
|
3269
|
+
const owned = foreign > 0 && verdict.entry.action === "remove" ? { action: "keep", reason: `${foreign} ${foreign === 1 ? "entry" : "entries"} owned by another user (a container's?)` } : {};
|
|
3270
|
+
entries.push({ ...verdict.entry, ...owned, bytes });
|
|
3271
|
+
}, onDone);
|
|
2705
3272
|
const listed = new Set(entries.filter((entry) => entry.action === "remove").map((entry) => entry.path));
|
|
2706
3273
|
return { entries: entries.filter((entry) => entry.inside === undefined || !listed.has(entry.inside)), skipped: rejected };
|
|
2707
3274
|
}
|
|
@@ -2742,12 +3309,81 @@ async function applyAll(entries, done) {
|
|
|
2742
3309
|
return outcomes;
|
|
2743
3310
|
}
|
|
2744
3311
|
|
|
3312
|
+
// src/busy.ts
|
|
3313
|
+
import { readdir as readdir5, readFile, readlink } from "fs/promises";
|
|
3314
|
+
import { basename as basename5, join as join14 } from "path";
|
|
3315
|
+
var DEV_PROGRAMS = new Set(["node", "bun", "deno", "npm", "npx", "pnpm", "yarn", "bunx", "vite", "esbuild", "ruby", "java", "cargo", "go", "php", "php-fpm"]);
|
|
3316
|
+
var DEV_PREFIXES = ["python", "php"];
|
|
3317
|
+
var DOCKER_MS = 5000;
|
|
3318
|
+
var PID = /^\d+$/;
|
|
3319
|
+
var PARENT = /^ \S+ (\d+)/;
|
|
3320
|
+
function isDevProgram(comm) {
|
|
3321
|
+
return DEV_PROGRAMS.has(comm) || DEV_PREFIXES.some((prefix) => comm.startsWith(prefix));
|
|
3322
|
+
}
|
|
3323
|
+
async function quietly(read) {
|
|
3324
|
+
try {
|
|
3325
|
+
return await read();
|
|
3326
|
+
} catch {
|
|
3327
|
+
return;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
async function lineage(pid, root) {
|
|
3331
|
+
const seen = new Set;
|
|
3332
|
+
for (let current = pid;current > 1 && !seen.has(current); ) {
|
|
3333
|
+
seen.add(current);
|
|
3334
|
+
const stat = await quietly(async () => readFile(join14(root, String(current), "stat"), "utf8"));
|
|
3335
|
+
const parent = Number(PARENT.exec(stat?.slice(stat.lastIndexOf(")") + 1) ?? "")?.[1]);
|
|
3336
|
+
if (!Number.isInteger(parent))
|
|
3337
|
+
break;
|
|
3338
|
+
current = parent;
|
|
3339
|
+
}
|
|
3340
|
+
return seen;
|
|
3341
|
+
}
|
|
3342
|
+
async function processPlaces(root = "/proc", self = process.pid) {
|
|
3343
|
+
const own = await lineage(self, root);
|
|
3344
|
+
const pids = (await quietly(async () => readdir5(root)) ?? []).filter((name) => PID.test(name)).map(Number).filter((pid) => !own.has(pid));
|
|
3345
|
+
const places = [];
|
|
3346
|
+
await Promise.all(pids.map(async (pid) => {
|
|
3347
|
+
const comm = (await quietly(async () => readFile(join14(root, String(pid), "comm"), "utf8")))?.trim();
|
|
3348
|
+
if (comm === undefined || !isDevProgram(comm))
|
|
3349
|
+
return;
|
|
3350
|
+
const cwd = await quietly(async () => readlink(join14(root, String(pid), "cwd")));
|
|
3351
|
+
const argv = (await quietly(async () => readFile(join14(root, String(pid), "cmdline"), "utf8")))?.split("\x00").filter((arg) => arg.startsWith("/")) ?? [];
|
|
3352
|
+
const who = `pid ${pid} ${comm}`;
|
|
3353
|
+
for (const path of [cwd, ...argv.slice(1)]) {
|
|
3354
|
+
if (path !== undefined)
|
|
3355
|
+
places.push({ path, who });
|
|
3356
|
+
}
|
|
3357
|
+
}));
|
|
3358
|
+
return places;
|
|
3359
|
+
}
|
|
3360
|
+
async function containerPlaces() {
|
|
3361
|
+
const ids = await quietly(async () => runCommand(["docker", "ps", "-q"], { timeoutMs: DOCKER_MS }));
|
|
3362
|
+
if (ids === undefined || ids.code !== 0 || ids.text.trim() === "")
|
|
3363
|
+
return [];
|
|
3364
|
+
const inspected = await quietly(async () => runCommand(["docker", "inspect", "--format", '{{.Name}}{{range .Mounts}}{{if eq .Type "bind"}}\t{{.Source}}{{end}}{{end}}', ...ids.text.trim().split(`
|
|
3365
|
+
`)], { timeoutMs: DOCKER_MS }));
|
|
3366
|
+
if (inspected === undefined || inspected.code !== 0)
|
|
3367
|
+
return [];
|
|
3368
|
+
return inspected.text.trim().split(`
|
|
3369
|
+
`).flatMap((line) => {
|
|
3370
|
+
const [name = "", ...sources] = line.split("\t");
|
|
3371
|
+
return sources.map((path) => ({ path, who: `container ${basename5(name)}` }));
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
var within = (path, folder) => path === folder || path.startsWith(`${folder}/`);
|
|
3375
|
+
function userOf(folder, processes, containers) {
|
|
3376
|
+
return processes.find((place) => within(place.path, folder))?.who ?? containers.find((place) => within(place.path, folder) || within(folder, place.path))?.who;
|
|
3377
|
+
}
|
|
3378
|
+
|
|
2745
3379
|
// src/sweep.ts
|
|
2746
3380
|
var LARGE = 100 * 1024 ** 2;
|
|
2747
3381
|
var BIG = 1024 ** 3;
|
|
2748
|
-
var USAGE3 = `sweep [options] [root]: lists the regenerable folders
|
|
3382
|
+
var USAGE3 = `ws sweep [options] [root]: lists the regenerable folders, caches and worktrees under root (the configured workspace by default, ${MAX_DEPTH3} levels down), largest first with the age of the repo's last commit
|
|
2749
3383
|
|
|
2750
|
-
Dry unless --apply, which deletes after a confirm showing the total (
|
|
3384
|
+
Dry unless --apply, which deletes for good, not trashed, after a confirm showing the total (off a terminal, pass --yes).
|
|
3385
|
+
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.
|
|
3386
|
+
What a running dev process or container uses, a folder holding files another user owns and a worktree that is not removable stay listed as kept, with the reason, and count for nothing in the total.`;
|
|
2751
3387
|
var EXITS3 = [[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"]];
|
|
2752
3388
|
var ONLY_KINDS = { worktrees: "worktree", folders: "folder", caches: "cache" };
|
|
2753
3389
|
var OPTIONS3 = {
|
|
@@ -2770,7 +3406,7 @@ async function dockerUsage() {
|
|
|
2770
3406
|
}
|
|
2771
3407
|
}
|
|
2772
3408
|
async function sweep(args) {
|
|
2773
|
-
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, 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"] });
|
|
3409
|
+
const { values, positionals } = parse(args, USAGE3, OPTIONS3, { exits: EXITS3, positionals: ["[root]"], replaces: "find ~/Workspace -name node_modules, du -sh and rm -rf by hand", examples: ["ws sweep", "ws sweep ~/Workspace --older 30d --min 100M --apply", "ws sweep --only worktrees --apply"] });
|
|
2774
3410
|
if (positionals.length > 1)
|
|
2775
3411
|
badUsage("give one root");
|
|
2776
3412
|
const root = workspaceRoot({ given: positionals[0] });
|
|
@@ -2781,9 +3417,20 @@ async function sweep(args) {
|
|
|
2781
3417
|
if (minBytes === undefined)
|
|
2782
3418
|
badUsage(`--min takes a size such as 500K, 10M or 1G, not ${values.min}`);
|
|
2783
3419
|
const now = Date.now();
|
|
2784
|
-
const
|
|
2785
|
-
|
|
2786
|
-
|
|
3420
|
+
const progress = progressLine();
|
|
3421
|
+
let scanned;
|
|
3422
|
+
try {
|
|
3423
|
+
progress.update({ step: "finding the folders" });
|
|
3424
|
+
const found = await findCandidates(root, homedir6(), positionals.length === 0 || values.only === "caches");
|
|
3425
|
+
const wanted = values.only === undefined ? found.candidates : found.candidates.filter((candidate) => candidate.kind === ONLY_KINDS[values.only]);
|
|
3426
|
+
progress.update({ step: "sizing", done: 0, total: wanted.length, unit: "folders" });
|
|
3427
|
+
scanned = await inspect2({ candidates: wanted, skipped: found.skipped }, (done, total) => progress.update({ step: "sizing", done, total, unit: "folders" }));
|
|
3428
|
+
progress.update({ step: "looking for running servers and containers" });
|
|
3429
|
+
await keepWhatIsInUse(scanned.entries);
|
|
3430
|
+
} finally {
|
|
3431
|
+
progress.stop();
|
|
3432
|
+
}
|
|
3433
|
+
const { entries: all, skipped } = scanned;
|
|
2787
3434
|
const entries = all.filter((entry) => entry.bytes >= minBytes && (olderMs === undefined || entry.committedAt !== undefined && now - entry.committedAt >= olderMs)).sort((a, b) => b.bytes - a.bytes || a.path.localeCompare(b.path));
|
|
2788
3435
|
const removable = entries.filter((entry) => entry.action === "remove");
|
|
2789
3436
|
const reclaimable = removable.reduce((sum, entry) => sum + entry.bytes, 0);
|
|
@@ -2828,6 +3475,19 @@ function report2(root, outcome, json) {
|
|
|
2828
3475
|
else
|
|
2829
3476
|
problem(`kept ${relative3(root, outcome.path)}`, outcome.error);
|
|
2830
3477
|
}
|
|
3478
|
+
async function keepWhatIsInUse(entries) {
|
|
3479
|
+
const candidates = entries.filter((entry) => entry.action === "remove" && entry.project !== undefined);
|
|
3480
|
+
if (candidates.length === 0)
|
|
3481
|
+
return;
|
|
3482
|
+
const [processes, containers] = await Promise.all([processPlaces(), containerPlaces()]);
|
|
3483
|
+
for (const entry of candidates) {
|
|
3484
|
+
const who = userOf(entry.project, processes, containers);
|
|
3485
|
+
if (who !== undefined) {
|
|
3486
|
+
entry.action = "keep";
|
|
3487
|
+
entry.reason = `in use by ${who}`;
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
2831
3491
|
function print(root, entries, skipped, reclaimable, now) {
|
|
2832
3492
|
if (entries.length === 0) {
|
|
2833
3493
|
console.log("nothing to sweep");
|
|
@@ -2846,7 +3506,7 @@ ${tt(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2846
3506
|
}
|
|
2847
3507
|
|
|
2848
3508
|
// src/cli.ts
|
|
2849
|
-
|
|
3509
|
+
process26.exitCode = await runCli({
|
|
2850
3510
|
name: "ws",
|
|
2851
3511
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2852
3512
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|