@kaynooo/cli-git 0.14.0 → 0.15.1

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/gst.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gst.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";
@@ -108,7 +108,7 @@ function Fe(r = {}) {
108
108
  var o = Fe();
109
109
 
110
110
  // ../kit/src/theme.ts
111
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
111
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
112
112
  import { homedir as homedir2 } from "os";
113
113
  import { join as join3, resolve as resolve2 } from "path";
114
114
  import process5 from "process";
@@ -129,6 +129,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
129
129
  }
130
130
 
131
131
  // ../kit/src/user-config.ts
132
+ import { existsSync as existsSync2, readFileSync } from "fs";
132
133
  import { homedir } from "os";
133
134
  import { join as join2 } from "path";
134
135
  import process4 from "process";
@@ -139,9 +140,59 @@ function configBase(where = {}) {
139
140
  function userConfigPath(bin, where = {}) {
140
141
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
141
142
  }
143
+ function userConfigReadPath(bin, legacy = [], where = {}) {
144
+ const current = userConfigPath(bin, where);
145
+ if (existsSync2(current))
146
+ return current;
147
+ const base = configBase(where);
148
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
149
+ }
150
+ function readUserConfig(bin, where = {}, legacy = []) {
151
+ const path = userConfigReadPath(bin, legacy, where);
152
+ if (!existsSync2(path))
153
+ return {};
154
+ try {
155
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
156
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
157
+ } catch {
158
+ return {};
159
+ }
160
+ }
142
161
 
143
162
  // ../kit/src/theme.ts
163
+ function toLinear(channel) {
164
+ const value = channel / 255;
165
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
166
+ }
167
+ 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)));
168
+ function toOklab(hex) {
169
+ const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
170
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
171
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
172
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
173
+ 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];
174
+ }
175
+ function fromOklab([lightness, a, b]) {
176
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
177
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
178
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
179
+ 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];
180
+ return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
181
+ }
144
182
  var ENDS = new Map;
183
+ function gradientAt(theme, ratio) {
184
+ if (theme.gradient === undefined)
185
+ return;
186
+ const key = theme.gradient.join();
187
+ let ends = ENDS.get(key);
188
+ if (ends === undefined) {
189
+ ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
190
+ ENDS.set(key, ends);
191
+ }
192
+ const at = Math.min(1, Math.max(0, ratio));
193
+ const [from, to] = ends;
194
+ return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
195
+ }
145
196
  var DEFAULT = {
146
197
  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
198
  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 +244,9 @@ function tinted(colors, spec, env = process5.env) {
193
244
  return chain[token] ?? chain;
194
245
  }, colors);
195
246
  }
247
+ function shaded(theme, colors, glyph, cells, width, env = process5.env) {
248
+ return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
249
+ }
196
250
  function isRecord(value) {
197
251
  return typeof value === "object" && value !== null && !Array.isArray(value);
198
252
  }
@@ -205,7 +259,7 @@ function readThemeFile(path, warn) {
205
259
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
206
260
  return;
207
261
  }
208
- const parsed = JSON.parse(readFileSync(path, "utf8"));
262
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
209
263
  if (isRecord(parsed))
210
264
  return parsed;
211
265
  warn(`${path} is not a JSON object, theme ignored`);
@@ -271,7 +325,7 @@ function applyFile(theme, file, where, warn) {
271
325
  }
272
326
  }
273
327
  function endsWalk(home) {
274
- return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
328
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
275
329
  }
276
330
  var warned = new Set;
