@kaynooo/cli-git 0.15.1 → 0.16.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/gc.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/gc.ts
5
- import process18 from "process";
5
+ import process19 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -493,7 +493,7 @@ function printJson(value) {
493
493
 
494
494
  // ../kit/src/help.ts
495
495
  import process8 from "process";
496
- var OPTIONAL = /\[[^\]]+\]/g;
496
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
497
497
  var USAGE_PREFIX = /^usage:\s*/i;
498
498
  var FULL_STOP = /\.$/;
499
499
  function usageLine(usage, colors = paint(process8.stdout)) {
@@ -532,29 +532,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
532
532
  return [];
533
533
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
534
534
  }
535
+ var MAX_INLINE_CHOICES = 24;
535
536
  function optionRows(options, colors = paint(process8.stdout)) {
536
537
  const rows = Object.entries(options).map(([name, option]) => {
537
538
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
538
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
539
+ const choices = option.choices?.join("|");
540
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
541
+ const named = inline ? `<${choices}>` : "<value>";
539
542
  const placeholder = option.optional === undefined ? named : `[${named}]`;
540
543
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
541
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
544
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
545
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
542
546
  });
543
547
  const width = Math.max(0, ...rows.map((row) => row.width));
544
548
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
545
549
  }
546
550
 
547
551
  // ../kit/src/text.ts
