@kaynooo/cli-check 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -15
- package/dist/cli.js +456 -201
- package/dist/errs-cli.js +442 -164
- package/dist/j-cli.js +1545 -1234
- package/package.json +7 -9
- package/dist/fix-cli.js +0 -2135
package/dist/j-cli.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
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
|
-
|
|
6
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process10 from "process";
|
|
8
|
-
import { parseArgs } from "util";
|
|
9
|
-
|
|
10
|
-
// ../kit/src/format.ts
|
|
11
|
-
import process7 from "process";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
-
var N = new Map;
|
|
15
|
-
var Nt = /\s+\S*$/;
|
|
16
|
-
var Y = /\s/;
|
|
17
|
-
function ko(t, e, r = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
18
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
18
|
if (t.length <= e)
|
|
20
19
|
return t;
|
|
@@ -25,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
25
24
|
c = c.trimEnd();
|
|
26
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
27
26
|
}
|
|
28
|
-
var
|
|
29
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
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));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
// ../kit/src/mode.ts
|
|
32
42
|
import process2 from "process";
|
|
33
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
43
|
function isSet(value) {
|
|
36
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
45
|
}
|
|
@@ -48,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
48
56
|
function isInteractive(streams = process2) {
|
|
49
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
58
|
}
|
|
59
|
+
var MODES, AGENT_VARIABLES;
|
|
60
|
+
var init_mode = __esm(() => {
|
|
61
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
+
});
|
|
51
64
|
|
|
52
|
-
//
|
|
53
|
-
import process6 from "process";
|
|
54
|
-
|
|
55
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
56
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
57
66
|
function b(r) {
|
|
58
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
68
|
if (!G2.test(e))
|
|
@@ -64,11 +73,6 @@ function b(r) {
|
|
|
64
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
75
|
}
|
|
67
|
-
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") => {
|
|
68
|
-
let [l, n, c] = b(r);
|
|
69
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
70
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
71
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
72
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
77
|
if (e.FORCE_COLOR !== undefined)
|
|
74
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -82,7 +86,7 @@ function f(r, e = []) {
|
|
|
82
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
88
|
return new Proxy(c, { get(t, i) {
|
|
85
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
86
90
|
if (Array.isArray(a)) {
|
|
87
91
|
let s = g.get(i);
|
|
88
92
|
if (s === undefined)
|
|
@@ -105,13 +109,21 @@ function f(r, e = []) {
|
|
|
105
109
|
function Fe(r = {}) {
|
|
106
110
|
return f(r);
|
|
107
111
|
}
|
|
108
|
-
var
|
|
112
|
+
var G2, B, h, o;
|
|
113
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
+
G2 = /^[a-f0-9]+$/i;
|
|
115
|
+
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") => {
|
|
116
|
+
let [l, n, c] = b(r);
|
|
117
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
+
o = Fe();
|
|
121
|
+
});
|
|
109
122
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import process5 from "process";
|
|
123
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
+
var init_colors = __esm(() => {
|
|
125
|
+
init_chunk_x450vn3m();
|
|
126
|
+
});
|
|
115
127
|
|
|
116
128
|
// ../kit/src/config.ts
|
|
117
129
|
import { existsSync } from "fs";
|
|
@@ -127,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
127
139
|
return;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
130
145
|
|
|
131
146
|
// ../kit/src/user-config.ts
|
|
132
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -158,36 +173,18 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
158
173
|
return {};
|
|
159
174
|
}
|
|
160
175
|
}
|
|
176
|
+
var init_user_config = () => {};
|
|
161
177
|
|
|
162
178
|
// ../kit/src/theme.ts
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
168
|
-
bins: {},
|
|
169
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
170
|
-
};
|
|
171
|
-
var 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" };
|
|
172
|
-
var 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" };
|
|
173
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
174
|
-
var PRESETS = {
|
|
175
|
-
default: {},
|
|
176
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
177
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
178
|
-
ascii: { glyphs: ASCII }
|
|
179
|
-
};
|
|
180
|
-
var 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"]);
|
|
181
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
182
|
-
var CONTROL = /\p{Cc}/u;
|
|
183
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
184
|
-
var SPACES = /\s+/;
|
|
179
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
180
|
+
import { homedir as homedir2 } from "os";
|
|
181
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
182
|
+
import process5 from "process";
|
|
185
183
|
function isColorSpec(spec) {
|
|
186
184
|
if (typeof spec === "number")
|
|
187
185
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
188
186
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
189
187
|
}
|
|
190
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
191
188
|
function cubeLevel(channel) {
|
|
192
189
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
193
190
|
}
|
|
@@ -292,7 +289,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
292
289
|
function endsWalk(home) {
|
|
293
290
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
294
291
|
}
|
|
295
|
-
var warned = new Set;
|
|
296
292
|
function warnOnce(message) {
|
|
297
293
|
if (warned.has(message))
|
|
298
294
|
return;
|
|
@@ -329,8 +325,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
329
325
|
}
|
|
330
326
|
return { theme, sources, preset };
|
|
331
327
|
}
|
|
332
|
-
var current;
|
|
333
|
-
var currentKey = "";
|
|
334
328
|
function activeTheme() {
|
|
335
329
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
336
330
|
if (current === undefined || key !== currentKey) {
|
|
@@ -339,9 +333,38 @@ function activeTheme() {
|
|
|
339
333
|
}
|
|
340
334
|
return current;
|
|
341
335
|
}
|
|
336
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
337
|
+
var init_theme = __esm(() => {
|
|
338
|
+
init_config();
|
|
339
|
+
init_user_config();
|
|
340
|
+
ENDS = new Map;
|
|
341
|
+
DEFAULT = {
|
|
342
|
+
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" },
|
|
343
|
+
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" },
|
|
344
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
345
|
+
bins: {},
|
|
346
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
347
|
+
};
|
|
348
|
+
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" };
|
|
349
|
+
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" };
|
|
350
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
351
|
+
PRESETS = {
|
|
352
|
+
default: {},
|
|
353
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
354
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
355
|
+
ascii: { glyphs: ASCII }
|
|
356
|
+
};
|
|
357
|
+
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"]);
|
|
358
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
359
|
+
CONTROL = /\p{Cc}/u;
|
|
360
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
361
|
+
SPACES = /\s+/;
|
|
362
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
363
|
+
warned = new Set;
|
|
364
|
+
});
|
|
342
365
|
|
|
343
366
|
// ../kit/src/style.ts
|
|
344
|
-
|
|
367
|
+
import process6 from "process";
|
|
345
368
|
function takesControlCodes(stream, env = process6.env) {
|
|
346
369
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
347
370
|
}
|
|
@@ -364,14 +387,6 @@ function role(name, stream, env = process6.env) {
|
|
|
364
387
|
const colors = paint(stream, env);
|
|
365
388
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
366
389
|
}
|
|
367
|
-
var STATUS_WORDS = {
|
|
368
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
369
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
370
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
371
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
372
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
373
|
-
};
|
|
374
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
375
390
|
function header(bin, context, stream, env = process6.env) {
|
|
376
391
|
if (!takesControlCodes(stream, env))
|
|
377
392
|
return "";
|
|
@@ -382,9 +397,24 @@ function header(bin, context, stream, env = process6.env) {
|
|
|
382
397
|
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
383
398
|
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
384
399
|
}
|
|
400
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
401
|
+
var init_style = __esm(() => {
|
|
402
|
+
init_colors();
|
|
403
|
+
init_mode();
|
|
404
|
+
init_theme();
|
|
405
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
406
|
+
STATUS_WORDS = {
|
|
407
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
408
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
409
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
410
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
411
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
412
|
+
};
|
|
413
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
414
|
+
});
|
|
385
415
|
|
|
386
416
|
// ../kit/src/format.ts
|
|
387
|
-
|
|
417
|
+
import process7 from "process";
|
|
388
418
|
function formatSeconds(total) {
|
|
389
419
|
let rest = Math.max(0, Math.round(total));
|
|
390
420
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -406,10 +436,8 @@ function upTo(text, separator) {
|
|
|
406
436
|
return end === -1 ? text : text.slice(0, end);
|
|
407
437
|
}
|
|
408
438
|
function truncate(text, width) {
|
|
409
|
-
return
|
|
439
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
410
440
|
}
|
|
411
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
412
|
-
var ESCAPE = String.fromCharCode(27);
|
|
413
441
|
function textWidth(text) {
|
|
414
442
|
return Bun.stringWidth(text);
|
|
415
443
|
}
|
|
@@ -458,14 +486,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
458
486
|
function printJson(value) {
|
|
459
487
|
console.log(jsonText(value));
|
|
460
488
|
}
|
|
489
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
490
|
+
var init_format = __esm(() => {
|
|
491
|
+
init_text();
|
|
492
|
+
init_mode();
|
|
493
|
+
init_style();
|
|
494
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
495
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
496
|
+
ESCAPE = String.fromCharCode(27);
|
|
497
|
+
});
|
|
461
498
|
|
|
462
499
|
// ../kit/src/help.ts
|
|
463
500
|
import process8 from "process";
|
|
464
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
465
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
466
|
-
var FULL_STOP = /\.$/;
|
|
467
501
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
468
|
-
|
|
502
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
503
|
+
`);
|
|
504
|
+
const blank = lines.indexOf("");
|
|
505
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
506
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
507
|
+
const colon = synopses[0].indexOf(": ");
|
|
508
|
+
const inline = synopses[0].slice(colon + 2);
|
|
509
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
510
|
+
if (colon !== -1)
|
|
511
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
512
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
513
|
+
`)}`;
|
|
514
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
515
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
516
|
+
return [head, ...lead, ...rest].join(`
|
|
517
|
+
`);
|
|
518
|
+
}
|
|
519
|
+
function prose(line, colors) {
|
|
520
|
+
if (colors.cyan("x") === "x")
|
|
521
|
+
return line;
|
|
522
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
469
523
|
}
|
|
470
524
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
471
525
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -500,7 +554,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
500
554
|
return [];
|
|
501
555
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
502
556
|
}
|
|
503
|
-
var MAX_INLINE_CHOICES = 24;
|
|
504
557
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
505
558
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
506
559
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -515,9 +568,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
515
568
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
516
569
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
517
570
|
}
|
|
571
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
572
|
+
var init_help = __esm(() => {
|
|
573
|
+
init_mode();
|
|
574
|
+
init_style();
|
|
575
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
576
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
577
|
+
FULL_STOP = /\.$/;
|
|
578
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
579
|
+
});
|
|
518
580
|
|
|
519
581
|
// ../kit/src/text.ts
|
|
520
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
521
582
|
function stripAnsi(text) {
|
|
522
583
|
return text.replace(ANSI, "");
|
|
523
584
|
}
|
|
@@ -546,10 +607,13 @@ function closest(name, names) {
|
|
|
546
607
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
547
608
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
548
609
|
}
|
|
610
|
+
var ANSI;
|
|
611
|
+
var init_text2 = __esm(() => {
|
|
612
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
613
|
+
});
|
|
614
|
+
|
|
549
615
|
// ../kit/src/input.ts
|
|
550
616
|
import process9 from "process";
|
|
551
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
552
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
553
617
|
function duration(value, name, fallback, unit = "s") {
|
|
554
618
|
if (value === undefined)
|
|
555
619
|
return fallback;
|
|
@@ -570,40 +634,26 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
570
634
|
fail(`no file ${path}`);
|
|
571
635
|
return file.text();
|
|
572
636
|
}
|
|
637
|
+
var DURATION, UNIT_MS;
|
|
638
|
+
var init_input = __esm(() => {
|
|
639
|
+
init_args();
|
|
640
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
641
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
642
|
+
});
|
|
573
643
|
|
|
574
644
|
// ../kit/src/args.ts
|
|
575
|
-
|
|
645
|
+
import process10 from "process";
|
|
646
|
+
import { parseArgs } from "util";
|
|
576
647
|
function jsonOption(holds) {
|
|
577
648
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
578
649
|
}
|
|
579
|
-
class Exit extends Error {
|
|
580
|
-
code;
|
|
581
|
-
hint;
|
|
582
|
-
constructor(message, code, hint) {
|
|
583
|
-
super(message);
|
|
584
|
-
this.code = code;
|
|
585
|
-
this.hint = hint;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
650
|
function fail(message, code = 2, hint) {
|
|
589
651
|
throw new Exit(message, code, hint);
|
|
590
652
|
}
|
|
591
|
-
|
|
592
|
-
class UsageError extends Exit {
|
|
593
|
-
constructor(message, hint) {
|
|
594
|
-
super(message, 2, hint);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
653
|
function badUsage(message) {
|
|
598
654
|
throw new UsageError(message);
|
|
599
655
|
}
|
|
600
656
|
|
|
601
|
-
class HelpShown extends Exit {
|
|
602
|
-
constructor() {
|
|
603
|
-
super("help shown", 0);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
657
|
class Completing {
|
|
608
658
|
options;
|
|
609
659
|
positionals;
|
|
@@ -614,11 +664,6 @@ class Completing {
|
|
|
614
664
|
this.candidates = candidates;
|
|
615
665
|
}
|
|
616
666
|
}
|
|
617
|
-
var completion = { active: false };
|
|
618
|
-
var OUTPUT_OPTIONS = {
|
|
619
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
620
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
621
|
-
};
|
|
622
667
|
function applyOutput(color, plain, env = process10.env) {
|
|
623
668
|
const when = plain === true ? "never" : color ?? "auto";
|
|
624
669
|
if (when === "auto")
|
|
@@ -772,7 +817,6 @@ function parseError(error) {
|
|
|
772
817
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
773
818
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
774
819
|
}
|
|
775
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
776
820
|
function nearestOption(message, options, allowNegative) {
|
|
777
821
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
778
822
|
if (typed === undefined)
|
|
@@ -788,1008 +832,1459 @@ function nearestOption(message, options, allowNegative) {
|
|
|
788
832
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
789
833
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
790
834
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
}
|
|
809
|
-
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
810
|
-
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
811
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
812
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
813
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
814
|
-
}
|
|
815
|
-
// ../kit/src/process.ts
|
|
816
|
-
import { constants } from "os";
|
|
817
|
-
import process12 from "process";
|
|
818
|
-
var KILL_GRACE_MS = 2000;
|
|
819
|
-
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
820
|
-
function exitCodeOf(code, signal) {
|
|
821
|
-
if (code !== null)
|
|
822
|
-
return code;
|
|
823
|
-
if (typeof signal === "number")
|
|
824
|
-
return 128 + signal;
|
|
825
|
-
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
826
|
-
}
|
|
827
|
-
function holdSignals(cleanup) {
|
|
828
|
-
let received;
|
|
829
|
-
let child;
|
|
830
|
-
const held = {
|
|
831
|
-
get signal() {
|
|
832
|
-
return received;
|
|
833
|
-
},
|
|
834
|
-
forward: (to) => {
|
|
835
|
-
child = to;
|
|
836
|
-
},
|
|
837
|
-
release: () => {
|
|
838
|
-
for (const signal of SIGNALS)
|
|
839
|
-
process12.off(signal, onSignal);
|
|
835
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
836
|
+
var init_args = __esm(() => {
|
|
837
|
+
init_format();
|
|
838
|
+
init_help();
|
|
839
|
+
init_text2();
|
|
840
|
+
init_help();
|
|
841
|
+
init_input();
|
|
842
|
+
DASHES = /^-+/;
|
|
843
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
844
|
+
Exit = class Exit extends Error {
|
|
845
|
+
code;
|
|
846
|
+
hint;
|
|
847
|
+
[EXIT] = true;
|
|
848
|
+
constructor(message, code, hint) {
|
|
849
|
+
super(message);
|
|
850
|
+
this.code = code;
|
|
851
|
+
this.hint = hint;
|
|
840
852
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
child.kill(signal);
|
|
846
|
-
return;
|
|
853
|
+
static [Symbol.hasInstance](value) {
|
|
854
|
+
if (this !== Exit)
|
|
855
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
856
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
847
857
|
}
|
|
848
|
-
if (cleanup === undefined)
|
|
849
|
-
return;
|
|
850
|
-
held.release();
|
|
851
|
-
cleanup(signal);
|
|
852
|
-
process12.kill(process12.pid, signal);
|
|
853
|
-
}
|
|
854
|
-
for (const signal of SIGNALS)
|
|
855
|
-
process12.on(signal, onSignal);
|
|
856
|
-
return held;
|
|
857
|
-
}
|
|
858
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
859
|
-
const chunks = [];
|
|
860
|
-
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
861
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
862
|
-
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
863
|
-
const timers = [];
|
|
864
|
-
const killGroup = (killing) => {
|
|
865
|
-
if (state.done)
|
|
866
|
-
return;
|
|
867
|
-
try {
|
|
868
|
-
if (grouped)
|
|
869
|
-
process12.kill(-proc.pid, killing);
|
|
870
|
-
else
|
|
871
|
-
proc.kill(killing);
|
|
872
|
-
} catch {}
|
|
873
|
-
};
|
|
874
|
-
const stop = () => {
|
|
875
|
-
killGroup("SIGTERM");
|
|
876
|
-
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
877
858
|
};
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
state.timedOut = true;
|
|
882
|
-
stop();
|
|
883
|
-
}, timeoutMs));
|
|
884
|
-
}
|
|
885
|
-
if (signal?.aborted === true)
|
|
886
|
-
onAbort();
|
|
887
|
-
else
|
|
888
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
889
|
-
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
890
|
-
const drain = async (stream, name) => {
|
|
891
|
-
for await (const data of stream) {
|
|
892
|
-
if (state.failure !== undefined)
|
|
893
|
-
continue;
|
|
894
|
-
try {
|
|
895
|
-
onChunk?.({ stream: name, data });
|
|
896
|
-
} catch (error) {
|
|
897
|
-
state.failure = error;
|
|
898
|
-
stop();
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
if (state.kept + data.length > maxBytes) {
|
|
902
|
-
state.truncated = true;
|
|
903
|
-
continue;
|
|
904
|
-
}
|
|
905
|
-
state.kept += data.length;
|
|
906
|
-
chunks.push({ stream: name, data });
|
|
859
|
+
UsageError = class UsageError extends Exit {
|
|
860
|
+
constructor(message, hint) {
|
|
861
|
+
super(message, 2, hint);
|
|
907
862
|
}
|
|
908
863
|
};
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
} finally {
|
|
913
|
-
state.done = true;
|
|
914
|
-
for (const timer of timers)
|
|
915
|
-
clearTimeout(timer);
|
|
916
|
-
signal?.removeEventListener("abort", onAbort);
|
|
917
|
-
}
|
|
918
|
-
if (state.failure !== undefined)
|
|
919
|
-
throw state.failure;
|
|
920
|
-
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
921
|
-
let output;
|
|
922
|
-
let text;
|
|
923
|
-
return {
|
|
924
|
-
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
925
|
-
chunks,
|
|
926
|
-
timedOut: state.timedOut,
|
|
927
|
-
truncated: state.truncated,
|
|
928
|
-
get output() {
|
|
929
|
-
return output ??= joined();
|
|
930
|
-
},
|
|
931
|
-
get text() {
|
|
932
|
-
return text ??= (output ??= joined()).toString();
|
|
864
|
+
HelpShown = class HelpShown extends Exit {
|
|
865
|
+
constructor() {
|
|
866
|
+
super("help shown", 0);
|
|
933
867
|
}
|
|
934
868
|
};
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
// ../kit/src/cli.ts
|
|
943
|
-
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
944
|
-
import { dirname as dirname3, join as join6 } from "path";
|
|
945
|
-
import process16 from "process";
|
|
869
|
+
completion = { active: false };
|
|
870
|
+
OUTPUT_OPTIONS = {
|
|
871
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
872
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
873
|
+
};
|
|
874
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
875
|
+
});
|
|
946
876
|
|
|
947
|
-
// ../kit/src/
|
|
948
|
-
import
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
function
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const id = `kit${process13.pid}`;
|
|
956
|
-
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\\`];
|
|
957
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
877
|
+
// ../kit/src/folders.ts
|
|
878
|
+
import { homedir as homedir5 } from "os";
|
|
879
|
+
import { join as join7 } from "path";
|
|
880
|
+
import process18 from "process";
|
|
881
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
882
|
+
const configured = readUserConfig("config", where).ignore;
|
|
883
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
884
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
958
885
|
}
|
|
959
|
-
function
|
|
960
|
-
|
|
961
|
-
return;
|
|
962
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
886
|
+
function cacheFolder({ home = homedir5(), env = process18.env } = {}) {
|
|
887
|
+
return env.XDG_CACHE_HOME ?? join7(home, ".cache");
|
|
963
888
|
}
|
|
889
|
+
var SKIPPED_FOLDERS;
|
|
890
|
+
var init_folders = __esm(() => {
|
|
891
|
+
init_user_config();
|
|
892
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
893
|
+
});
|
|
964
894
|
|
|
965
|
-
// ../kit/src/
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
969
|
-
import process15 from "process";
|
|
970
|
-
|
|
971
|
-
// ../kit/src/logs.ts
|
|
972
|
-
import { lstatSync, openSync } from "fs";
|
|
973
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
974
|
-
import { homedir as homedir3, tmpdir } from "os";
|
|
975
|
-
import { join as join4 } from "path";
|
|
976
|
-
import process14 from "process";
|
|
977
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
978
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
979
|
-
function isPrivateDirectory(path) {
|
|
980
|
-
try {
|
|
981
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
982
|
-
return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
983
|
-
} catch {
|
|
984
|
-
return false;
|
|
985
|
-
}
|
|
895
|
+
// ../kit/src/picker/line.ts
|
|
896
|
+
function isEditKey(key) {
|
|
897
|
+
return EDIT_KEYS.has(key);
|
|
986
898
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
990
|
-
const path = join4(base, name);
|
|
991
|
-
try {
|
|
992
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
993
|
-
if (isPrivateDirectory(path))
|
|
994
|
-
return path;
|
|
995
|
-
} catch {}
|
|
996
|
-
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
899
|
+
function endsKills(key) {
|
|
900
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
997
901
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
try {
|
|
1001
|
-
names = await readdir(dir);
|
|
1002
|
-
} catch {
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
for (const name of names) {
|
|
1006
|
-
const path = join4(dir, name);
|
|
1007
|
-
try {
|
|
1008
|
-
const info = await stat(path);
|
|
1009
|
-
if (info.isDirectory())
|
|
1010
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
1011
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
1012
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1013
|
-
} catch {
|
|
1014
|
-
continue;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// ../kit/src/usage.ts
|
|
1020
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1021
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1022
|
-
var LONGEST_NAME = 40;
|
|
1023
|
-
var usageError;
|
|
1024
|
-
function noteUsageError(message) {
|
|
1025
|
-
usageError = message;
|
|
902
|
+
function isWord(char) {
|
|
903
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
1026
904
|
}
|
|
1027
|
-
function
|
|
1028
|
-
|
|
1029
|
-
|
|
905
|
+
function wordStart(chars, from) {
|
|
906
|
+
let at = from;
|
|
907
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
908
|
+
at--;
|
|
909
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
910
|
+
at--;
|
|
911
|
+
return at;
|
|
1030
912
|
}
|
|
1031
|
-
function
|
|
1032
|
-
|
|
913
|
+
function wordEnd(chars, from) {
|
|
914
|
+
let at = from;
|
|
915
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
916
|
+
at++;
|
|
917
|
+
while (at < chars.length && isWord(chars[at]))
|
|
918
|
+
at++;
|
|
919
|
+
return at;
|
|
1033
920
|
}
|
|
1034
|
-
function
|
|
1035
|
-
|
|
1036
|
-
|
|
921
|
+
function spacedStart(chars, from) {
|
|
922
|
+
let at = from;
|
|
923
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
924
|
+
at--;
|
|
925
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
926
|
+
at--;
|
|
927
|
+
return at;
|
|
1037
928
|
}
|
|
1038
|
-
function
|
|
1039
|
-
|
|
1040
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1041
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
929
|
+
function cut2(chars, from, to) {
|
|
930
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1042
931
|
}
|
|
1043
|
-
function
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
932
|
+
function insert(chars, at, text) {
|
|
933
|
+
const typed = [...text];
|
|
934
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1047
935
|
}
|
|
1048
|
-
function
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
936
|
+
function editLine(line, key) {
|
|
937
|
+
const { killed = "", chained = false } = line;
|
|
938
|
+
const chars = [...line.text];
|
|
939
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
940
|
+
const edited = edit(chars, at, key, killed);
|
|
941
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
942
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
943
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
944
|
+
if (taken === "")
|
|
945
|
+
return { ...edited, killed, chained };
|
|
946
|
+
if (!chained)
|
|
947
|
+
return { ...edited, killed: taken, chained: true };
|
|
948
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1057
949
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
950
|
+
function edit(chars, at, key, killed) {
|
|
951
|
+
const text = chars.join("");
|
|
952
|
+
if (typeof key === "object")
|
|
953
|
+
return insert(chars, at, key.text);
|
|
954
|
+
switch (key) {
|
|
955
|
+
case "left":
|
|
956
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
957
|
+
case "right":
|
|
958
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
959
|
+
case "wordleft":
|
|
960
|
+
return { text, caret: wordStart(chars, at) };
|
|
961
|
+
case "wordright":
|
|
962
|
+
return { text, caret: wordEnd(chars, at) };
|
|
963
|
+
case "linestart":
|
|
964
|
+
return { text, caret: 0 };
|
|
965
|
+
case "lineend":
|
|
966
|
+
return { text, caret: chars.length };
|
|
967
|
+
case "erase":
|
|
968
|
+
return cut2(chars, Math.max(at - 1, 0), at);
|
|
969
|
+
case "delete":
|
|
970
|
+
return cut2(chars, at, Math.min(at + 1, chars.length));
|
|
971
|
+
case "word":
|
|
972
|
+
return cut2(chars, spacedStart(chars, at), at);
|
|
973
|
+
case "killword":
|
|
974
|
+
return cut2(chars, wordStart(chars, at), at);
|
|
975
|
+
case "killnext":
|
|
976
|
+
return cut2(chars, at, wordEnd(chars, at));
|
|
977
|
+
case "clear":
|
|
978
|
+
return cut2(chars, 0, at);
|
|
979
|
+
case "killend":
|
|
980
|
+
return cut2(chars, at, chars.length);
|
|
981
|
+
case "yank":
|
|
982
|
+
return insert(chars, at, killed);
|
|
983
|
+
}
|
|
1072
984
|
}
|
|
1073
|
-
function
|
|
1074
|
-
|
|
985
|
+
function visible({ text, caret }, room) {
|
|
986
|
+
const chars = [...text];
|
|
987
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
988
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
989
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
990
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
991
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
992
|
+
let start = at;
|
|
993
|
+
let end = at + 1;
|
|
994
|
+
while (start > 0 && fits(start - 1, end))
|
|
995
|
+
start--;
|
|
996
|
+
while (end < cells.length && fits(start, end + 1))
|
|
997
|
+
end++;
|
|
998
|
+
const left = start > 0 ? "\u2026" : "";
|
|
999
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1000
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1075
1001
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1002
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1003
|
+
var init_line = __esm(() => {
|
|
1004
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1005
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1006
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1007
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1008
|
+
SPACE = /\s/;
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
// ../kit/src/picker/score.ts
|
|
1012
|
+
function startsWord(text, index) {
|
|
1013
|
+
if (index === 0)
|
|
1014
|
+
return true;
|
|
1015
|
+
const before = text[index - 1];
|
|
1016
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1079
1017
|
}
|
|
1080
|
-
function
|
|
1081
|
-
if (
|
|
1082
|
-
return 0;
|
|
1083
|
-
const
|
|
1084
|
-
const
|
|
1085
|
-
const
|
|
1086
|
-
if (
|
|
1087
|
-
|
|
1088
|
-
const
|
|
1089
|
-
|
|
1090
|
-
|
|
1018
|
+
function fuzzy(query, text) {
|
|
1019
|
+
if (query === "")
|
|
1020
|
+
return { score: 0, positions: [] };
|
|
1021
|
+
const exact = query !== query.toLowerCase();
|
|
1022
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1023
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1024
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1025
|
+
return;
|
|
1026
|
+
const width = haystack.length;
|
|
1027
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1028
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1029
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1030
|
+
let run = NONE;
|
|
1031
|
+
let runAt = -1;
|
|
1032
|
+
for (let i = j;i < width; i++) {
|
|
1033
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1034
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1035
|
+
if (candidate > run) {
|
|
1036
|
+
run = candidate;
|
|
1037
|
+
runAt = i - 2;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
if (haystack[i] !== needle[j])
|
|
1041
|
+
continue;
|
|
1042
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY2 : 0) + (i === 0 ? PREFIX : 0);
|
|
1043
|
+
if (j === 0) {
|
|
1044
|
+
best[0][i] = here - i * GAP;
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1048
|
+
const skipped = run - (i - 1) * GAP;
|
|
1049
|
+
if (joined > NONE && joined >= skipped) {
|
|
1050
|
+
best[j][i] = joined + here;
|
|
1051
|
+
from[j][i] = i - 1;
|
|
1052
|
+
} else if (skipped > NONE) {
|
|
1053
|
+
best[j][i] = skipped + here;
|
|
1054
|
+
from[j][i] = runAt;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
const last = best[needle.length - 1];
|
|
1059
|
+
let end = -1;
|
|
1060
|
+
for (let i = 0;i < width; i++) {
|
|
1061
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1062
|
+
end = i;
|
|
1063
|
+
}
|
|
1064
|
+
if (end === -1)
|
|
1065
|
+
return;
|
|
1066
|
+
const positions = [];
|
|
1067
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1068
|
+
positions.unshift(i);
|
|
1069
|
+
i = from[j][i];
|
|
1070
|
+
}
|
|
1071
|
+
return { score: last[end], positions };
|
|
1091
1072
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
return error;
|
|
1101
|
-
} finally {
|
|
1102
|
-
completion.active = false;
|
|
1073
|
+
function rank(query, lines) {
|
|
1074
|
+
if (query === "")
|
|
1075
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1076
|
+
const found = [];
|
|
1077
|
+
for (const [index, line] of lines.entries()) {
|
|
1078
|
+
const match = fuzzy(query, line);
|
|
1079
|
+
if (match !== undefined)
|
|
1080
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1103
1081
|
}
|
|
1104
|
-
return
|
|
1082
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1105
1083
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1084
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY2 = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1085
|
+
var init_score = __esm(() => {
|
|
1086
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1087
|
+
UPPER = /\p{Lu}/u;
|
|
1088
|
+
LOWER = /\p{Ll}/u;
|
|
1089
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// ../kit/src/picker/state.ts
|
|
1093
|
+
function repeat(value, count) {
|
|
1094
|
+
return Array.from({ length: count }).fill(value);
|
|
1108
1095
|
}
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1111
|
-
const
|
|
1112
|
-
let
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
typed.push(word);
|
|
1121
|
-
else if (takesValue(word))
|
|
1122
|
-
at++;
|
|
1123
|
-
at++;
|
|
1096
|
+
function styled(line) {
|
|
1097
|
+
let text = "";
|
|
1098
|
+
const styles = [];
|
|
1099
|
+
let active = "";
|
|
1100
|
+
let colored = false;
|
|
1101
|
+
let last = 0;
|
|
1102
|
+
function add(chunk) {
|
|
1103
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1104
|
+
text += flat;
|
|
1105
|
+
colored ||= active !== "" && flat !== "";
|
|
1106
|
+
styles.push(...repeat(active, flat.length));
|
|
1124
1107
|
}
|
|
1125
|
-
const
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1108
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1109
|
+
add(line.slice(last, found.index));
|
|
1110
|
+
last = found.index + found[0].length;
|
|
1111
|
+
if (SGR.test(found[0]))
|
|
1112
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1113
|
+
}
|
|
1114
|
+
add(line.slice(last));
|
|
1115
|
+
return { text, styles: colored ? styles : undefined };
|
|
1129
1116
|
}
|
|
1130
|
-
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1117
|
+
function lay(rows, searched) {
|
|
1118
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1119
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1120
|
+
return parsed.map((cells, at) => {
|
|
1121
|
+
let text = "";
|
|
1122
|
+
const styles = [];
|
|
1123
|
+
let colored = false;
|
|
1124
|
+
let searchEnd = 0;
|
|
1125
|
+
for (const [column, cell] of cells.entries()) {
|
|
1126
|
+
const last = column === cells.length - 1;
|
|
1127
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1128
|
+
text += shown;
|
|
1129
|
+
colored ||= cell.styles !== undefined;
|
|
1130
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1131
|
+
if (column < searched)
|
|
1132
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1133
|
+
if (!last) {
|
|
1134
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1135
|
+
text += " ".repeat(pad);
|
|
1136
|
+
styles.push(...repeat("", pad));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1143
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1144
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1145
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1146
|
+
if (wheel !== undefined)
|
|
1147
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1148
|
+
const named = codes.get(sequence);
|
|
1149
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1150
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1151
|
+
paste.active = sequence === PASTE_START;
|
|
1152
|
+
return [];
|
|
1153
|
+
}
|
|
1154
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1155
|
+
`))
|
|
1156
|
+
return [];
|
|
1157
|
+
if (key !== undefined)
|
|
1158
|
+
return [key];
|
|
1159
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1163
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1164
|
+
return withRows(state, rows);
|
|
1165
|
+
}
|
|
1166
|
+
function withRows(state, rows, header = state.header) {
|
|
1167
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1168
|
+
const laid = lay(cells, state.searched);
|
|
1169
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1170
|
+
const matches = rank(state.query, searchable);
|
|
1171
|
+
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1172
|
+
}
|
|
1173
|
+
function withQuery(state, key) {
|
|
1174
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1175
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1176
|
+
}
|
|
1177
|
+
function move(state, by) {
|
|
1178
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1179
|
+
}
|
|
1180
|
+
function highlighted(state) {
|
|
1181
|
+
return state.matches[state.cursor]?.index;
|
|
1182
|
+
}
|
|
1183
|
+
function press(state, key) {
|
|
1184
|
+
if (state.done !== undefined)
|
|
1185
|
+
return state;
|
|
1186
|
+
if (state.chained && endsKills(key))
|
|
1187
|
+
state = { ...state, chained: false };
|
|
1188
|
+
if (state.help)
|
|
1189
|
+
return { ...state, help: false };
|
|
1190
|
+
if (typeof key === "object") {
|
|
1191
|
+
if ("text" in key)
|
|
1192
|
+
return withQuery(state, key);
|
|
1193
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1194
|
+
}
|
|
1195
|
+
if (isEditKey(key))
|
|
1196
|
+
return withQuery(state, key);
|
|
1197
|
+
switch (key) {
|
|
1198
|
+
case "up":
|
|
1199
|
+
return move(state, -1);
|
|
1200
|
+
case "down":
|
|
1201
|
+
return move(state, 1);
|
|
1202
|
+
case "pageup":
|
|
1203
|
+
return move(state, -state.page);
|
|
1204
|
+
case "pagedown":
|
|
1205
|
+
return move(state, state.page);
|
|
1206
|
+
case "home":
|
|
1207
|
+
return move(state, -state.matches.length);
|
|
1208
|
+
case "end":
|
|
1209
|
+
return move(state, state.matches.length);
|
|
1210
|
+
case "cancel":
|
|
1211
|
+
return { ...state, done: "cancel" };
|
|
1212
|
+
case "help":
|
|
1213
|
+
return { ...state, help: true };
|
|
1214
|
+
case "suspend":
|
|
1215
|
+
return state;
|
|
1216
|
+
case "enter":
|
|
1217
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1218
|
+
case "tab": {
|
|
1219
|
+
const at = highlighted(state);
|
|
1220
|
+
if (!state.multi || at === undefined)
|
|
1221
|
+
return state;
|
|
1222
|
+
const marked = new Set(state.marked);
|
|
1223
|
+
if (!marked.delete(at))
|
|
1224
|
+
marked.add(at);
|
|
1225
|
+
return move({ ...state, marked }, 1);
|
|
1226
|
+
}
|
|
1140
1227
|
}
|
|
1141
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1142
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1143
1228
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1229
|
+
function chosen(state) {
|
|
1230
|
+
if (state.marked.size > 0)
|
|
1231
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1232
|
+
const at = highlighted(state);
|
|
1233
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1148
1234
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1235
|
+
var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
|
|
1236
|
+
var init_state = __esm(() => {
|
|
1237
|
+
init_text2();
|
|
1238
|
+
init_line();
|
|
1239
|
+
init_score();
|
|
1240
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1241
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1242
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1243
|
+
RESET = /^\x1B\[0?m$/;
|
|
1244
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1245
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1246
|
+
KEYS = {
|
|
1247
|
+
"\x1B[A": "up",
|
|
1248
|
+
"\x1BOA": "up",
|
|
1249
|
+
"\x10": "up",
|
|
1250
|
+
"\x1B[B": "down",
|
|
1251
|
+
"\x1BOB": "down",
|
|
1252
|
+
"\x0E": "down",
|
|
1253
|
+
"\x1B[5~": "pageup",
|
|
1254
|
+
"\x1B[6~": "pagedown",
|
|
1255
|
+
"\x1B[H": "home",
|
|
1256
|
+
"\x1B[1~": "home",
|
|
1257
|
+
"\x1BOH": "home",
|
|
1258
|
+
"\x1B[F": "end",
|
|
1259
|
+
"\x1B[4~": "end",
|
|
1260
|
+
"\x1BOF": "end",
|
|
1261
|
+
"\r": "enter",
|
|
1262
|
+
"\n": "enter",
|
|
1263
|
+
"\x03": "cancel",
|
|
1264
|
+
"\x1B": "cancel",
|
|
1265
|
+
"\x1B[D": "left",
|
|
1266
|
+
"\x1BOD": "left",
|
|
1267
|
+
"\x1B[C": "right",
|
|
1268
|
+
"\x1BOC": "right",
|
|
1269
|
+
"\x1B[1;5D": "wordleft",
|
|
1270
|
+
"\x1B[1;3D": "wordleft",
|
|
1271
|
+
"\x1Bb": "wordleft",
|
|
1272
|
+
"\x1B[1;5C": "wordright",
|
|
1273
|
+
"\x1B[1;3C": "wordright",
|
|
1274
|
+
"\x1Bf": "wordright",
|
|
1275
|
+
"\x01": "linestart",
|
|
1276
|
+
"\x05": "lineend",
|
|
1277
|
+
"\x7F": "erase",
|
|
1278
|
+
"\x1B[3~": "delete",
|
|
1279
|
+
"\b": "killword",
|
|
1280
|
+
"\x1B\x7F": "killword",
|
|
1281
|
+
"\x1B[3;5~": "killnext",
|
|
1282
|
+
"\x1Bd": "killnext",
|
|
1283
|
+
"\x15": "clear",
|
|
1284
|
+
"\v": "killend",
|
|
1285
|
+
"\x17": "word",
|
|
1286
|
+
"\x19": "yank",
|
|
1287
|
+
"\x1A": "suspend",
|
|
1288
|
+
"\t": "tab",
|
|
1289
|
+
"\x1F": "help",
|
|
1290
|
+
"\x1BOP": "help",
|
|
1291
|
+
"\x1B[11~": "help"
|
|
1292
|
+
};
|
|
1293
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
// ../kit/src/job.ts
|
|
1297
|
+
import process20 from "process";
|
|
1298
|
+
function stopJob() {
|
|
1299
|
+
process20.kill(0, "SIGTSTP");
|
|
1300
|
+
}
|
|
1301
|
+
var init_job = () => {};
|
|
1302
|
+
|
|
1303
|
+
// ../kit/src/redraw.ts
|
|
1304
|
+
function overwrite(lines, columns) {
|
|
1305
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1306
|
+
`);
|
|
1307
|
+
}
|
|
1308
|
+
function rowsTaken(lines, columns) {
|
|
1309
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1310
|
+
}
|
|
1311
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1312
|
+
var init_redraw = __esm(() => {
|
|
1313
|
+
init_format();
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
// ../kit/src/answers.ts
|
|
1317
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
|
|
1318
|
+
import { dirname as dirname5, join as join9 } from "path";
|
|
1319
|
+
function answersFile() {
|
|
1320
|
+
return join9(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
1321
|
+
}
|
|
1322
|
+
function stored() {
|
|
1151
1323
|
try {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
return version;
|
|
1159
|
-
} catch {}
|
|
1160
|
-
if (dirname3(dir) === dir)
|
|
1161
|
-
return "0.0.0";
|
|
1324
|
+
const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
|
|
1325
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
1326
|
+
return {};
|
|
1327
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
1328
|
+
} catch {
|
|
1329
|
+
return {};
|
|
1162
1330
|
}
|
|
1163
1331
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
let code;
|
|
1172
|
-
const started = performance.now();
|
|
1332
|
+
function earlierAnswers(key) {
|
|
1333
|
+
return stored()[key] ?? [];
|
|
1334
|
+
}
|
|
1335
|
+
function rememberAnswer(key, answer) {
|
|
1336
|
+
const all = stored();
|
|
1337
|
+
const file = answersFile();
|
|
1338
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
1173
1339
|
try {
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1340
|
+
mkdirSync3(dirname5(file), { recursive: true });
|
|
1341
|
+
writeFileSync2(file, JSON.stringify(all));
|
|
1342
|
+
} catch {}
|
|
1343
|
+
}
|
|
1344
|
+
var KEPT = 50;
|
|
1345
|
+
var init_answers = __esm(() => {
|
|
1346
|
+
init_folders();
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
// ../kit/src/prompt.ts
|
|
1350
|
+
import process24 from "process";
|
|
1351
|
+
function readKeys(input, paste = { active: false }) {
|
|
1352
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1353
|
+
}
|
|
1354
|
+
function roomAfter(question, columns) {
|
|
1355
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1356
|
+
}
|
|
1357
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1358
|
+
const { before, at, after } = visible(line, room);
|
|
1359
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1360
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1361
|
+
}
|
|
1362
|
+
function sharedStart(texts) {
|
|
1363
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1364
|
+
let length = first.length;
|
|
1365
|
+
for (const chars of rest) {
|
|
1366
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1367
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1183
1368
|
}
|
|
1184
|
-
return
|
|
1369
|
+
return first.slice(0, length).join("");
|
|
1185
1370
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1371
|
+
function listed2(colors, found, columns) {
|
|
1372
|
+
const shared = sharedStart(found);
|
|
1373
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1374
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1375
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1376
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1377
|
+
}
|
|
1378
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1379
|
+
let line = { text: "", caret: 0 };
|
|
1380
|
+
let invalid;
|
|
1381
|
+
let completions = [];
|
|
1382
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1383
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1384
|
+
let recalled = -1;
|
|
1385
|
+
let draft = line;
|
|
1386
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1387
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1388
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1389
|
+
if (state !== "asking")
|
|
1390
|
+
return [answer(colors, question, state, shown())];
|
|
1391
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1392
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1393
|
+
}, (key) => {
|
|
1394
|
+
if (key === "cancel")
|
|
1395
|
+
return "cancel";
|
|
1396
|
+
invalid = undefined;
|
|
1397
|
+
completions = [];
|
|
1398
|
+
if (line.chained === true && endsKills(key))
|
|
1399
|
+
line = { ...line, chained: false };
|
|
1400
|
+
if (key === "tab") {
|
|
1401
|
+
const chars = [...line.text];
|
|
1402
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1403
|
+
const found = complete?.(before) ?? [];
|
|
1404
|
+
const filled = sharedStart(found);
|
|
1405
|
+
if ([...filled].length > [...before].length)
|
|
1406
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1407
|
+
else
|
|
1408
|
+
completions = found;
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
if (key === "enter") {
|
|
1412
|
+
invalid = validate?.(taken());
|
|
1413
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1414
|
+
}
|
|
1415
|
+
if (key === "up" || key === "down") {
|
|
1416
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1417
|
+
if (recalled === -1)
|
|
1418
|
+
draft = line;
|
|
1419
|
+
recalled = to;
|
|
1420
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1421
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1425
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1426
|
+
line = editLine(line, edit);
|
|
1237
1427
|
return;
|
|
1238
|
-
const errors = blocks.map((block) => {
|
|
1239
|
-
const { file, line, column, code, message } = bunCheckFields(block);
|
|
1240
|
-
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
1241
1428
|
});
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
`)
|
|
1429
|
+
if (!accepted)
|
|
1430
|
+
return;
|
|
1431
|
+
if (remembered !== undefined && taken() !== "")
|
|
1432
|
+
rememberAnswer(remembered, taken());
|
|
1433
|
+
return taken();
|
|
1434
|
+
}
|
|
1435
|
+
function answer(colors, question, state, picked) {
|
|
1436
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1437
|
+
}
|
|
1438
|
+
async function ask(question, { hint, terminal = process24 }, render, press) {
|
|
1439
|
+
const { stdin, stderr } = terminal;
|
|
1440
|
+
if (!isInteractive(terminal))
|
|
1441
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1442
|
+
const colors = paint(stderr);
|
|
1443
|
+
let current = "asking";
|
|
1444
|
+
let outcome;
|
|
1445
|
+
const columns = () => stderr.columns || 80;
|
|
1446
|
+
const draw = (state, last = false) => {
|
|
1447
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1448
|
+
const rows = rowsTaken(frame, columns());
|
|
1449
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1450
|
+
current = state;
|
|
1451
|
+
};
|
|
1452
|
+
const redraw = () => draw(current);
|
|
1453
|
+
const paste = { active: false };
|
|
1454
|
+
const stop = terminal.stop ?? (terminal === process24 ? stopJob : undefined);
|
|
1455
|
+
const suspend = () => {
|
|
1456
|
+
if (stop === undefined)
|
|
1457
|
+
return;
|
|
1458
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1459
|
+
stdin.setRawMode(false);
|
|
1460
|
+
stop();
|
|
1461
|
+
stdin.setRawMode(true);
|
|
1462
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1255
1463
|
};
|
|
1464
|
+
try {
|
|
1465
|
+
stderr.on?.("resize", redraw);
|
|
1466
|
+
stdin.setRawMode(true);
|
|
1467
|
+
stdin.resume();
|
|
1468
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1469
|
+
draw("asking");
|
|
1470
|
+
return await new Promise((resolve) => {
|
|
1471
|
+
function onData(data) {
|
|
1472
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1473
|
+
if (key === "suspend") {
|
|
1474
|
+
suspend();
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
const pressed = press(key);
|
|
1478
|
+
if (pressed !== undefined) {
|
|
1479
|
+
settle(pressed);
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
draw("asking");
|
|
1484
|
+
}
|
|
1485
|
+
function onEnd() {
|
|
1486
|
+
settle("cancel");
|
|
1487
|
+
}
|
|
1488
|
+
function settle(settled) {
|
|
1489
|
+
outcome = settled;
|
|
1490
|
+
stdin.off("data", onData);
|
|
1491
|
+
stdin.off("end", onEnd);
|
|
1492
|
+
resolve(settled === "enter");
|
|
1493
|
+
}
|
|
1494
|
+
stdin.on("data", onData);
|
|
1495
|
+
stdin.on("end", onEnd);
|
|
1496
|
+
});
|
|
1497
|
+
} finally {
|
|
1498
|
+
stderr.off?.("resize", redraw);
|
|
1499
|
+
draw(outcome ?? "cancel", true);
|
|
1500
|
+
stderr.write(`
|
|
1501
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1502
|
+
stdin.setRawMode(false);
|
|
1503
|
+
stdin.pause();
|
|
1504
|
+
}
|
|
1256
1505
|
}
|
|
1257
|
-
var
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1506
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1507
|
+
var init_prompt = __esm(() => {
|
|
1508
|
+
init_answers();
|
|
1509
|
+
init_args();
|
|
1510
|
+
init_format();
|
|
1511
|
+
init_job();
|
|
1512
|
+
init_mode();
|
|
1513
|
+
init_line();
|
|
1514
|
+
init_state();
|
|
1515
|
+
init_redraw();
|
|
1516
|
+
init_style();
|
|
1517
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// src/j-cli.ts
|
|
1521
|
+
import process27 from "process";
|
|
1522
|
+
|
|
1523
|
+
// ../kit/src/index.ts
|
|
1524
|
+
init_args();
|
|
1525
|
+
|
|
1526
|
+
// ../kit/src/argv.ts
|
|
1527
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
1528
|
+
import { resolve as resolve3 } from "path";
|
|
1529
|
+
import process11 from "process";
|
|
1530
|
+
function commandLine() {
|
|
1531
|
+
try {
|
|
1532
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1533
|
+
} catch {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
function realPath(word) {
|
|
1538
|
+
try {
|
|
1539
|
+
return realpathSync(resolve3(word));
|
|
1540
|
+
} catch {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
1545
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1546
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1547
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1548
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1549
|
+
}
|
|
1550
|
+
// ../kit/src/chart.ts
|
|
1551
|
+
init_format();
|
|
1552
|
+
init_mode();
|
|
1553
|
+
init_style();
|
|
1554
|
+
init_theme();
|
|
1555
|
+
// ../kit/src/ci.ts
|
|
1556
|
+
init_args();
|
|
1557
|
+
init_format();
|
|
1558
|
+
|
|
1559
|
+
// ../kit/src/progress.ts
|
|
1560
|
+
init_format();
|
|
1561
|
+
|
|
1562
|
+
// ../kit/src/process.ts
|
|
1563
|
+
import { constants } from "os";
|
|
1564
|
+
import process12 from "process";
|
|
1565
|
+
var KILL_GRACE_MS = 2000;
|
|
1566
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1567
|
+
function exitCodeOf(code, signal) {
|
|
1568
|
+
if (code !== null)
|
|
1569
|
+
return code;
|
|
1570
|
+
if (typeof signal === "number")
|
|
1571
|
+
return 128 + signal;
|
|
1572
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
1573
|
+
}
|
|
1574
|
+
function holdSignals(cleanup) {
|
|
1575
|
+
let received;
|
|
1576
|
+
let child;
|
|
1577
|
+
const held = {
|
|
1578
|
+
get signal() {
|
|
1579
|
+
return received;
|
|
1580
|
+
},
|
|
1581
|
+
forward: (to) => {
|
|
1582
|
+
child = to;
|
|
1583
|
+
},
|
|
1584
|
+
release: () => {
|
|
1585
|
+
for (const signal of SIGNALS)
|
|
1586
|
+
process12.off(signal, onSignal);
|
|
1271
1587
|
}
|
|
1588
|
+
};
|
|
1589
|
+
function onSignal(signal) {
|
|
1590
|
+
received = signal;
|
|
1591
|
+
if (child !== undefined) {
|
|
1592
|
+
child.kill(signal);
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
if (cleanup === undefined)
|
|
1596
|
+
return;
|
|
1597
|
+
held.release();
|
|
1598
|
+
cleanup(signal);
|
|
1599
|
+
process12.kill(process12.pid, signal);
|
|
1272
1600
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1601
|
+
for (const signal of SIGNALS)
|
|
1602
|
+
process12.on(signal, onSignal);
|
|
1603
|
+
return held;
|
|
1604
|
+
}
|
|
1605
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1606
|
+
const chunks = [];
|
|
1607
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
1608
|
+
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 } : {} });
|
|
1609
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
1610
|
+
const timers = [];
|
|
1611
|
+
const killGroup = (killing) => {
|
|
1612
|
+
if (state.done)
|
|
1613
|
+
return;
|
|
1614
|
+
try {
|
|
1615
|
+
if (grouped)
|
|
1616
|
+
process12.kill(-proc.pid, killing);
|
|
1617
|
+
else
|
|
1618
|
+
proc.kill(killing);
|
|
1619
|
+
} catch {}
|
|
1620
|
+
};
|
|
1621
|
+
const stop = () => {
|
|
1622
|
+
killGroup("SIGTERM");
|
|
1623
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
1624
|
+
};
|
|
1625
|
+
const onAbort = () => stop();
|
|
1626
|
+
if (timeoutMs !== undefined) {
|
|
1627
|
+
timers.push(setTimeout(() => {
|
|
1628
|
+
state.timedOut = true;
|
|
1629
|
+
stop();
|
|
1630
|
+
}, timeoutMs));
|
|
1631
|
+
}
|
|
1632
|
+
if (signal?.aborted === true)
|
|
1633
|
+
onAbort();
|
|
1634
|
+
else
|
|
1635
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1636
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
1637
|
+
const drain = async (stream, name) => {
|
|
1638
|
+
for await (const data of stream) {
|
|
1639
|
+
if (state.failure !== undefined)
|
|
1640
|
+
continue;
|
|
1641
|
+
try {
|
|
1642
|
+
onChunk?.({ stream: name, data });
|
|
1643
|
+
} catch (error) {
|
|
1644
|
+
state.failure = error;
|
|
1645
|
+
stop();
|
|
1646
|
+
continue;
|
|
1284
1647
|
}
|
|
1285
|
-
kept.
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1648
|
+
if (state.kept + data.length > maxBytes) {
|
|
1649
|
+
state.truncated = true;
|
|
1650
|
+
continue;
|
|
1651
|
+
}
|
|
1652
|
+
state.kept += data.length;
|
|
1653
|
+
chunks.push({ stream: name, data });
|
|
1290
1654
|
}
|
|
1655
|
+
};
|
|
1656
|
+
try {
|
|
1657
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
1658
|
+
await proc.exited;
|
|
1659
|
+
} finally {
|
|
1660
|
+
state.done = true;
|
|
1661
|
+
for (const timer of timers)
|
|
1662
|
+
clearTimeout(timer);
|
|
1663
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1291
1664
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
};
|
|
1310
|
-
var phpCsFixer = (lines) => {
|
|
1311
|
-
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
1312
|
-
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
1313
|
-
};
|
|
1314
|
-
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
1315
|
-
function squeeze(lines) {
|
|
1316
|
-
const out = [];
|
|
1317
|
-
for (const line of lines.map((text) => text.trimEnd())) {
|
|
1318
|
-
if (line !== "" || out.at(-1) !== "")
|
|
1319
|
-
out.push(line);
|
|
1320
|
-
}
|
|
1321
|
-
while (out.at(-1) === "")
|
|
1322
|
-
out.pop();
|
|
1323
|
-
return out;
|
|
1665
|
+
if (state.failure !== undefined)
|
|
1666
|
+
throw state.failure;
|
|
1667
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
1668
|
+
let output;
|
|
1669
|
+
let text;
|
|
1670
|
+
return {
|
|
1671
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
1672
|
+
chunks,
|
|
1673
|
+
timedOut: state.timedOut,
|
|
1674
|
+
truncated: state.truncated,
|
|
1675
|
+
get output() {
|
|
1676
|
+
return output ??= joined();
|
|
1677
|
+
},
|
|
1678
|
+
get text() {
|
|
1679
|
+
return text ??= (output ??= joined()).toString();
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1324
1682
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1683
|
+
|
|
1684
|
+
// ../kit/src/progress.ts
|
|
1685
|
+
init_style();
|
|
1686
|
+
init_theme();
|
|
1687
|
+
var ESC = String.fromCharCode(27);
|
|
1688
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1689
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1690
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1691
|
+
|
|
1692
|
+
// ../kit/src/ci.ts
|
|
1693
|
+
init_style();
|
|
1694
|
+
|
|
1695
|
+
// ../kit/src/tool.ts
|
|
1696
|
+
init_format();
|
|
1697
|
+
// ../kit/src/cli.ts
|
|
1698
|
+
init_args();
|
|
1699
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1700
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1701
|
+
import process17 from "process";
|
|
1702
|
+
|
|
1703
|
+
// ../kit/src/askpass.ts
|
|
1704
|
+
import process13 from "process";
|
|
1705
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1706
|
+
async function askpassClient(argv) {
|
|
1707
|
+
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
1708
|
+
if (socketPath === undefined)
|
|
1709
|
+
return;
|
|
1710
|
+
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1711
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1712
|
+
let received = "";
|
|
1713
|
+
try {
|
|
1714
|
+
await Bun.connect({
|
|
1715
|
+
unix: socketPath,
|
|
1716
|
+
socket: {
|
|
1717
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1718
|
+
`),
|
|
1719
|
+
data: (_, chunk) => {
|
|
1720
|
+
received += chunk.toString();
|
|
1721
|
+
},
|
|
1722
|
+
close: () => resolve(received),
|
|
1723
|
+
error: () => resolve("")
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
} catch {
|
|
1727
|
+
return 1;
|
|
1728
|
+
}
|
|
1729
|
+
const reply = await promise;
|
|
1730
|
+
if (reply === "")
|
|
1731
|
+
return 1;
|
|
1732
|
+
const { answer } = JSON.parse(reply);
|
|
1733
|
+
if (request.notice === true)
|
|
1734
|
+
return 0;
|
|
1735
|
+
if (answer === undefined)
|
|
1736
|
+
return 1;
|
|
1737
|
+
process13.stdout.write(`${answer}
|
|
1328
1738
|
`);
|
|
1739
|
+
return 0;
|
|
1329
1740
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1741
|
+
|
|
1742
|
+
// ../kit/src/completions.ts
|
|
1743
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1744
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1745
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1746
|
+
set -l current (commandline -ct)
|
|
1747
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1748
|
+
if test "$line" = __files__
|
|
1749
|
+
__fish_complete_path $current
|
|
1750
|
+
else
|
|
1751
|
+
echo $line
|
|
1752
|
+
end
|
|
1753
|
+
end
|
|
1754
|
+
end`;
|
|
1755
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1756
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1757
|
+
local -a lines
|
|
1758
|
+
COMPREPLY=()
|
|
1759
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1760
|
+
for line in "\${lines[@]}"; do
|
|
1761
|
+
if [[ $line == __files__ ]]; then
|
|
1762
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1763
|
+
else
|
|
1764
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1765
|
+
fi
|
|
1766
|
+
done
|
|
1767
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1768
|
+
}`;
|
|
1769
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1770
|
+
local line
|
|
1771
|
+
local -a described plain
|
|
1772
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1773
|
+
if [[ $line == __files__ ]]; then
|
|
1774
|
+
_files
|
|
1775
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1776
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1777
|
+
else
|
|
1778
|
+
plain+=("$line")
|
|
1779
|
+
fi
|
|
1780
|
+
done
|
|
1781
|
+
(( \${#described} )) && _describe -V value described
|
|
1782
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1783
|
+
return 0
|
|
1784
|
+
}`;
|
|
1785
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1786
|
+
if (shell === "fish")
|
|
1787
|
+
return `${header}
|
|
1788
|
+
${FISH_FUNCTION}
|
|
1789
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1790
|
+
`).join("")}`;
|
|
1791
|
+
if (shell === "bash")
|
|
1792
|
+
return `${header}
|
|
1793
|
+
${BASH_FUNCTION}
|
|
1794
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1795
|
+
`;
|
|
1796
|
+
return `${header}
|
|
1797
|
+
${ZSH_FUNCTION}
|
|
1798
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1799
|
+
`;
|
|
1332
1800
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1801
|
+
|
|
1802
|
+
// ../kit/src/notify.ts
|
|
1803
|
+
init_format();
|
|
1804
|
+
init_mode();
|
|
1805
|
+
import process14 from "process";
|
|
1806
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1807
|
+
var CANCELLED = 130;
|
|
1808
|
+
function base64(text) {
|
|
1809
|
+
return Buffer.from(text).toString("base64");
|
|
1339
1810
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
import process17 from "process";
|
|
1345
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1346
|
-
function ignoredFolders(extra = [], where = {}) {
|
|
1347
|
-
const configured = readUserConfig("config", where).ignore;
|
|
1348
|
-
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
1349
|
-
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
1811
|
+
function notification(title, body, env = process14.env) {
|
|
1812
|
+
const id = `kit${process14.pid}`;
|
|
1813
|
+
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\\`];
|
|
1814
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1350
1815
|
}
|
|
1351
|
-
function
|
|
1352
|
-
|
|
1816
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1817
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1818
|
+
return;
|
|
1819
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1353
1820
|
}
|
|
1354
|
-
// ../kit/src/secrets.ts
|
|
1355
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1356
|
-
// ../kit/src/sessions.ts
|
|
1357
|
-
var {Glob } = globalThis.Bun;
|
|
1358
|
-
var SESSION_FILES = new Glob("*.json");
|
|
1359
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1360
|
-
// package.json
|
|
1361
|
-
var version = "0.20.0";
|
|
1362
1821
|
|
|
1363
|
-
// src/
|
|
1364
|
-
|
|
1822
|
+
// ../kit/src/cli.ts
|
|
1823
|
+
init_style();
|
|
1824
|
+
init_text2();
|
|
1365
1825
|
|
|
1366
|
-
// ../kit/src/
|
|
1367
|
-
import {
|
|
1368
|
-
import {
|
|
1369
|
-
import
|
|
1826
|
+
// ../kit/src/usage.ts
|
|
1827
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1828
|
+
import { homedir as homedir4 } from "os";
|
|
1829
|
+
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
1830
|
+
import process16 from "process";
|
|
1370
1831
|
|
|
1371
|
-
// ../kit/src/
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
function wordStart(chars, from) {
|
|
1387
|
-
let at = from;
|
|
1388
|
-
while (at > 0 && !isWord(chars[at - 1]))
|
|
1389
|
-
at--;
|
|
1390
|
-
while (at > 0 && isWord(chars[at - 1]))
|
|
1391
|
-
at--;
|
|
1392
|
-
return at;
|
|
1393
|
-
}
|
|
1394
|
-
function wordEnd(chars, from) {
|
|
1395
|
-
let at = from;
|
|
1396
|
-
while (at < chars.length && !isWord(chars[at]))
|
|
1397
|
-
at++;
|
|
1398
|
-
while (at < chars.length && isWord(chars[at]))
|
|
1399
|
-
at++;
|
|
1400
|
-
return at;
|
|
1401
|
-
}
|
|
1402
|
-
function spacedStart(chars, from) {
|
|
1403
|
-
let at = from;
|
|
1404
|
-
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
1405
|
-
at--;
|
|
1406
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1407
|
-
at--;
|
|
1408
|
-
return at;
|
|
1409
|
-
}
|
|
1410
|
-
function cut2(chars, from, to) {
|
|
1411
|
-
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
1412
|
-
}
|
|
1413
|
-
function insert(chars, at, text) {
|
|
1414
|
-
const typed = [...text];
|
|
1415
|
-
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
1416
|
-
}
|
|
1417
|
-
function editLine(line, key) {
|
|
1418
|
-
const { killed = "", chained = false } = line;
|
|
1419
|
-
const chars = [...line.text];
|
|
1420
|
-
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1421
|
-
const edited = edit(chars, at, key, killed);
|
|
1422
|
-
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1423
|
-
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1424
|
-
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1425
|
-
if (taken === "")
|
|
1426
|
-
return { ...edited, killed, chained };
|
|
1427
|
-
if (!chained)
|
|
1428
|
-
return { ...edited, killed: taken, chained: true };
|
|
1429
|
-
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1430
|
-
}
|
|
1431
|
-
function edit(chars, at, key, killed) {
|
|
1432
|
-
const text = chars.join("");
|
|
1433
|
-
if (typeof key === "object")
|
|
1434
|
-
return insert(chars, at, key.text);
|
|
1435
|
-
switch (key) {
|
|
1436
|
-
case "left":
|
|
1437
|
-
return { text, caret: Math.max(at - 1, 0) };
|
|
1438
|
-
case "right":
|
|
1439
|
-
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1440
|
-
case "wordleft":
|
|
1441
|
-
return { text, caret: wordStart(chars, at) };
|
|
1442
|
-
case "wordright":
|
|
1443
|
-
return { text, caret: wordEnd(chars, at) };
|
|
1444
|
-
case "linestart":
|
|
1445
|
-
return { text, caret: 0 };
|
|
1446
|
-
case "lineend":
|
|
1447
|
-
return { text, caret: chars.length };
|
|
1448
|
-
case "erase":
|
|
1449
|
-
return cut2(chars, Math.max(at - 1, 0), at);
|
|
1450
|
-
case "delete":
|
|
1451
|
-
return cut2(chars, at, Math.min(at + 1, chars.length));
|
|
1452
|
-
case "word":
|
|
1453
|
-
return cut2(chars, spacedStart(chars, at), at);
|
|
1454
|
-
case "killword":
|
|
1455
|
-
return cut2(chars, wordStart(chars, at), at);
|
|
1456
|
-
case "killnext":
|
|
1457
|
-
return cut2(chars, at, wordEnd(chars, at));
|
|
1458
|
-
case "clear":
|
|
1459
|
-
return cut2(chars, 0, at);
|
|
1460
|
-
case "killend":
|
|
1461
|
-
return cut2(chars, at, chars.length);
|
|
1462
|
-
case "yank":
|
|
1463
|
-
return insert(chars, at, killed);
|
|
1832
|
+
// ../kit/src/logs.ts
|
|
1833
|
+
import { lstatSync, openSync } from "fs";
|
|
1834
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
1835
|
+
import { homedir as homedir3, tmpdir } from "os";
|
|
1836
|
+
import { join as join4 } from "path";
|
|
1837
|
+
import process15 from "process";
|
|
1838
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1839
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
1840
|
+
function isPrivateDirectory(path) {
|
|
1841
|
+
try {
|
|
1842
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
1843
|
+
return info !== undefined && info.isDirectory() && info.uid === (process15.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
1844
|
+
} catch {
|
|
1845
|
+
return false;
|
|
1464
1846
|
}
|
|
1465
1847
|
}
|
|
1466
|
-
function
|
|
1467
|
-
const
|
|
1468
|
-
const
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
start--;
|
|
1477
|
-
while (end < cells.length && fits(start, end + 1))
|
|
1478
|
-
end++;
|
|
1479
|
-
const left = start > 0 ? "\u2026" : "";
|
|
1480
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
1481
|
-
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
// ../kit/src/picker/score.ts
|
|
1485
|
-
var MATCH = 16;
|
|
1486
|
-
var CONSECUTIVE = 12;
|
|
1487
|
-
var BOUNDARY2 = 10;
|
|
1488
|
-
var PREFIX = 8;
|
|
1489
|
-
var GAP = 1;
|
|
1490
|
-
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1491
|
-
var UPPER = /\p{Lu}/u;
|
|
1492
|
-
var LOWER = /\p{Ll}/u;
|
|
1493
|
-
var NONE = Number.NEGATIVE_INFINITY;
|
|
1494
|
-
function startsWord(text, index) {
|
|
1495
|
-
if (index === 0)
|
|
1496
|
-
return true;
|
|
1497
|
-
const before = text[index - 1];
|
|
1498
|
-
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1848
|
+
async function privateLogDirectory(name, env = process15.env) {
|
|
1849
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
1850
|
+
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1851
|
+
const path = join4(base, name);
|
|
1852
|
+
try {
|
|
1853
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
1854
|
+
if (isPrivateDirectory(path))
|
|
1855
|
+
return path;
|
|
1856
|
+
} catch {}
|
|
1857
|
+
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
1499
1858
|
}
|
|
1500
|
-
function
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
const haystack = exact ? text : text.toLowerCase();
|
|
1506
|
-
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1859
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
1860
|
+
let names;
|
|
1861
|
+
try {
|
|
1862
|
+
names = await readdir(dir);
|
|
1863
|
+
} catch {
|
|
1507
1864
|
return;
|
|
1508
|
-
const width = haystack.length;
|
|
1509
|
-
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1510
|
-
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1511
|
-
for (let j = 0;j < needle.length; j++) {
|
|
1512
|
-
let run = NONE;
|
|
1513
|
-
let runAt = -1;
|
|
1514
|
-
for (let i = j;i < width; i++) {
|
|
1515
|
-
if (j > 0 && i - 2 >= j - 1) {
|
|
1516
|
-
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1517
|
-
if (candidate > run) {
|
|
1518
|
-
run = candidate;
|
|
1519
|
-
runAt = i - 2;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
if (haystack[i] !== needle[j])
|
|
1523
|
-
continue;
|
|
1524
|
-
const here = MATCH + (startsWord(text, i) ? BOUNDARY2 : 0) + (i === 0 ? PREFIX : 0);
|
|
1525
|
-
if (j === 0) {
|
|
1526
|
-
best[0][i] = here - i * GAP;
|
|
1527
|
-
continue;
|
|
1528
|
-
}
|
|
1529
|
-
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1530
|
-
const skipped = run - (i - 1) * GAP;
|
|
1531
|
-
if (joined > NONE && joined >= skipped) {
|
|
1532
|
-
best[j][i] = joined + here;
|
|
1533
|
-
from[j][i] = i - 1;
|
|
1534
|
-
} else if (skipped > NONE) {
|
|
1535
|
-
best[j][i] = skipped + here;
|
|
1536
|
-
from[j][i] = runAt;
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
const last = best[needle.length - 1];
|
|
1541
|
-
let end = -1;
|
|
1542
|
-
for (let i = 0;i < width; i++) {
|
|
1543
|
-
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1544
|
-
end = i;
|
|
1545
1865
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1866
|
+
for (const name of names) {
|
|
1867
|
+
const path = join4(dir, name);
|
|
1868
|
+
try {
|
|
1869
|
+
const info = await stat(path);
|
|
1870
|
+
if (info.isDirectory())
|
|
1871
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
1872
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
1873
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
1874
|
+
} catch {
|
|
1875
|
+
continue;
|
|
1876
|
+
}
|
|
1552
1877
|
}
|
|
1553
|
-
return { score: last[end], positions };
|
|
1554
1878
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1879
|
+
|
|
1880
|
+
// ../kit/src/usage.ts
|
|
1881
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1882
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1883
|
+
var LONGEST_NAME = 40;
|
|
1884
|
+
var usageError;
|
|
1885
|
+
function noteUsageError(message) {
|
|
1886
|
+
usageError = message;
|
|
1887
|
+
}
|
|
1888
|
+
function stateHome(env = process16.env) {
|
|
1889
|
+
const dir = env.XDG_STATE_HOME;
|
|
1890
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1891
|
+
}
|
|
1892
|
+
function usagePath(env = process16.env) {
|
|
1893
|
+
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1894
|
+
}
|
|
1895
|
+
function usageRecorded(env = process16.env) {
|
|
1896
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1897
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1898
|
+
}
|
|
1899
|
+
function flagNames(argv) {
|
|
1900
|
+
const end = argv.indexOf("--");
|
|
1901
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1902
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1903
|
+
}
|
|
1904
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1905
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1906
|
+
usageError = undefined;
|
|
1907
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1908
|
+
}
|
|
1909
|
+
function recordUsage(entry, env = process16.env) {
|
|
1910
|
+
if (!usageRecorded(env))
|
|
1911
|
+
return;
|
|
1912
|
+
try {
|
|
1913
|
+
const path = usagePath(env);
|
|
1914
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1915
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1916
|
+
`, { mode: 384 });
|
|
1917
|
+
} catch {}
|
|
1565
1918
|
}
|
|
1566
1919
|
|
|
1567
|
-
// ../kit/src/
|
|
1568
|
-
var
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
var RESET = /^\x1B\[0?m$/;
|
|
1572
|
-
var COLUMN_GAP = 2;
|
|
1573
|
-
var PASTE_START = "\x1B[200~";
|
|
1574
|
-
var PASTE_END = "\x1B[201~";
|
|
1575
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1576
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1577
|
-
var WHEEL_LINES = 3;
|
|
1578
|
-
var KEYS = {
|
|
1579
|
-
"\x1B[A": "up",
|
|
1580
|
-
"\x1BOA": "up",
|
|
1581
|
-
"\x10": "up",
|
|
1582
|
-
"\x1B[B": "down",
|
|
1583
|
-
"\x1BOB": "down",
|
|
1584
|
-
"\x0E": "down",
|
|
1585
|
-
"\x1B[5~": "pageup",
|
|
1586
|
-
"\x1B[6~": "pagedown",
|
|
1587
|
-
"\x1B[H": "home",
|
|
1588
|
-
"\x1B[1~": "home",
|
|
1589
|
-
"\x1BOH": "home",
|
|
1590
|
-
"\x1B[F": "end",
|
|
1591
|
-
"\x1B[4~": "end",
|
|
1592
|
-
"\x1BOF": "end",
|
|
1593
|
-
"\r": "enter",
|
|
1594
|
-
"\n": "enter",
|
|
1595
|
-
"\x03": "cancel",
|
|
1596
|
-
"\x1B": "cancel",
|
|
1597
|
-
"\x1B[D": "left",
|
|
1598
|
-
"\x1BOD": "left",
|
|
1599
|
-
"\x1B[C": "right",
|
|
1600
|
-
"\x1BOC": "right",
|
|
1601
|
-
"\x1B[1;5D": "wordleft",
|
|
1602
|
-
"\x1B[1;3D": "wordleft",
|
|
1603
|
-
"\x1Bb": "wordleft",
|
|
1604
|
-
"\x1B[1;5C": "wordright",
|
|
1605
|
-
"\x1B[1;3C": "wordright",
|
|
1606
|
-
"\x1Bf": "wordright",
|
|
1607
|
-
"\x01": "linestart",
|
|
1608
|
-
"\x05": "lineend",
|
|
1609
|
-
"\x7F": "erase",
|
|
1610
|
-
"\x1B[3~": "delete",
|
|
1611
|
-
"\b": "killword",
|
|
1612
|
-
"\x1B\x7F": "killword",
|
|
1613
|
-
"\x1B[3;5~": "killnext",
|
|
1614
|
-
"\x1Bd": "killnext",
|
|
1615
|
-
"\x15": "clear",
|
|
1616
|
-
"\v": "killend",
|
|
1617
|
-
"\x17": "word",
|
|
1618
|
-
"\x19": "yank",
|
|
1619
|
-
"\x1A": "suspend",
|
|
1620
|
-
"\t": "tab",
|
|
1621
|
-
"\x1F": "help",
|
|
1622
|
-
"\x1BOP": "help",
|
|
1623
|
-
"\x1B[11~": "help"
|
|
1920
|
+
// ../kit/src/cli.ts
|
|
1921
|
+
var LEVEL_OPTIONS = {
|
|
1922
|
+
...OUTPUT_OPTIONS,
|
|
1923
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1624
1924
|
};
|
|
1625
|
-
var
|
|
1626
|
-
|
|
1627
|
-
|
|
1925
|
+
var TOP_OPTIONS = {
|
|
1926
|
+
...LEVEL_OPTIONS,
|
|
1927
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1928
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1929
|
+
};
|
|
1930
|
+
function printError(prefix, message, hint, cause) {
|
|
1931
|
+
const colors = paint(process17.stderr);
|
|
1932
|
+
const styled = takesControlCodes(process17.stderr);
|
|
1933
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1934
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1935
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1936
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1628
1937
|
}
|
|
1629
|
-
function
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1938
|
+
function printJsonError(message, hint, cause) {
|
|
1939
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1940
|
+
}
|
|
1941
|
+
function wantsJson(argv) {
|
|
1942
|
+
const end = argv.indexOf("--");
|
|
1943
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1944
|
+
}
|
|
1945
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1946
|
+
if (error instanceof HelpShown)
|
|
1947
|
+
return 0;
|
|
1948
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1949
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1950
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1951
|
+
if (error instanceof Exit && error.code === 2)
|
|
1952
|
+
noteUsageError(error.message);
|
|
1953
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1954
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1955
|
+
return error instanceof Exit ? error.code : 1;
|
|
1956
|
+
}
|
|
1957
|
+
var COMPLETE = "__complete";
|
|
1958
|
+
var FILES = "__files__";
|
|
1959
|
+
async function completingOf(run) {
|
|
1960
|
+
completion.active = true;
|
|
1961
|
+
try {
|
|
1962
|
+
await run([]);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
if (error instanceof Completing)
|
|
1965
|
+
return error;
|
|
1966
|
+
} finally {
|
|
1967
|
+
completion.active = false;
|
|
1646
1968
|
}
|
|
1647
|
-
|
|
1648
|
-
return { text, styles: colored ? styles : undefined };
|
|
1969
|
+
return new Completing({});
|
|
1649
1970
|
}
|
|
1650
|
-
function
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
colored ||= cell.styles !== undefined;
|
|
1663
|
-
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1664
|
-
if (column < searched)
|
|
1665
|
-
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1666
|
-
if (!last) {
|
|
1667
|
-
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1668
|
-
text += " ".repeat(pad);
|
|
1669
|
-
styles.push(...repeat("", pad));
|
|
1670
|
-
}
|
|
1971
|
+
function candidateLine(candidate) {
|
|
1972
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1973
|
+
}
|
|
1974
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
1975
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1976
|
+
const typed = [];
|
|
1977
|
+
let at = 0;
|
|
1978
|
+
while (at < before.length) {
|
|
1979
|
+
const word = before[at];
|
|
1980
|
+
if (word === "--") {
|
|
1981
|
+
typed.push(...before.slice(at + 1));
|
|
1982
|
+
break;
|
|
1671
1983
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1984
|
+
if (!word.startsWith("-"))
|
|
1985
|
+
typed.push(word);
|
|
1986
|
+
else if (takesValue(word))
|
|
1987
|
+
at++;
|
|
1988
|
+
at++;
|
|
1989
|
+
}
|
|
1990
|
+
const last = positionals.at(-1);
|
|
1991
|
+
if (typed.length < positionals.length)
|
|
1992
|
+
return { name: positionals[typed.length], typed };
|
|
1993
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1994
|
+
}
|
|
1995
|
+
async function leafCandidates(run, words) {
|
|
1996
|
+
const completing = await completingOf(run);
|
|
1997
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1998
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1999
|
+
const flag = words.at(-2);
|
|
2000
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
2001
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
2002
|
+
if (option?.type === "string") {
|
|
2003
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
2004
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
2005
|
+
}
|
|
2006
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
2007
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1674
2008
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
return
|
|
1678
|
-
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1679
|
-
if (wheel !== undefined)
|
|
1680
|
-
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1681
|
-
const named = codes.get(sequence);
|
|
1682
|
-
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1683
|
-
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1684
|
-
paste.active = sequence === PASTE_START;
|
|
1685
|
-
return [];
|
|
1686
|
-
}
|
|
1687
|
-
if (paste.active && (sequence === "\r" || sequence === `
|
|
1688
|
-
`))
|
|
1689
|
-
return [];
|
|
1690
|
-
if (key !== undefined)
|
|
1691
|
-
return [key];
|
|
1692
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1693
|
-
});
|
|
2009
|
+
var COMPLETIONS = "--completions";
|
|
2010
|
+
function flagValue([flag = "", ...rest]) {
|
|
2011
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1694
2012
|
}
|
|
1695
|
-
function
|
|
1696
|
-
const
|
|
1697
|
-
|
|
2013
|
+
function printCompletionScript(name, args) {
|
|
2014
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
2015
|
+
if (shell === undefined || args.length !== 1) {
|
|
2016
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
2017
|
+
return 2;
|
|
2018
|
+
}
|
|
2019
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
2020
|
+
return 0;
|
|
1698
2021
|
}
|
|
1699
|
-
function
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
const matches = rank(state.query, searchable);
|
|
1704
|
-
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
2022
|
+
async function printCandidates(found) {
|
|
2023
|
+
for (const line of await found)
|
|
2024
|
+
console.log(line);
|
|
2025
|
+
return 0;
|
|
1705
2026
|
}
|
|
1706
|
-
function
|
|
1707
|
-
|
|
1708
|
-
|
|
2027
|
+
function packageVersion(entry = Bun.main) {
|
|
2028
|
+
let resolved = entry;
|
|
2029
|
+
try {
|
|
2030
|
+
resolved = realpathSync2(entry);
|
|
2031
|
+
} catch {}
|
|
2032
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
2033
|
+
try {
|
|
2034
|
+
const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
|
|
2035
|
+
if (typeof version === "string")
|
|
2036
|
+
return version;
|
|
2037
|
+
} catch {}
|
|
2038
|
+
if (dirname3(dir) === dir)
|
|
2039
|
+
return "0.0.0";
|
|
2040
|
+
}
|
|
1709
2041
|
}
|
|
1710
|
-
function
|
|
1711
|
-
|
|
2042
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2043
|
+
const answered = await askpassClient(argv);
|
|
2044
|
+
if (answered !== undefined)
|
|
2045
|
+
return answered;
|
|
2046
|
+
if (argv[0] === COMPLETE)
|
|
2047
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
2048
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
2049
|
+
return printCompletionScript(name, flagValue(argv));
|
|
2050
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
2051
|
+
console.log(version ?? packageVersion());
|
|
2052
|
+
return 0;
|
|
2053
|
+
}
|
|
2054
|
+
let code;
|
|
2055
|
+
const started = performance.now();
|
|
2056
|
+
try {
|
|
2057
|
+
code = await run(argv);
|
|
2058
|
+
} catch (error) {
|
|
2059
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
2060
|
+
}
|
|
2061
|
+
notifyEnd(name, code, performance.now() - started);
|
|
2062
|
+
if (usage !== false) {
|
|
2063
|
+
try {
|
|
2064
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
2065
|
+
} catch {}
|
|
2066
|
+
}
|
|
2067
|
+
return code;
|
|
1712
2068
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
2069
|
+
|
|
2070
|
+
// ../kit/src/index.ts
|
|
2071
|
+
init_config();
|
|
2072
|
+
|
|
2073
|
+
// ../kit/src/excerpt.ts
|
|
2074
|
+
init_text2();
|
|
2075
|
+
var BASH_ECHO = /^\$ /;
|
|
2076
|
+
var DURATION2 = / \[[\d.]+m?s\]$/;
|
|
2077
|
+
var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
|
|
2078
|
+
var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
|
|
2079
|
+
var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
|
|
2080
|
+
var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
|
|
2081
|
+
var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
2082
|
+
var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
|
|
2083
|
+
var TSC_ERROR = /\berror TS\d+/;
|
|
2084
|
+
var TSC_CONTINUATION = /^\s{2,}\S/;
|
|
2085
|
+
var TSC_FRAME = /^\s*[~^|]/;
|
|
2086
|
+
var TSC_SUMMARY = /^Found \d+ errors?/;
|
|
2087
|
+
var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
|
|
2088
|
+
var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
|
|
2089
|
+
var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
|
|
2090
|
+
var PHPSTAN_NOISE = /^\s*\[OK\]/;
|
|
2091
|
+
var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
|
|
2092
|
+
var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
|
|
2093
|
+
var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
|
|
2094
|
+
var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
|
|
2095
|
+
var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
|
|
2096
|
+
var MAX_TESTS = 10;
|
|
2097
|
+
var MAX_LINES = 100;
|
|
2098
|
+
var TAIL = 30;
|
|
2099
|
+
var bunTest = (lines) => {
|
|
2100
|
+
const seen = new Set;
|
|
2101
|
+
const blocks = [];
|
|
2102
|
+
for (const [index, line] of lines.entries()) {
|
|
2103
|
+
const name = line.replace(DURATION2, "");
|
|
2104
|
+
if (!line.startsWith("(fail) ") || seen.has(name))
|
|
2105
|
+
continue;
|
|
2106
|
+
seen.add(name);
|
|
2107
|
+
if (blocks.length < MAX_TESTS)
|
|
2108
|
+
blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
|
|
2109
|
+
`).trim());
|
|
2110
|
+
}
|
|
2111
|
+
if (blocks.length === 0)
|
|
2112
|
+
return;
|
|
2113
|
+
if (seen.size > MAX_TESTS)
|
|
2114
|
+
blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
|
|
2115
|
+
return [...blocks.join(`
|
|
2116
|
+
|
|
2117
|
+
`).split(`
|
|
2118
|
+
`), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
|
|
2119
|
+
};
|
|
2120
|
+
var bunCheck = (lines) => {
|
|
2121
|
+
const text = lines.join(`
|
|
2122
|
+
`);
|
|
2123
|
+
const blocks = text.match(BUN_CHECK_BLOCK);
|
|
2124
|
+
if (blocks === null)
|
|
2125
|
+
return;
|
|
2126
|
+
const errors = blocks.map((block) => {
|
|
2127
|
+
const { file, line, column, code, message } = bunCheckFields(block);
|
|
2128
|
+
return `${file}:${line}:${column} ${code}: ${message}`;
|
|
2129
|
+
});
|
|
2130
|
+
return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
|
|
2131
|
+
};
|
|
2132
|
+
function bunCheckFields(block) {
|
|
2133
|
+
const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
|
|
2134
|
+
`)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
|
|
2135
|
+
return {
|
|
2136
|
+
file: attributes.file ?? "",
|
|
2137
|
+
line: attributes.line ?? "",
|
|
2138
|
+
column: attributes.column ?? "",
|
|
2139
|
+
code: attributes.code ?? "",
|
|
2140
|
+
message: block.replace(BUN_CHECK_SOURCE, "").split(`
|
|
2141
|
+
`).slice(1, -1).join(`
|
|
2142
|
+
`).trim()
|
|
2143
|
+
};
|
|
1715
2144
|
}
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
2145
|
+
var tsc = (lines) => {
|
|
2146
|
+
const kept = [];
|
|
2147
|
+
let inError = false;
|
|
2148
|
+
for (const line of lines) {
|
|
2149
|
+
if (TSC_ERROR.test(line)) {
|
|
2150
|
+
inError = true;
|
|
2151
|
+
kept.push(line);
|
|
2152
|
+
} else if (TSC_SUMMARY.test(line)) {
|
|
2153
|
+
inError = false;
|
|
2154
|
+
kept.push(line);
|
|
2155
|
+
} else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
|
|
2156
|
+
kept.push(line);
|
|
2157
|
+
} else {
|
|
2158
|
+
inError = false;
|
|
2159
|
+
}
|
|
1727
2160
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
case "help":
|
|
1746
|
-
return { ...state, help: true };
|
|
1747
|
-
case "suspend":
|
|
1748
|
-
return state;
|
|
1749
|
-
case "enter":
|
|
1750
|
-
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1751
|
-
case "tab": {
|
|
1752
|
-
const at = highlighted(state);
|
|
1753
|
-
if (!state.multi || at === undefined)
|
|
1754
|
-
return state;
|
|
1755
|
-
const marked = new Set(state.marked);
|
|
1756
|
-
if (!marked.delete(at))
|
|
1757
|
-
marked.add(at);
|
|
1758
|
-
return move({ ...state, marked }, 1);
|
|
2161
|
+
return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
|
|
2162
|
+
};
|
|
2163
|
+
var eslint = (lines) => {
|
|
2164
|
+
const kept = [];
|
|
2165
|
+
let file = "";
|
|
2166
|
+
let shown = "";
|
|
2167
|
+
for (const line of lines) {
|
|
2168
|
+
if (ESLINT_PROBLEM.test(line)) {
|
|
2169
|
+
if (file !== shown) {
|
|
2170
|
+
kept.push(file);
|
|
2171
|
+
shown = file;
|
|
2172
|
+
}
|
|
2173
|
+
kept.push(line);
|
|
2174
|
+
} else if (ESLINT_SUMMARY.test(line)) {
|
|
2175
|
+
kept.push(line);
|
|
2176
|
+
} else if (line.trim() !== "") {
|
|
2177
|
+
file = line;
|
|
1759
2178
|
}
|
|
1760
2179
|
}
|
|
2180
|
+
return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
|
|
2181
|
+
};
|
|
2182
|
+
var phpstan = (lines) => {
|
|
2183
|
+
const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
|
|
2184
|
+
return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
|
|
2185
|
+
};
|
|
2186
|
+
var php = (lines) => {
|
|
2187
|
+
const start = lines.findIndex((line) => PHP_FAILURES.test(line));
|
|
2188
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2189
|
+
};
|
|
2190
|
+
var vitest = (lines) => {
|
|
2191
|
+
const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
|
|
2192
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2193
|
+
};
|
|
2194
|
+
var playwright = (lines) => {
|
|
2195
|
+
const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
|
|
2196
|
+
return start === -1 ? undefined : lines.slice(start);
|
|
2197
|
+
};
|
|
2198
|
+
var phpCsFixer = (lines) => {
|
|
2199
|
+
const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
|
|
2200
|
+
return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
|
|
2201
|
+
};
|
|
2202
|
+
var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
|
|
2203
|
+
function squeeze(lines) {
|
|
2204
|
+
const out = [];
|
|
2205
|
+
for (const line of lines.map((text) => text.trimEnd())) {
|
|
2206
|
+
if (line !== "" || out.at(-1) !== "")
|
|
2207
|
+
out.push(line);
|
|
2208
|
+
}
|
|
2209
|
+
while (out.at(-1) === "")
|
|
2210
|
+
out.pop();
|
|
2211
|
+
return out;
|
|
1761
2212
|
}
|
|
1762
|
-
function
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2213
|
+
function cut(shown) {
|
|
2214
|
+
return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
|
|
2215
|
+
`) : shown.join(`
|
|
2216
|
+
`);
|
|
2217
|
+
}
|
|
2218
|
+
function recognised(lines, parsers) {
|
|
2219
|
+
return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
|
|
2220
|
+
}
|
|
2221
|
+
function failureExcerpt(output) {
|
|
2222
|
+
const lines = stripAnsi(output).split(`
|
|
2223
|
+
`);
|
|
2224
|
+
if (BASH_ECHO.test(lines[0] ?? ""))
|
|
2225
|
+
lines.shift();
|
|
2226
|
+
return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
|
|
1767
2227
|
}
|
|
2228
|
+
var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
|
|
2229
|
+
|
|
2230
|
+
// ../kit/src/index.ts
|
|
2231
|
+
init_folders();
|
|
2232
|
+
init_format();
|
|
2233
|
+
|
|
2234
|
+
// ../kit/src/git.ts
|
|
2235
|
+
init_args();
|
|
2236
|
+
// ../kit/src/limit.ts
|
|
2237
|
+
init_args();
|
|
2238
|
+
|
|
2239
|
+
// ../kit/src/index.ts
|
|
2240
|
+
init_mode();
|
|
2241
|
+
|
|
2242
|
+
// ../kit/src/report.ts
|
|
2243
|
+
init_style();
|
|
2244
|
+
init_text2();
|
|
2245
|
+
// ../kit/src/secrets.ts
|
|
2246
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2247
|
+
// ../kit/src/sessions.ts
|
|
2248
|
+
var {Glob } = globalThis.Bun;
|
|
2249
|
+
var SESSION_FILES = new Glob("*.json");
|
|
2250
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2251
|
+
|
|
2252
|
+
// ../kit/src/index.ts
|
|
2253
|
+
init_style();
|
|
2254
|
+
init_text2();
|
|
2255
|
+
init_theme();
|
|
2256
|
+
init_user_config();
|
|
2257
|
+
|
|
2258
|
+
// ../kit/src/watch.ts
|
|
2259
|
+
init_args();
|
|
2260
|
+
init_input();
|
|
2261
|
+
init_style();
|
|
2262
|
+
// ../kit/src/workspace-root.ts
|
|
2263
|
+
init_user_config();
|
|
2264
|
+
// package.json
|
|
2265
|
+
var version = "0.21.1";
|
|
2266
|
+
|
|
2267
|
+
// src/j.ts
|
|
2268
|
+
import process26 from "process";
|
|
2269
|
+
|
|
2270
|
+
// ../kit/src/picker.ts
|
|
2271
|
+
init_folders();
|
|
2272
|
+
init_state();
|
|
2273
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
2274
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
2275
|
+
import process23 from "process";
|
|
1768
2276
|
|
|
1769
2277
|
// ../kit/src/picker/terminal.ts
|
|
2278
|
+
init_args();
|
|
2279
|
+
init_job();
|
|
2280
|
+
init_redraw();
|
|
2281
|
+
init_style();
|
|
1770
2282
|
import { openSync as openSync2 } from "fs";
|
|
1771
|
-
import
|
|
2283
|
+
import process22 from "process";
|
|
1772
2284
|
import tty from "tty";
|
|
1773
2285
|
|
|
1774
|
-
// ../kit/src/job.ts
|
|
1775
|
-
import process19 from "process";
|
|
1776
|
-
function stopJob() {
|
|
1777
|
-
process19.kill(0, "SIGTSTP");
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
// ../kit/src/redraw.ts
|
|
1781
|
-
var SYNC_START = "\x1B[?2026h";
|
|
1782
|
-
var SYNC_END = "\x1B[?2026l";
|
|
1783
|
-
function overwrite(lines, columns) {
|
|
1784
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1785
|
-
`);
|
|
1786
|
-
}
|
|
1787
|
-
function rowsTaken(lines, columns) {
|
|
1788
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
2286
|
// ../kit/src/picker/preview.ts
|
|
1792
|
-
import
|
|
2287
|
+
import process21 from "process";
|
|
1793
2288
|
|
|
1794
2289
|
// ../kit/src/shell.ts
|
|
1795
2290
|
var SEPARATORS = new Set([`
|
|
@@ -1858,7 +2353,7 @@ async function runPreview(template, line, signal, hidden = []) {
|
|
|
1858
2353
|
${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
|
|
1859
2354
|
const stop = () => {
|
|
1860
2355
|
try {
|
|
1861
|
-
|
|
2356
|
+
process21.kill(-proc.pid, "SIGKILL");
|
|
1862
2357
|
} catch {
|
|
1863
2358
|
proc.kill();
|
|
1864
2359
|
}
|
|
@@ -1883,7 +2378,12 @@ ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe",
|
|
|
1883
2378
|
return signal.aborted ? [] : previewLines(Buffer.concat(chunks).subarray(0, PREVIEW_BYTES).toString());
|
|
1884
2379
|
}
|
|
1885
2380
|
|
|
2381
|
+
// ../kit/src/picker/terminal.ts
|
|
2382
|
+
init_state();
|
|
2383
|
+
|
|
1886
2384
|
// ../kit/src/picker/view.ts
|
|
2385
|
+
init_line();
|
|
2386
|
+
init_state();
|
|
1887
2387
|
var MIN_HEIGHT = 4;
|
|
1888
2388
|
var PREVIEW_MIN_COLUMNS = 80;
|
|
1889
2389
|
var PREVIEW_MIN_ROWS = 10;
|
|
@@ -2016,7 +2516,7 @@ function openTerminal() {
|
|
|
2016
2516
|
return fail("no terminal to read keys from (/dev/tty)");
|
|
2017
2517
|
}
|
|
2018
2518
|
const keys = Bun.file("/dev/tty").stream().getReader();
|
|
2019
|
-
const out =
|
|
2519
|
+
const out = process22.stderr;
|
|
2020
2520
|
let resize;
|
|
2021
2521
|
async function read(onChunk) {
|
|
2022
2522
|
const decoder = new TextDecoder;
|
|
@@ -2205,9 +2705,9 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2205
2705
|
const ended = new Promise((resolve) => {
|
|
2206
2706
|
finish = resolve;
|
|
2207
2707
|
});
|
|
2208
|
-
|
|
2708
|
+
process22.once("exit", restore);
|
|
2209
2709
|
for (const signal of SIGNALS2)
|
|
2210
|
-
|
|
2710
|
+
process22.once(signal, stop);
|
|
2211
2711
|
try {
|
|
2212
2712
|
terminal.write(`${PASTE_ON}${MOUSE_ON}`);
|
|
2213
2713
|
terminal.listen(onChunk, () => draw(true));
|
|
@@ -2220,8 +2720,8 @@ async function select(rows, settings, terminal = openTerminal()) {
|
|
|
2220
2720
|
await ended;
|
|
2221
2721
|
} finally {
|
|
2222
2722
|
for (const signal of SIGNALS2)
|
|
2223
|
-
|
|
2224
|
-
|
|
2723
|
+
process22.off(signal, stop);
|
|
2724
|
+
process22.off("exit", restore);
|
|
2225
2725
|
restore();
|
|
2226
2726
|
}
|
|
2227
2727
|
return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
|
|
@@ -2235,6 +2735,7 @@ async function previewOf(preview, hidden, signal) {
|
|
|
2235
2735
|
}
|
|
2236
2736
|
|
|
2237
2737
|
// ../kit/src/picker.ts
|
|
2738
|
+
init_score();
|
|
2238
2739
|
var REMEMBERED = 20;
|
|
2239
2740
|
async function pick(rows, options) {
|
|
2240
2741
|
const height = parseHeight(options.height ?? "100%");
|
|
@@ -2263,12 +2764,12 @@ function history(name) {
|
|
|
2263
2764
|
}
|
|
2264
2765
|
}
|
|
2265
2766
|
function runs(name) {
|
|
2266
|
-
return history(name)[
|
|
2767
|
+
return history(name)[process23.cwd()] ?? [];
|
|
2267
2768
|
}
|
|
2268
2769
|
function record(name, run) {
|
|
2269
2770
|
const all = history(name);
|
|
2270
2771
|
const file = historyFile(name);
|
|
2271
|
-
all[
|
|
2772
|
+
all[process23.cwd()] = [run, ...(all[process23.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
|
|
2272
2773
|
mkdirSync2(dirname4(file), { recursive: true });
|
|
2273
2774
|
writeFileSync(file, JSON.stringify(all));
|
|
2274
2775
|
}
|
|
@@ -2291,200 +2792,11 @@ function list(rows) {
|
|
|
2291
2792
|
console.log(JSON.stringify(rows));
|
|
2292
2793
|
}
|
|
2293
2794
|
|
|
2294
|
-
//
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
// ../kit/src/answers.ts
|
|
2298
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
|
|
2299
|
-
import { dirname as dirname5, join as join9 } from "path";
|
|
2300
|
-
var KEPT = 50;
|
|
2301
|
-
function answersFile() {
|
|
2302
|
-
return join9(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2303
|
-
}
|
|
2304
|
-
function stored() {
|
|
2305
|
-
try {
|
|
2306
|
-
const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
|
|
2307
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
2308
|
-
return {};
|
|
2309
|
-
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2310
|
-
} catch {
|
|
2311
|
-
return {};
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
function earlierAnswers(key) {
|
|
2315
|
-
return stored()[key] ?? [];
|
|
2316
|
-
}
|
|
2317
|
-
function rememberAnswer(key, answer) {
|
|
2318
|
-
const all = stored();
|
|
2319
|
-
const file = answersFile();
|
|
2320
|
-
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2321
|
-
try {
|
|
2322
|
-
mkdirSync3(dirname5(file), { recursive: true });
|
|
2323
|
-
writeFileSync2(file, JSON.stringify(all));
|
|
2324
|
-
} catch {}
|
|
2325
|
-
}
|
|
2326
|
-
|
|
2327
|
-
// ../kit/src/prompt.ts
|
|
2328
|
-
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
2329
|
-
var MAX_LISTED = 12;
|
|
2330
|
-
function readKeys(input, paste = { active: false }) {
|
|
2331
|
-
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
2332
|
-
}
|
|
2333
|
-
function roomAfter(question, columns) {
|
|
2334
|
-
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2335
|
-
}
|
|
2336
|
-
function withCaret(colors, line, room, dim = false) {
|
|
2337
|
-
const { before, at, after } = visible(line, room);
|
|
2338
|
-
const tone = dim ? colors.dim : (text) => text;
|
|
2339
|
-
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2340
|
-
}
|
|
2341
|
-
function sharedStart(texts) {
|
|
2342
|
-
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
2343
|
-
let length = first.length;
|
|
2344
|
-
for (const chars of rest) {
|
|
2345
|
-
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
2346
|
-
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
2347
|
-
}
|
|
2348
|
-
return first.slice(0, length).join("");
|
|
2349
|
-
}
|
|
2350
|
-
function listed2(colors, found, columns) {
|
|
2351
|
-
const shared = sharedStart(found);
|
|
2352
|
-
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
2353
|
-
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
2354
|
-
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
2355
|
-
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
2356
|
-
}
|
|
2357
|
-
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2358
|
-
let line = { text: "", caret: 0 };
|
|
2359
|
-
let invalid;
|
|
2360
|
-
let completions = [];
|
|
2361
|
-
const remembered = history === undefined || mask ? undefined : history;
|
|
2362
|
-
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2363
|
-
let recalled = -1;
|
|
2364
|
-
let draft = line;
|
|
2365
|
-
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
2366
|
-
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
2367
|
-
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
2368
|
-
if (state !== "asking")
|
|
2369
|
-
return [answer(colors, question, state, shown())];
|
|
2370
|
-
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2371
|
-
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
2372
|
-
}, (key) => {
|
|
2373
|
-
if (key === "cancel")
|
|
2374
|
-
return "cancel";
|
|
2375
|
-
invalid = undefined;
|
|
2376
|
-
completions = [];
|
|
2377
|
-
if (line.chained === true && endsKills(key))
|
|
2378
|
-
line = { ...line, chained: false };
|
|
2379
|
-
if (key === "tab") {
|
|
2380
|
-
const chars = [...line.text];
|
|
2381
|
-
const before = chars.slice(0, line.caret).join("");
|
|
2382
|
-
const found = complete?.(before) ?? [];
|
|
2383
|
-
const filled = sharedStart(found);
|
|
2384
|
-
if ([...filled].length > [...before].length)
|
|
2385
|
-
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2386
|
-
else
|
|
2387
|
-
completions = found;
|
|
2388
|
-
return;
|
|
2389
|
-
}
|
|
2390
|
-
if (key === "enter") {
|
|
2391
|
-
invalid = validate?.(taken());
|
|
2392
|
-
return invalid === undefined ? "enter" : undefined;
|
|
2393
|
-
}
|
|
2394
|
-
if (key === "up" || key === "down") {
|
|
2395
|
-
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2396
|
-
if (recalled === -1)
|
|
2397
|
-
draft = line;
|
|
2398
|
-
recalled = to;
|
|
2399
|
-
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2400
|
-
line = { ...shown, killed: line.killed ?? "" };
|
|
2401
|
-
return;
|
|
2402
|
-
}
|
|
2403
|
-
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2404
|
-
if (typeof edit === "object" || isEditKey(edit))
|
|
2405
|
-
line = editLine(line, edit);
|
|
2406
|
-
return;
|
|
2407
|
-
});
|
|
2408
|
-
if (!accepted)
|
|
2409
|
-
return;
|
|
2410
|
-
if (remembered !== undefined && taken() !== "")
|
|
2411
|
-
rememberAnswer(remembered, taken());
|
|
2412
|
-
return taken();
|
|
2413
|
-
}
|
|
2414
|
-
function answer(colors, question, state, picked) {
|
|
2415
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2416
|
-
}
|
|
2417
|
-
async function ask(question, { hint, terminal = process23 }, render, press) {
|
|
2418
|
-
const { stdin, stderr } = terminal;
|
|
2419
|
-
if (!isInteractive(terminal))
|
|
2420
|
-
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
2421
|
-
const colors = paint(stderr);
|
|
2422
|
-
let current = "asking";
|
|
2423
|
-
let outcome;
|
|
2424
|
-
const columns = () => stderr.columns || 80;
|
|
2425
|
-
const draw = (state, last = false) => {
|
|
2426
|
-
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2427
|
-
const rows = rowsTaken(frame, columns());
|
|
2428
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2429
|
-
current = state;
|
|
2430
|
-
};
|
|
2431
|
-
const redraw = () => draw(current);
|
|
2432
|
-
const paste = { active: false };
|
|
2433
|
-
const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
|
|
2434
|
-
const suspend = () => {
|
|
2435
|
-
if (stop === undefined)
|
|
2436
|
-
return;
|
|
2437
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2438
|
-
stdin.setRawMode(false);
|
|
2439
|
-
stop();
|
|
2440
|
-
stdin.setRawMode(true);
|
|
2441
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2442
|
-
};
|
|
2443
|
-
try {
|
|
2444
|
-
stderr.on?.("resize", redraw);
|
|
2445
|
-
stdin.setRawMode(true);
|
|
2446
|
-
stdin.resume();
|
|
2447
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2448
|
-
draw("asking");
|
|
2449
|
-
return await new Promise((resolve) => {
|
|
2450
|
-
function onData(data) {
|
|
2451
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
2452
|
-
if (key === "suspend") {
|
|
2453
|
-
suspend();
|
|
2454
|
-
continue;
|
|
2455
|
-
}
|
|
2456
|
-
const pressed = press(key);
|
|
2457
|
-
if (pressed !== undefined) {
|
|
2458
|
-
settle(pressed);
|
|
2459
|
-
return;
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
draw("asking");
|
|
2463
|
-
}
|
|
2464
|
-
function onEnd() {
|
|
2465
|
-
settle("cancel");
|
|
2466
|
-
}
|
|
2467
|
-
function settle(settled) {
|
|
2468
|
-
outcome = settled;
|
|
2469
|
-
stdin.off("data", onData);
|
|
2470
|
-
stdin.off("end", onEnd);
|
|
2471
|
-
resolve(settled === "enter");
|
|
2472
|
-
}
|
|
2473
|
-
stdin.on("data", onData);
|
|
2474
|
-
stdin.on("end", onEnd);
|
|
2475
|
-
});
|
|
2476
|
-
} finally {
|
|
2477
|
-
stderr.off?.("resize", redraw);
|
|
2478
|
-
draw(outcome ?? "cancel", true);
|
|
2479
|
-
stderr.write(`
|
|
2480
|
-
\x1B[?25h\x1B[?2004l`);
|
|
2481
|
-
stdin.setRawMode(false);
|
|
2482
|
-
stdin.pause();
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2795
|
+
// src/j.ts
|
|
2796
|
+
init_prompt();
|
|
2485
2797
|
|
|
2486
2798
|
// src/job-picker.ts
|
|
2487
|
-
import
|
|
2799
|
+
import process25 from "process";
|
|
2488
2800
|
|
|
2489
2801
|
// src/jobs.ts
|
|
2490
2802
|
import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync7 } from "fs";
|
|
@@ -2904,7 +3216,7 @@ function labelled(entries) {
|
|
|
2904
3216
|
return new Set(entries.map((entry) => entry.tag)).size > 1;
|
|
2905
3217
|
}
|
|
2906
3218
|
function row(entry, labels, signed) {
|
|
2907
|
-
const colors = paint(
|
|
3219
|
+
const colors = paint(process25.stderr);
|
|
2908
3220
|
const keyed = entry.dir === "." ? entry.name : `${colors.dim(`${entry.dir}/`)}${entry.name}`;
|
|
2909
3221
|
return {
|
|
2910
3222
|
hidden: [entry.kind, entry.dir, entry.name, id(entry)],
|
|
@@ -2918,7 +3230,7 @@ async function pickJob(entries, narrowed = false) {
|
|
|
2918
3230
|
prompt: `${[...new Set(entries.map((entry) => entry.tag))].join("/")}> `,
|
|
2919
3231
|
searched: labels ? 2 : 1,
|
|
2920
3232
|
...narrowed ? { height: heightFor(entries.length) } : {},
|
|
2921
|
-
preview: `${
|
|
3233
|
+
preview: `${process25.execPath} ${process25.argv[1]} --show {1} {2} {3}`
|
|
2922
3234
|
});
|
|
2923
3235
|
return entries.find((candidate) => id(candidate) === picked?.hidden[3]);
|
|
2924
3236
|
}
|
|
@@ -2927,10 +3239,9 @@ async function pickJob(entries, narrowed = false) {
|
|
|
2927
3239
|
var usage2 = `j [name] [args...]
|
|
2928
3240
|
j -
|
|
2929
3241
|
|
|
2930
|
-
Without a name, picks a recipe,
|
|
2931
|
-
\`j -\` runs the last one again with the same arguments, \`j <name> [args...]\` runs without the picker, the words after the name filling the parameters in order
|
|
2932
|
-
The sources are a Justfile, a Makefile,
|
|
2933
|
-
A name is the key behind the folder it runs from, \`api/test\`, bare for this folder. A name several entries share offers them, unless it comes qualified by its runner: \`just:check\`, \`bun:api/test\`.`;
|
|
3242
|
+
Without a name, picks a recipe, script or task of this folder, its parents and its child folders and runs it, the ones run last first; without a terminal it lists them instead.
|
|
3243
|
+
\`j -\` runs the last one again with the same arguments, \`j <name> [args...]\` runs without the picker, the words after the name filling the parameters in order.
|
|
3244
|
+
The sources are a Justfile, a Makefile, package.json and composer.json scripts, deno tasks, a Taskfile, mise tasks and a pyproject; a name several share offers them, unless qualified by its runner (\`just:check\`).`;
|
|
2934
3245
|
var EXITS = [["its own", "the code of the command it ran"], [1, "there is nothing to run here or nothing by that name"]];
|
|
2935
3246
|
var options = {
|
|
2936
3247
|
json: jsonOption("[{ id, key, runner, dir, name, doc, parameters }]")
|
|
@@ -2939,7 +3250,7 @@ function preview(kind, dir, name) {
|
|
|
2939
3250
|
const entry = readKind(kind, dir).find((candidate) => candidate.name === name);
|
|
2940
3251
|
if (entry === undefined)
|
|
2941
3252
|
return;
|
|
2942
|
-
const colors = paint(
|
|
3253
|
+
const colors = paint(process26.stdout);
|
|
2943
3254
|
console.log(`${colors.dim(`$ ${dir === "." ? "" : `env -C ${dir} `}`)}${colors.bold([...entry.runner, entry.name].join(" "))}
|
|
2944
3255
|
`);
|
|
2945
3256
|
if (entry.body !== undefined)
|
|
@@ -2954,7 +3265,7 @@ function names(found) {
|
|
|
2954
3265
|
return same.length === 1 ? [[name, described(same[0])]] : [[name, same.map((entry) => entry.tag).join(", ")], ...same.map((entry) => [id(entry), described(entry)])];
|
|
2955
3266
|
});
|
|
2956
3267
|
}
|
|
2957
|
-
function
|
|
3268
|
+
function completions2() {
|
|
2958
3269
|
try {
|
|
2959
3270
|
return [...names(everything()), ["-", "the last one again, with its arguments"]];
|
|
2960
3271
|
} catch {
|
|
@@ -2972,7 +3283,7 @@ function listed3(found) {
|
|
|
2972
3283
|
}));
|
|
2973
3284
|
}
|
|
2974
3285
|
function listing(found) {
|
|
2975
|
-
const colors = paint(
|
|
3286
|
+
const colors = paint(process26.stdout);
|
|
2976
3287
|
const labels = labelled(found);
|
|
2977
3288
|
return table(found.map((entry) => [...labels ? [entry.tag] : [], key(entry), signature(entry), colors.dim(entry.doc ?? "")]));
|
|
2978
3289
|
}
|
|
@@ -3011,7 +3322,7 @@ async function j2(argv) {
|
|
|
3011
3322
|
const parsed = last ? { values: {}, positionals: ["-"], rest: args.slice(1) } : parse(args, usage2, options, {
|
|
3012
3323
|
exits: EXITS,
|
|
3013
3324
|
positionals: ["[name]"],
|
|
3014
|
-
candidates: { "[name]":
|
|
3325
|
+
candidates: { "[name]": completions2 },
|
|
3015
3326
|
trailing: true,
|
|
3016
3327
|
replaces: "reading the Justfile, Makefile, package.json scripts or composer scripts to find what to run, then retyping it",
|
|
3017
3328
|
examples: ["j", ["j test", "run the test recipe, script or task"], ["j api/test --watch", "a child folder's, with an argument"], ["j just:check", "the one of a runner, when several share the name"], ["j -", "the last one again"]]
|
|
@@ -3073,4 +3384,4 @@ async function j2(argv) {
|
|
|
3073
3384
|
}
|
|
3074
3385
|
|
|
3075
3386
|
// src/j-cli.ts
|
|
3076
|
-
|
|
3387
|
+
process27.exitCode = await runMain({ name: "j", version, run: j2 });
|