277
331
  function warnOnce(message) {
@@ -366,6 +420,12 @@ function formatSeconds(total) {
366
420
  const next = amounts[first + 1];
367
421
  return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
368
422
  }
423
+ function formatDuration(ms) {
424
+ return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
425
+ }
426
+ function formatElapsed(ms) {
427
+ return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
428
+ }
369
429
  function upTo(text, separator) {
370
430
  const end = text.indexOf(separator);
371
431
  return end === -1 ? text : text.slice(0, end);
@@ -439,18 +499,14 @@ var FULL_STOP = /\.$/;
439
499
  function usageLine(usage, colors = paint(process8.stdout)) {
440
500
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
441
501
  }
442
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
443
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
502
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
503
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
444
504
  `);
445
505
  }
446
506
  function exitRows(exits, colors = paint(process8.stdout)) {
447
507
  if (exits.length === 0)
448
508
  return [];
449
- const width = Math.max(...exits.map(([code]) => String(code).length));
450
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
451
- }
452
- function replacesRows(replaces, colors = paint(process8.stdout)) {
453
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
509
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
454
510
  }
455
511
  function wantsHelpJson(env = process8.env) {
456
512
  return env.KIT_HELP === "json";
@@ -747,12 +803,12 @@ function nearestOption(message, options, allowNegative) {
747
803
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
748
804
  }
749
805
  // ../kit/src/argv.ts
750
- import { readFileSync as readFileSync2, realpathSync } from "fs";
806
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
751
807
  import { resolve as resolve3 } from "path";
752
808
  import process10 from "process";
753
809
  function commandLine() {
754
810
  try {
755
- return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
811
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
756
812
  } catch {
757
813
  return;
758
814
  }
@@ -770,6 +826,9 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
770
826
  const after = at === -1 ? [] : cmdline.slice(at + 1);
771
827
  return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
772
828
  }
829
+ // ../kit/src/progress.ts
830
+ import process12 from "process";
831
+
773
832
  // ../kit/src/process.ts
774
833
  import { constants } from "os";
775
834
  import process11 from "process";
@@ -893,20 +952,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
893
952
  }
894
953
 
895
954
  // ../kit/src/progress.ts
955
+ var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
956
+ var FRAME_MS = 200;
957
+ var BAR_WIDTH = 20;
958
+ var CLEAR_BELOW = "\r\x1B[J";
896
959
  var ESC = String.fromCharCode(27);
897
960
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
898
961
  var RESET_STYLE = `${ESC}[0m`;
962
+ var CTRL_C = 3;
899
963
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
964
+ var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
965
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
966
+ if (!takesControlCodes(stream, env))
967
+ return { redraw: () => {
968
+ return;
969
+ }, print: (text) => void stream.write(`${text}
970
+ `), stop: () => {
971
+ return;
972
+ } };
973
+ const write = stream.write.bind(stream);
974
+ let frame = 0;
975
+ let drawn = false;
976
+ const columns = () => {
977
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
978
+ return now === undefined || now === 0 ? 80 : now;
979
+ };
980
+ const clear = () => {
981
+ if (drawn)
982
+ write(CLEAR_BELOW);
983
+ drawn = false;
984
+ };
985
+ const draw = () => {
986
+ const width = columns() - 1;
987
+ const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
988
+ const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
989
+ if (lines.length === 0) {
990
+ clear();
991
+ return;
992
+ }
993
+ write(`${CLEAR_BELOW}${lines.join(`
994
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
995
+ drawn = true;
996
+ };
997
+ const timer = setInterval(draw, FRAME_MS);
998
+ stream.on?.("resize", draw);
999
+ const restore = interceptOutput(clear);
1000
+ const release = swallowInput();
1001
+ const onExit = () => {
1002
+ clear();
1003
+ release();
1004
+ };
1005
+ const signals = holdSignals(stop);
1006
+ function stop() {
1007
+ clearInterval(timer);
1008
+ stream.off?.("resize", draw);
1009
+ clear();
1010
+ restore();
1011
+ release();
1012
+ process12.off("exit", onExit);
1013
+ signals.release();
1014
+ }
1015
+ timer.unref();
1016
+ process12.on("exit", onExit);
1017
+ return {
1018
+ redraw: draw,
1019
+ print: (text) => {
1020
+ clear();
1021
+ write(`${text}
1022
+ `);
1023
+ draw();
1024
+ },
1025
+ stop
1026
+ };
1027
+ }
1028
+ function progressLine(stream = process12.stderr, env = process12.env) {
1029
+ const colors = paint(stream, env);
1030
+ const write = stream.write.bind(stream);
1031
+ const begun = performance.now();
1032
+ let started = begun;
1033
+ let current;
1034
+ const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
1035
+ const end = (line) => {
1036
+ region.stop();
1037
+ write(`${line}
1038
+ `);
1039
+ };
1040
+ return {
1041
+ update: (progress) => {
1042
+ const step = current?.step;
1043
+ current = progress;
1044
+ if (progress.step !== step) {
1045
+ started = performance.now();
1046
+ region.redraw();
1047
+ }
1048
+ },
1049
+ stop: region.stop,
1050
+ done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
1051
+ failed: (text) => end(marked("problem", text, stream, undefined, env))
1052
+ };
1053
+ }
1054
+ function progressParts({ step, done, total, unit }, spinner, ms) {
1055
+ const { theme } = activeTheme();
1056
+ const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
1057
+ if (total !== undefined && total > 0) {
1058
+ const counted = Math.min(done ?? 0, total);
1059
+ const filled = Math.round(counted / total * BAR_WIDTH);
1060
+ 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 });
1061
+ }
1062
+ parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
1063
+ return parts;
1064
+ }
1065
+ function plain(text) {
1066
+ return text;
1067
+ }
1068
+ function tintedParts(parts, colors) {
1069
+ return parts.map(({ text, tint }) => tint(colors)(text)).join("");
1070
+ }
1071
+ function cutToWidth(line, width) {
1072
+ if (Bun.stringWidth(line) <= width)
1073
+ return line;
1074
+ let room = width;
1075
+ let kept = "";
1076
+ let index = 0;
1077
+ let linked = false;
1078
+ while (index < line.length) {
1079
+ ESCAPE_CODE.lastIndex = index;
1080
+ const escape = ESCAPE_CODE.exec(line);
1081
+ if (escape !== null) {
1082
+ kept += escape[0];
1083
+ linked ||= escape[0].startsWith(`${ESC}]`);
1084
+ index = ESCAPE_CODE.lastIndex;
1085
+ continue;
1086
+ }
1087
+ const char = String.fromCodePoint(line.codePointAt(index));
1088
+ const columns = Bun.stringWidth(char);
1089
+ if (columns > room)
1090
+ break;
1091
+ kept += char;
1092
+ room -= columns;
1093
+ index += char.length;
1094
+ }
1095
+ return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1096
+ }
1097
+ function swallowInput() {
1098
+ const input = process12.stdin;
1099
+ if (!input.isTTY)
1100
+ return () => {
1101
+ return;
1102
+ };
1103
+ const onData = (data) => {
1104
+ if (data.includes(CTRL_C))
1105
+ process12.kill(process12.pid, "SIGINT");
1106
+ };
1107
+ input.setRawMode(true);
1108
+ input.on("data", onData);
1109
+ input.resume();
1110
+ let released = false;
1111
+ return () => {
1112
+ if (released)
1113
+ return;
1114
+ released = true;
1115
+ input.off("data", onData);
1116
+ input.pause();
1117
+ input.setRawMode(false);
1118
+ };
1119
+ }
1120
+ function interceptOutput(clear) {
1121
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1122
+ const wrapped = targets.map(([target, name]) => {
1123
+ const original = Reflect.get(target, name);
1124
+ const wrapper = (...args) => {
1125
+ clear();
1126
+ return original.apply(target, args);
1127
+ };
1128
+ Reflect.set(target, name, wrapper);
1129
+ return { target, name, original, wrapper };
1130
+ });
1131
+ return () => {
1132
+ for (const { target, name, original, wrapper } of wrapped) {
1133
+ if (Reflect.get(target, name) === wrapper)
1134
+ Reflect.set(target, name, original);
1135
+ }
1136
+ };
1137
+ }
900
1138
  // ../kit/src/cli.ts
901
- import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
1139
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
902
1140
  import { dirname as dirname3, join as join5 } from "path";
903
- import process13 from "process";
1141
+ import process14 from "process";
904
1142
 
905
1143
  // ../kit/src/usage.ts
906
1144
  import { appendFileSync, mkdirSync } from "fs";
907
1145
  import { homedir as homedir3 } from "os";
908
1146
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
909
- import process12 from "process";
1147
+ import process13 from "process";
910
1148
 
911
1149
  // ../kit/src/logs.ts
912
1150
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -920,14 +1158,14 @@ var usageError;
920
1158
  function noteUsageError(message) {
921
1159
  usageError = message;
922
1160
  }
923
- function stateHome(env = process12.env) {
1161
+ function stateHome(env = process13.env) {
924
1162
  const dir = env.XDG_STATE_HOME;
925
1163
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
926
1164
  }
927
- function usagePath(env = process12.env) {
1165
+ function usagePath(env = process13.env) {
928
1166
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
929
1167
  }
930
- function usageRecorded(env = process12.env) {
1168
+ function usageRecorded(env = process13.env) {
931
1169
  const off = env.KAYNOOO_CLI_NO_USAGE;
932
1170
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
933
1171
  }
@@ -941,7 +1179,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
941
1179
  usageError = undefined;
942
1180
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
943
1181
  }
944
- function recordUsage(entry, env = process12.env) {
1182
+ function recordUsage(entry, env = process13.env) {
945
1183
  if (!usageRecorded(env))
946
1184
  return;
947
1185
  try {
@@ -959,8 +1197,8 @@ var LEVEL_OPTIONS = {
959
1197
  };
960
1198
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
961
1199
  function printError(prefix, message, hint, cause) {
962
- const colors = paint(process13.stderr);
963
- const styled = takesControlCodes(process13.stderr);
1200
+ const colors = paint(process14.stderr);
1201
+ const styled = takesControlCodes(process14.stderr);
964
1202
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
965
1203
  const under = (label, text, tint) => text === undefined ? "" : `
966
1204
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1046,9 +1284,13 @@ async function printCandidates(found) {
1046
1284
  return 0;
1047
1285
  }
1048
1286
  function packageVersion(entry = Bun.main) {
1049
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1287
+ let resolved = entry;
1288
+ try {
1289
+ resolved = realpathSync2(entry);
1290
+ } catch {}
1291
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1050
1292
  try {
1051
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1293
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1052
1294
  if (typeof version === "string")
1053
1295
  return version;
1054
1296
  } catch {}
@@ -1085,7 +1327,7 @@ var {Glob } = globalThis.Bun;
1085
1327
  var SESSION_FILES = new Glob("*.json");
1086
1328
  var ACCOUNT_DIRS = new Glob("*/sessions");
1087
1329
  // ../kit/src/watch.ts
1088
- import process14 from "process";
1330
+ import process15 from "process";
1089
1331
  import { format } from "util";
1090
1332
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1091
1333
  var DEFAULT_SECONDS = 2;
@@ -1107,7 +1349,7 @@ function withoutWatch(args) {
1107
1349
  }
1108
1350
  return rest;
1109
1351
  }
1110
- async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1352
+ async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1111
1353
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1112
1354
  if (!takesControlCodes(stream))
1113
1355
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1115,12 +1357,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1115
1357
  for (let round = 0;round < rounds; round++) {
1116
1358
  const held = [];
1117
1359
  const { log, info } = console;
1118
- const write = process14.stdout.write.bind(process14.stdout);
1360
+ const write = process15.stdout.write.bind(process15.stdout);
1119
1361
  const hold = (...parts) => void held.push(`${format(...parts)}
1120
1362
  `);
1121
1363
  console.log = hold;
1122
1364
  console.info = hold;
1123
- process14.stdout.write = (text) => {
1365
+ process15.stdout.write = (text) => {
1124
1366
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1125
1367
  return true;
1126
1368
  };
@@ -1129,16 +1371,33 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
1129
1371
  } finally {
1130
1372
  console.log = log;
1131
1373
  console.info = info;
1132
- process14.stdout.write = write;
1374
+ process15.stdout.write = write;
1133
1375
  }
1134
1376
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1135
1377
  await sleep(interval);
1136
1378
  }
1137
1379
  return code;
1138
1380
  }
1139
- // src/colour.ts
1381
+ // ../kit/src/workspace-root.ts
1382
+ import { homedir as homedir4 } from "os";
1383
+ import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1140
1384
  import process16 from "process";
1141
- function letter(status, stream = process16.stdout) {
1385
+ function expandHome(path, home) {
1386
+ if (path === "~")
1387
+ return home;
1388
+ return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
1389
+ }
1390
+ function configured(env, home) {
1391
+ const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1392
+ return typeof folder === "string" && folder !== "" ? folder : undefined;
1393
+ }
1394
+ function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1395
+ const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1396
+ return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1397
+ }
1398
+ // src/colour.ts
1399
+ import process18 from "process";
1400
+ function letter(status, stream = process18.stdout) {
1142
1401
  const colors = paint(stream);
1143
1402
  const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
1144
1403
  return tint(status);
@@ -1153,8 +1412,8 @@ async function git2(args, env) {
1153
1412
 
1154
1413
  // src/repos.ts
1155
1414
  import { readdir } from "fs/promises";
1156
- import { join as join6, relative, resolve as resolve4 } from "path";
1157
- import process17 from "process";
1415
+ import { join as join7, relative, resolve as resolve5 } from "path";
1416
+ import process19 from "process";
1158
1417
 
1159
1418
  // src/status.ts
1160
1419
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
@@ -1244,9 +1503,9 @@ async function reposUnder(root, depth = DEPTH) {
1244
1503
  found.push(dir);
1245
1504
  if (left === 0)
1246
1505
  return;
1247
- await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join6(dir, entry.name), left - 1)));
1506
+ await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join7(dir, entry.name), left - 1)));
1248
1507
  }