548
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
552
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
549
553
  function distance(a, b) {
550
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
551
- for (const [i, left] of [...a].entries()) {
554
+ const left = [...a];
555
+ const right = [...b];
556
+ let before = [];
557
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
558
+ for (const [i, x] of left.entries()) {
552
559
  const current = [i + 1];
553
- for (const [j, right] of [...b].entries())
554
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
560
+ for (const [j, y] of right.entries()) {
561
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
562
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
563
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
564
+ current.push(cost);
565
+ }
566
+ before = previous;
555
567
  previous = current;
556
568
  }
557
- return previous[b.length] ?? 0;
569
+ return previous[right.length] ?? 0;
558
570
  }
559
571
  function closest(name, names) {
560
572
  const started = names.find((known) => known.startsWith(name));
@@ -1138,13 +1150,31 @@ function interceptOutput(clear) {
1138
1150
  // ../kit/src/cli.ts
1139
1151
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1140
1152
  import { dirname as dirname3, join as join5 } from "path";
1141
- import process14 from "process";
1153
+ import process15 from "process";
1154
+
1155
+ // ../kit/src/notify.ts
1156
+ import process13 from "process";
1157
+ var NOTIFY_AFTER_MS = 1e4;
1158
+ var CANCELLED = 130;
1159
+ function base64(text) {
1160
+ return Buffer.from(text).toString("base64");
1161
+ }
1162
+ function notification(title, body, env = process13.env) {
1163
+ const id = `kit${process13.pid}`;
1164
+ const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1165
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1166
+ }
1167
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
1168
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1169
+ return;
1170
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1171
+ }
1142
1172
 
1143
1173
  // ../kit/src/usage.ts
1144
1174
  import { appendFileSync, mkdirSync } from "fs";
1145
1175
  import { homedir as homedir3 } from "os";
1146
1176
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1147
- import process13 from "process";
1177
+ import process14 from "process";
1148
1178
 
1149
1179
  // ../kit/src/logs.ts
1150
1180
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -1158,14 +1188,14 @@ var usageError;
1158
1188
  function noteUsageError(message) {
1159
1189
  usageError = message;
1160
1190
  }
1161
- function stateHome(env = process13.env) {
1191
+ function stateHome(env = process14.env) {
1162
1192
  const dir = env.XDG_STATE_HOME;
1163
1193
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1164
1194
  }
1165
- function usagePath(env = process13.env) {
1195
+ function usagePath(env = process14.env) {
1166
1196
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1167
1197
  }
1168
- function usageRecorded(env = process13.env) {
1198
+ function usageRecorded(env = process14.env) {
1169
1199
  const off = env.KAYNOOO_CLI_NO_USAGE;
1170
1200
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1171
1201
  }
@@ -1179,7 +1209,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1179
1209
  usageError = undefined;
1180
1210
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1181
1211
  }
1182
- function recordUsage(entry, env = process13.env) {
1212
+ function recordUsage(entry, env = process14.env) {
1183
1213
  if (!usageRecorded(env))
1184
1214
  return;
1185
1215
  try {
@@ -1197,8 +1227,8 @@ var LEVEL_OPTIONS = {
1197
1227
  };
1198
1228
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1199
1229
  function printError(prefix, message, hint, cause) {
1200
- const colors = paint(process14.stderr);
1201
- const styled = takesControlCodes(process14.stderr);
1230
+ const colors = paint(process15.stderr);
1231
+ const styled = takesControlCodes(process15.stderr);
1202
1232
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1203
1233
  const under = (label, text, tint) => text === undefined ? "" : `
1204
1234
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1306,11 +1336,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1306
1336
  return 0;
1307
1337
  }
1308
1338
  let code;
1339
+ const started = performance.now();
1309
1340
  try {
1310
1341
  code = await run(argv);
1311
1342
  } catch (error) {
1312
1343
  code = reportThrown(name, error, redact, wantsJson(argv));
1313
1344
  }
1345
+ notifyEnd(name, code, performance.now() - started);
1314
1346
  if (usage !== false) {
1315
1347
  try {
1316
1348
  recordUsage(usageEntry(name, undefined, argv, code));
@@ -1327,7 +1359,7 @@ var {Glob } = globalThis.Bun;
1327
1359
  var SESSION_FILES = new Glob("*.json");
1328
1360
  var ACCOUNT_DIRS = new Glob("*/sessions");
1329
1361
  // ../kit/src/watch.ts
1330
- import process15 from "process";
1362
+ import process16 from "process";
1331
1363
  import { format } from "util";
1332
1364
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1333
1365
  var DEFAULT_SECONDS = 2;
@@ -1349,7 +1381,7 @@ function withoutWatch(args) {
1349
1381
  }
1350
1382
  return rest;
1351
1383
  }
1352
- async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1384
+ async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1353
1385
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1354
1386
  if (!takesControlCodes(stream))
1355
1387
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1357,12 +1389,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1357
1389
  for (let round = 0;round < rounds; round++) {
1358
1390
  const held = [];
1359
1391
  const { log, info } = console;
1360
- const write = process15.stdout.write.bind(process15.stdout);
1392
+ const write = process16.stdout.write.bind(process16.stdout);
1361
1393
  const hold = (...parts) => void held.push(`${format(...parts)}
1362
1394
  `);
1363
1395
  console.log = hold;
1364
1396
  console.info = hold;
1365
- process15.stdout.write = (text) => {
1397
+ process16.stdout.write = (text) => {
1366
1398
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1367
1399
  return true;
1368
1400
  };
@@ -1371,7 +1403,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1371
1403
  } finally {
1372
1404
  console.log = log;
1373
1405
  console.info = info;
1374
- process15.stdout.write = write;
1406
+ process16.stdout.write = write;
1375
1407
  }
1376
1408
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1377
1409
  await sleep(interval);
@@ -1381,7 +1413,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1381
1413
  // ../kit/src/workspace-root.ts
1382
1414
  import { homedir as homedir4 } from "os";
1383
1415
  import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1384
- import process16 from "process";
1416
+ import process17 from "process";
1385
1417
  function expandHome(path, home) {
1386
1418
  if (path === "~")
1387
1419
  return home;
@@ -1391,7 +1423,7 @@ function configured(env, home) {
1391
1423
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1392
1424
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1393
1425
  }
1394
- function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1426
+ function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
1395
1427
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1396
1428
  return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1397
1429
  }
@@ -1467,7 +1499,7 @@ var OPTIONS = {
1467
1499
  };
1468
1500
  var RENAME = /^[RC]\d*$/;
1469
1501
  var NOT_A_REPOSITORY = /not a git repository/i;
1470
- var LITERAL = { ...process18.env, GIT_LITERAL_PATHSPECS: "1" };
1502
+ var LITERAL = { ...process19.env, GIT_LITERAL_PATHSPECS: "1" };
1471
1503
  function messageOf(title, lines, tickets) {
1472
1504
  return [title, lines.join(`
1473
1505
  `), tickets.join(`
@@ -1487,6 +1519,20 @@ async function stagedElsewhere(paths) {
1487
1519
  const ours = new Set(given.split("\x00"));
1488
1520
  return all.split("\x00").filter((path) => path !== "" && !ours.has(path));
1489
1521
  }
1522
+ async function renameSources(paths) {
1523
+ const fields = (await checked(["diff", "--cached", "-M", "--name-status", "-z"])).split("\x00");
1524
+ const sources = [];
1525
+ for (let i = 0;i < fields.length; i++) {
1526
+ if (!RENAME.test(fields[i] ?? ""))
1527
+ continue;
1528
+ const from = fields[i + 1] ?? "";
1529
+ const to = fields[i + 2] ?? "";
1530
+ if (paths.includes(to) && !paths.includes(from))
1531
+ sources.push(from);
1532
+ i += 2;
1533
+ }
1534
+ return sources;
1535
+ }
1490
1536
  async function unstage(paths) {
1491
1537
  const hasHead = (await git2(["rev-parse", "--verify", "-q", "HEAD"], LITERAL)).code === 0;
1492
1538
  await git2(hasHead ? ["reset", "-q", "--", ...paths] : ["rm", "-r", "-q", "--cached", "--", ...paths], LITERAL);
@@ -1498,12 +1544,12 @@ function fileLine(line) {
1498
1544
  async function main(argv) {
1499
1545
  const parsed = parse(argv, USAGE, OPTIONS, { rest: true, replaces: "git add, git status and git commit chained", examples: ['gc "fix(api): retry a timed-out fetch" -- src/api.ts', ['gc "feat(ui): a dark theme" -m "The toggle sits in the header." --ticket "#12 - Dark theme" -- src/theme.ts src/header.ts', "a body line and a ticket"]] });
1500
1546
  const { values, positionals, rest = [] } = parsed;
1501
- const paths = [...new Set(rest)];
1547
+ const given = [...new Set(rest)];
1502
1548
  if (positionals.length !== 1)
1503
1549
  fail(`give the title as one quoted argument and the paths after --
1504
1550
 
1505
1551
  ${USAGE}`);
1506
- if (paths.length === 0)
1552
+ if (given.length === 0)
1507
1553
  fail(`give the paths to commit after --
1508
1554
 
1509
1555
  ${USAGE}`);
@@ -1520,12 +1566,14 @@ ${USAGE}`);
1520
1566
  const violation = commitMessageViolation(message);
1521
1567
  if (violation !== null)
1522
1568
  fail(`nothing staged: ${violation}`, 1);
1523
- const statuses = await Promise.all(paths.map(async (path) => checked(["status", "--porcelain", "--untracked-files=all", "--", path])));
1524
- const unchanged = paths.filter((_, i) => statuses[i] === "");
1525
- const addable = paths.filter((_, i) => !(statuses[i] ?? "").trimEnd().split(`
1569
+ const statuses = await Promise.all(given.map(async (path) => checked(["status", "--porcelain", "--untracked-files=all", "--", path])));
1570
+ const unchanged = given.filter((_, i) => statuses[i] === "");
1571
+ const addable = given.filter((_, i) => !(statuses[i] ?? "").trimEnd().split(`
1526
1572
  `).every((line) => line.startsWith("D ")));
1527
1573
  if (unchanged.length > 0)
1528
1574
  fail(`nothing staged: no change to commit in ${unchanged.join(", ")} (unchanged, ignored or missing)`, 1, runHint("gst", "see what changed"));
1575
+ const sources = await renameSources(given);
1576
+ const paths = [...given, ...sources];
1529
1577
  const others = await stagedElsewhere(paths);
1530
1578
  if (others.length > 0)
1531
1579
  fail(`nothing staged: the index already holds ${others.join(", ")}, which this commit would carry along`, 1, runHint(`git restore --staged -- ${others.join(" ")}`, "unstage them, or name them in the paths too"));
@@ -1557,7 +1605,7 @@ ${(commit.stderr + commit.stdout).trim()}`;
1557
1605
  });
1558
1606
  printJson({ sha: (await checked(["rev-parse", "HEAD"])).trim(), subject: head.slice(head.indexOf(" ") + 1), files: changes });
1559
1607
  } else if (values.quiet !== true) {
1560
- console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
1608
+ console.log([head, ...lines.filter(Boolean).map(fileLine), ...sources.map((from) => `also committed ${from}, the other side of a staged rename`)].join(`
1561
1609
  `));
1562
1610
  }
1563
1611
  return signals.signal === undefined ? 0 : exitCodeOf(null, signals.signal);
@@ -1565,4 +1613,4 @@ ${(commit.stderr + commit.stdout).trim()}`;
1565
1613
  signals.release();
1566
1614
  }
1567
1615
  }
1568
- process18.exitCode = await runMain({ name: "gc", run: main });
1616
+ process19.exitCode = await runMain({ name: "gc", run: main });
package/dist/gcl.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { existsSync as existsSync4, readdirSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
6
6
  import { homedir as homedir5 } from "os";
7
7
  import { basename, join as join8, resolve as resolve6 } from "path";
8
- import process19 from "process";
8
+ import process20 from "process";
9
9
  // ../kit/src/args.ts
10
10
  import process9 from "process";
11
11
  import { parseArgs } from "util";
@@ -496,7 +496,7 @@ function printJson(value) {
496
496
 
497
497
  // ../kit/src/help.ts
498
498
  import process8 from "process";
499
- var OPTIONAL = /\[[^\]]+\]/g;
499
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
500
500
  var USAGE_PREFIX = /^usage:\s*/i;
501
501
  var FULL_STOP = /\.$/;
502
502
  function usageLine(usage, colors = paint(process8.stdout)) {
@@ -535,29 +535,41 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
535
535
  return [];
536
536
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
537
537
  }
538
+ var MAX_INLINE_CHOICES = 24;
538
539
  function optionRows(options, colors = paint(process8.stdout)) {
539
540
  const rows = Object.entries(options).map(([name, option]) => {
540
541
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
541
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
542
+ const choices = option.choices?.join("|");
543
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
544
+ const named = inline ? `<${choices}>` : "<value>";
542
545
  const placeholder = option.optional === undefined ? named : `[${named}]`;
543
546
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
544
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
547
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
548
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
545
549
  });
546
550
  const width = Math.max(0, ...rows.map((row) => row.width));
547
551
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
548
552
  }
549
553
 
550
554
  // ../kit/src/text.ts
551
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
555
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
552
556
  function distance(a, b) {
553
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
554
- for (const [i, left] of [...a].entries()) {
557
+ const left = [...a];
558
+ const right = [...b];
559
+ let before = [];
560
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
561
+ for (const [i, x] of left.entries()) {
555
562
  const current = [i + 1];
556
- for (const [j, right] of [...b].entries())
557
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
563
+ for (const [j, y] of right.entries()) {
564
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
565
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
566
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
567
+ current.push(cost);
568
+ }
569
+ before = previous;
558
570
  previous = current;
559
571
  }
560
- return previous[b.length] ?? 0;
572
+ return previous[right.length] ?? 0;
561
573
  }
562
574
  function closest(name, names) {
563
575
  const started = names.find((known) => known.startsWith(name));
@@ -1141,13 +1153,31 @@ function interceptOutput(clear) {
1141
1153
  // ../kit/src/cli.ts
1142
1154
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1143
1155
  import { dirname as dirname3, join as join5 } from "path";
1144
- import process14 from "process";
1156
+ import process15 from "process";
1157
+
1158
+ // ../kit/src/notify.ts
1159
+ import process13 from "process";
1160
+ var NOTIFY_AFTER_MS = 1e4;
1161
+ var CANCELLED = 130;
1162
+ function base64(text) {
1163
+ return Buffer.from(text).toString("base64");
1164
+ }
1165
+ function notification(title, body, env = process13.env) {
1166
+ const id = `kit${process13.pid}`;
1167
+ const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
1168
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
1169
+ }
1170
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
1171
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
1172
+ return;
1173
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
1174
+ }
1145
1175
 
1146
1176
  // ../kit/src/usage.ts
1147
1177
  import { appendFileSync, mkdirSync } from "fs";
1148
1178
  import { homedir as homedir3 } from "os";
1149
1179
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
1150
- import process13 from "process";
1180
+ import process14 from "process";
1151
1181
 
1152
1182
  // ../kit/src/logs.ts
1153
1183
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -1161,14 +1191,14 @@ var usageError;
1161
1191
  function noteUsageError(message) {
1162
1192
  usageError = message;
1163
1193
  }
1164
- function stateHome(env = process13.env) {
1194
+ function stateHome(env = process14.env) {
1165
1195
  const dir = env.XDG_STATE_HOME;
1166
1196
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
1167
1197
  }
1168
- function usagePath(env = process13.env) {
1198
+ function usagePath(env = process14.env) {
1169
1199
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
1170
1200
  }
1171
- function usageRecorded(env = process13.env) {
1201
+ function usageRecorded(env = process14.env) {
1172
1202
  const off = env.KAYNOOO_CLI_NO_USAGE;
1173
1203
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1174
1204
  }
@@ -1182,7 +1212,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1182
1212
  usageError = undefined;
1183
1213
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1184
1214
  }
1185
- function recordUsage(entry, env = process13.env) {
1215
+ function recordUsage(entry, env = process14.env) {
1186
1216
  if (!usageRecorded(env))
1187
1217
  return;
1188
1218
  try {
@@ -1200,8 +1230,8 @@ var LEVEL_OPTIONS = {
1200
1230
  };
1201
1231
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1202
1232
  function printError(prefix, message, hint, cause) {
1203
- const colors = paint(process14.stderr);
1204
- const styled = takesControlCodes(process14.stderr);
1233
+ const colors = paint(process15.stderr);
1234
+ const styled = takesControlCodes(process15.stderr);
1205
1235
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1206
1236
  const under = (label, text, tint) => text === undefined ? "" : `
1207
1237
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1309,11 +1339,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1309
1339
  return 0;
1310
1340
  }
1311
1341
  let code;
1342
+ const started = performance.now();
1312
1343
  try {
1313
1344
  code = await run(argv);
1314
1345
  } catch (error) {
1315
1346
  code = reportThrown(name, error, redact, wantsJson(argv));
1316
1347
  }
1348
+ notifyEnd(name, code, performance.now() - started);
1317
1349
  if (usage !== false) {
1318
1350
  try {
1319
1351
  recordUsage(usageEntry(name, undefined, argv, code));
@@ -1330,7 +1362,7 @@ var {Glob } = globalThis.Bun;
1330
1362
  var SESSION_FILES = new Glob("*.json");
1331
1363
  var ACCOUNT_DIRS = new Glob("*/sessions");
1332
1364
  // ../kit/src/watch.ts
1333
- import process15 from "process";
1365
+ import process16 from "process";
1334
1366
  import { format } from "util";
1335
1367
  var CLEAR_SCREEN = "\x1B[H\x1B[2J";
1336
1368
  var DEFAULT_SECONDS = 2;
@@ -1352,7 +1384,7 @@ function withoutWatch(args) {
1352
1384
  }
1353
1385
  return rest;
1354
1386
  }
1355
- async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1387
+ async function watching(value, step, stream = process16.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
1356
1388
  const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
1357
1389
  if (!takesControlCodes(stream))
1358
1390
  badUsage("--watch redraws the screen, so it needs a terminal");
@@ -1360,12 +1392,12 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1360
1392
  for (let round = 0;round < rounds; round++) {
1361
1393
  const held = [];
1362
1394
  const { log, info } = console;
1363
- const write = process15.stdout.write.bind(process15.stdout);
1395
+ const write = process16.stdout.write.bind(process16.stdout);
1364
1396
  const hold = (...parts) => void held.push(`${format(...parts)}
1365
1397
  `);
1366
1398
  console.log = hold;
1367
1399
  console.info = hold;
1368
- process15.stdout.write = (text) => {
1400
+ process16.stdout.write = (text) => {
1369
1401
  held.push(typeof text === "string" ? text : Buffer.from(text).toString());
1370
1402
  return true;
1371
1403
  };
@@ -1374,7 +1406,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1374
1406
  } finally {
1375
1407
  console.log = log;
1376
1408
  console.info = info;
1377
- process15.stdout.write = write;
1409
+ process16.stdout.write = write;
1378
1410
  }
1379
1411
  stream.write(`${CLEAR_SCREEN}${held.join("")}`);
1380
1412
  await sleep(interval);
@@ -1384,7 +1416,7 @@ async function watching(value, step, stream = process15.stdout, sleep = Bun.slee
1384
1416
  // ../kit/src/workspace-root.ts
1385
1417
  import { homedir as homedir4 } from "os";
1386
1418
  import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
1387
- import process16 from "process";
1419
+ import process17 from "process";
1388
1420
  function expandHome(path, home) {
1389
1421
  if (path === "~")
1390
1422
  return home;
@@ -1394,7 +1426,7 @@ function configured(env, home) {
1394
1426
  const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
1395
1427
  return typeof folder === "string" && folder !== "" ? folder : undefined;
1396
1428
  }
1397
- function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
1429
+ function workspaceRoot({ given, env = process17.env, home = homedir4() } = {}) {
1398
1430
  const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
1399
1431
  return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
1400
1432
  }
@@ -1408,14 +1440,18 @@ async function git2(args, env) {
1408
1440
  // src/repos.ts
1409
1441
  import { readdir } from "fs/promises";
1410
1442
  import { join as join7, relative, resolve as resolve5 } from "path";
1411
- import process18 from "process";
1443
+ import process19 from "process";
1412
1444
 
1413
1445
  // src/status.ts
1414
1446
  var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
1447
+ var STASH = /^# stash (\d+)$/m;
1415
1448
  var OCTAL = /[0-7]/;
1416
1449
  var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13 };
1417
1450
  var ENCODER = new TextEncoder;
1418
1451
  var DECODER = new TextDecoder;
1452
+ function stashOf(text) {
1453
+ return Number(STASH.exec(text)?.[1] ?? 0);
1454
+ }
1419
1455
  function unquote(path) {
1420
1456
  if (!path.startsWith('"') || !path.endsWith('"'))
1421
1457
  return path;
@@ -1470,16 +1506,18 @@ function parseStatus(text) {
1470
1506
  }
1471
1507
  return hasBranch ? status : null;
1472
1508
  }
1473
- function summary(status, head) {
1509
+ function summary(status, head, { operation = null, stash = 0 } = {}) {
1474
1510
  const { branch, oid, upstream, aheadBehind, changes, conflicted, untracked } = status;
1475
- const on = branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``;
1511
+ const steps = operation?.step !== undefined && operation.total !== undefined ? ` ${operation.step}/${operation.total}` : "";
1512
+ const during = operation === null ? "" : ` (${operation.kind}${steps} in progress)`;
1513
+ const on = (branch === "(detached)" ? `detached at ${oid.slice(0, 7)}` : `branch \`${branch}\``) + during;
1476
1514
  let tracking = "no upstream";
1477
1515
  if (upstream !== null)
1478
1516
  tracking = aheadBehind === null ? `upstream \`${upstream}\` gone or never fetched` : `${aheadBehind.ahead} ahead and ${aheadBehind.behind} behind \`${upstream}\` as of the last fetch`;
1479
1517
  const files = [`${changes.length} changed`, untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean).join(", ");
1480
1518
  const [sha, title] = head.trim().split("\x00");
1481
1519
  const last = sha === undefined || sha === "" ? "; no commit yet" : `; HEAD ${sha} ${title ?? ""}`.trimEnd();
1482
- return `${on}, ${tracking}; ${files} files${last}`;
1520
+ return `${on}, ${tracking}; ${files} files${stash > 0 ? `; ${stash} stashed` : ""}${last}`;
1483
1521
  }
1484
1522
 
1485
1523
  // src/repos.ts
@@ -1508,14 +1546,14 @@ async function toplevelOf(dir) {
1508
1546
  return read.code === 0 ? read.stdout.trim() : undefined;
1509
1547
  }
1510
1548
  async function reposOf(roots) {
1511
- const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process18.cwd()];
1549
+ const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process19.cwd()];
1512
1550
  const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
1513
1551
  return [...new Set(found.flat())].sort();
1514
1552
  }
1515
1553
  async function repoState(dir) {
1516
1554
  const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
1517
1555
  const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
1518
- return { path: relative(process18.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1556
+ return { path: relative(process19.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
1519
1557
  }
1520
1558
  function trackingOf(status) {
1521
1559
  if (status.upstream === null)
@@ -1655,7 +1693,7 @@ ${cloned.stderr.trim()}`, 1);
1655
1693
  return 0;
1656
1694
  }
1657
1695
  if (import.meta.main)
1658
- process19.exitCode = await runMain({ name: "gcl", run: main });
1696
+ process20.exitCode = await runMain({ name: "gcl", run: main });
1659
1697
  export {
1660
1698
  nameOf,
1661
1699
  urlOf