@kaynooo/cli-code 0.14.2 → 0.15.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/peek-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/peek-cli.ts
5
- import process15 from "process";
5
+ import process17 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -422,6 +422,23 @@ function fileLink(text, path, stream, from = process6.cwd(), env = process6.env)
422
422
  }
423
423
 
424
424
  // ../kit/src/format.ts
425
+ var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
426
+ function formatSeconds(total) {
427
+ let rest = Math.max(0, Math.round(total));
428
+ const amounts = UNITS.map(([unit, size]) => {
429
+ const amount = Math.floor(rest / size);
430
+ rest -= amount * size;
431
+ return `${amount}${unit}`;
432
+ });
433
+ const first = amounts.findIndex((amount) => !amount.startsWith("0"));
434
+ if (first === -1)
435
+ return "0s";
436
+ const next = amounts[first + 1];
437
+ return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
438
+ }
439
+ function formatDuration(ms) {
440
+ return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
441
+ }
425
442
  function upTo(text, separator) {
426
443
  const end = text.indexOf(separator);
427
444
  return end === -1 ? text : text.slice(0, end);
@@ -482,24 +499,20 @@ function printJson(value) {
482
499
 
483
500
  // ../kit/src/help.ts
484
501
  import process8 from "process";
485
- var OPTIONAL = /\[[^\]]+\]/g;
502
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
486
503
  var USAGE_PREFIX = /^usage:\s*/i;
487
504
  var FULL_STOP = /\.$/;
488
505
  function usageLine(usage, colors = paint(process8.stdout)) {
489
506
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
490
507
  }
491
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
492
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
508
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
509
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
493
510
  `);
494
511
  }
495
512
  function exitRows(exits, colors = paint(process8.stdout)) {
496
513
  if (exits.length === 0)
497
514
  return [];
498
- const width = Math.max(...exits.map(([code]) => String(code).length));
499
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
500
- }
501
- function replacesRows(replaces, colors = paint(process8.stdout)) {
502
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
515
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
503
516
  }
504
517
  function wantsHelpJson(env = process8.env) {
505
518
  return env.KIT_HELP === "json";
@@ -525,29 +538,40 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
525
538
  return [];
526
539
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
527
540
  }
541
+ var MAX_INLINE_CHOICES = 24;
528
542
  function optionRows(options, colors = paint(process8.stdout)) {
529
543
  const rows = Object.entries(options).map(([name, option]) => {
530
544
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
531
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
545
+ const choices = option.choices?.join("|");
546
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
547
+ const named = inline ? `<${choices}>` : "<value>";
532
548
  const placeholder = option.optional === undefined ? named : `[${named}]`;
533
549
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
534
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
550
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
551
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
535
552
  });
536
553
  const width = Math.max(0, ...rows.map((row) => row.width));
537
554
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
538
555
  }
539
556
 
540
557
  // ../kit/src/text.ts
541
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
542
558
  function distance(a, b) {
543
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
544
- for (const [i, left] of [...a].entries()) {
559
+ const left = [...a];
560
+ const right = [...b];
561
+ let before = [];
562
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
563
+ for (const [i, x] of left.entries()) {
545
564
  const current = [i + 1];
546
- for (const [j, right] of [...b].entries())
547
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
565
+ for (const [j, y] of right.entries()) {
566
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
567
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
568
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
569
+ current.push(cost);
570
+ }
571
+ before = previous;
548
572
  previous = current;
549
573
  }
550
- return previous[b.length] ?? 0;
574
+ return previous[right.length] ?? 0;
551
575
  }
552
576
  function closest(name, names) {
553
577
  const started = names.find((known) => known.startsWith(name));
@@ -800,9 +824,33 @@ function nearestOption(message, options, allowNegative) {
800
824
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
801
825
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
802
826
  }
827
+ // ../kit/src/argv.ts
828
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
829
+ import { resolve as resolve4 } from "path";
830
+ import process10 from "process";
831
+ function commandLine() {
832
+ try {
833
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
834
+ } catch {
835
+ return;
836
+ }
837
+ }
838
+ function realPath(word) {
839
+ try {
840
+ return realpathSync(resolve4(word));
841
+ } catch {
842
+ return;
843
+ }
844
+ }
845
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
846
+ const target = script === undefined ? undefined : realPath(script) ?? script;
847
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve4(word) === script || realPath(word) === target));
848
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
849
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
850
+ }
803
851
  // ../kit/src/process.ts
804
852
  import { constants } from "os";
805
- import process10 from "process";
853
+ import process11 from "process";
806
854
  var KILL_GRACE_MS = 2000;
807
855
  function exitCodeOf(code, signal) {
808
856
  if (code !== null)
@@ -822,7 +870,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
822
870
  return;
823
871
  try {
824
872
  if (grouped)
825
- process10.kill(-proc.pid, killing);
873
+ process11.kill(-proc.pid, killing);
826
874
  else
827
875
  proc.kill(killing);
828
876
  } catch {}
@@ -896,15 +944,33 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
896
944
  var RESET_STYLE = `${ESC}[0m`;
897
945
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
898
946
  // ../kit/src/cli.ts
899
- import { readFileSync as readFileSync3, realpathSync } from "fs";
947
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
900
948
  import { dirname as dirname3, join as join5 } from "path";
949
+ import process14 from "process";
950
+
951
+ // ../kit/src/notify.ts
901
952
  import process12 from "process";
953
+ var NOTIFY_AFTER_MS = 1e4;
954
+ var CANCELLED = 130;
955
+ function base64(text) {
956
+ return Buffer.from(text).toString("base64");
957
+ }
958
+ function notification(title, body, env = process12.env) {
959
+ const id = `kit${process12.pid}`;
960
+ 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\\`];
961
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
962
+ }
963
+ function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
964
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
965
+ return;
966
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
967
+ }
902
968
 
