@kaynooo/cli-git 0.13.0 → 0.13.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
@@ -4,17 +4,17 @@ Git for Claude Code, where a session would otherwise chain `git status --short`
4
4
 
5
5
  ```sh
6
6
  bun install -g @kaynooo/cli-git
7
- gst --log 3
7
+ gst -n 3
8
8
  gc 'fix(band): keep it visible' -m 'The band stays above a long prompt.' --ticket '#5 - deliver every pointer' -- src/band.ts tests/band.test.ts
9
9
  ```
10
10
 
11
11
  ## gst
12
12
 
13
- Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `--log N` adds the last N commits as `<sha7> <title>`. `--json` prints the same as `{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}`, a change as `{status, path, from?}`. It takes no index lock, so it runs beside another git command. Exit codes: 0, 2 outside a repository or a usage error.
13
+ Prints one line with the branch, its upstream and how far ahead and behind it is as of the last fetch, the counts of changed, untracked and conflicted files and HEAD, then the paths grouped as `staged`, `unstaged`, `untracked` and `conflicted`, each with git's letter (`M`, `A`, `D`, `R old -> new`). `-n N` (`--limit`, and the former `--log` and `-l`) adds the last N commits as `<sha7> <title>`. `--json` prints the same as `{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}`, a change as `{status, path, from?}`. It takes no index lock, so it runs beside another git command. Exit codes: 0, 2 outside a repository or a usage error.
14
14
 
15
15
  ## gc
16
16
 
17
- `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter; `--json` prints `{sha, subject, files: [{status, path, from?}]}`.
17
+ `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...` commits exactly the paths given and prints `<sha7> <title>` then each file committed with its letter, nothing with `-q`/`--quiet`; `--json` prints `{sha, subject, files: [{status, path, from?}]}`.
18
18
 
19
19
  - The message is the title, then the `-m` lines, then the `--ticket` lines, each block after a blank line; ticket lines are copied verbatim and read `#<n> - <title>`.
20
20
  - Before anything is staged it refuses, exit 1, saying which rule broke: a title that is no Conventional Commit, a title over one line, more than two description lines, a bullet list, a hard-wrapped sentence, any trailer (`Co-Authored-By`, `Signed-off-by`, "Generated with"). A breaking change (`feat!:` or a `BREAKING CHANGE:` line) may give full details.
