@kaynooo/cli-wait 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +351 -107
- package/dist/slot-cli.js +348 -104
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2,17 +2,35 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import { existsSync as
|
|
6
|
-
import
|
|
5
|
+
import { existsSync as existsSync5 } from "fs";
|
|
6
|
+
import process18 from "process";
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process9 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/format.ts
|
|
12
|
-
import
|
|
12
|
+
import process7 from "process";
|
|
13
13
|
|
|
14
|
-
// ../kit/src/
|
|
14
|
+
// ../kit/src/mode.ts
|
|
15
15
|
import process2 from "process";
|
|
16
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
17
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
18
|
+
function isSet(value) {
|
|
19
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
20
|
+
}
|
|
21
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
22
|
+
const chosen = env.KIT_MODE;
|
|
23
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
24
|
+
return chosen;
|
|
25
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
26
|
+
return "agent";
|
|
27
|
+
if (stream.isTTY === true)
|
|
28
|
+
return "terminal";
|
|
29
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ../kit/src/style.ts
|
|
33
|
+
import process6 from "process";
|
|
16
34
|
|
|
17
35
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
18
36
|
function x(s) {
|
|
@@ -275,21 +293,235 @@ function le(i = {}) {
|
|
|
275
293
|
}
|
|
276
294
|
var t = le();
|
|
277
295
|
|
|
296
|
+
// ../kit/src/theme.ts
|
|
297
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
298
|
+
import { homedir as homedir2 } from "os";
|
|
299
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
300
|
+
import process5 from "process";
|
|
301
|
+
|
|
302
|
+
// ../kit/src/config.ts
|
|
303
|
+
import { existsSync } from "fs";
|
|
304
|
+
import { dirname, join, resolve } from "path";
|
|
305
|
+
import process3 from "process";
|
|
306
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
307
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
308
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
309
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
310
|
+
if (found !== undefined)
|
|
311
|
+
return found;
|
|
312
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ../kit/src/user-config.ts
|
|
318
|
+
import { homedir } from "os";
|
|
319
|
+
import { join as join2 } from "path";
|
|
320
|
+
import process4 from "process";
|
|
321
|
+
function configBase(where = {}) {
|
|
322
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
323
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
324
|
+
}
|
|
325
|
+
function userConfigPath(bin, where = {}) {
|
|
326
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ../kit/src/theme.ts
|
|
330
|
+
var DEFAULT = {
|
|
331
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
332
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
|
|
333
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
334
|
+
bins: {}
|
|
335
|
+
};
|
|
336
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
337
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
338
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
|
|
339
|
+
var PRESETS = {
|
|
340
|
+
default: {},
|
|
341
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
342
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
343
|
+
ascii: { glyphs: ASCII }
|
|
344
|
+
};
|
|
345
|
+
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"]);
|
|
346
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
347
|
+
var CONTROL = /\p{Cc}/u;
|
|
348
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
349
|
+
var SPACES = /\s+/;
|
|
350
|
+
function isColorSpec(spec) {
|
|
351
|
+
if (typeof spec === "number")
|
|
352
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
353
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
354
|
+
}
|
|
355
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
356
|
+
function cubeLevel(channel) {
|
|
357
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
358
|
+
}
|
|
359
|
+
function nearest256(hex) {
|
|
360
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
361
|
+
const levels = rgb.map(cubeLevel);
|
|
362
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
363
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
364
|
+
const greyValue = 8 + grey * 10;
|
|
365
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
366
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
367
|
+
}
|
|
368
|
+
function hasTrueColor(env) {
|
|
369
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
370
|
+
}
|
|
371
|
+
function tinted(colors, spec, env = process5.env) {
|
|
372
|
+
if (typeof spec === "number")
|
|
373
|
+
return colors.ansi256(spec);
|
|
374
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
375
|
+
if (HEX.test(token))
|
|
376
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
377
|
+
return chain[token] ?? chain;
|
|
378
|
+
}, colors);
|
|
379
|
+
}
|
|
380
|
+
function isRecord(value) {
|
|
381
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
382
|
+
}
|
|
383
|
+
function readThemeFile(path, warn) {
|
|
384
|
+
try {
|
|
385
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
386
|
+
if (stat === undefined)
|
|
387
|
+
return;
|
|
388
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
389
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
393
|
+
if (isRecord(parsed))
|
|
394
|
+
return parsed;
|
|
395
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
396
|
+
} catch (error) {
|
|
397
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
function applyPreset(theme, name, warn, where) {
|
|
402
|
+
if (name === undefined)
|
|
403
|
+
return;
|
|
404
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
405
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const preset = PRESETS[name];
|
|
409
|
+
Object.assign(theme.colors, preset.colors);
|
|
410
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
411
|
+
if (preset.accents !== undefined)
|
|
412
|
+
theme.accents = [...preset.accents];
|
|
413
|
+
return name;
|
|
414
|
+
}
|
|
415
|
+
function applyFile(theme, file, where, warn) {
|
|
416
|
+
if (isRecord(file.colors)) {
|
|
417
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
418
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
419
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
420
|
+
else if (!isColorSpec(value))
|
|
421
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
422
|
+
else
|
|
423
|
+
theme.colors[key] = value;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (isRecord(file.glyphs)) {
|
|
427
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
428
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
429
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
430
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
431
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
432
|
+
else
|
|
433
|
+
theme.glyphs[key] = value;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
437
|
+
theme.accents = [...file.accents];
|
|
438
|
+
else if (file.accents !== undefined)
|
|
439
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
440
|
+
if (isRecord(file.bins)) {
|
|
441
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
442
|
+
if (isColorSpec(value))
|
|
443
|
+
theme.bins[bin] = value;
|
|
444
|
+
else
|
|
445
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function endsWalk(home) {
|
|
450
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
451
|
+
}
|
|
452
|
+
var warned = new Set;
|
|
453
|
+
function warnOnce(message) {
|
|
454
|
+
if (warned.has(message))
|
|
455
|
+
return;
|
|
456
|
+
warned.add(message);
|
|
457
|
+
console.error(`warning: theme ${message}`);
|
|
458
|
+
}
|
|
459
|
+
function isPath(chosen) {
|
|
460
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
461
|
+
}
|
|
462
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
463
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
464
|
+
const sources = [];
|
|
465
|
+
const chosen = env.KIT_THEME ?? "";
|
|
466
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
467
|
+
if (isPath(chosen))
|
|
468
|
+
wanted.push(resolve2(from, chosen));
|
|
469
|
+
const files = [];
|
|
470
|
+
for (const path of wanted) {
|
|
471
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
472
|
+
if (path !== undefined && file !== undefined)
|
|
473
|
+
files.push({ path, file });
|
|
474
|
+
}
|
|
475
|
+
let preset = "default";
|
|
476
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
477
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
478
|
+
} else {
|
|
479
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
480
|
+
if (named !== undefined)
|
|
481
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
482
|
+
}
|
|
483
|
+
for (const { path, file } of files) {
|
|
484
|
+
applyFile(theme, file, path, warn);
|
|
485
|
+
sources.push(path);
|
|
486
|
+
}
|
|
487
|
+
return { theme, sources, preset };
|
|
488
|
+
}
|
|
489
|
+
var current;
|
|
490
|
+
var currentKey = "";
|
|
491
|
+
function activeTheme() {
|
|
492
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
493
|
+
if (current === undefined || key !== currentKey) {
|
|
494
|
+
current = loadTheme();
|
|
495
|
+
currentKey = key;
|
|
496
|
+
}
|
|
497
|
+
return current;
|
|
498
|
+
}
|
|
499
|
+
|
|
278
500
|
// ../kit/src/style.ts
|
|
279
|
-
function takesControlCodes(stream, env =
|
|
280
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
501
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
502
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
281
503
|
}
|
|
282
|
-
function paint(stream, env =
|
|
504
|
+
function paint(stream, env = process6.env) {
|
|
283
505
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
284
506
|
}
|
|
285
|
-
var
|
|
286
|
-
passed:
|
|
287
|
-
failed:
|
|
288
|
-
running:
|
|
289
|
-
queued:
|
|
290
|
-
skipped:
|
|
507
|
+
var STATUS_WORDS = {
|
|
508
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
509
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
510
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
511
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
512
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
291
513
|
};
|
|
292
|
-
var STATUS_OF = new Map(Object.entries(
|
|
514
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
515
|
+
function statusOf(word) {
|
|
516
|
+
return STATUS_OF.get(word.toLowerCase());
|
|
517
|
+
}
|
|
518
|
+
function badge(word, stream, env = process6.env) {
|
|
519
|
+
const status = statusOf(word);
|
|
520
|
+
if (status === undefined || !takesControlCodes(stream, env))
|
|
521
|
+
return word;
|
|
522
|
+
const { theme } = activeTheme();
|
|
523
|
+
return tinted(paint(stream, env), theme.colors[status], env)(`${theme.glyphs[status]} ${word}`);
|
|
524
|
+
}
|
|
293
525
|
|
|
294
526
|
// ../kit/src/format.ts
|
|
295
527
|
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
@@ -331,15 +563,18 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
331
563
|
function textWidth(text) {
|
|
332
564
|
return Bun.stringWidth(text);
|
|
333
565
|
}
|
|
334
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
566
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
335
567
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
568
|
+
if (outputMode(stream, env) === "agent")
|
|
569
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
570
|
+
`);
|
|
336
571
|
const widths = [];
|
|
337
572
|
for (const row of cells) {
|
|
338
573
|
for (const [index, cell] of row.entries())
|
|
339
574
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
340
575
|
}
|
|
341
576
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
342
|
-
const colors = paint(
|
|
577
|
+
const colors = paint(stream);
|
|
343
578
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
344
579
|
const width = widths[index] ?? 0;
|
|
345
580
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -347,7 +582,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
347
582
|
return `${gap}${cell}`;
|
|
348
583
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
349
584
|
}).join(" ").trimEnd());
|
|
350
|
-
|
|
585
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
586
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
351
587
|
`);
|
|
352
588
|
}
|
|
353
589
|
function narrow(rows, widths, limit) {
|
|
@@ -366,32 +602,35 @@ function narrow(rows, widths, limit) {
|
|
|
366
602
|
}
|
|
367
603
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
368
604
|
}
|
|
605
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
606
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
607
|
+
}
|
|
369
608
|
function printJson(value) {
|
|
370
|
-
console.log(
|
|
609
|
+
console.log(jsonText(value));
|
|
371
610
|
}
|
|
372
611
|
|
|
373
612
|
// ../kit/src/help.ts
|
|
374
|
-
import
|
|
613
|
+
import process8 from "process";
|
|
375
614
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
376
615
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
377
616
|
var FULL_STOP = /\.$/;
|
|
378
|
-
function usageLine(usage, colors = paint(
|
|
617
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
379
618
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
380
619
|
}
|
|
381
|
-
function helpText(usage, options, colors = paint(
|
|
620
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
382
621
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
383
622
|
`);
|
|
384
623
|
}
|
|
385
|
-
function exitRows(exits, colors = paint(
|
|
624
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
386
625
|
if (exits.length === 0)
|
|
387
626
|
return [];
|
|
388
627
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
389
628
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
390
629
|
}
|
|
391
|
-
function replacesRows(replaces, colors = paint(
|
|
392
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
630
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
631
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
393
632
|
}
|
|
394
|
-
function wantsHelpJson(env =
|
|
633
|
+
function wantsHelpJson(env = process8.env) {
|
|
395
634
|
return env.KIT_HELP === "json";
|
|
396
635
|
}
|
|
397
636
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -410,12 +649,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
410
649
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
411
650
|
};
|
|
412
651
|
}
|
|
413
|
-
function exampleRows(examples, colors = paint(
|
|
414
|
-
if (examples.length === 0)
|
|
652
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
653
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
415
654
|
return [];
|
|
416
655
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
417
656
|
}
|
|
418
|
-
function optionRows(options, colors = paint(
|
|
657
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
419
658
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
420
659
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
421
660
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -473,7 +712,6 @@ var DASHES = /^-+/;
|
|
|
473
712
|
function jsonOption(holds) {
|
|
474
713
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
475
714
|
}
|
|
476
|
-
|
|
477
715
|
class Exit extends Error {
|
|
478
716
|
code;
|
|
479
717
|
hint;
|
|
@@ -517,7 +755,7 @@ var OUTPUT_OPTIONS = {
|
|
|
517
755
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
518
756
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
519
757
|
};
|
|
520
|
-
function applyOutput(color, plain, env =
|
|
758
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
521
759
|
const when = plain === true ? "never" : color ?? "auto";
|
|
522
760
|
if (when === "auto")
|
|
523
761
|
return;
|
|
@@ -687,11 +925,11 @@ function nearestOption(message, options, allowNegative) {
|
|
|
687
925
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
688
926
|
}
|
|
689
927
|
// ../kit/src/progress.ts
|
|
690
|
-
import
|
|
928
|
+
import process11 from "process";
|
|
691
929
|
|
|
692
930
|
// ../kit/src/process.ts
|
|
693
931
|
import { constants } from "os";
|
|
694
|
-
import
|
|
932
|
+
import process10 from "process";
|
|
695
933
|
var KILL_GRACE_MS = 2000;
|
|
696
934
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
697
935
|
function exitCodeOf(code, signal) {
|
|
@@ -713,7 +951,7 @@ function holdSignals(cleanup) {
|
|
|
713
951
|
},
|
|
714
952
|
release: () => {
|
|
715
953
|
for (const signal of SIGNALS)
|
|
716
|
-
|
|
954
|
+
process10.off(signal, onSignal);
|
|
717
955
|
}
|
|
718
956
|
};
|
|
719
957
|
function onSignal(signal) {
|
|
@@ -726,10 +964,10 @@ function holdSignals(cleanup) {
|
|
|
726
964
|
return;
|
|
727
965
|
held.release();
|
|
728
966
|
cleanup(signal);
|
|
729
|
-
|
|
967
|
+
process10.kill(process10.pid, signal);
|
|
730
968
|
}
|
|
731
969
|
for (const signal of SIGNALS)
|
|
732
|
-
|
|
970
|
+
process10.on(signal, onSignal);
|
|
733
971
|
return held;
|
|
734
972
|
}
|
|
735
973
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -743,7 +981,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
743
981
|
return;
|
|
744
982
|
try {
|
|
745
983
|
if (grouped)
|
|
746
|
-
|
|
984
|
+
process10.kill(-proc.pid, killing);
|
|
747
985
|
else
|
|
748
986
|
proc.kill(killing);
|
|
749
987
|
} catch {}
|
|
@@ -822,7 +1060,7 @@ var RESET_STYLE = `${ESC}[0m`;
|
|
|
822
1060
|
var CTRL_C = 3;
|
|
823
1061
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
824
1062
|
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
825
|
-
function liveRegion(render, stream =
|
|
1063
|
+
function liveRegion(render, stream = process11.stderr, env = process11.env) {
|
|
826
1064
|
if (!takesControlCodes(stream, env))
|
|
827
1065
|
return { redraw: () => {
|
|
828
1066
|
return;
|
|
@@ -832,25 +1070,28 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
|
|
|
832
1070
|
} };
|
|
833
1071
|
const write = stream.write.bind(stream);
|
|
834
1072
|
let frame = 0;
|
|
835
|
-
let drawn =
|
|
1073
|
+
let drawn = [];
|
|
1074
|
+
const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
|
|
1075
|
+
const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
|
|
836
1076
|
const clear = () => {
|
|
837
|
-
if (drawn > 0)
|
|
838
|
-
write(`${CLEAR_LINE}${LINE_UP.repeat(
|
|
839
|
-
drawn =
|
|
1077
|
+
if (drawn.length > 0)
|
|
1078
|
+
write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
|
|
1079
|
+
drawn = [];
|
|
840
1080
|
};
|
|
841
1081
|
const draw = () => {
|
|
842
|
-
const width = (
|
|
1082
|
+
const width = columns() - 1;
|
|
843
1083
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
844
1084
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
845
1085
|
if (lines.length === 0) {
|
|
846
1086
|
clear();
|
|
847
1087
|
return;
|
|
848
1088
|
}
|
|
849
|
-
write(`${drawn > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(
|
|
1089
|
+
write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
|
|
850
1090
|
`)}`);
|
|
851
|
-
drawn = lines.
|
|
1091
|
+
drawn = lines.map((line) => Bun.stringWidth(line));
|
|
852
1092
|
};
|
|
853
1093
|
const timer = setInterval(draw, FRAME_MS);
|
|
1094
|
+
stream.on?.("resize", draw);
|
|
854
1095
|
const restore = interceptOutput(clear);
|
|
855
1096
|
const release = swallowInput();
|
|
856
1097
|
const onExit = () => {
|
|
@@ -860,14 +1101,15 @@ function liveRegion(render, stream = process7.stderr, env = process7.env) {
|
|
|
860
1101
|
const signals = holdSignals(stop);
|
|
861
1102
|
function stop() {
|
|
862
1103
|
clearInterval(timer);
|
|
1104
|
+
stream.off?.("resize", draw);
|
|
863
1105
|
clear();
|
|
864
1106
|
restore();
|
|
865
1107
|
release();
|
|
866
|
-
|
|
1108
|
+
process11.off("exit", onExit);
|
|
867
1109
|
signals.release();
|
|
868
1110
|
}
|
|
869
1111
|
timer.unref();
|
|
870
|
-
|
|
1112
|
+
process11.on("exit", onExit);
|
|
871
1113
|
return {
|
|
872
1114
|
redraw: draw,
|
|
873
1115
|
print: (text) => {
|
|
@@ -906,14 +1148,14 @@ function cutToWidth(line, width) {
|
|
|
906
1148
|
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
907
1149
|
}
|
|
908
1150
|
function swallowInput() {
|
|
909
|
-
const input =
|
|
1151
|
+
const input = process11.stdin;
|
|
910
1152
|
if (!input.isTTY)
|
|
911
1153
|
return () => {
|
|
912
1154
|
return;
|
|
913
1155
|
};
|
|
914
1156
|
const onData = (data) => {
|
|
915
1157
|
if (data.includes(CTRL_C))
|
|
916
|
-
|
|
1158
|
+
process11.kill(process11.pid, "SIGINT");
|
|
917
1159
|
};
|
|
918
1160
|
input.setRawMode(true);
|
|
919
1161
|
input.on("data", onData);
|
|
@@ -929,7 +1171,7 @@ function swallowInput() {
|
|
|
929
1171
|
};
|
|
930
1172
|
}
|
|
931
1173
|
function interceptOutput(clear) {
|
|
932
|
-
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [
|
|
1174
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
|
|
933
1175
|
const wrapped = targets.map(([target, name]) => {
|
|
934
1176
|
const original = Reflect.get(target, name);
|
|
935
1177
|
const wrapper = (...args) => {
|
|
@@ -947,42 +1189,42 @@ function interceptOutput(clear) {
|
|
|
947
1189
|
};
|
|
948
1190
|
}
|
|
949
1191
|
// ../kit/src/cli.ts
|
|
950
|
-
import { readFileSync, realpathSync } from "fs";
|
|
951
|
-
import { dirname as
|
|
952
|
-
import
|
|
1192
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1193
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
1194
|
+
import process14 from "process";
|
|
953
1195
|
|
|
954
1196
|
// ../kit/src/usage.ts
|
|
955
1197
|
import { appendFileSync, mkdirSync } from "fs";
|
|
956
|
-
import { homedir as
|
|
957
|
-
import { dirname, isAbsolute, join as
|
|
958
|
-
import
|
|
1198
|
+
import { homedir as homedir4 } from "os";
|
|
1199
|
+
import { dirname as dirname2, isAbsolute, join as join5 } from "path";
|
|
1200
|
+
import process13 from "process";
|
|
959
1201
|
|
|
960
1202
|
// ../kit/src/logs.ts
|
|
961
1203
|
import { lstatSync, openSync } from "fs";
|
|
962
1204
|
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
963
|
-
import { homedir, tmpdir } from "os";
|
|
964
|
-
import { join } from "path";
|
|
965
|
-
import
|
|
1205
|
+
import { homedir as homedir3, tmpdir } from "os";
|
|
1206
|
+
import { join as join4 } from "path";
|
|
1207
|
+
import process12 from "process";
|
|
966
1208
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
967
1209
|
var CLI_FOLDER = "kaynooo-cli";
|
|
968
1210
|
function isPrivateDirectory(path) {
|
|
969
1211
|
try {
|
|
970
1212
|
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
971
|
-
return info !== undefined && info.isDirectory() && info.uid === (
|
|
1213
|
+
return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
972
1214
|
} catch {
|
|
973
1215
|
return false;
|
|
974
1216
|
}
|
|
975
1217
|
}
|
|
976
|
-
async function privateLogDirectory(name, env =
|
|
1218
|
+
async function privateLogDirectory(name, env = process12.env) {
|
|
977
1219
|
const runtime = env.XDG_RUNTIME_DIR;
|
|
978
|
-
const base = runtime === undefined || runtime === "" ?
|
|
979
|
-
const path =
|
|
1220
|
+
const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
|
|
1221
|
+
const path = join4(base, name);
|
|
980
1222
|
try {
|
|
981
1223
|
await mkdir(path, { recursive: true, mode: 448 });
|
|
982
1224
|
if (isPrivateDirectory(path))
|
|
983
1225
|
return path;
|
|
984
1226
|
} catch {}
|
|
985
|
-
return mkdtemp(
|
|
1227
|
+
return mkdtemp(join4(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
986
1228
|
}
|
|
987
1229
|
|
|
988
1230
|
// ../kit/src/usage.ts
|
|
@@ -993,14 +1235,14 @@ var usageError;
|
|
|
993
1235
|
function noteUsageError(message) {
|
|
994
1236
|
usageError = message;
|
|
995
1237
|
}
|
|
996
|
-
function stateHome(env =
|
|
1238
|
+
function stateHome(env = process13.env) {
|
|
997
1239
|
const dir = env.XDG_STATE_HOME;
|
|
998
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1240
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
|
|
999
1241
|
}
|
|
1000
|
-
function usagePath(env =
|
|
1001
|
-
return
|
|
1242
|
+
function usagePath(env = process13.env) {
|
|
1243
|
+
return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1002
1244
|
}
|
|
1003
|
-
function usageRecorded(env =
|
|
1245
|
+
function usageRecorded(env = process13.env) {
|
|
1004
1246
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1005
1247
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1006
1248
|
}
|
|
@@ -1014,12 +1256,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
1014
1256
|
usageError = undefined;
|
|
1015
1257
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1016
1258
|
}
|
|
1017
|
-
function recordUsage(entry, env =
|
|
1259
|
+
function recordUsage(entry, env = process13.env) {
|
|
1018
1260
|
if (!usageRecorded(env))
|
|
1019
1261
|
return;
|
|
1020
1262
|
try {
|
|
1021
1263
|
const path = usagePath(env);
|
|
1022
|
-
mkdirSync(
|
|
1264
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1023
1265
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1024
1266
|
`, { mode: 384 });
|
|
1025
1267
|
} catch {}
|
|
@@ -1032,8 +1274,8 @@ var LEVEL_OPTIONS = {
|
|
|
1032
1274
|
};
|
|
1033
1275
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
1034
1276
|
function printError(prefix, message, hint, cause) {
|
|
1035
|
-
const colors = paint(
|
|
1036
|
-
const styled = takesControlCodes(
|
|
1277
|
+
const colors = paint(process14.stderr);
|
|
1278
|
+
const styled = takesControlCodes(process14.stderr);
|
|
1037
1279
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1038
1280
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1039
1281
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1116,17 +1358,17 @@ async function printCandidates(found) {
|
|
|
1116
1358
|
return 0;
|
|
1117
1359
|
}
|
|
1118
1360
|
function packageVersion(entry = Bun.main) {
|
|
1119
|
-
for (let dir =
|
|
1361
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1120
1362
|
try {
|
|
1121
|
-
const { version } = JSON.parse(
|
|
1363
|
+
const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
|
|
1122
1364
|
if (typeof version === "string")
|
|
1123
1365
|
return version;
|
|
1124
1366
|
} catch {}
|
|
1125
|
-
if (
|
|
1367
|
+
if (dirname3(dir) === dir)
|
|
1126
1368
|
return "0.0.0";
|
|
1127
1369
|
}
|
|
1128
1370
|
}
|
|
1129
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1371
|
+
async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
|
|
1130
1372
|
if (argv[0] === COMPLETE)
|
|
1131
1373
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1132
1374
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1146,22 +1388,24 @@ async function runMain({ name, version, run, redact, usage }, argv = process10.a
|
|
|
1146
1388
|
}
|
|
1147
1389
|
return code;
|
|
1148
1390
|
}
|
|
1391
|
+
// ../kit/src/folders.ts
|
|
1392
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1149
1393
|
// ../kit/src/secrets.ts
|
|
1150
1394
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1151
1395
|
// ../kit/src/sessions.ts
|
|
1152
|
-
import { homedir as
|
|
1153
|
-
import { join as
|
|
1154
|
-
import
|
|
1396
|
+
import { homedir as homedir5 } from "os";
|
|
1397
|
+
import { join as join7 } from "path";
|
|
1398
|
+
import process15 from "process";
|
|
1155
1399
|
var {Glob } = globalThis.Bun;
|
|
1156
1400
|
var SESSION_FILES = new Glob("*.json");
|
|
1157
1401
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1158
1402
|
async function sessionDirs() {
|
|
1159
|
-
const home =
|
|
1160
|
-
const dirs = new Set([
|
|
1161
|
-
if (
|
|
1162
|
-
dirs.add(
|
|
1403
|
+
const home = homedir5();
|
|
1404
|
+
const dirs = new Set([join7(home, ".claude", "sessions")]);
|
|
1405
|
+
if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
|
|
1406
|
+
dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
|
|
1163
1407
|
try {
|
|
1164
|
-
for await (const dir of ACCOUNT_DIRS.scan({ cwd:
|
|
1408
|
+
for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
|
|
1165
1409
|
dirs.add(dir);
|
|
1166
1410
|
} catch {}
|
|
1167
1411
|
return [...dirs];
|
|
@@ -1205,7 +1449,7 @@ async function liveSessions() {
|
|
|
1205
1449
|
}
|
|
1206
1450
|
async function currentSession(sessions) {
|
|
1207
1451
|
const byPid = new Map(sessions.map((session) => [session.pid, session]));
|
|
1208
|
-
let pid =
|
|
1452
|
+
let pid = process15.ppid;
|
|
1209
1453
|
for (let depth = 0;depth < 32 && pid > 1; depth++) {
|
|
1210
1454
|
const session = byPid.get(pid);
|
|
1211
1455
|
if (session !== undefined)
|
|
@@ -1218,7 +1462,7 @@ async function currentSession(sessions) {
|
|
|
1218
1462
|
return;
|
|
1219
1463
|
}
|
|
1220
1464
|
// src/conditions.ts
|
|
1221
|
-
import { existsSync, statSync } from "fs";
|
|
1465
|
+
import { existsSync as existsSync3, statSync as statSync2 } from "fs";
|
|
1222
1466
|
var TAIL = 20;
|
|
1223
1467
|
var AROUND = 5;
|
|
1224
1468
|
var CARRIAGE_RETURN = /\r$/;
|
|
@@ -1250,7 +1494,7 @@ class FileWatch {
|
|
|
1250
1494
|
return this.failure !== undefined;
|
|
1251
1495
|
}
|
|
1252
1496
|
get exists() {
|
|
1253
|
-
return
|
|
1497
|
+
return existsSync3(this.path);
|
|
1254
1498
|
}
|
|
1255
1499
|
async poll() {
|
|
1256
1500
|
const events = [];
|
|
@@ -1284,9 +1528,9 @@ class FileWatch {
|
|
|
1284
1528
|
return this.recent;
|
|
1285
1529
|
}
|
|
1286
1530
|
async nextLines() {
|
|
1287
|
-
if (!
|
|
1531
|
+
if (!existsSync3(this.path))
|
|
1288
1532
|
return;
|
|
1289
|
-
const { size, dev, ino } =
|
|
1533
|
+
const { size, dev, ino } = statSync2(this.path);
|
|
1290
1534
|
const replaced = this.identity !== undefined && (this.identity.dev !== dev || this.identity.ino !== ino);
|
|
1291
1535
|
this.identity = { dev, ino };
|
|
1292
1536
|
if (size < this.offset || replaced) {
|
|
@@ -1342,9 +1586,9 @@ async function urlCheck(url, timeout) {
|
|
|
1342
1586
|
}
|
|
1343
1587
|
|
|
1344
1588
|
// src/task.ts
|
|
1345
|
-
import { existsSync as
|
|
1346
|
-
import { join as
|
|
1347
|
-
import
|
|
1589
|
+
import { existsSync as existsSync4, lstatSync as lstatSync2, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
|
|
1590
|
+
import { join as join8 } from "path";
|
|
1591
|
+
import process17 from "process";
|
|
1348
1592
|
var EXITED = /(?:^|\n)\[exited with code (-?\d+)\]\n*$/;
|
|
1349
1593
|
var FAILURE = /\(fail\)|\berror:/i;
|
|
1350
1594
|
var TASK_ID = /^[\w-]+$/;
|
|
@@ -1352,29 +1596,29 @@ var TAIL_BYTES = 256;
|
|
|
1352
1596
|
var LONGEST_FAILURES = 30;
|
|
1353
1597
|
var CARRIAGE_RETURN2 = /\r$/;
|
|
1354
1598
|
function tasksRoot(env) {
|
|
1355
|
-
return
|
|
1599
|
+
return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process17.getuid?.() ?? 0}`);
|
|
1356
1600
|
}
|
|
1357
|
-
function taskFile(task, env =
|
|
1601
|
+
function taskFile(task, env = process17.env) {
|
|
1358
1602
|
if (task.includes("/") || task.endsWith(".output"))
|
|
1359
1603
|
return task;
|
|
1360
1604
|
if (!TASK_ID.test(task))
|
|
1361
1605
|
return;
|
|
1362
1606
|
const root = tasksRoot(env);
|
|
1363
|
-
const found =
|
|
1364
|
-
return found.length === 0 ? undefined :
|
|
1607
|
+
const found = existsSync4(root) ? [...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({ cwd: root, onlyFiles: false })] : [];
|
|
1608
|
+
return found.length === 0 ? undefined : join8(root, found[0] ?? "");
|
|
1365
1609
|
}
|
|
1366
1610
|
function isTranscript(path) {
|
|
1367
|
-
return
|
|
1611
|
+
return existsSync4(path) && lstatSync2(path).isSymbolicLink() && path.endsWith(".output");
|
|
1368
1612
|
}
|
|
1369
1613
|
async function exitCode(path) {
|
|
1370
|
-
if (!
|
|
1614
|
+
if (!existsSync4(path))
|
|
1371
1615
|
return;
|
|
1372
|
-
const size =
|
|
1616
|
+
const size = statSync3(path).size;
|
|
1373
1617
|
const found = EXITED.exec(await Bun.file(path).slice(Math.max(0, size - TAIL_BYTES), size).text());
|
|
1374
1618
|
return found === null ? undefined : Number(found[1]);
|
|
1375
1619
|
}
|
|
1376
1620
|
async function taskEnd(path, lines) {
|
|
1377
|
-
if (!
|
|
1621
|
+
if (!existsSync4(path))
|
|
1378
1622
|
return { failures: [], tail: [] };
|
|
1379
1623
|
const text = (await Bun.file(path).text()).replace(EXITED, "");
|
|
1380
1624
|
const all = text.split(`
|
|
@@ -1387,7 +1631,7 @@ async function taskEnd(path, lines) {
|
|
|
1387
1631
|
}
|
|
1388
1632
|
function pidAlive(pid) {
|
|
1389
1633
|
try {
|
|
1390
|
-
|
|
1634
|
+
process17.kill(pid, 0);
|
|
1391
1635
|
} catch (error) {
|
|
1392
1636
|
return error.code === "EPERM";
|
|
1393
1637
|
}
|
|
@@ -1395,7 +1639,7 @@ function pidAlive(pid) {
|
|
|
1395
1639
|
}
|
|
1396
1640
|
function isZombie(pid) {
|
|
1397
1641
|
try {
|
|
1398
|
-
const stat =
|
|
1642
|
+
const stat = readFileSync3(`/proc/${pid}/stat`, "utf8");
|
|
1399
1643
|
return stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3) === "Z";
|
|
1400
1644
|
} catch {
|
|
1401
1645
|
return false;
|
|
@@ -1471,14 +1715,14 @@ async function waitTask(args) {
|
|
|
1471
1715
|
const path = taskFile(task);
|
|
1472
1716
|
if (path === undefined)
|
|
1473
1717
|
fail(`no background task ${task}: give the id a background Bash call returned, or the path of its .output file`);
|
|
1474
|
-
if (!
|
|
1718
|
+
if (!existsSync5(path))
|
|
1475
1719
|
fail(`no output file ${path}: ${task} is no background task of this machine`);
|
|
1476
1720
|
if (isTranscript(path))
|
|
1477
1721
|
fail(`${task} is a subagent, whose end its notification reports: waitfor task waits on a background Bash task`);
|
|
1478
1722
|
const lines = wholeNumber(values.lines, "lines", 20);
|
|
1479
1723
|
const timeout = duration(values.timeout, "timeout", 5 * 60000);
|
|
1480
1724
|
const started = Date.now();
|
|
1481
|
-
const { dim } = paint(
|
|
1725
|
+
const { dim } = paint(process18.stderr);
|
|
1482
1726
|
const region = values.quiet === true ? undefined : liveRegion((spinner) => [`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now() - started))}`]);
|
|
1483
1727
|
let code;
|
|
1484
1728
|
try {
|
|
@@ -1549,7 +1793,7 @@ ${USAGE}`);
|
|
|
1549
1793
|
let isPidLeft = pid !== undefined;
|
|
1550
1794
|
let cmdLeft = values.cmd === undefined ? undefined : "not run yet";
|
|
1551
1795
|
let cmdRanAt = 0;
|
|
1552
|
-
const { dim } = paint(
|
|
1796
|
+
const { dim } = paint(process18.stderr);
|
|
1553
1797
|
const region = values.quiet === true ? undefined : liveRegion((spinner) => {
|
|
1554
1798
|
const waited = dim(formatElapsed(Date.now() - started));
|
|
1555
1799
|
const left = [
|
|
@@ -1640,4 +1884,4 @@ ${numbered(event.excerpt, event.line)}`);
|
|
|
1640
1884
|
last lines of ${watch?.path}:
|
|
1641
1885
|
${numbered(lines)}`}`);
|
|
1642
1886
|
}
|
|
1643
|
-
|
|
1887
|
+
process18.exitCode = await runMain({ name: "waitfor", run: main });
|