@kaynooo/cli-proc 0.4.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 +265 -49
- package/dist/ports-cli.js +272 -55
- package/dist/proc-cli.js +289 -70
- package/dist/procs-cli.js +278 -60
- package/package.json +2 -2
- package/src/ports.ts +2 -1
- package/src/procs.ts +6 -3
package/dist/procs-cli.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/procs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 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
13
|
// ../kit/src/mode.ts
|
|
14
14
|
import process2 from "process";
|
|
@@ -32,7 +32,7 @@ function isInteractive(streams = process2) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// ../kit/src/style.ts
|
|
35
|
-
import
|
|
35
|
+
import process6 from "process";
|
|
36
36
|
|
|
37
37
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
38
38
|
function x(s) {
|
|
@@ -296,15 +296,214 @@ function le(i = {}) {
|
|
|
296
296
|
var t = le();
|
|
297
297
|
|
|
298
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
|
+
};
|
|
299
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;
|
|
300
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
|
+
}
|
|
301
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
|
+
}
|
|
302
501
|
|
|
303
502
|
// ../kit/src/style.ts
|
|
304
|
-
function takesControlCodes(stream, env =
|
|
503
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
305
504
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
306
505
|
}
|
|
307
|
-
function paint(stream, env =
|
|
506
|
+
function paint(stream, env = process6.env) {
|
|
308
507
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
309
508
|
}
|
|
310
509
|
var STATUS_WORDS = {
|
|
@@ -315,6 +514,21 @@ var STATUS_WORDS = {
|
|
|
315
514
|
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
316
515
|
};
|
|
317
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
|
+
}
|
|
318
532
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-hrsswv1w.js
|
|
319
533
|
function $e(t, e = false, i = 1) {
|
|
320
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;
|
|
@@ -354,7 +568,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
354
568
|
function textWidth(text) {
|
|
355
569
|
return Bun.stringWidth(text);
|
|
356
570
|
}
|
|
357
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream =
|
|
571
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
358
572
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
359
573
|
if (outputMode(stream, env) === "agent")
|
|
360
574
|
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
@@ -393,7 +607,7 @@ function narrow(rows, widths, limit) {
|
|
|
393
607
|
}
|
|
394
608
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
395
609
|
}
|
|
396
|
-
function jsonText(value, replacer, { stream =
|
|
610
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
397
611
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
398
612
|
}
|
|
399
613
|
function printJson(value) {
|
|
@@ -401,27 +615,27 @@ function printJson(value) {
|
|
|
401
615
|
}
|
|
402
616
|
|
|
403
617
|
// ../kit/src/help.ts
|
|
404
|
-
import
|
|
618
|
+
import process8 from "process";
|
|
405
619
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
406
620
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
407
621
|
var FULL_STOP = /\.$/;
|
|
408
|
-
function usageLine(usage, colors = paint(
|
|
622
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
409
623
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
410
624
|
}
|
|
411
|
-
function helpText(usage, options, colors = paint(
|
|
625
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
412
626
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
413
627
|
`);
|
|
414
628
|
}
|
|
415
|
-
function exitRows(exits, colors = paint(
|
|
629
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
416
630
|
if (exits.length === 0)
|
|
417
631
|
return [];
|
|
418
632
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
419
633
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
420
634
|
}
|
|
421
|
-
function replacesRows(replaces, colors = paint(
|
|
635
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
422
636
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
423
637
|
}
|
|
424
|
-
function wantsHelpJson(env =
|
|
638
|
+
function wantsHelpJson(env = process8.env) {
|
|
425
639
|
return env.KIT_HELP === "json";
|
|
426
640
|
}
|
|
427
641
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -440,12 +654,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
440
654
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
441
655
|
};
|
|
442
656
|
}
|
|
443
|
-
function exampleRows(examples, colors = paint(
|
|
657
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
444
658
|
if (examples.length === 0 || outputMode() === "agent")
|
|
445
659
|
return [];
|
|
446
660
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
447
661
|
}
|
|
448
|
-
function optionRows(options, colors = paint(
|
|
662
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
449
663
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
450
664
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
451
665
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -546,7 +760,7 @@ var OUTPUT_OPTIONS = {
|
|
|
546
760
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
547
761
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
548
762
|
};
|
|
549
|
-
function applyOutput(color, plain, env =
|
|
763
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
550
764
|
const when = plain === true ? "never" : color ?? "auto";
|
|
551
765
|
if (when === "auto")
|
|
552
766
|
return;
|
|
@@ -717,7 +931,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
717
931
|
}
|
|
718
932
|
// ../kit/src/process.ts
|
|
719
933
|
import { constants } from "os";
|
|
720
|
-
import
|
|
934
|
+
import process10 from "process";
|
|
721
935
|
var KILL_GRACE_MS = 2000;
|
|
722
936
|
function exitCodeOf(code, signal) {
|
|
723
937
|
if (code !== null)
|
|
@@ -737,7 +951,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
737
951
|
return;
|
|
738
952
|
try {
|
|
739
953
|
if (grouped)
|
|
740
|
-
|
|
954
|
+
process10.kill(-proc.pid, killing);
|
|
741
955
|
else
|
|
742
956
|
proc.kill(killing);
|
|
743
957
|
} catch {}
|
|
@@ -811,15 +1025,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
811
1025
|
var RESET_STYLE = `${ESC}[0m`;
|
|
812
1026
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
813
1027
|
// ../kit/src/cli.ts
|
|
814
|
-
import { readFileSync, realpathSync } from "fs";
|
|
815
|
-
import { dirname as
|
|
816
|
-
import
|
|
1028
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
1029
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1030
|
+
import process12 from "process";
|
|
817
1031
|
|
|
818
1032
|
// ../kit/src/usage.ts
|
|
819
1033
|
import { appendFileSync, mkdirSync } from "fs";
|
|
820
|
-
import { homedir } from "os";
|
|
821
|
-
import { dirname, isAbsolute, join } from "path";
|
|
822
|
-
import
|
|
1034
|
+
import { homedir as homedir3 } from "os";
|
|
1035
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1036
|
+
import process11 from "process";
|
|
823
1037
|
|
|
824
1038
|
// ../kit/src/logs.ts
|
|
825
1039
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -833,14 +1047,14 @@ var usageError;
|
|
|
833
1047
|
function noteUsageError(message) {
|
|
834
1048
|
usageError = message;
|
|
835
1049
|
}
|
|
836
|
-
function stateHome(env =
|
|
1050
|
+
function stateHome(env = process11.env) {
|
|
837
1051
|
const dir = env.XDG_STATE_HOME;
|
|
838
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
1052
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
839
1053
|
}
|
|
840
|
-
function usagePath(env =
|
|
841
|
-
return
|
|
1054
|
+
function usagePath(env = process11.env) {
|
|
1055
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
842
1056
|
}
|
|
843
|
-
function usageRecorded(env =
|
|
1057
|
+
function usageRecorded(env = process11.env) {
|
|
844
1058
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
845
1059
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
846
1060
|
}
|
|
@@ -854,12 +1068,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
854
1068
|
usageError = undefined;
|
|
855
1069
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
856
1070
|
}
|
|
857
|
-
function recordUsage(entry, env =
|
|
1071
|
+
function recordUsage(entry, env = process11.env) {
|
|
858
1072
|
if (!usageRecorded(env))
|
|
859
1073
|
return;
|
|
860
1074
|
try {
|
|
861
1075
|
const path = usagePath(env);
|
|
862
|
-
mkdirSync(
|
|
1076
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
863
1077
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
864
1078
|
`, { mode: 384 });
|
|
865
1079
|
} catch {}
|
|
@@ -945,8 +1159,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
945
1159
|
`);
|
|
946
1160
|
}
|
|
947
1161
|
function printError(prefix, message, hint, cause) {
|
|
948
|
-
const colors = paint(
|
|
949
|
-
const styled = takesControlCodes(
|
|
1162
|
+
const colors = paint(process12.stderr);
|
|
1163
|
+
const styled = takesControlCodes(process12.stderr);
|
|
950
1164
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
951
1165
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
952
1166
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -989,11 +1203,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
989
1203
|
}
|
|
990
1204
|
}
|
|
991
1205
|
if (name === undefined && level.path.length > 1) {
|
|
992
|
-
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));
|
|
993
1207
|
return 2;
|
|
994
1208
|
}
|
|
995
1209
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
996
|
-
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));
|
|
997
1211
|
return 0;
|
|
998
1212
|
}
|
|
999
1213
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1110,17 +1324,17 @@ async function printCandidates(found) {
|
|
|
1110
1324
|
return 0;
|
|
1111
1325
|
}
|
|
1112
1326
|
function packageVersion(entry = Bun.main) {
|
|
1113
|
-
for (let dir =
|
|
1327
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1114
1328
|
try {
|
|
1115
|
-
const { version } = JSON.parse(
|
|
1329
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1116
1330
|
if (typeof version === "string")
|
|
1117
1331
|
return version;
|
|
1118
1332
|
} catch {}
|
|
1119
|
-
if (
|
|
1333
|
+
if (dirname3(dir) === dir)
|
|
1120
1334
|
return "0.0.0";
|
|
1121
1335
|
}
|
|
1122
1336
|
}
|
|
1123
|
-
async function runCli(cli, argv =
|
|
1337
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
1124
1338
|
const version = cli.version ?? packageVersion();
|
|
1125
1339
|
if (argv[0] === COMPLETE)
|
|
1126
1340
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1147,7 +1361,7 @@ function commandPath(scope, argv) {
|
|
|
1147
1361
|
}
|
|
1148
1362
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1149
1363
|
}
|
|
1150
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1364
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
1151
1365
|
if (argv[0] === COMPLETE)
|
|
1152
1366
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1153
1367
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1167,6 +1381,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process9.ar
|
|
|
1167
1381
|
}
|
|
1168
1382
|
return code;
|
|
1169
1383
|
}
|
|
1384
|
+
// ../kit/src/folders.ts
|
|
1385
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1170
1386
|
// ../kit/src/secrets.ts
|
|
1171
1387
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1172
1388
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1189,7 +1405,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1189
1405
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1190
1406
|
}
|
|
1191
1407
|
// ../kit/src/watch.ts
|
|
1192
|
-
import
|
|
1408
|
+
import process13 from "process";
|
|
1193
1409
|
import { format } from "util";
|
|
1194
1410
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1195
1411
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1211,7 +1427,7 @@ function withoutWatch(args) {
|
|
|
1211
1427
|
}
|
|
1212
1428
|
return rest;
|
|
1213
1429
|
}
|
|
1214
|
-
async function watching(value, step, stream =
|
|
1430
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1215
1431
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1216
1432
|
if (!takesControlCodes(stream))
|
|
1217
1433
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1219,12 +1435,12 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1219
1435
|
for (let round = 0;round < rounds; round++) {
|
|
1220
1436
|
const held = [];
|
|
1221
1437
|
const { log, info } = console;
|
|
1222
|
-
const write =
|
|
1438
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1223
1439
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1224
1440
|
`);
|
|
1225
1441
|
console.log = hold;
|
|
1226
1442
|
console.info = hold;
|
|
1227
|
-
|
|
1443
|
+
process13.stdout.write = (text) => {
|
|
1228
1444
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1229
1445
|
return true;
|
|
1230
1446
|
};
|
|
@@ -1233,7 +1449,7 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1233
1449
|
} finally {
|
|
1234
1450
|
console.log = log;
|
|
1235
1451
|
console.info = info;
|
|
1236
|
-
|
|
1452
|
+
process13.stdout.write = write;
|
|
1237
1453
|
}
|
|
1238
1454
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1239
1455
|
await sleep(interval);
|
|
@@ -1241,9 +1457,9 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1241
1457
|
return code;
|
|
1242
1458
|
}
|
|
1243
1459
|
// src/procs.ts
|
|
1244
|
-
import { existsSync } from "fs";
|
|
1245
|
-
import { homedir as
|
|
1246
|
-
import
|
|
1460
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1461
|
+
import { homedir as homedir4 } from "os";
|
|
1462
|
+
import process15 from "process";
|
|
1247
1463
|
|
|
1248
1464
|
// src/read.ts
|
|
1249
1465
|
import { readdir, readFile, readlink } from "fs/promises";
|
|
@@ -1621,7 +1837,7 @@ function maskArgs(args) {
|
|
|
1621
1837
|
}
|
|
1622
1838
|
|
|
1623
1839
|
// src/select.ts
|
|
1624
|
-
import { basename as basename2, join as
|
|
1840
|
+
import { basename as basename2, join as join6, relative } from "path";
|
|
1625
1841
|
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;
|
|
1626
1842
|
var NATIVE = new Set(["rust-analyzer", "gopls", "clangd", "lua-language-server", "pyright-langserver", "pylsp", "intelephense", "phpactor", "tsgo", "esbuild", "biome", "ruff", "phpunit", "pytest", "vitest", "jest"]);
|
|
1627
1843
|
var RUNTIMES = new Set(["node", "bun", "bunx", "deno", "nodejs"]);
|
|
@@ -1658,9 +1874,9 @@ function projectOf(cwd, exists, home) {
|
|
|
1658
1874
|
if (cwd === undefined || !cwd.startsWith(`${home}/`))
|
|
1659
1875
|
return;
|
|
1660
1876
|
const folders = [];
|
|
1661
|
-
for (let dir = cwd;dir.startsWith(`${home}/`); dir =
|
|
1877
|
+
for (let dir = cwd;dir.startsWith(`${home}/`); dir = join6(dir, ".."))
|
|
1662
1878
|
folders.push(dir);
|
|
1663
|
-
return folders.find((dir) => exists(
|
|
1879
|
+
return folders.find((dir) => exists(join6(dir, ".git"))) ?? folders.find((dir) => MARKERS.some((marker) => exists(join6(dir, marker))));
|
|
1664
1880
|
}
|
|
1665
1881
|
function isOrphan(proc, byPid) {
|
|
1666
1882
|
if (proc.unit?.endsWith(".service") === true)
|
|
@@ -1767,7 +1983,7 @@ function summary(group) {
|
|
|
1767
1983
|
};
|
|
1768
1984
|
}
|
|
1769
1985
|
function render(groups) {
|
|
1770
|
-
const colors = paint(
|
|
1986
|
+
const colors = paint(process15.stdout);
|
|
1771
1987
|
const rows = groups.map((group) => [
|
|
1772
1988
|
group.origin,
|
|
1773
1989
|
String(group.members.length),
|
|
@@ -1794,21 +2010,23 @@ async function procs(args) {
|
|
|
1794
2010
|
if (values.watch !== undefined)
|
|
1795
2011
|
return watching(values.watch, async () => procs(withoutWatch(args)));
|
|
1796
2012
|
const olderMs = values.older === undefined ? undefined : duration(values.older, "older", 0, "m");
|
|
1797
|
-
const uid =
|
|
2013
|
+
const uid = process15.getuid?.() ?? -1;
|
|
1798
2014
|
const all = await snapshot("/proc", (owner) => owner === uid);
|
|
1799
|
-
const mine = new Set(ancestry(
|
|
1800
|
-
const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home:
|
|
2015
|
+
const mine = new Set(ancestry(process15.pid, new Map(all.map((proc) => [proc.pid, proc]))));
|
|
2016
|
+
const { groups, protectedCount } = selectGroups(all, { guard: { uid, mine }, now: Date.now(), home: homedir4(), exists: existsSync3, minMem, olderMs });
|
|
1801
2017
|
const pids = groups.flatMap((group) => group.members.map(({ proc }) => proc.pid));
|
|
1802
2018
|
const show = (extra = {}) => {
|
|
1803
|
-
if (values.json === true)
|
|
2019
|
+
if (values.json === true) {
|
|
1804
2020
|
printJson({ groups: groups.map(summary), skipped: protectedCount, ...extra });
|
|
1805
|
-
else
|
|
2021
|
+
} else {
|
|
2022
|
+
printHeader("procs");
|
|
1806
2023
|
console.log(groups.length === 0 ? "nothing to clean" : render(groups));
|
|
2024
|
+
}
|
|
1807
2025
|
};
|
|
1808
2026
|
if (values.kill !== true || pids.length === 0 || values.yes !== true) {
|
|
1809
2027
|
show();
|
|
1810
2028
|
if (values.json !== true && protectedCount > 0)
|
|
1811
|
-
console.error(paint(
|
|
2029
|
+
console.error(paint(process15.stderr).dim(`${protectedCount} more left out: shells, terminals and this command's ancestors are never touched`));
|
|
1812
2030
|
if (values.kill === true && pids.length > 0)
|
|
1813
2031
|
console.error(`dry run: would stop ${pids.length} ${pids.length === 1 ? "process" : "processes"} (${pids.join(" ")}), pass --yes to do it`);
|
|
1814
2032
|
return 0;
|
|
@@ -1823,4 +2041,4 @@ async function procs(args) {
|
|
|
1823
2041
|
}
|
|
1824
2042
|
|
|
1825
2043
|
// src/procs-cli.ts
|
|
1826
|
-
|
|
2044
|
+
process16.exitCode = await runMain({ name: "procs", run: procs });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-proc",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "pid, ports, procs: one process inspected, who listens on a port, and leftover or heavy dev processes cleaned, read straight from /proc (Linux).",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"procs": "$npm_execpath src/procs-cli.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
38
|
+
"@kaynooo/cli-kit": "0.28.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/ports.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Container, Protocol, Socket } from './parse'
|
|
|
2
2
|
import type { ProcInfo } from './read'
|
|
3
3
|
import { basename } from 'node:path'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
-
import { badUsage, duration, fail, jsonOption, paint, parse, printJson, table, truncate, watching, watchOption, wholeNumber, withoutWatch } from '@kaynooo/cli-kit'
|
|
5
|
+
import { badUsage, duration, fail, jsonOption, paint, parse, printHeader, printJson, table, truncate, watching, watchOption, wholeNumber, withoutWatch } from '@kaynooo/cli-kit'
|
|
6
6
|
import { confirm } from '@kaynooo/cli-kit/prompt'
|
|
7
7
|
import { dockerContainers } from './docker'
|
|
8
8
|
import { protectionOf, terminate } from './kill'
|
|
@@ -189,6 +189,7 @@ export async function ports(args: string[]): Promise<number> {
|
|
|
189
189
|
return 0
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
printHeader('ports')
|
|
192
193
|
console.log(render(rows))
|
|
193
194
|
|
|
194
195
|
const unknown = rows.filter(row => row.pid === undefined && row.container === undefined).length
|
package/src/procs.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Group } from './select'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
-
import { duration, fail, formatFileSize, formatSeconds, jsonOption, paint, parse, parseSize, printJson, table, truncate, watching, watchOption, withoutWatch } from '@kaynooo/cli-kit'
|
|
5
|
+
import { duration, fail, formatFileSize, formatSeconds, jsonOption, paint, parse, parseSize, printHeader, printJson, table, truncate, watching, watchOption, withoutWatch } from '@kaynooo/cli-kit'
|
|
6
6
|
import { terminate } from './kill'
|
|
7
7
|
import { maskArgs } from './mask'
|
|
8
8
|
import { ancestry, snapshot } from './read'
|
|
@@ -85,10 +85,13 @@ export async function procs(args: string[]): Promise<number> {
|
|
|
85
85
|
const pids = groups.flatMap(group => group.members.map(({ proc }) => proc.pid))
|
|
86
86
|
|
|
87
87
|
const show = (extra: object = {}): void => {
|
|
88
|
-
if (values.json === true)
|
|
88
|
+
if (values.json === true) {
|
|
89
89
|
printJson({ groups: groups.map(summary), skipped: protectedCount, ...extra })
|
|
90
|
-
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
printHeader('procs')
|
|
91
93
|
console.log(groups.length === 0 ? 'nothing to clean' : render(groups))
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
if (values.kill !== true || pids.length === 0 || values.yes !== true) {
|