@kaynooo/cli-proc 0.3.0 → 0.5.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/pid-cli.js +357 -57
- package/dist/ports-cli.js +444 -77
- package/dist/proc-cli.js +465 -93
- package/dist/procs-cli.js +374 -69
- package/package.json +2 -2
- package/src/ports.ts +8 -2
- package/src/procs.ts +11 -4
package/dist/proc-cli.js
CHANGED
|
@@ -2,16 +2,37 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/proc-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process7 from "process";
|
|
12
12
|
|
|
13
|
-
// ../kit/src/
|
|
13
|
+
// ../kit/src/mode.ts
|
|
14
14
|
import process2 from "process";
|
|
15
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
|
+
function isSet(value) {
|
|
18
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
|
+
}
|
|
20
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
21
|
+
const chosen = env.KIT_MODE;
|
|
22
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
23
|
+
return chosen;
|
|
24
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
25
|
+
return "agent";
|
|
26
|
+
if (stream.isTTY === true)
|
|
27
|
+
return "terminal";
|
|
28
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
|
+
}
|
|
30
|
+
function isInteractive(streams = process2) {
|
|
31
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ../kit/src/style.ts
|
|
35
|
+
import process6 from "process";
|
|
15
36
|
|
|
16
37
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
38
|
function x(s) {
|
|
@@ -274,21 +295,240 @@ function le(i = {}) {
|
|
|
274
295
|
}
|
|
275
296
|
var t = le();
|
|
276
297
|
|
|
298
|
+
// ../kit/src/theme.ts
|
|
299
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
300
|
+
import { homedir as homedir2 } from "os";
|
|
301
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
302
|
+
import process5 from "process";
|
|
303
|
+
|
|
304
|
+
// ../kit/src/config.ts
|
|
305
|
+
import { existsSync } from "fs";
|
|
306
|
+
import { dirname, join, resolve } from "path";
|
|
307
|
+
import process3 from "process";
|
|
308
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
309
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
310
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
311
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
312
|
+
if (found !== undefined)
|
|
313
|
+
return found;
|
|
314
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ../kit/src/user-config.ts
|
|
320
|
+
import { homedir } from "os";
|
|
321
|
+
import { join as join2 } from "path";
|
|
322
|
+
import process4 from "process";
|
|
323
|
+
function configBase(where = {}) {
|
|
324
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
325
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
326
|
+
}
|
|
327
|
+
function userConfigPath(bin, where = {}) {
|
|
328
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// ../kit/src/theme.ts
|
|
332
|
+
var DEFAULT = {
|
|
333
|
+
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" },
|
|
334
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
|
|
335
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
336
|
+
bins: {}
|
|
337
|
+
};
|
|
338
|
+
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" };
|
|
339
|
+
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" };
|
|
340
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
|
|
341
|
+
var PRESETS = {
|
|
342
|
+
default: {},
|
|
343
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
344
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
345
|
+
ascii: { glyphs: ASCII }
|
|
346
|
+
};
|
|
347
|
+
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"]);
|
|
348
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
349
|
+
var CONTROL = /\p{Cc}/u;
|
|
350
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
351
|
+
var SPACES = /\s+/;
|
|
352
|
+
function isColorSpec(spec) {
|
|
353
|
+
if (typeof spec === "number")
|
|
354
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
355
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
356
|
+
}
|
|
357
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
358
|
+
function cubeLevel(channel) {
|
|
359
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
360
|
+
}
|
|
361
|
+
function nearest256(hex) {
|
|
362
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
363
|
+
const levels = rgb.map(cubeLevel);
|
|
364
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
365
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
366
|
+
const greyValue = 8 + grey * 10;
|
|
367
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
368
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
369
|
+
}
|
|
370
|
+
function hasTrueColor(env) {
|
|
371
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
372
|
+
}
|
|
373
|
+
function tinted(colors, spec, env = process5.env) {
|
|
374
|
+
if (typeof spec === "number")
|
|
375
|
+
return colors.ansi256(spec);
|
|
376
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
377
|
+
if (HEX.test(token))
|
|
378
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
379
|
+
return chain[token] ?? chain;
|
|
380
|
+
}, colors);
|
|
381
|
+
}
|
|
382
|
+
function isRecord(value) {
|
|
383
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
384
|
+
}
|
|
385
|
+
function readThemeFile(path, warn) {
|
|
386
|
+
try {
|
|
387
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
388
|
+
if (stat === undefined)
|
|
389
|
+
return;
|
|
390
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
391
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
395
|
+
if (isRecord(parsed))
|
|
396
|
+
return parsed;
|
|
397
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
function applyPreset(theme, name, warn, where) {
|
|
404
|
+
if (name === undefined)
|
|
405
|
+
return;
|
|
406
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
407
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const preset = PRESETS[name];
|
|
411
|
+
Object.assign(theme.colors, preset.colors);
|
|
412
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
413
|
+
if (preset.accents !== undefined)
|
|
414
|
+
theme.accents = [...preset.accents];
|
|
415
|
+
return name;
|
|
416
|
+
}
|
|
417
|
+
function applyFile(theme, file, where, warn) {
|
|
418
|
+
if (isRecord(file.colors)) {
|
|
419
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
420
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
421
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
422
|
+
else if (!isColorSpec(value))
|
|
423
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
424
|
+
else
|
|
425
|
+
theme.colors[key] = value;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
if (isRecord(file.glyphs)) {
|
|
429
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
430
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
431
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
432
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
433
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
434
|
+
else
|
|
435
|
+
theme.glyphs[key] = value;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
439
|
+
theme.accents = [...file.accents];
|
|
440
|
+
else if (file.accents !== undefined)
|
|
441
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
442
|
+
if (isRecord(file.bins)) {
|
|
443
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
444
|
+
if (isColorSpec(value))
|
|
445
|
+
theme.bins[bin] = value;
|
|
446
|
+
else
|
|
447
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function endsWalk(home) {
|
|
452
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
453
|
+
}
|
|
454
|
+
var warned = new Set;
|
|
455
|
+
function warnOnce(message) {
|
|
456
|
+
if (warned.has(message))
|
|
457
|
+
return;
|
|
458
|
+
warned.add(message);
|
|
459
|
+
console.error(`warning: theme ${message}`);
|
|
460
|
+
}
|
|
461
|
+
function isPath(chosen) {
|
|
462
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
463
|
+
}
|
|
464
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
465
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
466
|
+
const sources = [];
|
|
467
|
+
const chosen = env.KIT_THEME ?? "";
|
|
468
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
469
|
+
if (isPath(chosen))
|
|
470
|
+
wanted.push(resolve2(from, chosen));
|
|
471
|
+
const files = [];
|
|
472
|
+
for (const path of wanted) {
|
|
473
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
474
|
+
if (path !== undefined && file !== undefined)
|
|
475
|
+
files.push({ path, file });
|
|
476
|
+
}
|
|
477
|
+
let preset = "default";
|
|
478
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
479
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
480
|
+
} else {
|
|
481
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
482
|
+
if (named !== undefined)
|
|
483
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
484
|
+
}
|
|
485
|
+
for (const { path, file } of files) {
|
|
486
|
+
applyFile(theme, file, path, warn);
|
|
487
|
+
sources.push(path);
|
|
488
|
+
}
|
|
489
|
+
return { theme, sources, preset };
|
|
490
|
+
}
|
|
491
|
+
var current;
|
|
492
|
+
var currentKey = "";
|
|
493
|
+
function activeTheme() {
|
|
494
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
495
|
+
if (current === undefined || key !== currentKey) {
|
|
496
|
+
current = loadTheme();
|
|
497
|
+
currentKey = key;
|
|
498
|
+
}
|
|
499
|
+
return current;
|
|
500
|
+
}
|
|
501
|
+
|
|
277
502
|
// ../kit/src/style.ts
|
|
278
|
-
function takesControlCodes(stream, env =
|
|
279
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
503
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
504
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
280
505
|
}
|
|
281
|
-
function paint(stream, env =
|
|
506
|
+
function paint(stream, env = process6.env) {
|
|
282
507
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
283
508
|
}
|
|
284
|
-
var
|
|
285
|
-
passed:
|
|
286
|
-
failed:
|
|
287
|
-
running:
|
|
288
|
-
queued:
|
|
289
|
-
skipped:
|
|
509
|
+
var STATUS_WORDS = {
|
|
510
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
511
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
512
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
513
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
514
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
290
515
|
};
|
|
291
|
-
var STATUS_OF = new Map(Object.entries(
|
|
516
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
517
|
+
function header(bin, context, stream, env = process6.env) {
|
|
518
|
+
if (!takesControlCodes(stream, env))
|
|
519
|
+
return "";
|
|
520
|
+
const colors = paint(stream, env);
|
|
521
|
+
const hash = [...bin].reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
522
|
+
const { theme } = activeTheme();
|
|
523
|
+
const spec = theme.bins[bin] ?? theme.accents[hash % theme.accents.length];
|
|
524
|
+
const accent = tinted(typeof spec === "string" && spec.split(" ").includes("bold") ? colors : colors.bold, spec, env);
|
|
525
|
+
return `${accent(bin)}${context === undefined ? "" : colors.dim(` \u203A ${context}`)}`;
|
|
526
|
+
}
|
|
527
|
+
function printHeader(bin, context, stream = process6.stdout, env = process6.env) {
|
|
528
|
+
const line = header(bin, context, stream, env);
|
|
529
|
+
if (line !== "")
|
|
530
|
+
console.log(line);
|
|
531
|
+
}
|
|
292
532
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-hrsswv1w.js
|
|
293
533
|
function $e(t, e = false, i = 1) {
|
|
294
534
|
let n = typeof e === "object" ? e : { units: e ? "si" : "iec", dp: i }, { units: s = "iec", dp: u = 1 } = n, r = s === "si" ? 1000 : 1024;
|
|
@@ -328,15 +568,18 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
328
568
|
function textWidth(text) {
|
|
329
569
|
return Bun.stringWidth(text);
|
|
330
570
|
}
|
|
331
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
571
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
332
572
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
573
|
+
if (outputMode(stream, env) === "agent")
|
|
574
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
575
|
+
`);
|
|
333
576
|
const widths = [];
|
|
334
577
|
for (const row of cells) {
|
|
335
578
|
for (const [index, cell] of row.entries())
|
|
336
579
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
337
580
|
}
|
|
338
581
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
339
|
-
const colors = paint(
|
|
582
|
+
const colors = paint(stream);
|
|
340
583
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
341
584
|
const width = widths[index] ?? 0;
|
|
342
585
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -344,7 +587,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
344
587
|
return `${gap}${cell}`;
|
|
345
588
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
346
589
|
}).join(" ").trimEnd());
|
|
347
|
-
|
|
590
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
591
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
348
592
|
`);
|
|
349
593
|
}
|
|
350
594
|
function narrow(rows, widths, limit) {
|
|
@@ -363,32 +607,35 @@ function narrow(rows, widths, limit) {
|
|
|
363
607
|
}
|
|
364
608
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
365
609
|
}
|
|
610
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
611
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
612
|
+
}
|
|
366
613
|
function printJson(value) {
|
|
367
|
-
console.log(
|
|
614
|
+
console.log(jsonText(value));
|
|
368
615
|
}
|
|
369
616
|
|
|
370
617
|
// ../kit/src/help.ts
|
|
371
|
-
import
|
|
618
|
+
import process8 from "process";
|
|
372
619
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
373
620
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
374
621
|
var FULL_STOP = /\.$/;
|
|
375
|
-
function usageLine(usage, colors = paint(
|
|
622
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
376
623
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
377
624
|
}
|
|
378
|
-
function helpText(usage, options, colors = paint(
|
|
625
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
379
626
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
380
627
|
`);
|
|
381
628
|
}
|
|
382
|
-
function exitRows(exits, colors = paint(
|
|
629
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
383
630
|
if (exits.length === 0)
|
|
384
631
|
return [];
|
|
385
632
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
386
633
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
387
634
|
}
|
|
388
|
-
function replacesRows(replaces, colors = paint(
|
|
389
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
635
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
636
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
390
637
|
}
|
|
391
|
-
function wantsHelpJson(env =
|
|
638
|
+
function wantsHelpJson(env = process8.env) {
|
|
392
639
|
return env.KIT_HELP === "json";
|
|
393
640
|
}
|
|
394
641
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -407,12 +654,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
407
654
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
408
655
|
};
|
|
409
656
|
}
|
|
410
|
-
function exampleRows(examples, colors = paint(
|
|
411
|
-
if (examples.length === 0)
|
|
657
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
658
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
412
659
|
return [];
|
|
413
660
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
414
661
|
}
|
|
415
|
-
function optionRows(options, colors = paint(
|
|
662
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
416
663
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
417
664
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
418
665
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -470,7 +717,6 @@ var DASHES = /^-+/;
|
|
|
470
717
|
function jsonOption(holds) {
|
|
471
718
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
472
719
|
}
|
|
473
|
-
|
|
474
720
|
class Exit extends Error {
|
|
475
721
|
code;
|
|
476
722
|
hint;
|
|
@@ -514,7 +760,7 @@ var OUTPUT_OPTIONS = {
|
|
|
514
760
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
515
761
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
516
762
|
};
|
|
517
|
-
function applyOutput(color, plain, env =
|
|
763
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
518
764
|
const when = plain === true ? "never" : color ?? "auto";
|
|
519
765
|
if (when === "auto")
|
|
520
766
|
return;
|
|
@@ -685,7 +931,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
685
931
|
}
|
|
686
932
|
// ../kit/src/process.ts
|
|
687
933
|
import { constants } from "os";
|
|
688
|
-
import
|
|
934
|
+
import process10 from "process";
|
|
689
935
|
var KILL_GRACE_MS = 2000;
|
|
690
936
|
function exitCodeOf(code, signal) {
|
|
691
937
|
if (code !== null)
|
|
@@ -705,7 +951,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
705
951
|
return;
|
|
706
952
|
try {
|
|
707
953
|
if (grouped)
|
|
708
|
-
|
|
954
|
+
process10.kill(-proc.pid, killing);
|
|
709
955
|
else
|
|
710
956
|
proc.kill(killing);
|
|
711
957
|
} catch {}
|
|
@@ -779,15 +1025,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
779
1025
|
var RESET_STYLE = `${ESC}[0m`;
|
|
780
1026
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
781
1027
|
// ../kit/src/cli.ts
|
|
782
|
-
import { readFileSync, realpathSync } from "fs";
|
|
783
|
-
import { dirname as
|
|
784
|
-
import
|
|
1028
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1029
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1030
|
+
import process12 from "process";
|
|
785
1031
|
|
|
786
1032
|
// ../kit/src/usage.ts
|
|
787
1033
|
import { appendFileSync, mkdirSync } from "fs";
|
|
788
|
-
import { homedir } from "os";
|
|
789
|
-
import { dirname, isAbsolute, join } from "path";
|
|
790
|
-
import
|
|
1034
|
+
import { homedir as homedir3 } from "os";
|
|
1035
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1036
|
+
import process11 from "process";
|
|
791
1037
|
|
|
792
1038
|
// ../kit/src/logs.ts
|
|
793
1039
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -801,14 +1047,14 @@ var usageError;
|
|
|
801
1047
|
function noteUsageError(message) {
|
|
802
1048
|
usageError = message;
|
|
803
1049
|
}
|
|
804
|
-
function stateHome(env =
|
|
1050
|
+
function stateHome(env = process11.env) {
|
|
805
1051
|
const dir = env.XDG_STATE_HOME;
|
|
806
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1052
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
807
1053
|
}
|
|
808
|
-
function usagePath(env =
|
|
809
|
-
return
|
|
1054
|
+
function usagePath(env = process11.env) {
|
|
1055
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
810
1056
|
}
|
|
811
|
-
function usageRecorded(env =
|
|
1057
|
+
function usageRecorded(env = process11.env) {
|
|
812
1058
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
813
1059
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
814
1060
|
}
|
|
@@ -822,12 +1068,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
822
1068
|
usageError = undefined;
|
|
823
1069
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
824
1070
|
}
|
|
825
|
-
function recordUsage(entry, env =
|
|
1071
|
+
function recordUsage(entry, env = process11.env) {
|
|
826
1072
|
if (!usageRecorded(env))
|
|
827
1073
|
return;
|
|
828
1074
|
try {
|
|
829
1075
|
const path = usagePath(env);
|
|
830
|
-
mkdirSync(
|
|
1076
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
831
1077
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
832
1078
|
`, { mode: 384 });
|
|
833
1079
|
} catch {}
|
|
@@ -913,8 +1159,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
913
1159
|
`);
|
|
914
1160
|
}
|
|
915
1161
|
function printError(prefix, message, hint, cause) {
|
|
916
|
-
const colors = paint(
|
|
917
|
-
const styled = takesControlCodes(
|
|
1162
|
+
const colors = paint(process12.stderr);
|
|
1163
|
+
const styled = takesControlCodes(process12.stderr);
|
|
918
1164
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
919
1165
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
920
1166
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -957,11 +1203,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
957
1203
|
}
|
|
958
1204
|
}
|
|
959
1205
|
if (name === undefined && level.path.length > 1) {
|
|
960
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1206
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
|
|
961
1207
|
return 2;
|
|
962
1208
|
}
|
|
963
1209
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
964
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1210
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
|
|
965
1211
|
return 0;
|
|
966
1212
|
}
|
|
967
1213
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1078,17 +1324,17 @@ async function printCandidates(found) {
|
|
|
1078
1324
|
return 0;
|
|
1079
1325
|
}
|
|
1080
1326
|
function packageVersion(entry = Bun.main) {
|
|
1081
|
-
for (let dir =
|
|
1327
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1082
1328
|
try {
|
|
1083
|
-
const { version } = JSON.parse(
|
|
1329
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1084
1330
|
if (typeof version === "string")
|
|
1085
1331
|
return version;
|
|
1086
1332
|
} catch {}
|
|
1087
|
-
if (
|
|
1333
|
+
if (dirname3(dir) === dir)
|
|
1088
1334
|
return "0.0.0";
|
|
1089
1335
|
}
|
|
1090
1336
|
}
|
|
1091
|
-
async function runCli(cli, argv =
|
|
1337
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
1092
1338
|
const version = cli.version ?? packageVersion();
|
|
1093
1339
|
if (argv[0] === COMPLETE)
|
|
1094
1340
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1115,7 +1361,7 @@ function commandPath(scope, argv) {
|
|
|
1115
1361
|
}
|
|
1116
1362
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1117
1363
|
}
|
|
1118
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1364
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
1119
1365
|
if (argv[0] === COMPLETE)
|
|
1120
1366
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1121
1367
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1135,6 +1381,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process8.ar
|
|
|
1135
1381
|
}
|
|
1136
1382
|
return code;
|
|
1137
1383
|
}
|
|
1384
|
+
// ../kit/src/folders.ts
|
|
1385
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1138
1386
|
// ../kit/src/secrets.ts
|
|
1139
1387
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1140
1388
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1156,8 +1404,60 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1156
1404
|
const suffix = match[2].toLowerCase();
|
|
1157
1405
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1158
1406
|
}
|
|
1407
|
+
// ../kit/src/watch.ts
|
|
1408
|
+
import process13 from "process";
|
|
1409
|
+
import { format } from "util";
|
|
1410
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1411
|
+
var DEFAULT_SECONDS = 2;
|
|
1412
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1413
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1414
|
+
function watchOption(what) {
|
|
1415
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1416
|
+
}
|
|
1417
|
+
function withoutWatch(args) {
|
|
1418
|
+
const rest = [];
|
|
1419
|
+
for (let at = 0;at < args.length; at++) {
|
|
1420
|
+
const arg = args[at];
|
|
1421
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1422
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1423
|
+
at++;
|
|
1424
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1425
|
+
rest.push(arg);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
return rest;
|
|
1429
|
+
}
|
|
1430
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1431
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1432
|
+
if (!takesControlCodes(stream))
|
|
1433
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1434
|
+
let code = 0;
|
|
1435
|
+
for (let round = 0;round < rounds; round++) {
|
|
1436
|
+
const held = [];
|
|
1437
|
+
const { log, info } = console;
|
|
1438
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1439
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1440
|
+
`);
|
|
1441
|
+
console.log = hold;
|
|
1442
|
+
console.info = hold;
|
|
1443
|
+
process13.stdout.write = (text) => {
|
|
1444
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1445
|
+
return true;
|
|
1446
|
+
};
|
|
1447
|
+
try {
|
|
1448
|
+
code = await step();
|
|
1449
|
+
} finally {
|
|
1450
|
+
console.log = log;
|
|
1451
|
+
console.info = info;
|
|
1452
|
+
process13.stdout.write = write;
|
|
1453
|
+
}
|
|
1454
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1455
|
+
await sleep(interval);
|
|
1456
|
+
}
|
|
1457
|
+
return code;
|
|
1458
|
+
}
|
|
1159
1459
|
// src/pid.ts
|
|
1160
|
-
import
|
|
1460
|
+
import process15 from "process";
|
|
1161
1461
|
|
|
1162
1462
|
// src/mask.ts
|
|
1163
1463
|
import { basename } from "path";
|
|
@@ -1548,7 +1848,7 @@ function limitLine(limits, name) {
|
|
|
1548
1848
|
return limit === undefined ? "-" : `soft ${limit.soft}, hard ${limit.hard}`;
|
|
1549
1849
|
}
|
|
1550
1850
|
function render(info, showEnv) {
|
|
1551
|
-
const colors = paint(
|
|
1851
|
+
const colors = paint(process15.stdout);
|
|
1552
1852
|
const memory = info.memory;
|
|
1553
1853
|
const size = (bytes) => bytes === undefined ? "-" : $e(bytes);
|
|
1554
1854
|
const rows = [
|
|
@@ -1601,15 +1901,70 @@ async function pid(args) {
|
|
|
1601
1901
|
|
|
1602
1902
|
// src/ports.ts
|
|
1603
1903
|
import { basename as basename2 } from "path";
|
|
1604
|
-
import
|
|
1904
|
+
import process17 from "process";
|
|
1605
1905
|
|
|
1606
1906
|
// ../kit/src/prompt.ts
|
|
1607
|
-
import
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
var
|
|
1611
|
-
|
|
1612
|
-
|
|
1907
|
+
import process16 from "process";
|
|
1908
|
+
|
|
1909
|
+
// ../kit/src/picker/score.ts
|
|
1910
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1911
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
1912
|
+
|
|
1913
|
+
// ../kit/src/picker/state.ts
|
|
1914
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1915
|
+
var PASTE_START = "\x1B[200~";
|
|
1916
|
+
var PASTE_END = "\x1B[201~";
|
|
1917
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1918
|
+
var KEYS = {
|
|
1919
|
+
"\x1B[A": "up",
|
|
1920
|
+
"\x1BOA": "up",
|
|
1921
|
+
"\x10": "up",
|
|
1922
|
+
"\x1B[B": "down",
|
|
1923
|
+
"\x1BOB": "down",
|
|
1924
|
+
"\x0E": "down",
|
|
1925
|
+
"\x1B[5~": "pageup",
|
|
1926
|
+
"\x1B[6~": "pagedown",
|
|
1927
|
+
"\x1B[H": "home",
|
|
1928
|
+
"\x1B[1~": "home",
|
|
1929
|
+
"\x1BOH": "home",
|
|
1930
|
+
"\x1B[F": "end",
|
|
1931
|
+
"\x1B[4~": "end",
|
|
1932
|
+
"\x1BOF": "end",
|
|
1933
|
+
"\r": "enter",
|
|
1934
|
+
"\n": "enter",
|
|
1935
|
+
"\x03": "cancel",
|
|
1936
|
+
"\x1B": "cancel",
|
|
1937
|
+
"\x7F": "erase",
|
|
1938
|
+
"\b": "erase",
|
|
1939
|
+
"\x15": "clear",
|
|
1940
|
+
"\x17": "word",
|
|
1941
|
+
"\t": "tab",
|
|
1942
|
+
"\x1F": "help",
|
|
1943
|
+
"\x1BOP": "help",
|
|
1944
|
+
"\x1B[11~": "help"
|
|
1945
|
+
};
|
|
1946
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1947
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1948
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1949
|
+
const named = codes.get(sequence);
|
|
1950
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1951
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1952
|
+
paste.active = sequence === PASTE_START;
|
|
1953
|
+
return [];
|
|
1954
|
+
}
|
|
1955
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1956
|
+
`))
|
|
1957
|
+
return [];
|
|
1958
|
+
if (key !== undefined)
|
|
1959
|
+
return [key];
|
|
1960
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
// ../kit/src/prompt.ts
|
|
1965
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
1966
|
+
function readKeys(input, paste = { active: false }) {
|
|
1967
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
1613
1968
|
}
|
|
1614
1969
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1615
1970
|
let answered = fallback;
|
|
@@ -1633,27 +1988,34 @@ function asking(colors, question, typed, keys) {
|
|
|
1633
1988
|
function answer(colors, question, state, picked) {
|
|
1634
1989
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1635
1990
|
}
|
|
1636
|
-
async function ask(question, { hint, terminal =
|
|
1991
|
+
async function ask(question, { hint, terminal = process16 }, render, press) {
|
|
1637
1992
|
const { stdin, stderr } = terminal;
|
|
1638
|
-
if (
|
|
1993
|
+
if (!isInteractive(terminal))
|
|
1639
1994
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1640
1995
|
const colors = paint(stderr);
|
|
1641
|
-
let drawn =
|
|
1996
|
+
let drawn = [];
|
|
1997
|
+
let current = "asking";
|
|
1642
1998
|
let outcome;
|
|
1999
|
+
const columns = () => stderr.columns || 80;
|
|
1643
2000
|
const draw = (state) => {
|
|
1644
|
-
const frame = render(colors, state, { columns:
|
|
1645
|
-
|
|
2001
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
2002
|
+
const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
|
|
2003
|
+
stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
|
|
1646
2004
|
`)}`);
|
|
1647
|
-
drawn = frame
|
|
2005
|
+
drawn = frame;
|
|
2006
|
+
current = state;
|
|
1648
2007
|
};
|
|
2008
|
+
const redraw = () => draw(current);
|
|
2009
|
+
const paste = { active: false };
|
|
1649
2010
|
try {
|
|
2011
|
+
stderr.on?.("resize", redraw);
|
|
1650
2012
|
stdin.setRawMode(true);
|
|
1651
2013
|
stdin.resume();
|
|
1652
|
-
stderr.write("\x1B[?25l");
|
|
2014
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1653
2015
|
draw("asking");
|
|
1654
2016
|
return await new Promise((resolve) => {
|
|
1655
2017
|
function onData(data) {
|
|
1656
|
-
for (const key of readKeys(data.toString())) {
|
|
2018
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1657
2019
|
const pressed = press(key);
|
|
1658
2020
|
if (pressed !== undefined) {
|
|
1659
2021
|
settle(pressed);
|
|
@@ -1675,9 +2037,10 @@ async function ask(question, { hint, terminal = process11 }, render, press) {
|
|
|
1675
2037
|
stdin.on("end", onEnd);
|
|
1676
2038
|
});
|
|
1677
2039
|
} finally {
|
|
2040
|
+
stderr.off?.("resize", redraw);
|
|
1678
2041
|
draw(outcome ?? "cancel");
|
|
1679
2042
|
stderr.write(`
|
|
1680
|
-
\x1B[?25h`);
|
|
2043
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1681
2044
|
stdin.setRawMode(false);
|
|
1682
2045
|
stdin.pause();
|
|
1683
2046
|
}
|
|
@@ -1768,7 +2131,8 @@ Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per
|
|
|
1768
2131
|
Exits 0 when it listed or stopped, 1 when nothing listens on the given port or the owner could not be stopped, 2 on a usage error.`;
|
|
1769
2132
|
var options2 = {
|
|
1770
2133
|
json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
|
|
1771
|
-
kill: { type: "boolean", description: "stop the owner of the given port" },
|
|
2134
|
+
kill: { type: "boolean", conflicts: ["watch"], description: "stop the owner of the given port" },
|
|
2135
|
+
watch: watchOption("the ports"),
|
|
1772
2136
|
force: { type: "boolean", description: "with --kill, SIGKILL what SIGTERM did not stop within --grace" },
|
|
1773
2137
|
yes: { type: "boolean", short: "y", description: "with --kill, do not ask first" },
|
|
1774
2138
|
grace: { type: "string", description: "with --force, how long SIGTERM gets before SIGKILL (5s)" }
|
|
@@ -1812,7 +2176,7 @@ function refusal(row, proc, guard) {
|
|
|
1812
2176
|
return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
|
|
1813
2177
|
}
|
|
1814
2178
|
function render2(rows) {
|
|
1815
|
-
const colors = paint(
|
|
2179
|
+
const colors = paint(process17.stdout);
|
|
1816
2180
|
const cells = rows.map((row) => [
|
|
1817
2181
|
colors.cyan(String(row.port)),
|
|
1818
2182
|
row.protocol,
|
|
@@ -1824,7 +2188,7 @@ function render2(rows) {
|
|
|
1824
2188
|
return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
|
|
1825
2189
|
}
|
|
1826
2190
|
async function stop(port, rows, procs, values) {
|
|
1827
|
-
const guard = { uid:
|
|
2191
|
+
const guard = { uid: process17.getuid?.() ?? -1, mine: new Set(ancestry(process17.pid, procs)) };
|
|
1828
2192
|
const targets = new Map;
|
|
1829
2193
|
for (const row of rows) {
|
|
1830
2194
|
const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
|
|
@@ -1837,7 +2201,7 @@ async function stop(port, rows, procs, values) {
|
|
|
1837
2201
|
return 1;
|
|
1838
2202
|
const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
|
|
1839
2203
|
if (values.yes !== true) {
|
|
1840
|
-
if (!
|
|
2204
|
+
if (!process17.stdin.isTTY)
|
|
1841
2205
|
fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
|
|
1842
2206
|
if (await confirm(`Stop ${names}?`, { default: false }) !== true)
|
|
1843
2207
|
return 1;
|
|
@@ -1860,13 +2224,15 @@ async function ports(args) {
|
|
|
1860
2224
|
"ports --json"
|
|
1861
2225
|
]
|
|
1862
2226
|
});
|
|
2227
|
+
if (values.watch !== undefined)
|
|
2228
|
+
return watching(values.watch, async () => ports(withoutWatch(args)));
|
|
1863
2229
|
const [given] = positionals;
|
|
1864
2230
|
const port = given === undefined ? undefined : wholeNumber(given, "<port>", 0);
|
|
1865
2231
|
if (port !== undefined && port > 65535)
|
|
1866
2232
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
|
|
1867
2233
|
if (values.kill === true && port === undefined)
|
|
1868
2234
|
badUsage("--kill takes the port to free: ports <port> --kill");
|
|
1869
|
-
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid ===
|
|
2235
|
+
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process17.getuid?.())]);
|
|
1870
2236
|
const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
|
|
1871
2237
|
const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
|
|
1872
2238
|
const needsDocker = wanted.some((socket) => {
|
|
@@ -1884,20 +2250,21 @@ async function ports(args) {
|
|
|
1884
2250
|
printJson(rows);
|
|
1885
2251
|
return 0;
|
|
1886
2252
|
}
|
|
2253
|
+
printHeader("ports");
|
|
1887
2254
|
console.log(render2(rows));
|
|
1888
2255
|
const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
|
|
1889
2256
|
if (unknown > 0)
|
|
1890
|
-
console.error(paint(
|
|
2257
|
+
console.error(paint(process17.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
|
|
1891
2258
|
return 0;
|
|
1892
2259
|
}
|
|
1893
2260
|
|
|
1894
2261
|
// src/procs.ts
|
|
1895
|
-
import { existsSync } from "fs";
|
|
1896
|
-
import { homedir as
|
|
1897
|
-
import
|
|
2262
|
+
import { existsSync as existsSync3 } from "fs";
|
|
2263
|
+
import { homedir as homedir4 } from "os";
|
|
2264
|
+
import process18 from "process";
|
|
1898
2265
|
|
|
1899
2266
|
// src/select.ts
|
|
1900
|
-
import { basename as basename3, join as
|
|
2267
|
+
import { basename as basename3, join as join6, relative } from "path";
|
|
1901
2268
|
var BROWSERS = /^(?:chrom(?:e|ium)(?:-browser)?|google-chrome(?:-stable|-beta|-unstable)?|chrome_crashpad_handler|chrome-headless-shell|headless_shell|chromium-headless-shell|brave|brave-browser|msedge|microsoft-edge|webkitwebprocess|webkitnetworkprocess|webkitgpuprocess|minibrowser|webkitwebdriver|wpewebprocess|wpenetworkprocess|bun-webview.*)$/i;
|
|
1902
2269
|
var NATIVE = new Set(["rust-analyzer", "gopls", "clangd", "lua-language-server", "pyright-langserver", "pylsp", "intelephense", "phpactor", "tsgo", "esbuild", "biome", "ruff", "phpunit", "pytest", "vitest", "jest"]);
|
|
1903
2270
|
var RUNTIMES = new Set(["node", "bun", "bunx", "deno", "nodejs"]);
|
|
@@ -1934,9 +2301,9 @@ function projectOf(cwd, exists, home) {
|
|
|
1934
2301
|
if (cwd === undefined || !cwd.startsWith(`${home}/`))
|
|
1935
2302
|
return;
|
|
1936
2303
|
const folders = [];
|
|
1937
|
-
for (let dir = cwd;dir.startsWith(`${home}/`); dir =
|
|
2304
|
+
for (let dir = cwd;dir.startsWith(`${home}/`); dir = join6(dir, ".."))
|
|
1938
2305
|
folders.push(dir);
|
|
1939
|
-
return folders.find((dir) => exists(
|
|
2306
|
+
return folders.find((dir) => exists(join6(dir, ".git"))) ?? folders.find((dir) => MARKERS.some((marker) => exists(join6(dir, marker))));
|
|
1940
2307
|
}
|
|
1941
2308
|
function isOrphan(proc, byPid) {
|
|
1942
2309
|
if (proc.unit?.endsWith(".service") === true)
|
|
@@ -2019,7 +2386,8 @@ A process is listed when it is a dev tool (bun, node, vite, nuxt, next, chromium
|
|
|
2019
2386
|
Exits 0 when it listed or stopped everything, 1 when a process survived SIGKILL, 2 on a usage error.`;
|
|
2020
2387
|
var options3 = {
|
|
2021
2388
|
json: jsonOption("{ groups: [{ origin, kind, count, rss, oldestSeconds, tools, orphans, pids, processes }], skipped }"),
|
|
2022
|
-
kill: { type: "boolean", description: "stop the listed processes: a dry run without --yes" },
|
|
2389
|
+
kill: { type: "boolean", conflicts: ["watch"], description: "stop the listed processes: a dry run without --yes" },
|
|
2390
|
+
watch: watchOption("the processes"),
|
|
2023
2391
|
yes: { type: "boolean", short: "y", description: "with --kill, really stop them, without asking" },
|
|
2024
2392
|
"min-mem": { type: "string", description: "heavy from this resident size (500M), and the least a left over process must use to be listed; a bare number counts megabytes" },
|
|
2025
2393
|
older: { type: "string", description: "only processes at least this old: 30m, 2h, 1d" },
|
|
@@ -2042,7 +2410,7 @@ function summary(group) {
|
|
|
2042
2410
|
};
|
|
2043
2411
|
}
|
|
2044
2412
|
function render3(groups) {
|
|
2045
|
-
const colors = paint(
|
|
2413
|
+
const colors = paint(process18.stdout);
|
|
2046
2414
|
const rows = groups.map((group) => [
|
|
2047
2415
|
group.origin,
|
|
2048
2416
|
String(group.members.length),
|
|
@@ -2066,22 +2434,26 @@ async function procs(args) {
|
|
|
2066
2434
|
const minMem = values["min-mem"] === undefined ? undefined : parseSize(values["min-mem"], 1024 ** 2);
|
|
2067
2435
|
if (values["min-mem"] !== undefined && minMem === undefined)
|
|
2068
2436
|
fail(`--min-mem takes a size such as 500M or 1.5G, not ${values["min-mem"]}`, 2);
|
|
2437
|
+
if (values.watch !== undefined)
|
|
2438
|
+
return watching(values.watch, async () => procs(withoutWatch(args)));
|
|
2069
2439
|
const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0, "m");
|
|
2070
|
-
const uid =
|
|
2440
|
+
const uid = process18.getuid?.() ?? -1;
|
|
2071
2441
|
const all = await snapshot("/proc", (owner) => owner === uid);
|
|
2072
|
-
const mine = new Set(ancestry(
|
|
2073
|
-
const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home:
|
|
2442
|
+
const mine = new Set(ancestry(process18.pid, new Map(all.map((proc) => [proc.pid, proc]))));
|
|
2443
|
+
const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home: homedir4(), exists: existsSync3, minMem, olderMs });
|
|
2074
2444
|
const pids = groups.flatMap((group) => group.members.map(({ proc }) => proc.pid));
|
|
2075
2445
|
const show = (extra = {}) => {
|
|
2076
|
-
if (values.json === true)
|
|
2446
|
+
if (values.json === true) {
|
|
2077
2447
|
printJson({ groups: groups.map(summary), skipped: protectedCount, ...extra });
|
|
2078
|
-
else
|
|
2448
|
+
} else {
|
|
2449
|
+
printHeader("procs");
|
|
2079
2450
|
console.log(groups.length === 0 ? "nothing to clean" : render3(groups));
|
|
2451
|
+
}
|
|
2080
2452
|
};
|
|
2081
2453
|
if (values.kill !== true || pids.length === 0 || values.yes !== true) {
|
|
2082
2454
|
show();
|
|
2083
2455
|
if (values.json !== true && protectedCount > 0)
|
|
2084
|
-
console.error(paint(
|
|
2456
|
+
console.error(paint(process18.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
|
|
2085
2457
|
if (values.kill === true && pids.length > 0)
|
|
2086
2458
|
console.error(`dry run: would stop ${pids.length} ${pids.length === 1 ? "process" : "processes"} (${pids.join(" ")}), pass --yes to do it`);
|
|
2087
2459
|
return 0;
|
|
@@ -2096,7 +2468,7 @@ async function procs(args) {
|
|
|
2096
2468
|
}
|
|
2097
2469
|
|
|
2098
2470
|
// src/proc-cli.ts
|
|
2099
|
-
|
|
2471
|
+
process19.exitCode = await runCli({
|
|
2100
2472
|
name: "proc",
|
|
2101
2473
|
about: "what a process is, who listens on a port and which dev processes are worth cleaning, read from /proc",
|
|
2102
2474
|
replaces: "cat /proc/<pid>/..., ss -ltnp, lsof -i and pgrep -f one-liners",
|