package/dist/gb.js CHANGED
@@ -324,10 +324,31 @@ var STATUS_WORDS = {
324
324
  var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
325
325
 
326
326
  // ../kit/src/format.ts
327
+ var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
328
+ function formatSeconds(total) {
329
+ let rest = Math.max(0, Math.round(total));
330
+ const amounts = UNITS.map(([unit, size]) => {
331
+ const amount = Math.floor(rest / size);
332
+ rest -= amount * size;
333
+ return `${amount}${unit}`;
334
+ });
335
+ const first = amounts.findIndex((amount) => !amount.startsWith("0"));
336
+ if (first === -1)
337
+ return "0s";
338
+ const next = amounts[first + 1];
339
+ return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
340
+ }
327
341
  function upTo(text, separator) {
328
342
  const end = text.indexOf(separator);
329
343
  return end === -1 ? text : text.slice(0, end);
330
344
  }
345
+ function formatAge(date, now = Date.now()) {
346
+ const at = typeof date === "number" ? date : Date.parse(date);
347
+ if (Number.isNaN(at))
348
+ return "-";
349
+ const seconds = (now - at) / 1000;
350
+ return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
351
+ }
331
352
  var ESCAPE = String.fromCharCode(27);
332
353
  function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
333
354
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
@@ -1114,7 +1135,9 @@ var COLUMN_GAP = 2;
1114
1135
  var PASTE_START = "\x1B[200~";
1115
1136
  var PASTE_END = "\x1B[201~";
1116
1137
  var LAST_WORD = /\S*\s*$/;
1117
- var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1138
+ var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1139
+ var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1140
+ var WHEEL_LINES = 3;
1118
1141
  var KEYS = {
1119
1142
  "\x1B[A": "up",
1120
1143
  "\x1BOA": "up",
@@ -1196,6 +1219,9 @@ function lay(rows, searched) {
1196
1219
  function parseKeys(input, paste = { active: false }, ctrls = []) {
1197
1220
  const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
1198
1221
  return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
1222
+ const wheel = MOUSE.exec(sequence)?.[1];
1223
+ if (wheel !== undefined)
1224
+ return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
1199
1225
  const named = codes.get(sequence);
1200
1226
  const key = named === undefined ? KEYS[sequence] : { ctrl: named };
1201
1227
  if (sequence === PASTE_START || sequence === PASTE_END) {
@@ -1438,7 +1464,7 @@ function caretColumn(state, layout) {
1438
1464
  }
1439
1465
  function helpLines(state, layout, theme) {
1440
1466
  const lines = [
1441
- "type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
1467
+ "type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
1442
1468
  `enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
1443
1469
  ...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
1444
1470
  ];
@@ -1488,8 +1514,11 @@ var ESCAPE_WAIT_MS = 30;
1488
1514
  var OPEN = { ctrl: "open" };
1489
1515
  var HIDE_CURSOR = "\x1B[?25l";
1490
1516
  var SHOW_CURSOR = "\x1B[?25h";
1517
+ var CARET = "\x1B[7m \x1B[27m";
1491
1518
  var PASTE_ON = "\x1B[?2004h";
1492
1519
  var PASTE_OFF = "\x1B[?2004l";
1520
+ var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
1521
+ var MOUSE_OFF = "\x1B[?1006l\x1B[?1000l";
1493
1522
  var CLEAR_BELOW = "\r\x1B[J";
1494
1523
  var SIGNALS2 = ["SIGINT", "SIGTERM", "SIGHUP"];
1495
1524
  function up(lines) {
@@ -1552,21 +1581,18 @@ async function select(rows, settings, terminal = openTerminal()) {
1552
1581
  let finish;
1553
1582
  let restored = false;
1554
1583
  let escape;
1555
- let caret;
1556
1584
  function draw(clear = false) {
1557
1585
  if (restored)
1558
1586
  return;
1559
1587
  const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
1560
1588
  let frame = HIDE_CURSOR;
1561
1589
  if (reserved !== layout.height || clear) {
1562
- frame += clear && caret !== undefined ? up(Math.floor((caret - 1) / terminal.columns)) : "";
1563
1590
  frame += CLEAR_BELOW + `
1564
1591
  `.repeat(layout.height - 1) + up(layout.height - 1);
1565
1592
  reserved = layout.height;
1566
1593
  }
1567
- caret = caretColumn(state, layout);
1568
1594
  frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
1569
- `)}${up(layout.height - 1)}\r\x1B[${caret}G${SHOW_CURSOR}`;
1595
+ `)}${up(layout.height - 1)}\r\x1B[${caretColumn(state, layout)}G${CARET}\r`;
1570
1596
  terminal.write(frame);
1571
1597
  }
1572
1598
  function pageSize() {
@@ -1605,7 +1631,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1605
1631
  clearTimeout(previewTimer);
1606
1632
  clearTimeout(escape);
1607
1633
  previewing.abort();
1608
- terminal.write(`${CLEAR_BELOW}${PASTE_OFF}${SHOW_CURSOR}`);
1634
+ terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1609
1635
  terminal.close();
1610
1636
  }
1611
1637
  const stop = () => {
@@ -1684,7 +1710,7 @@ async function select(rows, settings, terminal = openTerminal()) {
1684
1710
  for (const signal of SIGNALS2)
1685
1711
  process16.once(signal, stop);
1686
1712
  try {
1687
- terminal.write(PASTE_ON);
1713
+ terminal.write(`${PASTE_ON}${MOUSE_ON}`);
1688
1714
  terminal.listen(onChunk, () => draw(true));
1689
1715
  refreshPreview();
1690
1716
  draw(true);
@@ -1757,7 +1783,7 @@ var options = {
1757
1783
  delete: { type: "boolean", short: "d", description: "delete the local branch with git branch -d" },
1758
1784
  json: jsonOption("[{ name, remote, worktree, when, subject, date, upstream, track, merged }]")
1759
1785
  };
1760
- var FIELDS = ["%(refname)", "%(refname:short)", "%(committerdate:unix)", "%(committerdate:relative)", "%(subject)", "%(worktreepath)", "%(upstream:short)", "%(upstream:track,nobracket)"];
1786
+ var FIELDS = ["%(refname)", "%(refname:short)", "%(committerdate:unix)", "%(subject)", "%(worktreepath)", "%(upstream:short)", "%(upstream:track,nobracket)"];
1761
1787
  var CHECKOUT = /^checkout: moving from (\S+) to (\S+)$/;
1762
1788
  var KEYS2 = "enter go, ctrl-n new from query, ctrl-d delete if merged, ctrl-r fetch";
1763
1789
  var TRACK_TINTS = { ahead: "green", behind: "red", gone: "yellow" };
@@ -1800,13 +1826,13 @@ function branches(against) {
1800
1826
  `).filter(Boolean);
1801
1827
  const merged = new Set(against !== undefined ? read(["branch", "--merged", against, "--format=%(refname:short)"]).split(`
1802
1828
  `) : []);
1803
- return lines.map((line) => line.split("\x00")).filter(([ref = ""]) => !ref.endsWith("/HEAD")).map(([ref = "", name = "", date = "0", when = "", subject = "", worktree = "", upstream = "", track = ""]) => {
1829
+ return lines.map((line) => line.split("\x00")).filter(([ref = ""]) => !ref.endsWith("/HEAD")).map(([ref = "", name = "", date = "0", subject = "", worktree = "", upstream = "", track = ""]) => {
1804
1830
  const remote = ref.startsWith("refs/remotes/");
1805
1831
  return {
1806
1832
  name,
1807
1833
  remote,
1808
1834
  worktree: worktree === here ? "" : worktree,
1809
- when,
1835
+ when: formatAge(Number(date) * 1000),
1810
1836
  subject,
1811
1837
  date: Number(date),
1812
1838
  upstream,
package/dist/gc.js CHANGED
@@ -324,10 +324,31 @@ var STATUS_WORDS = {
324
324
  var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
325
325
 
326
326
  // ../kit/src/format.ts
327
+ var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
328
+ function formatSeconds(total) {
329
+ let rest = Math.max(0, Math.round(total));
330
+ const amounts = UNITS.map(([unit, size]) => {
331
+ const amount = Math.floor(rest / size);
332
+ rest -= amount * size;
333
+ return `${amount}${unit}`;
334
+ });
335
+ const first = amounts.findIndex((amount) => !amount.startsWith("0"));
336
+ if (first === -1)
337
+ return "0s";
338
+ const next = amounts[first + 1];
339
+ return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
340
+ }
327
341
  function upTo(text, separator) {
328
342
  const end = text.indexOf(separator);
329
343
  return end === -1 ? text : text.slice(0, end);
330
344
  }
345
+ function formatAge(date, now = Date.now()) {
346
+ const at = typeof date === "number" ? date : Date.parse(date);
347
+ if (Number.isNaN(at))
348
+ return "-";
349
+ const seconds = (now - at) / 1000;
350
+ return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
351
+ }
331
352
  var ESCAPE = String.fromCharCode(27);
332
353
  function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
333
354
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
@@ -1084,6 +1105,7 @@ Exits 0 when it committed, 1 when the message is refused or git fails (nothing i
1084
1105
  var OPTIONS = {
1085
1106
  message: { type: "string", short: "m", multiple: true, description: "a line on what changed, at most two" },
1086
1107
  ticket: { type: "string", multiple: true, description: "a ticket line, `#<n> - <title>` (`owner/repo#<n> - <title>` across repositories) copied verbatim from the ticket" },
1108
+ quiet: { type: "boolean", short: "q", description: "print nothing once committed, failures aside" },
1087
1109
  json: jsonOption("{sha, subject, files: [{status, path, from?}]} of the commit")
1088
1110
  };
1089
1111
  var RENAME = /^[RC]\d*$/;
@@ -1177,7 +1199,7 @@ ${(commit.stderr + commit.stdout).trim()}`;
1177
1199
  return RENAME.test(letter) ? { status: letter[0] ?? letter, path: to ?? from, from } : { status: letter, path: from };
1178
1200
  });
1179
1201
  printJson({ sha: (await checked(["rev-parse", "HEAD"])).trim(), subject: head.slice(head.indexOf(" ") + 1), files: changes });
1180
- } else {
1202
+ } else if (values.quiet !== true) {
1181
1203
  console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
1182
1204
  `));
1183
1205
  }
package/dist/gst.js CHANGED
@@ -324,10 +324,31 @@ var STATUS_WORDS = {
324
324
  var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
325
325
 
326
326
  // ../kit/src/format.ts
327
+ var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
328
+ function formatSeconds(total) {
329
+ let rest = Math.max(0, Math.round(total));
330
+ const amounts = UNITS.map(([unit, size]) => {
331
+ const amount = Math.floor(rest / size);
332
+ rest -= amount * size;
333
+ return `${amount}${unit}`;
334
+ });
335
+ const first = amounts.findIndex((amount) => !amount.startsWith("0"));
336
+ if (first === -1)
337
+ return "0s";
338
+ const next = amounts[first + 1];
339
+ return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
340
+ }
327
341
  function upTo(text, separator) {
328
342
  const end = text.indexOf(separator);
329
343
  return end === -1 ? text : text.slice(0, end);
330
344
  }
345
+ function formatAge(date, now = Date.now()) {
346
+ const at = typeof date === "number" ? date : Date.parse(date);
347
+ if (Number.isNaN(at))
348
+ return "-";
349
+ const seconds = (now - at) / 1000;
350
+ return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
351
+ }
331
352
  var ESCAPE = String.fromCharCode(27);
332
353
  function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
333
354
  return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
@@ -1105,11 +1126,12 @@ function summary(status, head) {
1105
1126
  }
1106
1127
 
1107
1128
  // src/gst.ts
1108
- 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
1129
+ var USAGE = `gst [-n N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
1109
1130
 
1110
1131
  Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
1111
1132
  var OPTIONS = {
1112
- log: { type: "string", short: "l", description: "add the last N commits as <sha7> <title>" },
1133
+ limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
1134
+ log: { type: "string", short: "l", description: "the former spelling of --limit" },
1113
1135
  watch: watchOption("the status"),
1114
1136
  json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
1115
1137
  };
@@ -1120,14 +1142,17 @@ function staged({ index, from, path }) {
1120
1142
  return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
1121
1143
  }
1122
1144
  async function main(argv) {
1123
- const parsed = parse(argv, USAGE, OPTIONS, { replaces: "git status --short and git log --oneline", examples: ["gst", ["gst --log 5", "with the last five commits"]] });
1145
+ const parsed = parse(argv, USAGE, OPTIONS, { replaces: "git status --short and git log --oneline", examples: ["gst", ["gst -n 5", "with the last five commits"]] });
1124
1146
  if (parsed.positionals.length > 0)
1125
1147
  fail(`gst takes no paths
1126
1148
 
1127
1149
  ${USAGE}`);
1128
1150
  if (parsed.values.watch !== undefined)
1129
1151
  return watching(parsed.values.watch, async () => main(withoutWatch(argv)));
1130
- const count = parsed.values.log === undefined ? 0 : wholeNumber(parsed.values.log, "log", 1);
1152
+ if (parsed.values.limit !== undefined && parsed.values.log !== undefined)
1153
+ fail("--limit and --log are the same flag, give one");
1154
+ const asked = parsed.values.limit ?? parsed.values.log;
1155
+ const count = asked === undefined ? 0 : wholeNumber(asked, "limit", 1);
1131
1156
  const [read, head, log] = await Promise.all([
1132
1157
  git2(["status", "--porcelain=v2", "--branch"]),
1133
1158
  git2(["log", "-1", "--format=%h%x00%s"]),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
3
  "type": "module",
4
- "version": "0.13.0",
4
+ "version": "0.13.1",
5
5
  "description": "gst, gc and gb: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, and a branch picked.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -44,6 +44,6 @@
44
44
  "gb": "$npm_execpath src/gb.ts"
45
45
  },
46
46
  "devDependencies": {
47
- "@kaynooo/cli-kit": "0.35.0"
47
+ "@kaynooo/cli-kit": "0.37.0"
48
48
  }
49
49
  }