@kaynooo/cli-git 0.14.0 → 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.
Files changed (5) hide show
  1. package/dist/gb.js +251 -28
  2. package/dist/gc.js +239 -16
  3. package/dist/gp.js +250 -23
  4. package/dist/gst.js +250 -27
  5. package/package.json +1 -1
package/dist/gc.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gc.ts
5
- import process16 from "process";
5
+ import process17 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -141,7 +141,39 @@ function userConfigPath(bin, where = {}) {
141
141
  }
142
142
 
143
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
+ }
144
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
+ }
145
177
  var DEFAULT = {
146
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" },
147
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" },
@@ -193,6 +225,9 @@ function tinted(colors, spec, env = process5.env) {
193
225
  return chain[token] ?? chain;
194
226
  }, colors);
195
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
+ }
196
231
  function isRecord(value) {
197
232
  return typeof value === "object" && value !== null && !Array.isArray(value);
198
233
  }
@@ -366,6 +401,12 @@ function formatSeconds(total) {
366
401
  const next = amounts[first + 1];
367
402
  return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
368
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
+ }
369
410
  function upTo(text, separator) {
370
411
  const end = text.indexOf(separator);
371
412
  return end === -1 ? text : text.slice(0, end);
@@ -770,6 +811,9 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
770
811
  const after = at === -1 ? [] : cmdline.slice(at + 1);
771
812
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
772
813
  }
814
+ // ../kit/src/progress.ts
815
+ import process12 from "process";
816
+
773
817
  // ../kit/src/process.ts
774
818
  import { constants } from "os";
775
819
  import process11 from "process";
@@ -893,20 +937,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
893
937
  }
894
938
 
895
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";
896
944
  var ESC = String.fromCharCode(27);
897
945
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
898
946
  var RESET_STYLE = `${ESC}[0m`;
947
+ var CTRL_C = 3;
899
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
+ }
900
1123
  // ../kit/src/cli.ts
901
1124
  import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
902
1125
  import { dirname as dirname3, join as join5 } from "path";
903
- import process13 from "process";
1126
+ import process14 from "process";
904
1127
 
905
1128
  // ../kit/src/usage.ts
906
1129
  import { appendFileSync, mkdirSync } from "fs";
907
1130
  import { homedir as homedir3 } from "os";
908
1131
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
909
- import process12 from "process";
1132
+ import process13 from "process";
910
1133
 
911
1134
  // ../kit/src/logs.ts
912
1135
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -920,14 +1143,14 @@ var usageError;
920
1143
  function noteUsageError(message) {
921
1144
  usageError = message;
922
1145
  }
923
- function stateHome(env = process12.env) {
1146
+ function stateHome(env = process13.env) {
924
1147
  const dir = env.XDG_STATE_HOME;
925
1148
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
926
1149
  }
927
- function usagePath(env = process12.env) {
1150
+ function usagePath(env = process13.env) {
928
1151
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
929
1152
  }
930
- function usageRecorded(env = process12.env) {
1153
+ function usageRecorded(env = process13.env) {
931
1154
  const off = env.KAYNOOO_CLI_NO_USAGE;
932
1155
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
933
1156
  }
@@ -941,7 +1164,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
941
1164
  usageError = undefined;
942
1165
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
943
1166
  }
944
- function recordUsage(entry, env = process12.env) {
1167
+ function recordUsage(entry, env = process13.env) {
945
1168
  if (!usageRecorded(env))
946
1169
  return;
947
1170
  try {
@@ -959,8 +1182,8 @@ var LEVEL_OPTIONS = {
959
1182
  };
960
1183
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
961
1184
  function printError(prefix, message, hint, cause) {
962
- const colors = paint(process13.stderr);
963
- const styled = takesControlCodes(process13.stderr);
1185
+ const colors = paint(process14.stderr);
1186
+ const styled = takesControlCodes(process14.stderr);
964
1187
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
965
1188
  const under = (label, text, tint) => text === undefined ? "" : `
966
1189
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1085,7 +1308,7 @@ var {Glob } = globalThis.Bun;
1085
1308
  var SESSION_FILES = new Glob("*.json");
1086
1309
  var ACCOUNT_DIRS = new Glob("*/sessions");
1087
1310
  // ../kit/src/watch.ts
1088
- import process14 from "process";
1311
+ import process15 from "process";
1089
1312
  import { format } from "util";
1090
1313
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1091
1314
  var DEFAULT_SECONDS = 2;
@@ -1107,7 +1330,7 @@ function withoutWatch(args) {
1107
1330
  }
1108
1331
  return rest;
1109
1332
  }
1110
- async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1333
+ async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1111
1334
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1112
1335
  if (!takesControlCodes(stream))
1113
1336
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1115,12 +1338,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1115
1338
  for (let round = 0;round < rounds; round++) {
1116
1339
  const held = [];
1117
1340
  const { log, info } = console;
1118
- const write = process14.stdout.write.bind(process14.stdout);
1341
+ const write = process15.stdout.write.bind(process15.stdout);
1119
1342
  const hold = (...parts) => void held.push(`${format(...parts)}
1120
1343
  `);
1121
1344
  console.log = hold;
1122
1345
  console.info = hold;
1123
- process14.stdout.write = (text) => {
1346
+ process15.stdout.write = (text) => {
1124
1347
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1125
1348
  return true;
1126
1349
  };
@@ -1129,7 +1352,7 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1129
1352
  } finally {
1130
1353
  console.log = log;
1131
1354
  console.info = info;
1132
- process14.stdout.write = write;
1355
+ process15.stdout.write = write;
1133
1356
  }
1134
1357
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1135
1358
  await sleep(interval);
@@ -1208,7 +1431,7 @@ var OPTIONS = {
1208
1431
  };
1209
1432
  var RENAME = /^[RC]\d*$/;
1210
1433
  var NOT_A_REPOSITORY = /not a git repository/i;
1211
- var LITERAL = { ...process16.env, GIT_LITERAL_PATHSPECS: "1" };
1434
+ var LITERAL = { ...process17.env, GIT_LITERAL_PATHSPECS: "1" };
1212
1435
  function messageOf(title, lines, tickets) {
1213
1436
  return [title, lines.join(`
1214
1437
  `), tickets.join(`
@@ -1306,4 +1529,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
1306
1529
  signals.release();
1307
1530
  }
1308
1531
  }
1309
- process16.exitCode = await runMain({ name: "gc", run: main });
1532
+ process17.exitCode = await runMain({ name: "gc", run: main });