@kaynooo/cli-wait 0.12.1 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +457 -173
- package/dist/slot-cli.js +460 -178
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -1,21 +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
|
-
import process20 from "process";
|
|
7
|
-
// ../kit/src/args.ts
|
|
8
|
-
import process9 from "process";
|
|
9
|
-
import { parseArgs } from "util";
|
|
10
|
-
|
|
11
|
-
// ../kit/src/format.ts
|
|
12
|
-
import process7 from "process";
|
|
13
|
-
|
|
14
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
15
|
-
var N = new Map;
|
|
16
|
-
var Nt = /\s+\S*$/;
|
|
17
|
-
var Y = /\s/;
|
|
18
|
-
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 = "...") {
|
|
19
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
20
18
|
if (t.length <= e)
|
|
21
19
|
return t;
|
|
@@ -26,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
26
24
|
c = c.trimEnd();
|
|
27
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
28
26
|
}
|
|
29
|
-
var
|
|
30
|
-
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
|
+
});
|
|
31
40
|
|
|
32
41
|
// ../kit/src/mode.ts
|
|
33
42
|
import process2 from "process";
|
|
34
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
35
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
36
43
|
function isSet(value) {
|
|
37
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
38
45
|
}
|
|
@@ -46,12 +53,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
46
53
|
return "terminal";
|
|
47
54
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
48
55
|
}
|
|
56
|
+
var MODES, AGENT_VARIABLES;
|
|
57
|
+
var init_mode = __esm(() => {
|
|
58
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
59
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
60
|
+
});
|
|
49
61
|
|
|
50
|
-
//
|
|
51
|
-
import process6 from "process";
|
|
52
|
-
|
|
53
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
54
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
62
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
55
63
|
function b(r) {
|
|
56
64
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
57
65
|
if (!G2.test(e))
|
|
@@ -62,11 +70,6 @@ function b(r) {
|
|
|
62
70
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
63
71
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
64
72
|
}
|
|
65
|
-
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") => {
|
|
66
|
-
let [l, n, c] = b(r);
|
|
67
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
68
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
69
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
70
73
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
71
74
|
if (e.FORCE_COLOR !== undefined)
|
|
72
75
|
return h.has(e.FORCE_COLOR);
|
|
@@ -80,7 +83,7 @@ function f(r, e = []) {
|
|
|
80
83
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
81
84
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
82
85
|
return new Proxy(c, { get(t, i) {
|
|
83
|
-
let a =
|
|
86
|
+
let a = B[i];
|
|
84
87
|
if (Array.isArray(a)) {
|
|
85
88
|
let s = g.get(i);
|
|
86
89
|
if (s === undefined)
|
|
@@ -103,13 +106,21 @@ function f(r, e = []) {
|
|
|
103
106
|
function Fe(r = {}) {
|
|
104
107
|
return f(r);
|
|
105
108
|
}
|
|
106
|
-
var
|
|
109
|
+
var G2, B, h, o;
|
|
110
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
111
|
+
G2 = /^[a-f0-9]+$/i;
|
|
112
|
+
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") => {
|
|
113
|
+
let [l, n, c] = b(r);
|
|
114
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
115
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
116
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
117
|
+
o = Fe();
|
|
118
|
+
});
|
|
107
119
|
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
import process5 from "process";
|
|
120
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
121
|
+
var init_colors = __esm(() => {
|
|
122
|
+
init_chunk_x450vn3m();
|
|
123
|
+
});
|
|
113
124
|
|
|
114
125
|
// ../kit/src/config.ts
|
|
115
126
|
import { existsSync } from "fs";
|
|
@@ -125,15 +136,21 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
125
136
|
return;
|
|
126
137
|
}
|
|
127
138
|
}
|
|
139
|
+
var init_config = __esm(() => {
|
|
140
|
+
init_args();
|
|
141
|
+
});
|
|
128
142
|
|
|
129
143
|
// ../kit/src/user-config.ts
|
|
130
144
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
131
145
|
import { homedir } from "os";
|
|
132
|
-
import { join as join2 } from "path";
|
|
146
|
+
import { isAbsolute, join as join2 } from "path";
|
|
133
147
|
import process4 from "process";
|
|
148
|
+
function xdgFolder(value, fallback) {
|
|
149
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
150
|
+
}
|
|
134
151
|
function configBase(where = {}) {
|
|
135
152
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
136
|
-
return xdg
|
|
153
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
137
154
|
}
|
|
138
155
|
function userConfigPath(bin, where = {}) {
|
|
139
156
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -160,36 +177,18 @@ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
|
|
|
160
177
|
const value = readUserConfig(bin, where, legacy)[key];
|
|
161
178
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
|
|
162
179
|
}
|
|
180
|
+
var init_user_config = () => {};
|
|
163
181
|
|
|
164
182
|
// ../kit/src/theme.ts
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
170
|
-
bins: {},
|
|
171
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
172
|
-
};
|
|
173
|
-
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" };
|
|
174
|
-
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" };
|
|
175
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
176
|
-
var PRESETS = {
|
|
177
|
-
default: {},
|
|
178
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
179
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
180
|
-
ascii: { glyphs: ASCII }
|
|
181
|
-
};
|
|
182
|
-
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"]);
|
|
183
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
184
|
-
var CONTROL = /\p{Cc}/u;
|
|
185
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
186
|
-
var SPACES = /\s+/;
|
|
183
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
184
|
+
import { homedir as homedir2 } from "os";
|
|
185
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
186
|
+
import process5 from "process";
|
|
187
187
|
function isColorSpec(spec) {
|
|
188
188
|
if (typeof spec === "number")
|
|
189
189
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
190
190
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
191
191
|
}
|
|
192
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
193
192
|
function cubeLevel(channel) {
|
|
194
193
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
195
194
|
}
|
|
@@ -294,7 +293,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
294
293
|
function endsWalk(home) {
|
|
295
294
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
296
295
|
}
|
|
297
|
-
var warned = new Set;
|
|
298
296
|
function warnOnce(message) {
|
|
299
297
|
if (warned.has(message))
|
|
300
298
|
return;
|
|
@@ -331,8 +329,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
331
329
|
}
|
|
332
330
|
return { theme, sources, preset };
|
|
333
331
|
}
|
|
334
|
-
var current;
|
|
335
|
-
var currentKey = "";
|
|
336
332
|
function activeTheme() {
|
|
337
333
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
338
334
|
if (current === undefined || key !== currentKey) {
|
|
@@ -341,9 +337,38 @@ function activeTheme() {
|
|
|
341
337
|
}
|
|
342
338
|
return current;
|
|
343
339
|
}
|
|
340
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
341
|
+
var init_theme = __esm(() => {
|
|
342
|
+
init_config();
|
|
343
|
+
init_user_config();
|
|
344
|
+
ENDS = new Map;
|
|
345
|
+
DEFAULT = {
|
|
346
|
+
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" },
|
|
347
|
+
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" },
|
|
348
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
349
|
+
bins: {},
|
|
350
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
351
|
+
};
|
|
352
|
+
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" };
|
|
353
|
+
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" };
|
|
354
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
355
|
+
PRESETS = {
|
|
356
|
+
default: {},
|
|
357
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
358
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
359
|
+
ascii: { glyphs: ASCII }
|
|
360
|
+
};
|
|
361
|
+
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"]);
|
|
362
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
363
|
+
CONTROL = /\p{Cc}/u;
|
|
364
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
365
|
+
SPACES = /\s+/;
|
|
366
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
367
|
+
warned = new Set;
|
|
368
|
+
});
|
|
344
369
|
|
|
345
370
|
// ../kit/src/style.ts
|
|
346
|
-
|
|
371
|
+
import process6 from "process";
|
|
347
372
|
function takesControlCodes(stream, env = process6.env) {
|
|
348
373
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
349
374
|
}
|
|
@@ -362,14 +387,6 @@ function marked(mark, text, stream, detail, env = process6.env) {
|
|
|
362
387
|
function problem(text, detail) {
|
|
363
388
|
console.error(marked("problem", text, process6.stderr, detail));
|
|
364
389
|
}
|
|
365
|
-
var STATUS_WORDS = {
|
|
366
|
-
passed: ["passed", "success", "succeeded", "ok"],
|
|
367
|
-
failed: ["failed", "failure", "error", "errored"],
|
|
368
|
-
running: ["running", "in_progress", "started", "holding"],
|
|
369
|
-
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
370
|
-
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
371
|
-
};
|
|
372
|
-
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
373
390
|
function statusOf(word) {
|
|
374
391
|
return STATUS_OF.get(word.toLowerCase());
|
|
375
392
|
}
|
|
@@ -380,9 +397,24 @@ function badge(word, stream, env = process6.env) {
|
|
|
380
397
|
const { theme } = activeTheme();
|
|
381
398
|
return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
|
|
382
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
|
+
});
|
|
383
415
|
|
|
384
416
|
// ../kit/src/format.ts
|
|
385
|
-
|
|
417
|
+
import process7 from "process";
|
|
386
418
|
function formatSeconds(total) {
|
|
387
419
|
let rest = Math.max(0, Math.round(total));
|
|
388
420
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -414,10 +446,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
414
446
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
415
447
|
}
|
|
416
448
|
function truncate(text, width) {
|
|
417
|
-
return
|
|
449
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
418
450
|
}
|
|
419
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
420
|
-
var ESCAPE = String.fromCharCode(27);
|
|
421
451
|
function textWidth(text) {
|
|
422
452
|
return Bun.stringWidth(text);
|
|
423
453
|
}
|
|
@@ -466,14 +496,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
466
496
|
function printJson(value) {
|
|
467
497
|
console.log(jsonText(value));
|
|
468
498
|
}
|
|
499
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
500
|
+
var init_format = __esm(() => {
|
|
501
|
+
init_text();
|
|
502
|
+
init_mode();
|
|
503
|
+
init_style();
|
|
504
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
505
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
506
|
+
ESCAPE = String.fromCharCode(27);
|
|
507
|
+
});
|
|
469
508
|
|
|
470
509
|
// ../kit/src/help.ts
|
|
471
510
|
import process8 from "process";
|
|
472
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
473
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
474
|
-
var FULL_STOP = /\.$/;
|
|
475
511
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
476
|
-
|
|
512
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
513
|
+
`);
|
|
514
|
+
const blank = lines.indexOf("");
|
|
515
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
516
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
517
|
+
const colon = synopses[0].indexOf(": ");
|
|
518
|
+
const inline = synopses[0].slice(colon + 2);
|
|
519
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
520
|
+
if (colon !== -1)
|
|
521
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
522
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
523
|
+
`)}`;
|
|
524
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
525
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
526
|
+
return [head, ...lead, ...rest].join(`
|
|
527
|
+
`);
|
|
528
|
+
}
|
|
529
|
+
function prose(line, colors) {
|
|
530
|
+
if (colors.cyan("x") === "x")
|
|
531
|
+
return line;
|
|
532
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
477
533
|
}
|
|
478
534
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
479
535
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -508,7 +564,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
508
564
|
return [];
|
|
509
565
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
510
566
|
}
|
|
511
|
-
var MAX_INLINE_CHOICES = 24;
|
|
512
567
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
513
568
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
514
569
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -523,6 +578,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
523
578
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
524
579
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
525
580
|
}
|
|
581
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
582
|
+
var init_help = __esm(() => {
|
|
583
|
+
init_mode();
|
|
584
|
+
init_style();
|
|
585
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
586
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
587
|
+
FULL_STOP = /\.$/;
|
|
588
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
589
|
+
});
|
|
526
590
|
|
|
527
591
|
// ../kit/src/text.ts
|
|
528
592
|
function distance(a, b) {
|
|
@@ -550,8 +614,9 @@ function closest(name, names) {
|
|
|
550
614
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
551
615
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
552
616
|
}
|
|
617
|
+
var init_text2 = () => {};
|
|
618
|
+
|
|
553
619
|
// ../kit/src/input.ts
|
|
554
|
-
var WHOLE = /^\d+$/;
|
|
555
620
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
556
621
|
if (value === undefined)
|
|
557
622
|
return fallback;
|
|
@@ -560,51 +625,47 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
560
625
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
561
626
|
return number;
|
|
562
627
|
}
|
|
563
|
-
|
|
564
|
-
|
|
628
|
+
function durationMs(text, unit) {
|
|
629
|
+
if (BARE_DURATION.test(text))
|
|
630
|
+
return Number(text) * UNIT_MS[unit];
|
|
631
|
+
if (!DURATION.test(text))
|
|
632
|
+
return 0;
|
|
633
|
+
let ms = 0;
|
|
634
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
635
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
636
|
+
return ms;
|
|
637
|
+
}
|
|
565
638
|
function duration(value, name, fallback, unit = "s") {
|
|
566
639
|
if (value === undefined)
|
|
567
640
|
return fallback;
|
|
568
|
-
const
|
|
569
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
641
|
+
const ms = durationMs(value.trim(), unit);
|
|
570
642
|
if (ms < 1)
|
|
571
643
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
572
644
|
return ms;
|
|
573
645
|
}
|
|
646
|
+
var WHOLE, BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
647
|
+
var init_input = __esm(() => {
|
|
648
|
+
init_args();
|
|
649
|
+
WHOLE = /^\d+$/;
|
|
650
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
651
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
652
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
653
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
654
|
+
});
|
|
574
655
|
|
|
575
656
|
// ../kit/src/args.ts
|
|
576
|
-
|
|
657
|
+
import process9 from "process";
|
|
658
|
+
import { parseArgs } from "util";
|
|
577
659
|
function jsonOption(holds) {
|
|
578
660
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
579
661
|
}
|
|
580
|
-
class Exit extends Error {
|
|
581
|
-
code;
|
|
582
|
-
hint;
|
|
583
|
-
constructor(message, code, hint) {
|
|
584
|
-
super(message);
|
|
585
|
-
this.code = code;
|
|
586
|
-
this.hint = hint;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
662
|
function fail(message, code = 2, hint) {
|
|
590
663
|
throw new Exit(message, code, hint);
|
|
591
664
|
}
|
|
592
|
-
|
|
593
|
-
class UsageError extends Exit {
|
|
594
|
-
constructor(message, hint) {
|
|
595
|
-
super(message, 2, hint);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
665
|
function badUsage(message) {
|
|
599
666
|
throw new UsageError(message);
|
|
600
667
|
}
|
|
601
668
|
|
|
602
|
-
class HelpShown extends Exit {
|
|
603
|
-
constructor() {
|
|
604
|
-
super("help shown", 0);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
669
|
class Completing {
|
|
609
670
|
options;
|
|
610
671
|
positionals;
|
|
@@ -615,11 +676,6 @@ class Completing {
|
|
|
615
676
|
this.candidates = candidates;
|
|
616
677
|
}
|
|
617
678
|
}
|
|
618
|
-
var completion = { active: false };
|
|
619
|
-
var OUTPUT_OPTIONS = {
|
|
620
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
621
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
622
|
-
};
|
|
623
679
|
function applyOutput(color, plain, env = process9.env) {
|
|
624
680
|
const when = plain === true ? "never" : color ?? "auto";
|
|
625
681
|
if (when === "auto")
|
|
@@ -773,7 +829,6 @@ function parseError(error) {
|
|
|
773
829
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
774
830
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
775
831
|
}
|
|
776
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
777
832
|
function nearestOption(message, options, allowNegative) {
|
|
778
833
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
779
834
|
if (typed === undefined)
|
|
@@ -789,6 +844,62 @@ function nearestOption(message, options, allowNegative) {
|
|
|
789
844
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
790
845
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
791
846
|
}
|
|
847
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
848
|
+
var init_args = __esm(() => {
|
|
849
|
+
init_format();
|
|
850
|
+
init_help();
|
|
851
|
+
init_text2();
|
|
852
|
+
init_help();
|
|
853
|
+
init_input();
|
|
854
|
+
DASHES = /^-+/;
|
|
855
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
856
|
+
Exit = class Exit extends Error {
|
|
857
|
+
code;
|
|
858
|
+
hint;
|
|
859
|
+
[EXIT] = true;
|
|
860
|
+
constructor(message, code, hint) {
|
|
861
|
+
super(message);
|
|
862
|
+
this.code = code;
|
|
863
|
+
this.hint = hint;
|
|
864
|
+
}
|
|
865
|
+
static [Symbol.hasInstance](value) {
|
|
866
|
+
if (this !== Exit)
|
|
867
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
868
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
UsageError = class UsageError extends Exit {
|
|
872
|
+
constructor(message, hint) {
|
|
873
|
+
super(message, 2, hint);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
HelpShown = class HelpShown extends Exit {
|
|
877
|
+
constructor() {
|
|
878
|
+
super("help shown", 0);
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
completion = { active: false };
|
|
882
|
+
OUTPUT_OPTIONS = {
|
|
883
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
884
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
885
|
+
};
|
|
886
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// ../kit/src/folders.ts
|
|
890
|
+
var SKIPPED_FOLDERS;
|
|
891
|
+
var init_folders = __esm(() => {
|
|
892
|
+
init_user_config();
|
|
893
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
// src/cli.ts
|
|
897
|
+
import { existsSync as existsSync6 } from "fs";
|
|
898
|
+
import process21 from "process";
|
|
899
|
+
|
|
900
|
+
// ../kit/src/index.ts
|
|
901
|
+
init_args();
|
|
902
|
+
|
|
792
903
|
// ../kit/src/argv.ts
|
|
793
904
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
794
905
|
import { resolve as resolve3 } from "path";
|
|
@@ -813,14 +924,26 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
813
924
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
814
925
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
815
926
|
}
|
|
927
|
+
// ../kit/src/chart.ts
|
|
928
|
+
init_format();
|
|
929
|
+
init_mode();
|
|
930
|
+
init_style();
|
|
931
|
+
init_theme();
|
|
932
|
+
// ../kit/src/ci.ts
|
|
933
|
+
init_args();
|
|
934
|
+
init_format();
|
|
935
|
+
|
|
816
936
|
// ../kit/src/progress.ts
|
|
937
|
+
init_format();
|
|
817
938
|
import process12 from "process";
|
|
818
939
|
|
|
819
940
|
// ../kit/src/process.ts
|
|
941
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
820
942
|
import { constants } from "os";
|
|
821
943
|
import process11 from "process";
|
|
822
944
|
var KILL_GRACE_MS = 2000;
|
|
823
945
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
946
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
824
947
|
function exitCodeOf(code, signal) {
|
|
825
948
|
if (code !== null)
|
|
826
949
|
return code;
|
|
@@ -828,6 +951,21 @@ function exitCodeOf(code, signal) {
|
|
|
828
951
|
return 128 + signal;
|
|
829
952
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
830
953
|
}
|
|
954
|
+
function groupsOf(pid) {
|
|
955
|
+
try {
|
|
956
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
957
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
958
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
959
|
+
} catch {
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
function heardTheTerminal(child) {
|
|
964
|
+
if (child.pid === undefined)
|
|
965
|
+
return false;
|
|
966
|
+
const own = groupsOf("self");
|
|
967
|
+
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
968
|
+
}
|
|
831
969
|
function holdSignals(cleanup) {
|
|
832
970
|
let received;
|
|
833
971
|
let child;
|
|
@@ -846,7 +984,8 @@ function holdSignals(cleanup) {
|
|
|
846
984
|
function onSignal(signal) {
|
|
847
985
|
received = signal;
|
|
848
986
|
if (child !== undefined) {
|
|
849
|
-
|
|
987
|
+
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
988
|
+
child.kill(signal);
|
|
850
989
|
return;
|
|
851
990
|
}
|
|
852
991
|
if (cleanup === undefined)
|
|
@@ -859,10 +998,10 @@ function holdSignals(cleanup) {
|
|
|
859
998
|
process11.on(signal, onSignal);
|
|
860
999
|
return held;
|
|
861
1000
|
}
|
|
862
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1001
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
863
1002
|
const chunks = [];
|
|
864
1003
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
865
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1004
|
+
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 } : {} });
|
|
866
1005
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
867
1006
|
const timers = [];
|
|
868
1007
|
const killGroup = (killing) => {
|
|
@@ -902,12 +1041,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
902
1041
|
stop();
|
|
903
1042
|
continue;
|
|
904
1043
|
}
|
|
1044
|
+
if (state.truncated)
|
|
1045
|
+
continue;
|
|
1046
|
+
let kept = data;
|
|
905
1047
|
if (state.kept + data.length > maxBytes) {
|
|
1048
|
+
let cut = maxBytes - state.kept;
|
|
1049
|
+
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1050
|
+
cut--;
|
|
1051
|
+
kept = data.subarray(0, cut);
|
|
906
1052
|
state.truncated = true;
|
|
907
|
-
continue;
|
|
908
1053
|
}
|
|
909
|
-
state.kept +=
|
|
910
|
-
|
|
1054
|
+
state.kept += kept.length;
|
|
1055
|
+
if (kept.length > 0)
|
|
1056
|
+
chunks.push({ stream: name, data: kept });
|
|
911
1057
|
}
|
|
912
1058
|
};
|
|
913
1059
|
try {
|
|
@@ -924,6 +1070,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
924
1070
|
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
925
1071
|
let output;
|
|
926
1072
|
let text;
|
|
1073
|
+
let stdout;
|
|
927
1074
|
return {
|
|
928
1075
|
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
929
1076
|
chunks,
|
|
@@ -934,11 +1081,16 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
934
1081
|
},
|
|
935
1082
|
get text() {
|
|
936
1083
|
return text ??= (output ??= joined()).toString();
|
|
1084
|
+
},
|
|
1085
|
+
get stdout() {
|
|
1086
|
+
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
937
1087
|
}
|
|
938
1088
|
};
|
|
939
1089
|
}
|
|
940
1090
|
|
|
941
1091
|
// ../kit/src/progress.ts
|
|
1092
|
+
init_style();
|
|
1093
|
+
init_theme();
|
|
942
1094
|
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
943
1095
|
var FRAME_MS = 200;
|
|
944
1096
|
var CLEAR_BELOW = "\r\x1B[J";
|
|
@@ -955,10 +1107,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
955
1107
|
}, print: (text) => void stream.write(`${text}
|
|
956
1108
|
`), stop: () => {
|
|
957
1109
|
return;
|
|
1110
|
+
}, pause: () => () => {
|
|
1111
|
+
return;
|
|
958
1112
|
} };
|
|
959
1113
|
const write = stream.write.bind(stream);
|
|
960
1114
|
let frame = 0;
|
|
961
1115
|
let drawn = false;
|
|
1116
|
+
let paused = false;
|
|
1117
|
+
let stopped = false;
|
|
962
1118
|
const columns = () => {
|
|
963
1119
|
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
964
1120
|
return now === undefined || now === 0 ? 80 : now;
|
|
@@ -969,6 +1125,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
969
1125
|
drawn = false;
|
|
970
1126
|
};
|
|
971
1127
|
const draw = () => {
|
|
1128
|
+
if (paused)
|
|
1129
|
+
return;
|
|
972
1130
|
const width = columns() - 1;
|
|
973
1131
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
974
1132
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
@@ -980,16 +1138,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
980
1138
|
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
981
1139
|
drawn = true;
|
|
982
1140
|
};
|
|
983
|
-
|
|
1141
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
984
1142
|
stream.on?.("resize", draw);
|
|
985
|
-
|
|
986
|
-
|
|
1143
|
+
let restore = interceptOutput(clear);
|
|
1144
|
+
let release = swallowInput();
|
|
987
1145
|
const onExit = () => {
|
|
988
1146
|
clear();
|
|
989
1147
|
release();
|
|
990
1148
|
};
|
|
991
1149
|
const signals = holdSignals(stop);
|
|
992
1150
|
function stop() {
|
|
1151
|
+
stopped = true;
|
|
993
1152
|
clearInterval(timer);
|
|
994
1153
|
stream.off?.("resize", draw);
|
|
995
1154
|
clear();
|
|
@@ -998,6 +1157,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
998
1157
|
process12.off("exit", onExit);
|
|
999
1158
|
signals.release();
|
|
1000
1159
|
}
|
|
1160
|
+
function pause() {
|
|
1161
|
+
if (paused || stopped)
|
|
1162
|
+
return () => {
|
|
1163
|
+
return;
|
|
1164
|
+
};
|
|
1165
|
+
paused = true;
|
|
1166
|
+
clearInterval(timer);
|
|
1167
|
+
stream.off?.("resize", draw);
|
|
1168
|
+
clear();
|
|
1169
|
+
restore();
|
|
1170
|
+
release();
|
|
1171
|
+
return () => {
|
|
1172
|
+
if (!paused || stopped)
|
|
1173
|
+
return;
|
|
1174
|
+
paused = false;
|
|
1175
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1176
|
+
timer.unref();
|
|
1177
|
+
stream.on?.("resize", draw);
|
|
1178
|
+
restore = interceptOutput(clear);
|
|
1179
|
+
release = swallowInput();
|
|
1180
|
+
draw();
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1001
1183
|
timer.unref();
|
|
1002
1184
|
process12.on("exit", onExit);
|
|
1003
1185
|
return {
|
|
@@ -1008,7 +1190,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1008
1190
|
`);
|
|
1009
1191
|
draw();
|
|
1010
1192
|
},
|
|
1011
|
-
stop
|
|
1193
|
+
stop,
|
|
1194
|
+
pause
|
|
1012
1195
|
};
|
|
1013
1196
|
}
|
|
1014
1197
|
function cutToWidth(line, width) {
|
|
@@ -1078,10 +1261,56 @@ function interceptOutput(clear) {
|
|
|
1078
1261
|
}
|
|
1079
1262
|
};
|
|
1080
1263
|
}
|
|
1264
|
+
|
|
1265
|
+
// ../kit/src/ci.ts
|
|
1266
|
+
init_style();
|
|
1267
|
+
|
|
1268
|
+
// ../kit/src/tool.ts
|
|
1269
|
+
init_format();
|
|
1081
1270
|
// ../kit/src/cli.ts
|
|
1082
|
-
|
|
1271
|
+
init_args();
|
|
1272
|
+
import { readFileSync as readFileSync5, realpathSync as realpathSync2 } from "fs";
|
|
1083
1273
|
import { dirname as dirname3, join as join6 } from "path";
|
|
1084
|
-
import
|
|
1274
|
+
import process17 from "process";
|
|
1275
|
+
|
|
1276
|
+
// ../kit/src/askpass.ts
|
|
1277
|
+
import process13 from "process";
|
|
1278
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1279
|
+
async function askpassClient(argv) {
|
|
1280
|
+
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
1281
|
+
if (socketPath === undefined)
|
|
1282
|
+
return;
|
|
1283
|
+
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1284
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1285
|
+
let received = "";
|
|
1286
|
+
try {
|
|
1287
|
+
await Bun.connect({
|
|
1288
|
+
unix: socketPath,
|
|
1289
|
+
socket: {
|
|
1290
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1291
|
+
`),
|
|
1292
|
+
data: (_, chunk) => {
|
|
1293
|
+
received += chunk.toString();
|
|
1294
|
+
},
|
|
1295
|
+
close: () => resolve(received),
|
|
1296
|
+
error: () => resolve("")
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
} catch {
|
|
1300
|
+
return 1;
|
|
1301
|
+
}
|
|
1302
|
+
const reply = await promise;
|
|
1303
|
+
if (reply === "")
|
|
1304
|
+
return 1;
|
|
1305
|
+
const { answer } = JSON.parse(reply);
|
|
1306
|
+
if (request.notice === true)
|
|
1307
|
+
return 0;
|
|
1308
|
+
if (answer === undefined)
|
|
1309
|
+
return 1;
|
|
1310
|
+
process13.stdout.write(`${answer}
|
|
1311
|
+
`);
|
|
1312
|
+
return 0;
|
|
1313
|
+
}
|
|
1085
1314
|
|
|
1086
1315
|
// ../kit/src/completions.ts
|
|
1087
1316
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1144,49 +1373,54 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1144
1373
|
}
|
|
1145
1374
|
|
|
1146
1375
|
// ../kit/src/notify.ts
|
|
1147
|
-
|
|
1376
|
+
init_format();
|
|
1377
|
+
init_mode();
|
|
1378
|
+
import process14 from "process";
|
|
1148
1379
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1149
1380
|
var CANCELLED = 130;
|
|
1150
1381
|
function base64(text) {
|
|
1151
1382
|
return Buffer.from(text).toString("base64");
|
|
1152
1383
|
}
|
|
1153
|
-
function notification(title, body, env =
|
|
1154
|
-
const id = `kit${
|
|
1384
|
+
function notification(title, body, env = process14.env) {
|
|
1385
|
+
const id = `kit${process14.pid}`;
|
|
1155
1386
|
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\\`];
|
|
1156
1387
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1157
1388
|
}
|
|
1158
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1389
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
1159
1390
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1160
1391
|
return;
|
|
1161
1392
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1162
1393
|
}
|
|
1163
1394
|
|
|
1395
|
+
// ../kit/src/cli.ts
|
|
1396
|
+
init_style();
|
|
1397
|
+
init_text2();
|
|
1398
|
+
|
|
1164
1399
|
// ../kit/src/usage.ts
|
|
1165
1400
|
import { appendFileSync, mkdirSync } from "fs";
|
|
1166
1401
|
import { homedir as homedir4 } from "os";
|
|
1167
|
-
import { dirname as dirname2,
|
|
1168
|
-
import
|
|
1402
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
1403
|
+
import process16 from "process";
|
|
1169
1404
|
|
|
1170
1405
|
// ../kit/src/logs.ts
|
|
1406
|
+
init_user_config();
|
|
1171
1407
|
import { lstatSync, openSync } from "fs";
|
|
1172
1408
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
1173
1409
|
import { homedir as homedir3, tmpdir } from "os";
|
|
1174
1410
|
import { join as join4 } from "path";
|
|
1175
|
-
import
|
|
1411
|
+
import process15 from "process";
|
|
1176
1412
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1177
1413
|
var CLI_FOLDER = "kaynooo-cli";
|
|
1178
1414
|
function isPrivateDirectory(path) {
|
|
1179
1415
|
try {
|
|
1180
1416
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
1181
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1417
|
+
return info !== undefined && info.isDirectory() && info.uid === (process15.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
1182
1418
|
} catch {
|
|
1183
1419
|
return false;
|
|
1184
1420
|
}
|
|
1185
1421
|
}
|
|
1186
|
-
async function privateLogDirectory(name, env =
|
|
1187
|
-
const
|
|
1188
|
-
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1189
|
-
const path = join4(base, name);
|
|
1422
|
+
async function privateLogDirectory(name, env = process15.env) {
|
|
1423
|
+
const path = join4(xdgFolder(env.XDG_RUNTIME_DIR, join4(homedir3(), ".cache")), CLI_FOLDER, name);
|
|
1190
1424
|
try {
|
|
1191
1425
|
await mkdir(path, { recursive: true, mode: 448 });
|
|
1192
1426
|
if (isPrivateDirectory(path))
|
|
@@ -1196,6 +1430,7 @@ async function privateLogDirectory(name, env = process14.env) {
|
|
|
1196
1430
|
}
|
|
1197
1431
|
|
|
1198
1432
|
// ../kit/src/usage.ts
|
|
1433
|
+
init_user_config();
|
|
1199
1434
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1200
1435
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1201
1436
|
var LONGEST_NAME = 40;
|
|
@@ -1203,14 +1438,13 @@ var usageError;
|
|
|
1203
1438
|
function noteUsageError(message) {
|
|
1204
1439
|
usageError = message;
|
|
1205
1440
|
}
|
|
1206
|
-
function stateHome(env =
|
|
1207
|
-
|
|
1208
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
1441
|
+
function stateHome(env = process16.env) {
|
|
1442
|
+
return xdgFolder(env.XDG_STATE_HOME, join5(homedir4(), ".local", "state"));
|
|
1209
1443
|
}
|
|
1210
|
-
function usagePath(env =
|
|
1444
|
+
function usagePath(env = process16.env) {
|
|
1211
1445
|
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1212
1446
|
}
|
|
1213
|
-
function usageRecorded(env =
|
|
1447
|
+
function usageRecorded(env = process16.env) {
|
|
1214
1448
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1215
1449
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1216
1450
|
}
|
|
@@ -1219,12 +1453,12 @@ function flagNames(argv) {
|
|
|
1219
1453
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1220
1454
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1221
1455
|
}
|
|
1222
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1456
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1223
1457
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1224
1458
|
usageError = undefined;
|
|
1225
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1459
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1226
1460
|
}
|
|
1227
|
-
function recordUsage(entry, env =
|
|
1461
|
+
function recordUsage(entry, env = process16.env) {
|
|
1228
1462
|
if (!usageRecorded(env))
|
|
1229
1463
|
return;
|
|
1230
1464
|
try {
|
|
@@ -1246,8 +1480,8 @@ var TOP_OPTIONS = {
|
|
|
1246
1480
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1247
1481
|
};
|
|
1248
1482
|
function printError(prefix, message, hint, cause) {
|
|
1249
|
-
const colors = paint(
|
|
1250
|
-
const styled = takesControlCodes(
|
|
1483
|
+
const colors = paint(process17.stderr);
|
|
1484
|
+
const styled = takesControlCodes(process17.stderr);
|
|
1251
1485
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1252
1486
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1253
1487
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1349,7 +1583,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1349
1583
|
} catch {}
|
|
1350
1584
|
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1351
1585
|
try {
|
|
1352
|
-
const { version } = JSON.parse(
|
|
1586
|
+
const { version } = JSON.parse(readFileSync5(join6(dir, "package.json"), "utf8"));
|
|
1353
1587
|
if (typeof version === "string")
|
|
1354
1588
|
return version;
|
|
1355
1589
|
} catch {}
|
|
@@ -1358,6 +1592,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1358
1592
|
}
|
|
1359
1593
|
}
|
|
1360
1594
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1595
|
+
const answered = await askpassClient(argv);
|
|
1596
|
+
if (answered !== undefined)
|
|
1597
|
+
return answered;
|
|
1361
1598
|
if (argv[0] === COMPLETE)
|
|
1362
1599
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1363
1600
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1376,27 +1613,48 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1376
1613
|
notifyEnd(name, code, performance.now() - started);
|
|
1377
1614
|
if (usage !== false) {
|
|
1378
1615
|
try {
|
|
1379
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1616
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1380
1617
|
} catch {}
|
|
1381
1618
|
}
|
|
1382
1619
|
return code;
|
|
1383
1620
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1621
|
+
|
|
1622
|
+
// ../kit/src/index.ts
|
|
1623
|
+
init_config();
|
|
1624
|
+
|
|
1625
|
+
// ../kit/src/excerpt.ts
|
|
1626
|
+
init_text2();
|
|
1627
|
+
|
|
1628
|
+
// ../kit/src/index.ts
|
|
1629
|
+
init_folders();
|
|
1630
|
+
init_format();
|
|
1631
|
+
|
|
1632
|
+
// ../kit/src/git.ts
|
|
1633
|
+
init_args();
|
|
1634
|
+
// ../kit/src/limit.ts
|
|
1635
|
+
init_args();
|
|
1636
|
+
|
|
1637
|
+
// ../kit/src/index.ts
|
|
1638
|
+
init_mode();
|
|
1639
|
+
|
|
1640
|
+
// ../kit/src/report.ts
|
|
1641
|
+
init_style();
|
|
1642
|
+
init_text2();
|
|
1386
1643
|
// ../kit/src/secrets.ts
|
|
1387
1644
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1645
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1388
1646
|
// ../kit/src/sessions.ts
|
|
1389
1647
|
import { homedir as homedir5 } from "os";
|
|
1390
1648
|
import { join as join7 } from "path";
|
|
1391
|
-
import
|
|
1649
|
+
import process18 from "process";
|
|
1392
1650
|
var {Glob } = globalThis.Bun;
|
|
1393
1651
|
var SESSION_FILES = new Glob("*.json");
|
|
1394
1652
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1395
1653
|
async function sessionDirs() {
|
|
1396
1654
|
const home = homedir5();
|
|
1397
1655
|
const dirs = new Set([join7(home, ".claude", "sessions")]);
|
|
1398
|
-
if (
|
|
1399
|
-
dirs.add(join7(
|
|
1656
|
+
if (process18.env.CLAUDE_CONFIG_DIR !== undefined)
|
|
1657
|
+
dirs.add(join7(process18.env.CLAUDE_CONFIG_DIR, "sessions"));
|
|
1400
1658
|
try {
|
|
1401
1659
|
for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
|
|
1402
1660
|
dirs.add(dir);
|
|
@@ -1442,7 +1700,7 @@ async function liveSessions() {
|
|
|
1442
1700
|
}
|
|
1443
1701
|
async function currentSession(sessions) {
|
|
1444
1702
|
const byPid = new Map(sessions.map((session) => [session.pid, session]));
|
|
1445
|
-
let pid =
|
|
1703
|
+
let pid = process18.ppid;
|
|
1446
1704
|
for (let depth = 0;depth < 32 && pid > 1; depth++) {
|
|
1447
1705
|
const session = byPid.get(pid);
|
|
1448
1706
|
if (session !== undefined)
|
|
@@ -1454,6 +1712,19 @@ async function currentSession(sessions) {
|
|
|
1454
1712
|
}
|
|
1455
1713
|
return;
|
|
1456
1714
|
}
|
|
1715
|
+
|
|
1716
|
+
// ../kit/src/index.ts
|
|
1717
|
+
init_style();
|
|
1718
|
+
init_text2();
|
|
1719
|
+
init_theme();
|
|
1720
|
+
init_user_config();
|
|
1721
|
+
|
|
1722
|
+
// ../kit/src/watch.ts
|
|
1723
|
+
init_args();
|
|
1724
|
+
init_input();
|
|
1725
|
+
init_style();
|
|
1726
|
+
// ../kit/src/workspace-root.ts
|
|
1727
|
+
init_user_config();
|
|
1457
1728
|
// src/conditions.ts
|
|
1458
1729
|
import { existsSync as existsSync4, statSync as statSync2 } from "fs";
|
|
1459
1730
|
var TAIL = configuredNumber("wait", "tail", 20);
|
|
@@ -1486,6 +1757,9 @@ class FileWatch {
|
|
|
1486
1757
|
get failing() {
|
|
1487
1758
|
return this.failure !== undefined;
|
|
1488
1759
|
}
|
|
1760
|
+
get failsFirst() {
|
|
1761
|
+
return this.failure?.isFirst === true;
|
|
1762
|
+
}
|
|
1489
1763
|
get exists() {
|
|
1490
1764
|
return existsSync4(this.path);
|
|
1491
1765
|
}
|
|
@@ -1499,7 +1773,7 @@ class FileWatch {
|
|
|
1499
1773
|
continue;
|
|
1500
1774
|
}
|
|
1501
1775
|
if (this.failOn?.test(line.text) === true) {
|
|
1502
|
-
this.failure = { before: this.recent.slice(-AROUND), line, after: [], waited: false };
|
|
1776
|
+
this.failure = { before: this.recent.slice(-AROUND), line, after: [], waited: false, isFirst: !this.matched };
|
|
1503
1777
|
continue;
|
|
1504
1778
|
}
|
|
1505
1779
|
this.recent.push(line);
|
|
@@ -1523,7 +1797,10 @@ class FileWatch {
|
|
|
1523
1797
|
async nextLines() {
|
|
1524
1798
|
if (!existsSync4(this.path))
|
|
1525
1799
|
return;
|
|
1526
|
-
const
|
|
1800
|
+
const stats = statSync2(this.path);
|
|
1801
|
+
if (stats.isDirectory())
|
|
1802
|
+
badUsage(`--file ${this.path} is a folder, not a log file`);
|
|
1803
|
+
const { size, dev, ino } = stats;
|
|
1527
1804
|
const replaced = this.identity !== undefined && (this.identity.dev !== dev || this.identity.ino !== ino);
|
|
1528
1805
|
this.identity = { dev, ino };
|
|
1529
1806
|
if (size < this.offset || replaced) {
|
|
@@ -1536,13 +1813,20 @@ class FileWatch {
|
|
|
1536
1813
|
if (size === this.offset)
|
|
1537
1814
|
return;
|
|
1538
1815
|
const end = Math.min(size, this.offset + SLICE_BYTES);
|
|
1539
|
-
const chunk = this.decoder.decode(await
|
|
1816
|
+
const chunk = this.decoder.decode(await this.slice(end), { stream: true });
|
|
1540
1817
|
this.offset = end;
|
|
1541
1818
|
const pieces = (this.partial + chunk).split(`
|
|
1542
1819
|
`);
|
|
1543
1820
|
this.partial = (pieces.pop() ?? "").slice(0, MAX_LINE);
|
|
1544
1821
|
return pieces.map((text) => ({ number: ++this.number, text: Bun.stripANSI(text.slice(0, MAX_LINE).replace(CARRIAGE_RETURN, "")) }));
|
|
1545
1822
|
}
|
|
1823
|
+
async slice(end) {
|
|
1824
|
+
try {
|
|
1825
|
+
return await Bun.file(this.path).slice(this.offset, end).bytes();
|
|
1826
|
+
} catch (error) {
|
|
1827
|
+
return badUsage(`--file ${this.path} cannot be read (${error.code ?? String(error)})`);
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1546
1830
|
}
|
|
1547
1831
|
async function portProblem(host, port, timeoutMs = PORT_TIMEOUT_MS) {
|
|
1548
1832
|
const attempt = Bun.connect({ hostname: host, port, socket: { data: (socket) => void socket.end() } });
|
|
@@ -1626,9 +1910,9 @@ async function urlCheck(url, timeout, expect = {}) {
|
|
|
1626
1910
|
}
|
|
1627
1911
|
|
|
1628
1912
|
// src/task.ts
|
|
1629
|
-
import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as
|
|
1913
|
+
import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
|
|
1630
1914
|
import { join as join8 } from "path";
|
|
1631
|
-
import
|
|
1915
|
+
import process20 from "process";
|
|
1632
1916
|
var EXITED = /(?:^|\n)\[exited with code (-?\d+)\]\n*$/;
|
|
1633
1917
|
var FAILURE = /\(fail\)|\berror:/i;
|
|
1634
1918
|
var TASK_ID = /^[\w-]+$/;
|
|
@@ -1636,9 +1920,9 @@ var TAIL_BYTES = 256;
|
|
|
1636
1920
|
var LONGEST_FAILURES = 30;
|
|
1637
1921
|
var CARRIAGE_RETURN2 = /\r$/;
|
|
1638
1922
|
function tasksRoot(env) {
|
|
1639
|
-
return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${
|
|
1923
|
+
return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process20.getuid?.() ?? 0}`);
|
|
1640
1924
|
}
|
|
1641
|
-
function taskFile(task, env =
|
|
1925
|
+
function taskFile(task, env = process20.env) {
|
|
1642
1926
|
if (task.includes("/") || task.endsWith(".output"))
|
|
1643
1927
|
return task;
|
|
1644
1928
|
if (!TASK_ID.test(task))
|
|
@@ -1671,7 +1955,7 @@ async function taskEnd(path, lines) {
|
|
|
1671
1955
|
}
|
|
1672
1956
|
function pidAlive(pid) {
|
|
1673
1957
|
try {
|
|
1674
|
-
|
|
1958
|
+
process20.kill(pid, 0);
|
|
1675
1959
|
} catch (error) {
|
|
1676
1960
|
return error.code === "EPERM";
|
|
1677
1961
|
}
|
|
@@ -1679,7 +1963,7 @@ function pidAlive(pid) {
|
|
|
1679
1963
|
}
|
|
1680
1964
|
function isZombie(pid) {
|
|
1681
1965
|
try {
|
|
1682
|
-
const stat =
|
|
1966
|
+
const stat = readFileSync6(`/proc/${pid}/stat`, "utf8");
|
|
1683
1967
|
return stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3) === "Z";
|
|
1684
1968
|
} catch {
|
|
1685
1969
|
return false;
|
|
@@ -1690,8 +1974,7 @@ function isZombie(pid) {
|
|
|
1690
1974
|
var USAGE = `waitfor [options]: waits until a file shows a line, a port listens, a URL answers 2xx, a process exits or a command exits 0
|
|
1691
1975
|
waitfor task <task id | file>: waits for a Claude Code background task to end (waitfor task --help)
|
|
1692
1976
|
|
|
1693
|
-
Every condition given must be met, or with --any the first of them to be; --port and --url may be repeated
|
|
1694
|
-
--json prints {met, ms, line, conditions} once met or on a --fail line, conditions naming each one met as {name, ms}, line being the last --until line or the --fail one as {number, text} (null when none), and the progress lines go to stderr.`;
|
|
1977
|
+
Every condition given must be met, or with --any the first of them to be; --port and --url may be repeated. A --fail line in --file ends the wait at once, and a timeout or a --fail line comes with an excerpt of what was seen last.`;
|
|
1695
1978
|
var TASK_USAGE = `waitfor task [options] <task id | file>: waits for a Claude Code background task to end, then prints its exit code, its last lines and the (fail) and error: lines above them
|
|
1696
1979
|
|
|
1697
1980
|
The task is the id a background Bash call returned, or the path of its .output file.
|
|
@@ -1719,7 +2002,7 @@ var OPTIONS = {
|
|
|
1719
2002
|
interval: { type: "string", description: "how long between two runs of --cmd (1s)" },
|
|
1720
2003
|
any: { type: "boolean", description: "met by the first condition that is, not all of them (needs two)" },
|
|
1721
2004
|
timeout: TIMEOUT,
|
|
1722
|
-
json: jsonOption("{met, ms, line}"),
|
|
2005
|
+
json: jsonOption("{met, ms, line, conditions: [{name, ms}]}, line being the last --until line or the --fail one as {number, text}; the progress lines go to stderr"),
|
|
1723
2006
|
quiet: { type: "boolean", short: "q", description: "no live progress line: only what was met and the failure" }
|
|
1724
2007
|
};
|
|
1725
2008
|
var POLL = 250;
|
|
@@ -1764,7 +2047,7 @@ async function waitTask(args) {
|
|
|
1764
2047
|
const lines = wholeNumber(values.lines, "lines", 20);
|
|
1765
2048
|
const timeout = duration(values.timeout, "timeout", 5 * 60000);
|
|
1766
2049
|
const started = Date.now();
|
|
1767
|
-
const { dim } = paint(
|
|
2050
|
+
const { dim } = paint(process21.stderr);
|
|
1768
2051
|
const region = values.quiet === true ? undefined : liveRegion((spinner) => [`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now() - started))}`]);
|
|
1769
2052
|
let code;
|
|
1770
2053
|
try {
|
|
@@ -1853,7 +2136,7 @@ ${USAGE}`);
|
|
|
1853
2136
|
let isPidLeft = pid !== undefined;
|
|
1854
2137
|
let cmdLeft = values.cmd === undefined ? undefined : "not run yet";
|
|
1855
2138
|
let cmdRanAt = 0;
|
|
1856
|
-
const { dim } = paint(
|
|
2139
|
+
const { dim } = paint(process21.stderr);
|
|
1857
2140
|
const region = values.quiet === true ? undefined : liveRegion((spinner) => {
|
|
1858
2141
|
const waited = dim(formatElapsed(Date.now() - started));
|
|
1859
2142
|
const left = [
|
|
@@ -1937,7 +2220,8 @@ ${numbered(event.excerpt, event.line)}`);
|
|
|
1937
2220
|
pid !== undefined && !isPidLeft,
|
|
1938
2221
|
values.cmd !== undefined && cmdLeft === undefined
|
|
1939
2222
|
];
|
|
1940
|
-
|
|
2223
|
+
const isAllMet = (watch?.done ?? true) && ports.every((probe) => probe.left === undefined) && urls.every((probe) => probe.left === undefined) && !isPidLeft && cmdLeft === undefined;
|
|
2224
|
+
if ((isAny ? isMet.includes(true) : isAllMet) && !(watch?.failsFirst ?? false)) {
|
|
1941
2225
|
if (json)
|
|
1942
2226
|
printJson({ met: true, ms: Date.now() - started, line: matched ?? null, conditions: metAt });
|
|
1943
2227
|
return 0;
|
|
@@ -1969,4 +2253,4 @@ ${numbered(event.excerpt, event.line)}`);
|
|
|
1969
2253
|
last lines of ${watch?.path}:
|
|
1970
2254
|
${numbered(lines)}`}`);
|
|
1971
2255
|
}
|
|
1972
|
-
|
|
2256
|
+
process21.exitCode = await runMain({ name: "waitfor", run: main });
|