@kaynooo/cli-git 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gst.js ADDED
@@ -0,0 +1,854 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/gst.ts
5
+ import process6 from "process";
6
+
7
+ // ../kit/src/args.ts
8
+ import process2 from "process";
9
+ import { parseArgs } from "util";
10
+
11
+ // ../kit/src/style.ts
12
+ import process from "process";
13
+
14
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
15
+ function x(s) {
16
+ let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
17
+ if (!/^[a-f0-9]+$/.test(r))
18
+ return [0, 0, 0];
19
+ let t = r.length, n = (c) => Number.parseInt(c, 16);
20
+ if (t === 3 || t === 4) {
21
+ let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
22
+ return g !== undefined ? [c, u, h, g] : [c, u, h];
23
+ }
24
+ if (t !== 6 && t !== 8)
25
+ throw Error(`Invalid hex color length: ${t}`);
26
+ let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
27
+ if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
28
+ throw Error(`Invalid hex color value: ${s}`);
29
+ return y !== undefined ? [a, b, o, y] : [a, b, o];
30
+ }
31
+ function A(s) {
32
+ let [r, t, n, a] = s;
33
+ if (a)
34
+ return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
35
+ return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
36
+ }
37
+ function R(s, r, t) {
38
+ s = (s % 360 + 360) % 360, t /= 100;
39
+ let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
40
+ let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
41
+ return Math.round(255 * y);
42
+ };
43
+ return [a(0), a(8), a(4)];
44
+ }
45
+ function k(s) {
46
+ let [r, t, n] = s;
47
+ r /= 255, t /= 255, n /= 255;
48
+ let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
49
+ if (a !== b) {
50
+ let u = a - b;
51
+ if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
52
+ o = (t - n) / u + (t < n ? 6 : 0);
53
+ else if (a === t)
54
+ o = (n - r) / u + 2;
55
+ else
56
+ o = (r - t) / u + 4;
57
+ o /= 6;
58
+ }
59
+ return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
60
+ }
61
+ function H(s, r, t) {
62
+ s = (s % 360 + 360) % 360, r /= 100, t /= 100;
63
+ let n = (a) => {
64
+ let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
65
+ return Math.round(255 * o);
66
+ };
67
+ return [n(5), n(3), n(1)];
68
+ }
69
+ function f(s) {
70
+ let [r, t, n] = s;
71
+ r /= 255, t /= 255, n /= 255;
72
+ let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
73
+ if (o !== 0) {
74
+ if (a === r)
75
+ y = (t - n) / o + (t < n ? 6 : 0);
76
+ else if (a === t)
77
+ y = (n - r) / o + 2;
78
+ else
79
+ y = (r - t) / o + 4;
80
+ y /= 6;
81
+ }
82
+ return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
83
+ }
84
+ function O(s) {
85
+ let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
86
+ if (a === 1)
87
+ return [0, 0, 0, 100];
88
+ let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
89
+ return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
90
+ }
91
+ function v(s, r, t, n) {
92
+ return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
93
+ }
94
+ var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
95
+ var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
96
+ var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
97
+ function T(s) {
98
+ let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
99
+ return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
100
+ }
101
+ function M(s, r, t) {
102
+ let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
103
+ return [u(o), u(y), u(c)];
104
+ }
105
+ function d(s) {
106
+ let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
107
+ return [i(r, 4), i(a, 4), i(b, 2)];
108
+ }
109
+ function C(s, r, t) {
110
+ let n = t * Math.PI / 180;
111
+ return M(s, r * Math.cos(n), r * Math.sin(n));
112
+ }
113
+ function l(s) {
114
+ let r = s / 255;
115
+ return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
116
+ }
117
+
118
+ class e {
119
+ r;
120
+ g;
121
+ b;
122
+ a;
123
+ constructor(s, r, t, n = 1) {
124
+ this.r = s, this.g = r, this.b = t, this.a = n;
125
+ }
126
+ static from(s, r) {
127
+ if (s === "hex") {
128
+ let [t, n, a, b] = x(r);
129
+ return new e(t, n, a, b);
130
+ }
131
+ if (s === "rgb") {
132
+ if (Array.isArray(r)) {
133
+ let [o, y, c, u] = r;
134
+ return new e(o, y, c, u);
135
+ }
136
+ let { r: t, g: n, b: a, a: b } = r;
137
+ return new e(t, n, a, b);
138
+ }
139
+ if (s === "hsl") {
140
+ let t, n, a, b;
141
+ if (Array.isArray(r))
142
+ [t, n, a, b] = r;
143
+ else
144
+ ({ h: t, s: n, l: a, a: b } = r);
145
+ let [o, y, c] = R(t, n, a);
146
+ return new e(o, y, c, b);
147
+ }
148
+ if (s === "hsv") {
149
+ let t, n, a, b;
150
+ if (Array.isArray(r))
151
+ [t, n, a, b] = r;
152
+ else
153
+ ({ h: t, s: n, v: a, a: b } = r);
154
+ let [o, y, c] = H(t, n, a);
155
+ return new e(o, y, c, b);
156
+ }
157
+ if (s === "cmyk") {
158
+ let t, n, a, b, o;
159
+ if (Array.isArray(r))
160
+ [t, n, a, b, o] = r;
161
+ else
162
+ ({ c: t, m: n, y: a, k: b, a: o } = r);
163
+ let [y, c, u] = v(t, n, a, b);
164
+ return new e(y, c, u, o);
165
+ }
166
+ if (s === "oklch") {
167
+ let t, n, a, b;
168
+ if (Array.isArray(r))
169
+ [t, n, a, b] = r;
170
+ else
171
+ ({ l: t, c: n, h: a, a: b } = r);
172
+ let [o, y, c] = C(t, n, a);
173
+ return new e(o, y, c, b);
174
+ }
175
+ if (s === "oklab") {
176
+ let t, n, a, b;
177
+ if (Array.isArray(r))
178
+ [t, n, a, b] = r;
179
+ else
180
+ ({ l: t, a: n, b: a, alpha: b } = r);
181
+ let [o, y, c] = M(t, n, a);
182
+ return new e(o, y, c, b);
183
+ }
184
+ throw Error("Invalid input");
185
+ }
186
+ to(s) {
187
+ switch (s) {
188
+ case "rgb":
189
+ return [this.r, this.g, this.b];
190
+ case "rgba":
191
+ return [this.r, this.g, this.b, this.a];
192
+ case "hex":
193
+ return A([this.r, this.g, this.b]);
194
+ case "hexa":
195
+ return A([this.r, this.g, this.b, this.a]);
196
+ case "hsl":
197
+ return k([this.r, this.g, this.b]);
198
+ case "hsla":
199
+ return [...k([this.r, this.g, this.b]), this.a];
200
+ case "hsv":
201
+ return f([this.r, this.g, this.b]);
202
+ case "hsva":
203
+ return [...f([this.r, this.g, this.b]), this.a];
204
+ case "cmyk":
205
+ return O([this.r, this.g, this.b]);
206
+ case "cmyka":
207
+ return [...O([this.r, this.g, this.b]), this.a];
208
+ case "oklch":
209
+ return d([this.r, this.g, this.b]);
210
+ case "oklcha":
211
+ return [...d([this.r, this.g, this.b]), this.a];
212
+ case "oklab":
213
+ return T([this.r, this.g, this.b]);
214
+ case "oklaba":
215
+ return [...T([this.r, this.g, this.b]), this.a];
216
+ default:
217
+ return [this.r, this.g, this.b];
218
+ }
219
+ }
220
+ getLuminance() {
221
+ let s = l(this.r), r = l(this.g), t = l(this.b);
222
+ return 0.2126 * s + 0.7152 * r + 0.0722 * t;
223
+ }
224
+ contrastRatio(s) {
225
+ let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
226
+ return (n + 0.05) / (a + 0.05);
227
+ }
228
+ bestContrastForeground() {
229
+ let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
230
+ return t >= n ? s : r;
231
+ }
232
+ }
233
+
234
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.0+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
235
+ var r = 39;
236
+ var o = 49;
237
+ var f2 = "\x1B[";
238
+ var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
239
+ let [a, l, s] = e.from("hex", i).to("rgb");
240
+ return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
241
+ }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
242
+ var b = new Set(["", "1", "2", "3", "true"]);
243
+ function h(i, n = globalThis.process?.env ?? {}) {
244
+ if (n.FORCE_COLOR !== undefined)
245
+ return b.has(n.FORCE_COLOR);
246
+ if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
247
+ return false;
248
+ return i?.isTTY === true;
249
+ }
250
+ function d2(i, n, a) {
251
+ if (!h(a.stream ?? globalThis.process?.stdout, a.env))
252
+ return n;
253
+ let l = "", s = "";
254
+ for (let g = 0, y = i.length;g < y; g++) {
255
+ let [c, p] = i[g];
256
+ l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
257
+ }
258
+ return l + n + s;
259
+ }
260
+ function u(i, n = []) {
261
+ return new Proxy((l) => d2(n, l, i), { get(l, s) {
262
+ let g = C2[s];
263
+ if (Array.isArray(g))
264
+ return u(i, [...n, g]);
265
+ if (typeof g === "function")
266
+ return (...y) => u(i, [...n, g(...y)]);
267
+ throw Error(`Unknown style: ${String(s)}`);
268
+ } });
269
+ }
270
+ function le(i = {}) {
271
+ return u(i);
272
+ }
273
+ var t = le();
274
+
275
+ // ../kit/src/style.ts
276
+ function takesControlCodes(stream, env = process.env) {
277
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
278
+ }
279
+ function paint(stream, env = process.env) {
280
+ return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
281
+ }
282
+ var STATUSES = {
283
+ passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
284
+ failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
285
+ running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
286
+ queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
287
+ skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
288
+ };
289
+ var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
290
+
291
+ // ../kit/src/format.ts
292
+ function upTo(text, separator) {
293
+ const end = text.indexOf(separator);
294
+ return end === -1 ? text : text.slice(0, end);
295
+ }
296
+ var ESCAPE = String.fromCharCode(27);
297
+ function printJson(value) {
298
+ console.log(JSON.stringify(value, undefined, 2));
299
+ }
300
+
301
+ // ../kit/src/text.ts
302
+ var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
303
+ function distance(a, b) {
304
+ let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
305
+ for (const [i, left] of [...a].entries()) {
306
+ const current = [i + 1];
307
+ for (const [j, right] of [...b].entries())
308
+ current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
309
+ previous = current;
310
+ }
311
+ return previous[b.length] ?? 0;
312
+ }
313
+ function closest(name, names) {
314
+ const started = names.find((known) => known.startsWith(name));
315
+ if (started !== undefined)
316
+ return started;
317
+ const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
318
+ return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
319
+ }
320
+
321
+ // ../kit/src/args.ts
322
+ function jsonOption(holds) {
323
+ return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
324
+ }
325
+
326
+ class Exit extends Error {
327
+ code;
328
+ hint;
329
+ constructor(message, code, hint) {
330
+ super(message);
331
+ this.code = code;
332
+ this.hint = hint;
333
+ }
334
+ }
335
+ function fail(message, code = 2, hint) {
336
+ throw new Exit(message, code, hint);
337
+ }
338
+
339
+ class UsageError extends Exit {
340
+ constructor(message, hint) {
341
+ super(message, 2, hint);
342
+ }
343
+ }
344
+ function badUsage(message) {
345
+ throw new UsageError(message);
346
+ }
347
+
348
+ class HelpShown extends Exit {
349
+ constructor() {
350
+ super("help shown", 0);
351
+ }
352
+ }
353
+
354
+ class Completing {
355
+ options;
356
+ constructor(options) {
357
+ this.options = options;
358
+ }
359
+ }
360
+ var completion = { active: false };
361
+ var OPTIONAL = /\[[^\]]+\]/g;
362
+ var USAGE_PREFIX = /^usage:\s*/i;
363
+ var FULL_STOP = /\.$/;
364
+ var DASHES = /^-+/;
365
+ function usageLine(usage, colors = paint(process2.stdout)) {
366
+ return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
367
+ }
368
+ function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
369
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
370
+ `);
371
+ }
372
+ function replacesRows(replaces, colors = paint(process2.stdout)) {
373
+ return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
374
+ }
375
+ function wantsHelpJson(env = process2.env) {
376
+ return env.KIT_HELP === "json";
377
+ }
378
+ function description(usage, { examples = [], replaces } = {}) {
379
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
380
+ `);
381
+ const first = lines[0];
382
+ const colon = first.indexOf(": ");
383
+ const prose = lines[lines.indexOf("") + 1] ?? "";
384
+ const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
385
+ return {
386
+ synopsis: colon === -1 ? first : first.slice(0, colon),
387
+ summary: colon === -1 ? fallback : first.slice(colon + 2),
388
+ ...replaces === undefined ? {} : { replaces },
389
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
390
+ };
391
+ }
392
+ function exampleRows(examples, colors = paint(process2.stdout)) {
393
+ if (examples.length === 0)
394
+ return [];
395
+ return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
396
+ }
397
+ function optionRows(options, colors = paint(process2.stdout)) {
398
+ const rows = Object.entries(options).map(([name, option]) => {
399
+ const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
400
+ const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
401
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
402
+ });
403
+ const width = Math.max(0, ...rows.map((row) => row.width));
404
+ return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
405
+ }
406
+ var OUTPUT_OPTIONS = {
407
+ color: { type: "string", description: "auto (on a terminal alone), always or never" },
408
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
409
+ };
410
+ function applyOutput(color, plain, env = process2.env) {
411
+ const when = plain === true ? "never" : color ?? "auto";
412
+ if (when === "auto")
413
+ return;
414
+ if (when !== "always" && when !== "never")
415
+ badUsage(`--color takes auto, always or never, not ${when}`);
416
+ if (when === "always") {
417
+ env.FORCE_COLOR = "1";
418
+ delete env.NO_COLOR;
419
+ } else {
420
+ env.NO_COLOR = "1";
421
+ delete env.FORCE_COLOR;
422
+ }
423
+ }
424
+ function parse(args, usage, options, settings = {}) {
425
+ const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
426
+ const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
427
+ if (completion.active)
428
+ throw new Completing(all);
429
+ const separator = settings.rest === true ? args.indexOf("--") : -1;
430
+ const own = separator === -1 ? args : args.slice(0, separator);
431
+ const rest = separator === -1 ? undefined : args.slice(separator + 1);
432
+ let parsed;
433
+ try {
434
+ parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
435
+ } catch (error) {
436
+ const message = parseError(error);
437
+ throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
438
+ }
439
+ const values = parsed.values;
440
+ applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
441
+ if (values.help === true) {
442
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, all, undefined, settings));
443
+ throw new HelpShown;
444
+ }
445
+ if (settings.positionals !== undefined)
446
+ checkPositionals(parsed.positionals, settings.positionals);
447
+ return { ...parsed, positionals: parsed.positionals, rest };
448
+ }
449
+ function checkPositionals(given, names) {
450
+ const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
451
+ const required = names.filter((name) => !name.startsWith("[")).length;
452
+ if (given.length < required)
453
+ badUsage(`missing ${names[given.length]}`);
454
+ if (!variadic && given.length > names.length)
455
+ badUsage(`unexpected argument ${given[names.length]}`);
456
+ }
457
+ function joinDashValues(args, options) {
458
+ const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
459
+ const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
460
+ const joined = [];
461
+ for (let i = 0;i < args.length; i++) {
462
+ const arg = args[i] ?? "";
463
+ if (arg === "--")
464
+ return [...joined, ...args.slice(i)];
465
+ const name = longOf.get(arg);
466
+ const next = args[i + 1];
467
+ if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
468
+ joined.push(`--${name}=${next}`);
469
+ i++;
470
+ } else {
471
+ joined.push(arg);
472
+ }
473
+ }
474
+ return joined;
475
+ }
476
+ function parseError(error) {
477
+ const message = upTo(error instanceof Error ? error.message : String(error), ". ");
478
+ return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
479
+ }
480
+ var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
481
+ function nearestOption(message, options, allowNegative) {
482
+ const typed = UNKNOWN_OPTION.exec(message)?.[1];
483
+ if (typed === undefined)
484
+ return;
485
+ const word = typed.replace(DASHES, "");
486
+ if (word.length < 2 && !typed.startsWith("--"))
487
+ return;
488
+ const known = Object.entries(options).flatMap(([name, option]) => [
489
+ ...option.short === undefined ? [] : [`-${option.short}`],
490
+ `--${name}`,
491
+ ...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
492
+ ]);
493
+ const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
494
+ return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
495
+ }
496
+ var WHOLE = /^\d+$/;
497
+ function wholeNumber(value, name, fallback, min = 1) {
498
+ if (value === undefined)
499
+ return fallback;
500
+ const number = Number(value);
501
+ if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
502
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
503
+ return number;
504
+ }
505
+ // ../kit/src/process.ts
506
+ import { constants } from "os";
507
+ import process3 from "process";
508
+ var KILL_GRACE_MS = 2000;
509
+ var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
510
+ function exitCodeOf(code, signal) {
511
+ if (code !== null)
512
+ return code;
513
+ if (typeof signal === "number")
514
+ return 128 + signal;
515
+ return signal === null ? 129 : 128 + constants.signals[signal];
516
+ }
517
+ function holdSignals(cleanup) {
518
+ let received;
519
+ let child;
520
+ const held = {
521
+ get signal() {
522
+ return received;
523
+ },
524
+ forward: (to) => {
525
+ child = to;
526
+ },
527
+ release: () => {
528
+ for (const signal of SIGNALS)
529
+ process3.off(signal, onSignal);
530
+ }
531
+ };
532
+ function onSignal(signal) {
533
+ received = signal;
534
+ if (child !== undefined) {
535
+ child.kill(signal);
536
+ return;
537
+ }
538
+ if (cleanup === undefined)
539
+ return;
540
+ held.release();
541
+ cleanup(signal);
542
+ process3.kill(process3.pid, signal);
543
+ }
544
+ for (const signal of SIGNALS)
545
+ process3.on(signal, onSignal);
546
+ return held;
547
+ }
548
+ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
549
+ const chunks = [];
550
+ const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
551
+ const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
552
+ const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
553
+ const timers = [];
554
+ const killGroup = (killing) => {
555
+ if (state.done)
556
+ return;
557
+ try {
558
+ if (grouped)
559
+ process3.kill(-proc.pid, killing);
560
+ else
561
+ proc.kill(killing);
562
+ } catch {}
563
+ };
564
+ const stop = () => {
565
+ killGroup("SIGTERM");
566
+ timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
567
+ };
568
+ const onAbort = () => stop();
569
+ if (timeoutMs !== undefined) {
570
+ timers.push(setTimeout(() => {
571
+ state.timedOut = true;
572
+ stop();
573
+ }, timeoutMs));
574
+ }
575
+ if (signal?.aborted === true)
576
+ onAbort();
577
+ else
578
+ signal?.addEventListener("abort", onAbort, { once: true });
579
+ onStart?.({ kill: (killing) => killGroup(killing) });
580
+ const drain = async (stream, name) => {
581
+ for await (const data of stream) {
582
+ if (state.failure !== undefined)
583
+ continue;
584
+ try {
585
+ onChunk?.({ stream: name, data });
586
+ } catch (error) {
587
+ state.failure = error;
588
+ stop();
589
+ continue;
590
+ }
591
+ if (state.kept + data.length > maxBytes) {
592
+ state.truncated = true;
593
+ continue;
594
+ }
595
+ state.kept += data.length;
596
+ chunks.push({ stream: name, data });
597
+ }
598
+ };
599
+ try {
600
+ await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
601
+ await proc.exited;
602
+ } finally {
603
+ state.done = true;
604
+ for (const timer of timers)
605
+ clearTimeout(timer);
606
+ signal?.removeEventListener("abort", onAbort);
607
+ }
608
+ if (state.failure !== undefined)
609
+ throw state.failure;
610
+ const joined = () => Buffer.concat(chunks.map(({ data }) => data));
611
+ let output;
612
+ let text;
613
+ return {
614
+ code: exitCodeOf(proc.exitCode, proc.signalCode),
615
+ chunks,
616
+ timedOut: state.timedOut,
617
+ truncated: state.truncated,
618
+ get output() {
619
+ return output ??= joined();
620
+ },
621
+ get text() {
622
+ return text ??= (output ??= joined()).toString();
623
+ }
624
+ };
625
+ }
626
+
627
+ // ../kit/src/progress.ts
628
+ var ESC = String.fromCharCode(27);
629
+ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
630
+ var RESET_STYLE = `${ESC}[0m`;
631
+ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
632
+ // ../kit/src/cli.ts
633
+ import process4 from "process";
634
+ var LEVEL_OPTIONS = {
635
+ ...OUTPUT_OPTIONS,
636
+ help: { type: "boolean", short: "h", description: "show this help" }
637
+ };
638
+ var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
639
+ function printError(prefix, message, hint, cause) {
640
+ const colors = paint(process4.stderr);
641
+ const styled = takesControlCodes(process4.stderr);
642
+ const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
643
+ const under = (label, text, tint) => text === undefined ? "" : `
644
+ ${styled ? tint(label) : `${label}:`} ${text}`;
645
+ console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
646
+ }
647
+ function runHint(command, effect) {
648
+ return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
649
+ }
650
+ function printJsonError(message, hint, cause) {
651
+ console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
652
+ }
653
+ function wantsJson(argv) {
654
+ const end = argv.indexOf("--");
655
+ return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
656
+ }
657
+ function reportThrown(prefix, error, redact = (text) => text, json = false) {
658
+ if (error instanceof HelpShown)
659
+ return 0;
660
+ const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
661
+ const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
662
+ const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
663
+ const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
664
+ report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
665
+ return error instanceof Exit ? error.code : 1;
666
+ }
667
+ var COMPLETE = "__complete";
668
+ var FILES = "__files__";
669
+ async function optionsOf(run) {
670
+ completion.active = true;
671
+ try {
672
+ await run([]);
673
+ } catch (error) {
674
+ if (error instanceof Completing)
675
+ return error.options;
676
+ } finally {
677
+ completion.active = false;
678
+ }
679
+ return {};
680
+ }
681
+ async function leafCandidates(run, words) {
682
+ if (!(words.at(-1) ?? "").startsWith("-"))
683
+ return [FILES];
684
+ return Object.entries(await optionsOf(run)).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
685
+ }
686
+ async function printCandidates(found) {
687
+ for (const line of await found)
688
+ console.log(line);
689
+ return 0;
690
+ }
691
+ async function runMain({ name, version, run, redact }, argv = process4.argv.slice(2)) {
692
+ if (argv[0] === COMPLETE)
693
+ return printCandidates(leafCandidates(run, argv.slice(1)));
694
+ if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
695
+ console.log(version);
696
+ return 0;
697
+ }
698
+ try {
699
+ return await run(argv);
700
+ } catch (error) {
701
+ return reportThrown(name, error, redact, wantsJson(argv));
702
+ }
703
+ }
704
+ // ../kit/src/logs.ts
705
+ var DAY_MS = 24 * 60 * 60 * 1000;
706
+ // ../kit/src/secrets.ts
707
+ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
708
+ // ../kit/src/sessions.ts
709
+ var {Glob } = globalThis.Bun;
710
+ var SESSION_FILES = new Glob("*.json");
711
+ var ACCOUNT_DIRS = new Glob("*/sessions");
712
+ // package.json
713
+ var version = "0.5.0";
714
+
715
+ // src/git.ts
716
+ async function git2(args, env) {
717
+ const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
718
+ const text = (stream) => Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === stream).map((chunk) => chunk.data)).toString();
719
+ return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
720
+ }
721
+
722
+ // src/status.ts
723
+ var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
724
+ var OCTAL = /[0-7]/;
725
+ var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
726
+ var ENCODER = new TextEncoder;
727
+ var DECODER = new TextDecoder;
728
+ function unquote(path) {
729
+ if (!path.startsWith('"') || !path.endsWith('"'))
730
+ return path;
731
+ const bytes = [];
732
+ const text = path.slice(1, -1);
733
+ for (let i = 0;i < text.length; i++) {
734
+ const char = text[i] ?? "";
735
+ const next = text[i + 1] ?? "";
736
+ if (char !== "\\") {
737
+ bytes.push(...ENCODER.encode(char));
738
+ } else if (OCTAL.test(next)) {
739
+ bytes.push(Number.parseInt(text.slice(i + 1, i + 4), 8));
740
+ i += 3;
741
+ } else {
742
+ bytes.push(ESCAPES[next] ?? next.charCodeAt(0));
743
+ i++;
744
+ }
745
+ }
746
+ return DECODER.decode(new Uint8Array(bytes));
747
+ }
748
+ function after(line, count) {
749
+ let index = 0;
750
+ for (let field = 0;field < count; field++)
751
+ index = line.indexOf(" ", index) + 1;
752
+ return line.slice(index);
753
+ }
754
+ function parseStatus(text) {
755
+ const status = { branch: "", oid: "", upstream: null, aheadBehind: null, changes: [], conflicted: [], untracked: [] };
756
+ let hasBranch = false;
757
+ for (const line of text.split(`
758
+ `)) {
759
+ if (line.startsWith("# branch.oid ")) {
760
+ status.oid = line.slice("# branch.oid ".length);
761
+ } else if (line.startsWith("# branch.head ")) {
762
+ status.branch = line.slice("# branch.head ".length);
763
+ hasBranch = true;
764
+ } else if (line.startsWith("# branch.upstream ")) {
765
+ status.upstream = line.slice("# branch.upstream ".length);
766
+ } else if (line.startsWith("# branch.ab ")) {
767
+ const [, ahead = "0", behind = "0"] = AHEAD_BEHIND.exec(line) ?? [];
768
+ status.aheadBehind = { ahead: Number(ahead), behind: Number(behind) };
769
+ } else if (line.startsWith("1 ")) {
770
+ status.changes.push({ path: unquote(after(line, 8)), index: line[2] ?? ".", worktree: line[3] ?? "." });
771
+ } else if (line.startsWith("2 ")) {
772
+ const [path = "", from = ""] = after(line, 9).split("\t");
773
+ status.changes.push({ path: unquote(path), from: unquote(from), index: line[2] ?? ".", worktree: line[3] ?? "." });
774
+ } else if (line.startsWith("u ")) {
775
+ status.conflicted.push(unquote(after(line, 10)));
776
+ } else if (line.startsWith("? ")) {
777
+ status.untracked.push(unquote(line.slice(2)));
778
+ }
779
+ }
780
+ return hasBranch ? status : null;
781
+ }
782
+ function summary(status, head) {
783
+ const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
784
+ const on = branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``;
785
+ let tracking = "no upstream";
786
+ if (upstream !== null)
787
+ tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
788
+ const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
789
+ const [sha, title] = head.trim().split("\x00");
790
+ const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
791
+ return `${on}, ${tracking}; ${files} files${last}`;
792
+ }
793
+
794
+ // src/gst.ts
795
+ var USAGE = `gst [--log N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
796
+
797
+ Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
798
+ var OPTIONS = {
799
+ log: { type: "string", short: "l", description: "add the last N commits as <sha7> <title>" },
800
+ json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
801
+ };
802
+ function group(title, lines) {
803
+ return lines.length === 0 ? [] : [`${title}:`, ...lines.map((line) => ` ${line}`)];
804
+ }
805
+ function staged({ index, from, path }) {
806
+ return `${index} ${from === undefined ? "" : `${from} -> `}${path}`;
807
+ }
808
+ async function main(argv) {
809
+ const parsed = parse(argv, USAGE, OPTIONS, { replaces: "git status --short and git log --oneline", examples: ["gst", ["gst --log 5", "with the last five commits"]] });
810
+ if (parsed.positionals.length > 0)
811
+ fail(`gst takes no paths
812
+
813
+ ${USAGE}`);
814
+ const count = parsed.values.log === undefined ? 0 : wholeNumber(parsed.values.log, "log", 1);
815
+ const [read, head, log] = await Promise.all([
816
+ git2(["status", "--porcelain=v2", "--branch"]),
817
+ git2(["log", "-1", "--format=%h%x00%s"]),
818
+ count === 0 ? undefined : git2(["log", `-${count}`, "--format=%h%x00%s"])
819
+ ]);
820
+ const status = read.code === 0 ? parseStatus(read.stdout) : null;
821
+ if (status === null)
822
+ fail(read.stderr.trim() || "not inside a git repository");
823
+ const commits = log?.code === 0 ? log.stdout.trimEnd().split(`
824
+ `).filter(Boolean).map((line) => line.split("\x00")) : [];
825
+ if (parsed.values.json === true) {
826
+ const [sha, title] = head.code === 0 && head.stdout.trim() !== "" ? head.stdout.trim().split("\x00") : [];
827
+ printJson({
828
+ branch: status.branch,
829
+ oid: status.oid,
830
+ upstream: status.upstream,
831
+ ahead: status.aheadBehind?.ahead ?? null,
832
+ behind: status.aheadBehind?.behind ?? null,
833
+ head: sha === undefined ? null : { sha, title: title ?? "" },
834
+ staged: status.changes.filter((change) => change.index !== ".").map(({ index, path, from }) => ({ status: index, path, ...from === undefined ? {} : { from } })),
835
+ unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
836
+ untracked: status.untracked,
837
+ conflicted: status.conflicted,
838
+ commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle }))
839
+ });
840
+ return 0;
841
+ }
842
+ const lines = [
843
+ summary(status, head.code === 0 ? head.stdout : ""),
844
+ ...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
845
+ ...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${change.worktree} ${change.path}`)),
846
+ ...group("untracked", status.untracked),
847
+ ...group("conflicted", status.conflicted),
848
+ ...group("commits", commits.map((parts) => parts.join(" ")))
849
+ ];
850
+ console.log(lines.join(`
851
+ `));
852
+ return 0;
853
+ }
854
+ process6.exitCode = await runMain({ name: "gst", version, run: main });