@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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # gst, gc, gb and gp
1
+ # gst, gc, gb, gp, gf, gcl, gd and gu
2
2
 
3
3
  Git for Claude Code, where a session would otherwise chain `git status --short` and `git log --oneline` to read the state, or `git add <paths> && git status && git commit -m ...` to commit and have the commit bounced over its message.
4
4
 
@@ -42,6 +42,39 @@ Prints one line with the branch, its upstream and how far ahead and behind it is
42
42
  - Hidden flags for wrappers: `--emit` (with any of the above) prints the command as lines for a shell function to run, `--list` the rows as JSON for term, `--names` the branches with their last commit for shell completions, `--show <branch>` the preview and `--fetch` what ctrl-r runs.
43
43
  - Exit codes: the git command's, 1 when no branch is picked or found, 2 outside a repository.
44
44
 
45
+ ## gf
46
+
47
+ `gf [dir]...` fetches with prune, then fast-forwards the current branch onto its upstream, and prints what came in (`main <- origin/main, 2 commits`). `--repos` (`-r`) does every repository `gst --repos` lists; `--no-pull` fetches only and says how far behind the branch is.
48
+
49
+ - It never merges or rebases: a branch that has diverged, or a working tree the fast-forward would overwrite, is refused and left as it was, with git's reason.
50
+ - A detached HEAD, a branch with no upstream and one whose upstream is gone are fetched only, saying so.
51
+ - `--json` prints `{path, branch, upstream, commits, outcome, reason?}` per repository, `outcome` being `updated`, `current`, `fetched`, `skipped` or `refused`.
52
+ - Exit codes: 0 every repository was fetched, and fast-forwarded when it could be, 1 a fetch failed, a branch diverged or a fast-forward was refused, 2 outside a repository or a usage error.
53
+
54
+ ## gcl
55
+
56
+ `gcl <repo> [dir]` clones into `<workspace>/<name>` (the workspace `cli config` reports) or into `dir`, and prints the path on stdout, so `cd (gcl kaynooo/cli)` lands in it. `<repo>` is a URL, an scp-style address, a local path or `owner/name`, read as `https://git.kaynooo.fr/owner/name.git`; the `forge` key of `~/.config/kaynooo-cli/config.json` names another host.
57
+
58
+ - A folder that already holds the repository is not cloned again: it is fetched and fast-forwarded as `gf` does. A folder holding anything else is refused, exit 1.
59
+ - `--json` prints `{url, path, branch, head, outcome}`, `outcome` being `cloned` or `existing`.
60
+
61
+ ## gd
62
+
63
+ `gd [path]...` lists the tracked files that changed with their added and removed lines, staged apart from unstaged; untracked files are `gst`'s. With paths, or `--patch` (`-p`), it prints the patch instead, through `view --diff` on a terminal when `view` is installed.
64
+
65
+ - `--staged` (`-s`) keeps what is staged; `--ref <rev>` compares the working tree to a commit, branch or tag, and `--ref a..b` two commits.
66
+ - `--json` prints `[{title, files: [{path, added, removed}]}]`, the counts being null for a binary file.
67
+ - Exit codes: 0, 1 git refused (an unknown ref), 2 outside a repository or a usage error.
68
+
69
+ ## gu
70
+
71
+ `gu <path>...` undoes changes and keeps what it takes away.
72
+
73
+ - By default it discards the unstaged changes of the paths, after saving them as a patch in the git folder (`gu/<time>.patch`); `git apply` puts them back. Without a path it is a usage error, never "everything".
74
+ - `--staged` unstages the paths, the working tree untouched.
75
+ - `--commit` undoes the last commit, its changes left staged (the commit stays in the reflog). It refuses a commit the upstream already holds, a merge and the first commit.
76
+ - Exit codes: 0, 1 a path with no change or a commit refused, 2 a usage error or outside a repository.
77
+
45
78
  ## Library
46
79
 
47
80
  `@kaynooo/cli-git/message` exports `commitMessageViolation(message)`, the rule a message breaks as the sentence to show or null, and the rule sentences, for the guard that checks a `git commit` typed by hand.
package/dist/gb.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gb.ts
5
- import process19 from "process";
5
+ import process21 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
  }
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";
1384
+ import process16 from "process";
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
+ }
1139
1398
  // src/branch.ts
1140
1399
  import { basename } from "path";
1141
- import process18 from "process";
1400
+ import process20 from "process";
1142
1401
 
1143
1402
  // ../kit/src/picker/score.ts
1144
1403
  var MATCH = 16;
