@kaynooo/cli-git 0.13.1 → 0.15.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/gb.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gb.ts
5
- import process18 from "process";
5
+ import process20 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -10,6 +10,24 @@ import { parseArgs } from "util";
10
10
  // ../kit/src/format.ts
11
11
  import process7 from "process";
12
12
 
13
+ // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
14
+ var N = new Map;
15
+ var Nt = /\s+\S*$/;
16
+ var Y = /\s/;
17
+ function ko(t, e, r = "...") {
18
+ let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
19
+ if (t.length <= e)
20
+ return t;
21
+ let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
22
+ if (o && !Y.test(t[c.length] ?? " "))
23
+ c = c.replace(Nt, "") || c;
24
+ if (o)
25
+ c = c.trimEnd();
26
+ return s ? (c + n).slice(0, l) : c + n;
27
+ }
28
+ var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
29
+ var z = new Map;
30
+
13
31
  // ../kit/src/mode.ts
14
32
  import process2 from "process";
15
33
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -35,10 +53,10 @@ function isInteractive(streams = process2) {
35
53
  import process6 from "process";
36
54
 
37
55
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
38
- var G = /^[a-f0-9]+$/i;
56
+ var G2 = /^[a-f0-9]+$/i;
39
57
  function b(r) {
40
58
  let e = r.startsWith("#") ? r.slice(1) : r;
41
- if (!G.test(e))
59
+ if (!G2.test(e))
42
60
  return [0, 0, 0];
43
61
  if (e.length === 3 || e.length === 4)
44
62
  return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
@@ -46,7 +64,7 @@ function b(r) {
46
64
  throw Error(`Invalid hex color length: ${e.length}`);
47
65
  return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
48
66
  }
49
- var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
67
+ var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
50
68
  let [l, n, c] = b(r);
51
69
  return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
52
70
  }, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
@@ -64,7 +82,7 @@ function f(r, e = []) {
64
82
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
65
83
  let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
66
84
  return new Proxy(c, { get(t, i) {
67
- let a = B[i];
85
+ let a = B2[i];
68
86
  if (Array.isArray(a)) {
69
87
  let s = g.get(i);
70
88
  if (s === undefined)
@@ -123,7 +141,39 @@ function userConfigPath(bin, where = {}) {
123
141
  }
124
142
 
125
143
  // ../kit/src/theme.ts
144
+ function toLinear(channel) {
145
+ const value = channel / 255;
146
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
147
+ }
148
+ var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
149
+ function toOklab(hex) {
150
+ const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
151
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
152
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
153
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
154
+ return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
155
+ }
156
+ function fromOklab([lightness, a, b]) {
157
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
158
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
159
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
160
+ const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
161
+ return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
162
+ }
126
163
  var ENDS = new Map;
164
+ function gradientAt(theme, ratio) {
165
+ if (theme.gradient === undefined)
166
+ return;
167
+ const key = theme.gradient.join();
168
+ let ends = ENDS.get(key);
169
+ if (ends === undefined) {
170
+ ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
171
+ ENDS.set(key, ends);
172
+ }
173
+ const at = Math.min(1, Math.max(0, ratio));
174
+ const [from, to] = ends;
175
+ return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
176
+ }
127
177
  var DEFAULT = {
128
178
  colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
129
179
  glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
@@ -175,6 +225,9 @@ function tinted(colors, spec, env = process5.env) {
175
225
  return chain[token] ?? chain;
176
226
  }, colors);
177
227
  }
228
+ function shaded(theme, colors, glyph, cells, width, env = process5.env) {
229
+ return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
230
+ }
178
231
  function isRecord(value) {
179
232
  return typeof value === "object" && value !== null && !Array.isArray(value);
180
233
  }
@@ -304,12 +357,22 @@ function activeTheme() {
304
357
  }
305
358
 
306
359
  // ../kit/src/style.ts
360
+ var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
307
361
  function takesControlCodes(stream, env = process6.env) {
308
362
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
309
363
  }
310
364
  function paint(stream, env = process6.env) {
311
365
  return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
312
366
  }
367
+ function marked(mark, text, stream, detail, env = process6.env) {
368
+ const colors = paint(stream, env);
369
+ let head = MARK_WORDS[mark];
370
+ if (takesControlCodes(stream, env)) {
371
+ const { theme } = activeTheme();
372
+ head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
373
+ }
374
+ return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
375
+ }
313
376
  function role(name, stream, env = process6.env) {
314
377
  const colors = paint(stream, env);
315
378
  return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
@@ -338,6 +401,12 @@ function formatSeconds(total) {
338
401
  const next = amounts[first + 1];
339
402
  return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
340
403
  }
404
+ function formatDuration(ms) {
405
+ return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
406
+ }
407
+ function formatElapsed(ms) {
408
+ return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
409
+ }
341
410
  function upTo(text, separator) {
342
411
  const end = text.indexOf(separator);
343
412
  return end === -1 ? text : text.slice(0, end);
@@ -349,7 +418,53 @@ function formatAge(date, now = Date.now()) {
349
418
  const seconds = (now - at) / 1000;
350
419
  return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
351
420
  }
421
+ function truncate(text, width) {
422
+ return ko(text, width, { suffix: "\u2026", includeSuffix: true });
423
+ }
424
+ var LINE_BREAKS = /\s*\n\s*/g;
352
425
  var ESCAPE = String.fromCharCode(27);
426
+ function textWidth(text) {
427
+ return Bun.stringWidth(text);
428
+ }
429
+ function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
430
+ const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
431
+ if (outputMode(stream, env) === "agent")
432
+ return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
433
+ `);
434
+ const widths = [];
435
+ for (const row of cells) {
436
+ for (const [index, cell] of row.entries())
437
+ widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
438
+ }
439
+ const shown = fit === undefined ? cells : narrow(cells, widths, fit);
440
+ const colors = paint(stream);
441
+ const lines = shown.map((row) => row.map((cell, index) => {
442
+ const width = widths[index] ?? 0;
443
+ const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
444
+ if (align[index] === "right")
445
+ return `${gap}${cell}`;
446
+ return index === row.length - 1 ? cell : `${cell}${gap}`;
447
+ }).join(" ").trimEnd());
448
+ const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
449
+ return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
450
+ `);
451
+ }
452
+ function narrow(rows, widths, limit) {
453
+ const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
454
+ const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
455
+ const floor = 8;
456
+ while (used() > limit) {
457
+ let widest = -1;
458
+ for (const [index, width] of widths.entries()) {
459
+ if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
460
+ widest = index;
461
+ }
462
+ if (widest === -1)
463
+ break;
464
+ widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
465
+ }
466
+ return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
467
+ }
353
468
  function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
354
469
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
355
470
  }
@@ -672,9 +787,36 @@ function nearestOption(message, options, allowNegative) {
672
787
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
673
788
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
674
789
  }
790
+ // ../kit/src/argv.ts
791
+ import { readFileSync as readFileSync2, realpathSync } from "fs";
792
+ import { resolve as resolve3 } from "path";
793
+ import process10 from "process";
794
+ function commandLine() {
795
+ try {
796
+ return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
797
+ } catch {
798
+ return;
799
+ }
800
+ }
801
+ function realPath(word) {
802
+ try {
803
+ return realpathSync(resolve3(word));
804
+ } catch {
805
+ return;
806
+ }
807
+ }
808
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
809
+ const target = script === undefined ? undefined : realPath(script) ?? script;
810
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
811
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
812
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
813
+ }
814
+ // ../kit/src/progress.ts
815
+ import process12 from "process";
816
+
675
817
  // ../kit/src/process.ts
676
818
  import { constants } from "os";
677
- import process10 from "process";
819
+ import process11 from "process";
678
820
  var KILL_GRACE_MS = 2000;
679
821
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
680
822
  function exitCodeOf(code, signal) {
@@ -696,7 +838,7 @@ function holdSignals(cleanup) {
696
838
  },
697
839
  release: () => {
698
840
  for (const signal of SIGNALS)
699
- process10.off(signal, onSignal);
841
+ process11.off(signal, onSignal);
700
842
  }
701
843
  };
702
844
  function onSignal(signal) {
@@ -709,10 +851,10 @@ function holdSignals(cleanup) {
709
851
  return;
710
852
  held.release();
711
853
  cleanup(signal);
712
- process10.kill(process10.pid, signal);
854
+ process11.kill(process11.pid, signal);
713
855
  }
714
856
  for (const signal of SIGNALS)
715
- process10.on(signal, onSignal);
857
+ process11.on(signal, onSignal);
716
858
  return held;
717
859
  }
718
860
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -726,7 +868,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
726
868
  return;
727
869
  try {
728
870
  if (grouped)
729
- process10.kill(-proc.pid, killing);
871
+ process11.kill(-proc.pid, killing);
730
872
  else
731
873
  proc.kill(killing);
732
874
  } catch {}
@@ -795,20 +937,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
795
937
  }
796
938
 
797
939
  // ../kit/src/progress.ts
940
+ var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
941
+ var FRAME_MS = 200;
942
+ var BAR_WIDTH = 20;
943
+ var CLEAR_BELOW = "\r\x1B[J";
798
944
  var ESC = String.fromCharCode(27);
799
945
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
800
946
  var RESET_STYLE = `${ESC}[0m`;
947
+ var CTRL_C = 3;
801
948
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
949
+ var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
950
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
951
+ if (!takesControlCodes(stream, env))
952
+ return { redraw: () => {
953
+ return;
954
+ }, print: (text) => void stream.write(`${text}
955
+ `), stop: () => {
956
+ return;
957
+ } };
958
+ const write = stream.write.bind(stream);
959
+ let frame = 0;
960
+ let drawn = false;
961
+ const columns = () => {
962
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
963
+ return now === undefined || now === 0 ? 80 : now;
964
+ };
965
+ const clear = () => {
966
+ if (drawn)
967
+ write(CLEAR_BELOW);
968
+ drawn = false;
969
+ };
970
+ const draw = () => {
971
+ const width = columns() - 1;
972
+ const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
973
+ const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
974
+ if (lines.length === 0) {
975
+ clear();
976
+ return;
977
+ }
978
+ write(`${CLEAR_BELOW}${lines.join(`
979
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
980
+ drawn = true;
981
+ };
982
+ const timer = setInterval(draw, FRAME_MS);
983
+ stream.on?.("resize", draw);
984
+ const restore = interceptOutput(clear);
985
+ const release = swallowInput();
986
+ const onExit = () => {
987
+ clear();
988
+ release();
989
+ };
990
+ const signals = holdSignals(stop);
991
+ function stop() {
992
+ clearInterval(timer);
993
+ stream.off?.("resize", draw);
994
+ clear();
995
+ restore();
996
+ release();
997
+ process12.off("exit", onExit);
998
+ signals.release();
999
+ }
1000
+ timer.unref();
1001
+ process12.on("exit", onExit);
1002
+ return {
1003
+ redraw: draw,
1004
+ print: (text) => {
1005
+ clear();
1006
+ write(`${text}
1007
+ `);
1008
+ draw();
1009
+ },
1010
+ stop
1011
+ };
1012
+ }
1013
+ function progressLine(stream = process12.stderr, env = process12.env) {
1014
+ const colors = paint(stream, env);
1015
+ const write = stream.write.bind(stream);
1016
+ const begun = performance.now();
1017
+ let started = begun;
1018
+ let current;
1019
+ const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
1020
+ const end = (line) => {
1021
+ region.stop();
1022
+ write(`${line}
1023
+ `);
1024
+ };
1025
+ return {
1026
+ update: (progress) => {
1027
+ const step = current?.step;
1028
+ current = progress;
1029
+ if (progress.step !== step) {
1030
+ started = performance.now();
1031
+ region.redraw();
1032
+ }
1033
+ },
1034
+ stop: region.stop,
1035
+ done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
1036
+ failed: (text) => end(marked("problem", text, stream, undefined, env))
1037
+ };
1038
+ }
1039
+ function progressParts({ step, done, total, unit }, spinner, ms) {
1040
+ const { theme } = activeTheme();
1041
+ const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
1042
+ if (total !== undefined && total > 0) {
1043
+ const counted = Math.min(done ?? 0, total);
1044
+ const filled = Math.round(counted / total * BAR_WIDTH);
1045
+ parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
1046
+ }
1047
+ parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
1048
+ return parts;
1049
+ }
1050
+ function plain(text) {
1051
+ return text;
1052
+ }
1053
+ function tintedParts(parts, colors) {
1054
+ return parts.map(({ text, tint }) => tint(colors)(text)).join("");
1055
+ }
1056
+ function cutToWidth(line, width) {
1057
+ if (Bun.stringWidth(line) <= width)
1058
+ return line;
1059
+ let room = width;
1060
+ let kept = "";
1061
+ let index = 0;
1062
+ let linked = false;
1063
+ while (index < line.length) {
1064
+ ESCAPE_CODE.lastIndex = index;
1065
+ const escape = ESCAPE_CODE.exec(line);
1066
+ if (escape !== null) {
1067
+ kept += escape[0];
1068
+ linked ||= escape[0].startsWith(`${ESC}]`);
1069
+ index = ESCAPE_CODE.lastIndex;
1070
+ continue;
1071
+ }
1072
+ const char = String.fromCodePoint(line.codePointAt(index));
1073
+ const columns = Bun.stringWidth(char);
1074
+ if (columns > room)
1075
+ break;
1076
+ kept += char;
1077
+ room -= columns;
1078
+ index += char.length;
1079
+ }
1080
+ return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1081
+ }
1082
+ function swallowInput() {
1083
+ const input = process12.stdin;
1084
+ if (!input.isTTY)
1085
+ return () => {
1086
+ return;
1087
+ };
1088
+ const onData = (data) => {
1089
+ if (data.includes(CTRL_C))
1090
+ process12.kill(process12.pid, "SIGINT");
1091
+ };
1092
+ input.setRawMode(true);
1093
+ input.on("data", onData);
1094
+ input.resume();
1095
+ let released = false;
1096
+ return () => {
1097
+ if (released)
1098
+ return;
1099
+ released = true;
1100
+ input.off("data", onData);
1101
+ input.pause();
1102
+ input.setRawMode(false);
1103
+ };
1104
+ }
1105
+ function interceptOutput(clear) {
1106
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1107
+ const wrapped = targets.map(([target, name]) => {
1108
+ const original = Reflect.get(target, name);
1109
+ const wrapper = (...args) => {
1110
+ clear();
1111
+ return original.apply(target, args);
1112
+ };
1113
+ Reflect.set(target, name, wrapper);
1114
+ return { target, name, original, wrapper };
1115
+ });
1116
+ return () => {
1117
+ for (const { target, name, original, wrapper } of wrapped) {
1118
+ if (Reflect.get(target, name) === wrapper)
1119
+ Reflect.set(target, name, original);
1120
+ }
1121
+ };
1122
+ }
802
1123
  // ../kit/src/cli.ts
803
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1124
+ import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
804
1125
  import { dirname as dirname3, join as join5 } from "path";
805
- import process12 from "process";
1126
+ import process14 from "process";
806
1127
 
807
1128
  // ../kit/src/usage.ts
808
1129
  import { appendFileSync, mkdirSync } from "fs";
809
1130
  import { homedir as homedir3 } from "os";
810
1131
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
811
- import process11 from "process";
1132
+ import process13 from "process";
812
1133
 
813
1134
  // ../kit/src/logs.ts
814
1135
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -822,14 +1143,14 @@ var usageError;
822
1143
  function noteUsageError(message) {
823
1144
  usageError = message;
824
1145
  }
825
- function stateHome(env = process11.env) {
1146
+ function stateHome(env = process13.env) {
826
1147
  const dir = env.XDG_STATE_HOME;
827
1148
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
828
1149
  }
829
- function usagePath(env = process11.env) {
1150
+ function usagePath(env = process13.env) {
830
1151
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
831
1152
  }
832
- function usageRecorded(env = process11.env) {
1153
+ function usageRecorded(env = process13.env) {
833
1154
  const off = env.KAYNOOO_CLI_NO_USAGE;
834
1155
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
835
1156
  }
@@ -843,7 +1164,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
843
1164
  usageError = undefined;
844
1165
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
845
1166
  }
846
- function recordUsage(entry, env = process11.env) {
1167
+ function recordUsage(entry, env = process13.env) {
847
1168
  if (!usageRecorded(env))
848
1169
  return;
849
1170
  try {
@@ -861,8 +1182,8 @@ var LEVEL_OPTIONS = {
861
1182
  };
862
1183
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
863
1184
  function printError(prefix, message, hint, cause) {
864
- const colors = paint(process12.stderr);
865
- const styled = takesControlCodes(process12.stderr);
1185
+ const colors = paint(process14.stderr);
1186
+ const styled = takesControlCodes(process14.stderr);
866
1187
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
867
1188
  const under = (label, text, tint) => text === undefined ? "" : `
868
1189
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -909,24 +1230,24 @@ function candidateLine(candidate) {
909
1230
  }
910
1231
  function positionalBeingTyped(before, { options, positionals }) {
911
1232
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
912
- let index = 0;
1233
+ const typed = [];
913
1234
  let at = 0;
914
1235
  while (at < before.length) {
915
1236
  const word = before[at];
916
1237
  if (word === "--") {
917
- index += before.length - at - 1;
1238
+ typed.push(...before.slice(at + 1));
918
1239
  break;
919
1240
  }
920
1241
  if (!word.startsWith("-"))
921
- index++;
1242
+ typed.push(word);
922
1243
  else if (takesValue(word))
923
1244
  at++;
924
1245
  at++;
925
1246
  }
926
1247
  const last = positionals.at(-1);
927
- if (index < positionals.length)
928
- return positionals[index];
929
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1248
+ if (typed.length < positionals.length)
1249
+ return { name: positionals[typed.length], typed };
1250
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
930
1251
  }
931
1252
  async function leafCandidates(run, words) {
932
1253
  const completing = await completingOf(run);
@@ -934,12 +1255,12 @@ async function leafCandidates(run, words) {
934
1255
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
935
1256
  const flag = words.at(-2);
936
1257
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1258
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
937
1259
  if (option?.type === "string") {
938
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1260
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
939
1261
  return values === undefined ? [FILES] : values.map(candidateLine);
940
1262
  }
941
- const name = positionalBeingTyped(words.slice(0, -1), completing);
942
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1263
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
943
1264
  return values === undefined ? [FILES] : values.map(candidateLine);
944
1265
  }
945
1266
  async function printCandidates(found) {
@@ -948,9 +1269,9 @@ async function printCandidates(found) {
948
1269
  return 0;
949
1270
  }
950
1271
  function packageVersion(entry = Bun.main) {
951
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1272
+ for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
952
1273
  try {
953
- const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
1274
+ const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
954
1275
  if (typeof version === "string")
955
1276
  return version;
956
1277
  } catch {}
@@ -958,7 +1279,7 @@ function packageVersion(entry = Bun.main) {
958
1279
  return "0.0.0";
959
1280
  }
960
1281
  }
961
- async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
1282
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
962
1283
  if (argv[0] === COMPLETE)
963
1284
  return printCandidates(leafCandidates(run, argv.slice(1)));
964
1285
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -987,7 +1308,7 @@ var {Glob } = globalThis.Bun;
987
1308
  var SESSION_FILES = new Glob("*.json");
988
1309
  var ACCOUNT_DIRS = new Glob("*/sessions");
989
1310
  // ../kit/src/watch.ts
990
- import process13 from "process";
1311
+ import process15 from "process";
991
1312
  import { format } from "util";
992
1313
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
993
1314
  var DEFAULT_SECONDS = 2;
@@ -1009,7 +1330,7 @@ function withoutWatch(args) {
1009
1330
  }
1010
1331
  return rest;
1011
1332
  }
1012
- async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1333
+ async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1013
1334
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1014
1335
  if (!takesControlCodes(stream))
1015
1336
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1017,12 +1338,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
1017
1338
  for (let round = 0;round < rounds; round++) {
1018
1339
  const held = [];
1019
1340
  const { log, info } = console;
1020
- const write = process13.stdout.write.bind(process13.stdout);
1341
+ const write = process15.stdout.write.bind(process15.stdout);
1021
1342
  const hold = (...parts) => void held.push(`${format(...parts)}
1022
1343
  `);
1023
1344
  console.log = hold;
1024
1345
  console.info = hold;
1025
- process13.stdout.write = (text) => {
1346
+ process15.stdout.write = (text) => {
1026
1347
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1027
1348
  return true;
1028
1349
  };
@@ -1031,7 +1352,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
1031
1352
  } finally {
1032
1353
  console.log = log;
1033
1354
  console.info = info;
1034
- process13.stdout.write = write;
1355
+ process15.stdout.write = write;
1035
1356
  }
1036
1357
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1037
1358
  await sleep(interval);
@@ -1040,7 +1361,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
1040
1361
  }
1041
1362
  // src/branch.ts
1042
1363
  import { basename } from "path";
1043
- import process17 from "process";
1364
+ import process19 from "process";
1044
1365
 
1045
1366
  // ../kit/src/picker/score.ts
1046
1367
  var MATCH = 16;
@@ -1311,11 +1632,11 @@ function chosen(state) {
1311
1632
 
1312
1633
  // ../kit/src/picker/terminal.ts
1313
1634
  import { openSync } from "fs";
1314
- import process16 from "process";
1635
+ import process18 from "process";
1315
1636
  import tty from "tty";
1316
1637
 
1317
1638
  // ../kit/src/picker/preview.ts
1318
- import process15 from "process";
1639
+ import process17 from "process";
1319
1640
 
1320
1641
  // ../kit/src/shell.ts
1321
1642
  var SEPARATORS = new Set([`
@@ -1384,7 +1705,7 @@ async function runPreview(template, line, signal, hidden = []) {
1384
1705
  ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
1385
1706
  const stop = () => {
1386
1707
  try {
1387
- process15.kill(-proc.pid, "SIGKILL");
1708
+ process17.kill(-proc.pid, "SIGKILL");
1388
1709
  } catch {
1389
1710
  proc.kill();
1390
1711
  }
@@ -1519,7 +1840,7 @@ var PASTE_ON = "\x1B[?2004h";
1519
1840
  var PASTE_OFF = "\x1B[?2004l";
1520
1841
  var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
1521
1842
  var MOUSE_OFF = "\x1B[?1006l\x1B[?1000l";
1522
- var CLEAR_BELOW = "\r\x1B[J";
1843
+ var CLEAR_BELOW2 = "\r\x1B[J";
1523
1844
  var SIGNALS2 = ["SIGINT", "SIGTERM", "SIGHUP"];
1524
1845
  function up(lines) {
1525
1846
  return lines > 0 ? `\x1B[${lines}A` : "";
@@ -1532,7 +1853,7 @@ function openTerminal() {
1532
1853
  return fail("no terminal to read keys from (/dev/tty)");
1533
1854
  }
1534
1855
  const keys = Bun.file("/dev/tty").stream().getReader();
1535
- const out = process16.stderr;
1856
+ const out = process18.stderr;
1536
1857
  let resize;
1537
1858
  async function read(onChunk) {
1538
1859
  const decoder = new TextDecoder;
@@ -1587,7 +1908,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1587
1908
  const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
1588
1909
  let frame = HIDE_CURSOR;
1589
1910
  if (reserved !== layout.height || clear) {
1590
- frame += CLEAR_BELOW + `
1911
+ frame += CLEAR_BELOW2 + `
1591
1912
  `.repeat(layout.height - 1) + up(layout.height - 1);
1592
1913
  reserved = layout.height;
1593
1914
  }
@@ -1631,7 +1952,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1631
1952
  clearTimeout(previewTimer);
1632
1953
  clearTimeout(escape);
1633
1954
  previewing.abort();
1634
- terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1955
+ terminal.write(`${CLEAR_BELOW2}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1635
1956
  terminal.close();
1636
1957
  }
1637
1958
  const stop = () => {
@@ -1706,9 +2027,9 @@ async function select(rows, settings, terminal = openTerminal()) {
1706
2027
  const ended = new Promise((resolve) => {
1707
2028
  finish = resolve;
1708
2029
  });
1709
- process16.once("exit", restore);
2030
+ process18.once("exit", restore);
1710
2031
  for (const signal of SIGNALS2)
1711
- process16.once(signal, stop);
2032
+ process18.once(signal, stop);
1712
2033
  try {
1713
2034
  terminal.write(`${PASTE_ON}${MOUSE_ON}`);
1714
2035
  terminal.listen(onChunk, () => draw(true));
@@ -1721,8 +2042,8 @@ async function select(rows, settings, terminal = openTerminal()) {
1721
2042
  await ended;
1722
2043
  } finally {
1723
2044
  for (const signal of SIGNALS2)
1724
- process16.off(signal, stop);
1725
- process16.off("exit", restore);
2045
+ process18.off(signal, stop);
2046
+ process18.off("exit", restore);
1726
2047
  restore();
1727
2048
  }
1728
2049
  return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
@@ -1735,7 +2056,7 @@ async function previewOf(preview, hidden, signal) {
1735
2056
  }
1736
2057
  }
1737
2058
  // ../kit/src/picker.ts
1738
- function table(rows) {
2059
+ function table2(rows) {
1739
2060
  const widths = rows[0]?.cells.map((_, index) => Math.max(...rows.map((row) => Bun.stringWidth(row.cells[index])))) ?? [];
1740
2061
  return rows.map((row) => [
1741
2062
  ...row.hidden,
@@ -1993,7 +2314,7 @@ async function gb(args) {
1993
2314
  if (parsed.values.json === true)
1994
2315
  printJson(all);
1995
2316
  else
1996
- console.log(table(all.map(row)).map((line) => takesControlCodes(process17.stdout) ? line : Bun.stripANSI(line)).join(`
2317
+ console.log(table2(all.map(row)).map((line) => takesControlCodes(process19.stdout) ? line : Bun.stripANSI(line)).join(`
1997
2318
  `));
1998
2319
  return 0;
1999
2320
  }
@@ -2050,4 +2371,4 @@ async function finish(command, typed, emitting) {
2050
2371
  }
2051
2372
 
2052
2373
  // src/gb.ts
2053
- process18.exitCode = await runMain({ name: "gb", run: gb });
2374
+ process20.exitCode = await runMain({ name: "gb", run: gb });