1249
- await walk(resolve4(root), depth);
1508
+ await walk(resolve5(root), depth);
1250
1509
  return found.sort();
1251
1510
  }
1252
1511
  async function toplevelOf(dir) {
@@ -1254,14 +1513,14 @@ async function toplevelOf(dir) {
1254
1513
  return read.code === 0 ? read.stdout.trim() : undefined;
1255
1514
  }
1256
1515
  async function reposOf(roots) {
1257
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process17.cwd()];
1516
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
1258
1517
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
1259
1518
  return [...new Set(found.flat())].sort();
1260
1519
  }
1261
1520
  async function repoState(dir) {
1262
1521
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
1263
1522
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
1264
- return { path: relative(process17.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1523
+ return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1265
1524
  }
1266
1525
  function trackingOf(status) {
1267
1526
  if (status.upstream === null)
@@ -1280,13 +1539,27 @@ function changesOf(status) {
1280
1539
  function branchOf(status) {
1281
1540
  return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
1282
1541
  }
1542
+ async function dirsOf(positionals, all) {
1543
+ const asked = positionals.length > 0 ? positionals : ["."];
1544
+ let dirs;
1545
+ if (all) {
1546
+ dirs = await reposOf(positionals);
1547
+ } else {
1548
+ const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
1549
+ if (found.includes(undefined))
1550
+ fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
1551
+ dirs = [...new Set(found)];
1552
+ }
1553
+ if (dirs.length === 0)
1554
+ fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
1555
+ return dirs;
1556
+ }
1283
1557
 
1284
1558
  // src/gst.ts
1285
1559
  var USAGE = `gst [-n N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
1286
1560
 
1287
- gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.
1288
-
1289
- Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
1561
+ gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.`;
1562
+ var EXITS = [[0, "it printed the status"], [2, "outside a git repository or a usage error"]];
1290
1563
  var OPTIONS = {
1291
1564
  limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
1292
1565
  log: { type: "string", short: "l", description: "the former spelling of --limit" },
@@ -1318,24 +1591,24 @@ async function listRepos(roots, json) {
1318
1591
  printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
1319
1592
  return 0;
1320
1593
  }
1321
- const dim = paint(process18.stdout).dim;
1594
+ const dim = paint(process20.stdout).dim;
1322
1595
  const cells = (repo) => {
1323
1596
  if (repo.status === null)
1324
- return [role("path", process18.stdout)(repo.path), "", "", "git could not read it"];
1597
+ return [role("path", process20.stdout)(repo.path), "", "", "git could not read it"];
1325
1598
  const changes = changesOf(repo.status);
1326
- return [role("path", process18.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
1599
+ return [role("path", process20.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
1327
1600
  };
1328
1601
  console.log(table(repos.map(cells)));
1329
1602
  return 0;
1330
1603
  }
1331
1604
  function group(title, lines) {
1332
- return lines.length === 0 ? [] : [paint(process18.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
1605
+ return lines.length === 0 ? [] : [paint(process20.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
1333
1606
  }
1334
1607
  function staged({ index, from, path }) {
1335
1608
  return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
1336
1609
  }
1337
1610
  async function main(argv) {
1338
- const parsed = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
1611
+ const parsed = parse(argv, USAGE, OPTIONS, { exits: EXITS, positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
1339
1612
  if (parsed.positionals.length > 0 && parsed.values.repos !== true)
1340
1613
  fail(`gst takes dirs with --repos alone
1341
1614
 
@@ -1367,12 +1640,12 @@ ${USAGE}`);
1367
1640
  summary(status, head.code === 0 ? head.stdout : ""),
1368
1641
  ...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
1369
1642
  ...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
1370
- ...group("untracked", status.untracked.map((file) => paint(process18.stdout).dim(file))),
1371
- ...group("conflicted", status.conflicted.map((file) => paint(process18.stdout).red(file))),
1372
- ...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process18.stdout)(commitSha)} ${commitTitle}`))
1643
+ ...group("untracked", status.untracked.map((file) => paint(process20.stdout).dim(file))),
1644
+ ...group("conflicted", status.conflicted.map((file) => paint(process20.stdout).red(file))),
1645
+ ...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process20.stdout)(commitSha)} ${commitTitle}`))
1373
1646
  ];
1374
1647
  console.log(lines.join(`
1375
1648
  `));
1376
1649
  return 0;
1377
1650
  }
1378
- process18.exitCode = await runMain({ name: "gst", run: main });
1651
+ process20.exitCode = await runMain({ name: "gst", run: main });