@@ -1409,11 +1668,11 @@ function chosen(state) {
1409
1668
 
1410
1669
  // ../kit/src/picker/terminal.ts
1411
1670
  import { openSync } from "fs";
1412
- import process17 from "process";
1671
+ import process19 from "process";
1413
1672
  import tty from "tty";
1414
1673
 
1415
1674
  // ../kit/src/picker/preview.ts
1416
- import process16 from "process";
1675
+ import process18 from "process";
1417
1676
 
1418
1677
  // ../kit/src/shell.ts
1419
1678
  var SEPARATORS = new Set([`
@@ -1482,7 +1741,7 @@ async function runPreview(template, line, signal, hidden = []) {
1482
1741
  ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
1483
1742
  const stop = () => {
1484
1743
  try {
1485
- process16.kill(-proc.pid, "SIGKILL");
1744
+ process18.kill(-proc.pid, "SIGKILL");
1486
1745
  } catch {
1487
1746
  proc.kill();
1488
1747
  }
@@ -1617,7 +1876,7 @@ var PASTE_ON = "\x1B[?2004h";
1617
1876
  var PASTE_OFF = "\x1B[?2004l";
1618
1877
  var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
1619
1878
  var MOUSE_OFF = "\x1B[?1006l\x1B[?1000l";
1620
- var CLEAR_BELOW = "\r\x1B[J";
1879
+ var CLEAR_BELOW2 = "\r\x1B[J";
1621
1880
  var SIGNALS2 = ["SIGINT", "SIGTERM", "SIGHUP"];
1622
1881
  function up(lines) {
1623
1882
  return lines > 0 ? `\x1B[${lines}A` : "";
@@ -1630,7 +1889,7 @@ function openTerminal() {
1630
1889
  return fail("no terminal to read keys from (/dev/tty)");
1631
1890
  }
1632
1891
  const keys = Bun.file("/dev/tty").stream().getReader();
1633
- const out = process17.stderr;
1892
+ const out = process19.stderr;
1634
1893
  let resize;
1635
1894
  async function read(onChunk) {
1636
1895
  const decoder = new TextDecoder;
@@ -1685,7 +1944,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1685
1944
  const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
1686
1945
  let frame = HIDE_CURSOR;
1687
1946
  if (reserved !== layout.height || clear) {
1688
- frame += CLEAR_BELOW + `
1947
+ frame += CLEAR_BELOW2 + `
1689
1948
  `.repeat(layout.height - 1) + up(layout.height - 1);
1690
1949
  reserved = layout.height;
1691
1950
  }
@@ -1729,7 +1988,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1729
1988
  clearTimeout(previewTimer);
1730
1989
  clearTimeout(escape);
1731
1990
  previewing.abort();
1732
- terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1991
+ terminal.write(`${CLEAR_BELOW2}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1733
1992
  terminal.close();
1734
1993
  }
1735
1994
  const stop = () => {
@@ -1804,9 +2063,9 @@ async function select(rows, settings, terminal = openTerminal()) {
1804
2063
  const ended = new Promise((resolve) => {
1805
2064
  finish = resolve;
1806
2065
  });
1807
- process17.once("exit", restore);
2066
+ process19.once("exit", restore);
1808
2067
  for (const signal of SIGNALS2)
1809
- process17.once(signal, stop);
2068
+ process19.once(signal, stop);
1810
2069
  try {
1811
2070
  terminal.write(`${PASTE_ON}${MOUSE_ON}`);
1812
2071
  terminal.listen(onChunk, () => draw(true));
@@ -1819,8 +2078,8 @@ async function select(rows, settings, terminal = openTerminal()) {
1819
2078
  await ended;
1820
2079
  } finally {
1821
2080
  for (const signal of SIGNALS2)
1822
- process17.off(signal, stop);
1823
- process17.off("exit", restore);
2081
+ process19.off(signal, stop);
2082
+ process19.off("exit", restore);
1824
2083
  restore();
1825
2084
  }
1826
2085
  return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
@@ -2091,7 +2350,7 @@ async function gb(args) {
2091
2350
  if (parsed.values.json === true)
2092
2351
  printJson(all);
2093
2352
  else
2094
- console.log(table2(all.map(row)).map((line) => takesControlCodes(process18.stdout) ? line : Bun.stripANSI(line)).join(`
2353
+ console.log(table2(all.map(row)).map((line) => takesControlCodes(process20.stdout) ? line : Bun.stripANSI(line)).join(`
2095
2354
  `));
2096
2355
  return 0;
2097
2356
  }
@@ -2148,4 +2407,4 @@ async function finish(command, typed, emitting) {
2148
2407
  }
2149
2408
 
2150
2409
  // src/gb.ts
2151
- process19.exitCode = await runMain({ name: "gb", run: gb });
2410
+ process21.exitCode = await runMain({ name: "gb", run: gb });