903
969
  // ../kit/src/usage.ts
904
970
  import { appendFileSync, mkdirSync } from "fs";
905
971
  import { homedir as homedir3 } from "os";
906
972
  import { dirname as dirname2, isAbsolute, join as join4 } from "path";
907
- import process11 from "process";
973
+ import process13 from "process";
908
974
 
909
975
  // ../kit/src/logs.ts
910
976
  var DAY_MS = 24 * 60 * 60 * 1000;
@@ -918,14 +984,14 @@ var usageError;
918
984
  function noteUsageError(message) {
919
985
  usageError = message;
920
986
  }
921
- function stateHome(env = process11.env) {
987
+ function stateHome(env = process13.env) {
922
988
  const dir = env.XDG_STATE_HOME;
923
989
  return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
924
990
  }
925
- function usagePath(env = process11.env) {
991
+ function usagePath(env = process13.env) {
926
992
  return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
927
993
  }
928
- function usageRecorded(env = process11.env) {
994
+ function usageRecorded(env = process13.env) {
929
995
  const off = env.KAYNOOO_CLI_NO_USAGE;
930
996
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
931
997
  }
@@ -939,7 +1005,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
939
1005
  usageError = undefined;
940
1006
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
941
1007
  }
942
- function recordUsage(entry, env = process11.env) {
1008
+ function recordUsage(entry, env = process13.env) {
943
1009
  if (!usageRecorded(env))
944
1010
  return;
945
1011
  try {
@@ -1016,7 +1082,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1016
1082
  header(colors, summary),
1017
1083
  "",
1018
1084
  usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
1019
- ...replacesRows(replaces, colors),
1020
1085
  "",
1021
1086
  ...await commandRows(commands, colors),
1022
1087
  ...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
@@ -1030,8 +1095,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
1030
1095
  `);
1031
1096
  }
1032
1097
  function printError(prefix, message, hint, cause) {
1033
- const colors = paint(process12.stderr);
1034
- const styled = takesControlCodes(process12.stderr);
1098
+ const colors = paint(process14.stderr);
1099
+ const styled = takesControlCodes(process14.stderr);
1035
1100
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1036
1101
  const under = (label, text, tint) => text === undefined ? "" : `
1037
1102
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1074,11 +1139,11 @@ async function dispatch(level, typed, { version, redact }) {
1074
1139
  }
1075
1140
  }
1076
1141
  if (name === undefined && level.path.length > 1) {
1077
- console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
1142
+ console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
1078
1143
  return 2;
1079
1144
  }
1080
1145
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
1081
- console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
1146
+ console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
1082
1147
  return 0;
1083
1148
  }
1084
1149
  if (level.path.length === 1 && (name === "--version" || name === "-v")) {
@@ -1134,24 +1199,24 @@ function candidateLine(candidate) {
1134
1199
  }
1135
1200
  function positionalBeingTyped(before, { options, positionals }) {
1136
1201
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1137
- let index = 0;
1202
+ const typed = [];
1138
1203
  let at = 0;
1139
1204
  while (at < before.length) {
1140
1205
  const word = before[at];
1141
1206
  if (word === "--") {
1142
- index += before.length - at - 1;
1207
+ typed.push(...before.slice(at + 1));
1143
1208
  break;
1144
1209
  }
1145
1210
  if (!word.startsWith("-"))
1146
- index++;
1211
+ typed.push(word);
1147
1212
  else if (takesValue(word))
1148
1213
  at++;
1149
1214
  at++;
1150
1215
  }
1151
1216
  const last = positionals.at(-1);
1152
- if (index < positionals.length)
1153
- return positionals[index];
1154
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1217
+ if (typed.length < positionals.length)
1218
+ return { name: positionals[typed.length], typed };
1219
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1155
1220
  }
1156
1221
  async function leafCandidates(run, words) {
1157
1222
  const completing = await completingOf(run);
@@ -1159,12 +1224,12 @@ async function leafCandidates(run, words) {
1159
1224
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1160
1225
  const flag = words.at(-2);
1161
1226
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1227
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1162
1228
  if (option?.type === "string") {
1163
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1229
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1164
1230
  return values === undefined ? [FILES] : values.map(candidateLine);
1165
1231
  }
1166
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1167
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1232
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1168
1233
  return values === undefined ? [FILES] : values.map(candidateLine);
1169
1234
  }
1170
1235
  async function candidates(scope, defaultCommand, words, before = []) {
@@ -1195,9 +1260,13 @@ async function printCandidates(found) {
1195
1260
  return 0;
1196
1261
  }
1197
1262
  function packageVersion(entry = Bun.main) {
1198
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1263
+ let resolved = entry;
1264
+ try {
1265
+ resolved = realpathSync2(entry);
1266
+ } catch {}
1267
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1199
1268
  try {
1200
- const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
1269
+ const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
1201
1270
  if (typeof version === "string")
1202
1271
  return version;
1203
1272
  } catch {}
@@ -1205,14 +1274,17 @@ function packageVersion(entry = Bun.main) {
1205
1274
  return "0.0.0";
1206
1275
  }
1207
1276
  }
1208
- async function runCli(cli, argv = process12.argv.slice(2)) {
1277
+ async function runCli(cli, argv = scriptArgs()) {
1209
1278
  const version = cli.version ?? packageVersion();
1210
1279
  if (argv[0] === COMPLETE)
1211
1280
  return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
1281
+ const started = performance.now();
1212
1282
  const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
1283
+ const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
1284
+ notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
1213
1285
  if (cli.usage !== false) {
1214
1286
  try {
1215
- recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
1287
+ recordUsage(usageEntry(cli.name, command, argv, code));
1216
1288
  } catch {}
1217
1289
  }
1218
1290
  return code;
@@ -1232,7 +1304,7 @@ function commandPath(scope, argv) {
1232
1304
  }
1233
1305
  return path.length === 0 ? undefined : path.join(" ");
1234
1306
  }
1235
- async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
1307
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1236
1308
  if (argv[0] === COMPLETE)
1237
1309
  return printCandidates(leafCandidates(run, argv.slice(1)));
1238
1310
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1240,11 +1312,13 @@ async function runMain({ name, version, run, redact, usage }, argv = process12.a
1240
1312
  return 0;
1241
1313
  }
1242
1314
  let code;
1315
+ const started = performance.now();
1243
1316
  try {
1244
1317
  code = await run(argv);
1245
1318
  } catch (error) {
1246
1319
  code = reportThrown(name, error, redact, wantsJson(argv));
1247
1320
  }
1321
+ notifyEnd(name, code, performance.now() - started);
1248
1322
  if (usage !== false) {
1249
1323
  try {
1250
1324
  recordUsage(usageEntry(name, undefined, argv, code));
@@ -1287,9 +1361,9 @@ var {Glob } = globalThis.Bun;
1287
1361
  var SESSION_FILES = new Glob("*.json");
1288
1362
  var ACCOUNT_DIRS = new Glob("*/sessions");
1289
1363
  // src/peek.ts
1290
- import { realpathSync as realpathSync2 } from "fs";
1291
- import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve4, sep } from "path";
1292
- import process14 from "process";
1364
+ import { realpathSync as realpathSync3 } from "fs";
1365
+ import { isAbsolute as isAbsolute2, join as join7, relative as relative2, resolve as resolve5, sep } from "path";
1366
+ import process16 from "process";
1293
1367
 
1294
1368
  // src/files.ts
1295
1369
  import { existsSync as existsSync4, readdirSync, statSync as statSync2 } from "fs";
@@ -1334,9 +1408,11 @@ async function readText(path) {
1334
1408
 
1335
1409
  // src/source.ts
1336
1410
  var LOCATION = /^(?:\.\/)?([^\s:()]+)(?::(\d+)(?::\d+)?|\((\d+),\d+\))(?=[:\s)]|$)/;
1337
- var DECLARATION = /^(?:export\s+)?(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:function\*?|class|interface|type|enum|const|let|var|namespace|module|def|func|fn|struct|trait|impl)\s/;
1338
- var MODIFIERS = /^(?:(?:public|private|protected|static|async|override|readonly|abstract|get|set|pub|fn|def|func)\s+)*/;
1339
- var MEMBER = /^(?:(?:public|private|protected|static|async|override|readonly|abstract|get|set|pub|fn|def|func)\s+)*[#\w$]+\s*(?:<[^>]*>\s*)?\(/;
1411
+ var DECLARATION = /^(?:(?:export|default|declare|abstract|async|pub(?:\([^)]*\))?|public|private|protected|internal|final|open|sealed|static|suspend)\s+)*(?:function\*?|class|interface|type|enum|const|let|var|namespace|module|def|func|fun|fn|struct|trait|impl)\s/;
1412
+ var MODIFIER_WORDS = String.raw`(?:public|private|protected|internal|final|open|sealed|static|async|suspend|override|readonly|abstract|get|set|pub(?:\([^)]*\))?|function|fn|def|func|fun)\s+`;
1413
+ var RETURN_TYPE = String.raw`(?:[\w$.]+(?:<[^>]*>)?(?:\[\])*\??\s+(?=[#\w$]+\s*(?:<[^>]*>\s*)?\())?`;
1414
+ var MODIFIERS = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?`);
1415
+ var MEMBER = new RegExp(String.raw`^(?:(?:${MODIFIER_WORDS})+${RETURN_TYPE})?[#\w$]+\s*(?:<[^>]*>\s*)?\(`);
1340
1416
  var RECEIVER = /^(?:\([^)]*\)\s*)?/;
1341
1417
  var STAR = /^\*?\s*/;
1342
1418
  var HOLDS_MEMBERS = /\b(?:class|interface|trait|impl|struct)\s/;
@@ -1466,7 +1542,7 @@ function outline(text, path) {
1466
1542
  if (indent === 0 && DECLARATION.test(text) && !LOCAL_BINDING.test(text)) {
1467
1543
  entries.push({ line: i + 1, depth: 0, text: signature(line) });
1468
1544
  memberIndent = HOLDS_MEMBERS.test(text) ? -1 : undefined;
1469
- } else if (indent === 0 && text !== "" && !text.startsWith("}") && !LEADING.test(text)) {
1545
+ } else if (indent === 0 && text !== "" && !text.startsWith("{") && !text.startsWith("}") && !LEADING.test(text)) {
1470
1546
  memberIndent = undefined;
1471
1547
  } else if (memberIndent !== undefined && indent > 0 && (memberIndent === -1 || indent === memberIndent) && MEMBER.test(text) && !CALL_KEYWORDS.test(text)) {
1472
1548
  memberIndent = indent;
@@ -1515,9 +1591,8 @@ peek --around <regex> [-C 3] [path...] the lines around each match, overlapping
1515
1591
  <output> | peek [-C 3] the lines around each path:line the output opens a line with (errs, rg -n, grep -n, tsc, linters)
1516
1592
  The paths default to the files git keeps here (.gitignore holds).
1517
1593
  --refs lists at most 100 lines and --around prints at most 20 spans, the count of the rest after them (--limit <n>, --full for all).
1518
- --json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.
1519
-
1520
- Exits 0 when it printed something, 1 when nothing is found, a file cannot be read or a span starts past the end, 2 on a usage error or a path outside the repository.`;
1594
+ --json prints spans as [{path, from, to, lines}], --refs as [{path, line, text}] ({definitions, references} with --defs-first), --outline as [{path, line, depth, text}], the lines never cut and the rows never counted off unless --limit is given.`;
1595
+ var EXITS = [[0, "it printed something"], [1, "nothing is found, a file cannot be read or a span starts past the end"], [2, "a usage error or a path outside the repository"]];
1521
1596
  var REFS_LIMIT = 100;
1522
1597
  var AROUND_LIMIT = 20;
1523
1598
  var PARENT = `..${sep}`;
@@ -1538,13 +1613,13 @@ function cut(text) {
1538
1613
  return text.length > LONGEST_LINE ? `${text.slice(0, LONGEST_LINE - 1)}\u2026` : text;
1539
1614
  }
1540
1615
  async function readableRoot() {
1541
- const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process14.cwd() });
1542
- return realpathSync2(ran.code === 0 ? ran.text.trim() : process14.cwd());
1616
+ const ran = await runCommand(["git", "rev-parse", "--show-toplevel"], { cwd: process16.cwd() });
1617
+ return realpathSync3(ran.code === 0 ? ran.text.trim() : process16.cwd());
1543
1618
  }
1544
1619
  async function isOutside(path) {
1545
1620
  let real;
1546
1621
  try {
1547
- real = realpathSync2(resolve4(process14.cwd(), path));
1622
+ real = realpathSync3(resolve5(process16.cwd(), path));
1548
1623
  } catch {
1549
1624
  return false;
1550
1625
  }
@@ -1558,7 +1633,7 @@ async function checkInside(path) {
1558
1633
  async function pipedSpans(text, context) {
1559
1634
  const spans = [];
1560
1635
  for (const [path, numbers] of locations(text)) {
1561
- const source = await isOutside(path) ? undefined : await readText(resolve4(process14.cwd(), path));
1636
+ const source = await isOutside(path) ? undefined : await readText(resolve5(process16.cwd(), path));
1562
1637
  if (source !== undefined)
1563
1638
  spans.push(...spansAround(path, source.replace(TRAILING_NEWLINE2, "").split(`
1564
1639
  `).length, numbers, context));
@@ -1567,7 +1642,7 @@ async function pipedSpans(text, context) {
1567
1642
  }
1568
1643
  async function textOf(path) {
1569
1644
  await checkInside(path);
1570
- const text = await readText(resolve4(process14.cwd(), path));
1645
+ const text = await readText(resolve5(process16.cwd(), path));
1571
1646
  if (text === undefined)
1572
1647
  fail(`cannot read ${path} (missing, binary or too large)`, 1);
1573
1648
  return text;
@@ -1625,8 +1700,8 @@ async function spanOf(target) {
1625
1700
  async function* sources(paths) {
1626
1701
  for (const path of paths)
1627
1702
  await checkInside(path);
1628
- for (const path of await listFiles(paths, process14.cwd())) {
1629
- const text = await readText(join7(process14.cwd(), path));
1703
+ for (const path of await listFiles(paths, process16.cwd())) {
1704
+ const text = await readText(join7(process16.cwd(), path));
1630
1705
  if (text !== undefined)
1631
1706
  yield { path, text };
1632
1707
  }
@@ -1650,7 +1725,7 @@ async function definitionsOf(symbols, paths) {
1650
1725
  return [...found.values()].flat();
1651
1726
  }
1652
1727
  async function peek(args) {
1653
- const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
1728
+ const { values, positionals } = parse(args, USAGE, OPTIONS, { exits: EXITS, positionals: ["[target...]"], replaces: "sed -n N,Mp, grep -n chains and whole-file reads", examples: [["peek src/a.ts:120-140 src/b.ts:1-40", "two spans in one call"], ["peek --def parseArgs src", "a whole declaration"]] });
1654
1729
  const modes = [values.def?.length === 0 ? undefined : values.def, values.refs, values.outline, values.around].filter((mode) => mode !== undefined && mode !== false);
1655
1730
  const json = values.json === true;
1656
1731
  if (values["defs-first"] === true && values.refs === undefined)
@@ -1726,4 +1801,4 @@ async function peek(args) {
1726
1801
  }
1727
1802
 
1728
1803
  // src/peek-cli.ts
1729
- process15.exitCode = await runMain({ name: "peek", run: peek });
1804
+ process17.exitCode = await runMain({ name: "peek", run: peek });