@kaynooo/cli-check 0.18.2 → 0.20.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/j-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/j-cli.ts
5
- import process23 from "process";
5
+ import process26 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process10 from "process";
8
8
  import { parseArgs } from "util";
@@ -461,24 +461,20 @@ function printJson(value) {
461
461
 
462
462
  // ../kit/src/help.ts
463
463
  import process8 from "process";
464
- var OPTIONAL = /\[[^\]]+\]/g;
464
+ var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
465
465
  var USAGE_PREFIX = /^usage:\s*/i;
466
466
  var FULL_STOP = /\.$/;
467
467
  function usageLine(usage, colors = paint(process8.stdout)) {
468
468
  return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
469
469
  }
470
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
471
- return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
470
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
471
+ return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
472
472
  `);
473
473
  }
474
474
  function exitRows(exits, colors = paint(process8.stdout)) {
475
475
  if (exits.length === 0)
476
476
  return [];
477
- const width = Math.max(...exits.map(([code]) => String(code).length));
478
- return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
479
- }
480
- function replacesRows(replaces, colors = paint(process8.stdout)) {
481
- return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
477
+ return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
482
478
  }
483
479
  function wantsHelpJson(env = process8.env) {
484
480
  return env.KIT_HELP === "json";
@@ -504,32 +500,44 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
504
500
  return [];
505
501
  return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
506
502
  }
503
+ var MAX_INLINE_CHOICES = 24;
507
504
  function optionRows(options, colors = paint(process8.stdout)) {
508
505
  const rows = Object.entries(options).map(([name, option]) => {
509
506
  const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
510
- const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
507
+ const choices = option.choices?.join("|");
508
+ const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
509
+ const named = inline ? `<${choices}>` : "<value>";
511
510
  const placeholder = option.optional === undefined ? named : `[${named}]`;
512
511
  const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
513
- return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
512
+ const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
513
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
514
514
  });
515
515
  const width = Math.max(0, ...rows.map((row) => row.width));
516
516
  return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
517
517
  }
518
518
 
519
519
  // ../kit/src/text.ts
520
- var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
520
+ var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
521
521
  function stripAnsi(text) {
522
522
  return text.replace(ANSI, "");
523
523
  }
524
524
  function distance(a, b) {
525
- let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
526
- for (const [i, left] of [...a].entries()) {
525
+ const left = [...a];
526
+ const right = [...b];
527
+ let before = [];
528
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
529
+ for (const [i, x] of left.entries()) {
527
530
  const current = [i + 1];
528
- for (const [j, right] of [...b].entries())
529
- current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
531
+ for (const [j, y] of right.entries()) {
532
+ let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
533
+ if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
534
+ cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
535
+ current.push(cost);
536
+ }
537
+ before = previous;
530
538
  previous = current;
531
539
  }
532
- return previous[b.length] ?? 0;
540
+ return previous[right.length] ?? 0;
533
541
  }
534
542
  function closest(name, names) {
535
543
  const started = names.find((known) => known.startsWith(name));
@@ -934,31 +942,49 @@ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
934
942
  // ../kit/src/cli.ts
935
943
  import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
936
944
  import { dirname as dirname3, join as join6 } from "path";
937
- import process15 from "process";
945
+ import process16 from "process";
946
+
947
+ // ../kit/src/notify.ts
948
+ import process13 from "process";
949
+ var NOTIFY_AFTER_MS = 1e4;
950
+ var CANCELLED = 130;
951
+ function base64(text) {
952
+ return Buffer.from(text).toString("base64");
953
+ }
954
+ function notification(title, body, env = process13.env) {
955
+ const id = `kit${process13.pid}`;
956
+ 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\\`];
957
+ return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
958
+ }
959
+ function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
960
+ if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
961
+ return;
962
+ stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
963
+ }
938
964
 
939
965
  // ../kit/src/usage.ts
940
966
  import { appendFileSync, mkdirSync } from "fs";
941
967
  import { homedir as homedir4 } from "os";
942
968
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
943
- import process14 from "process";
969
+ import process15 from "process";
944
970
 
945
971
  // ../kit/src/logs.ts
946
972
  import { lstatSync, openSync } from "fs";
947
973
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
948
974
  import { homedir as homedir3, tmpdir } from "os";
949
975
  import { join as join4 } from "path";
950
- import process13 from "process";
976
+ import process14 from "process";
951
977
  var DAY_MS = 24 * 60 * 60 * 1000;
952
978
  var CLI_FOLDER = "kaynooo-cli";
953
979
  function isPrivateDirectory(path) {
954
980
  try {
955
981
  const info = lstatSync(path, { throwIfNoEntry: false });
956
- return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
982
+ return info !== undefined && info.isDirectory() && info.uid === (process14.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
957
983
  } catch {
958
984
  return false;
959
985
  }
960
986
  }
961
- async function privateLogDirectory(name, env = process13.env) {
987
+ async function privateLogDirectory(name, env = process14.env) {
962
988
  const runtime = env.XDG_RUNTIME_DIR;
963
989
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
964
990
  const path = join4(base, name);
@@ -998,14 +1024,14 @@ var usageError;
998
1024
  function noteUsageError(message) {
999
1025
  usageError = message;
1000
1026
  }
1001
- function stateHome(env = process14.env) {
1027
+ function stateHome(env = process15.env) {
1002
1028
  const dir = env.XDG_STATE_HOME;
1003
1029
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1004
1030
  }
1005
- function usagePath(env = process14.env) {
1031
+ function usagePath(env = process15.env) {
1006
1032
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1007
1033
  }
1008
- function usageRecorded(env = process14.env) {
1034
+ function usageRecorded(env = process15.env) {
1009
1035
  const off = env.KAYNOOO_CLI_NO_USAGE;
1010
1036
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1011
1037
  }
@@ -1019,7 +1045,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1019
1045
  usageError = undefined;
1020
1046
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1021
1047
  }
1022
- function recordUsage(entry, env = process14.env) {
1048
+ function recordUsage(entry, env = process15.env) {
1023
1049
  if (!usageRecorded(env))
1024
1050
  return;
1025
1051
  try {
@@ -1037,8 +1063,8 @@ var LEVEL_OPTIONS = {
1037
1063
  };
1038
1064
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1039
1065
  function printError(prefix, message, hint, cause) {
1040
- const colors = paint(process15.stderr);
1041
- const styled = takesControlCodes(process15.stderr);
1066
+ const colors = paint(process16.stderr);
1067
+ const styled = takesControlCodes(process16.stderr);
1042
1068
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1043
1069
  const under = (label, text, tint) => text === undefined ? "" : `
1044
1070
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1121,7 +1147,11 @@ async function printCandidates(found) {
1121
1147
  return 0;
1122
1148
  }
1123
1149
  function packageVersion(entry = Bun.main) {
1124
- for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
1150
+ let resolved = entry;
1151
+ try {
1152
+ resolved = realpathSync2(entry);
1153
+ } catch {}
1154
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1125
1155
  try {
1126
1156
  const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1127
1157
  if (typeof version === "string")
@@ -1139,11 +1169,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1139
1169
  return 0;
1140
1170
  }
1141
1171
  let code;
1172
+ const started = performance.now();
1142
1173
  try {
1143
1174
  code = await run(argv);
1144
1175
  } catch (error) {
1145
1176
  code = reportThrown(name, error, redact, wantsJson(argv));
1146
1177
  }
1178
+ notifyEnd(name, code, performance.now() - started);
1147
1179
  if (usage !== false) {
1148
1180
  try {
1149
1181
  recordUsage(usageEntry(name, undefined, argv, code));
@@ -1151,13 +1183,174 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1151
1183
  }
1152
1184
  return code;
1153
1185
  }
1186
+ // ../kit/src/excerpt.ts
1187
+ var BASH_ECHO = /^\$ /;
1188
+ var DURATION2 = / \[[\d.]+m?s\]$/;
1189
+ var BOUNDARY = /^(?:\((?:pass|fail|skip|todo)\) |\S+\.test\.[jt]sx?:$)/;
1190
+ var BUN_TEST_SUMMARY = /^\s*\d+ (?:pass|fail|skip|todo)$|^Ran \d+ tests?/;
1191
+ var BUN_CHECK_BLOCK = /<error file=[\s\S]*?<\/error>/g;
1192
+ var BUN_CHECK_SOURCE = /<source>[\s\S]*?<\/source>\n?/g;
1193
+ var BUN_CHECK_ATTRIBUTE = /(\w+)="([^"]*)"/g;
1194
+ var BUN_CHECK_SUMMARY = /^Found \d+ errors?/;
1195
+ var TSC_ERROR = /\berror TS\d+/;
1196
+ var TSC_CONTINUATION = /^\s{2,}\S/;
1197
+ var TSC_FRAME = /^\s*[~^|]/;
1198
+ var TSC_SUMMARY = /^Found \d+ errors?/;
1199
+ var ESLINT_PROBLEM = /^\s+\d+:\d+\s+(?:error|warning)\s/;
1200
+ var ESLINT_SUMMARY = /^(?:\u2716 )?\d+ problems? \(/;
1201
+ var PHPSTAN_TABLE = /^\s*-{3,} -{3,}/;
1202
+ var PHPSTAN_NOISE = /^\s*\[OK\]/;
1203
+ var PHP_FAILURES = /^(?:There w(?:as|ere) \d+ (?:failure|error|risky|warning)|\s+(?:FAIL|FAILED)\s+\S|In \S+\.php line \d+:$)/;
1204
+ var VITEST_FAIL_LINE = /^ FAIL {2}\S/;
1205
+ var PLAYWRIGHT_FAIL_LINE = /^ {2}1\) .+:\d+:\d+ \u203A .+ \u2500+$/;
1206
+ var CS_FIXER_LINE = /^\s+\d+\) \S.*\.php(?: \(.+\))?$/;
1207
+ var CS_FIXER_TOTAL = /^Found \d+ of \d+ files/;
1208
+ var MAX_TESTS = 10;
1209
+ var MAX_LINES = 100;
1210
+ var TAIL = 30;
1211
+ var bunTest = (lines) => {
1212
+ const seen = new Set;
1213
+ const blocks = [];
1214
+ for (const [index, line] of lines.entries()) {
1215
+ const name = line.replace(DURATION2, "");
1216
+ if (!line.startsWith("(fail) ") || seen.has(name))
1217
+ continue;
1218
+ seen.add(name);
1219
+ if (blocks.length < MAX_TESTS)
1220
+ blocks.push(lines.slice(lines.findLastIndex((text, at) => at < index && BOUNDARY.test(text)) + 1, index + 1).join(`
1221
+ `).trim());
1222
+ }
1223
+ if (blocks.length === 0)
1224
+ return;
1225
+ if (seen.size > MAX_TESTS)
1226
+ blocks.push(`and ${seen.size - MAX_TESTS} more failed tests`);
1227
+ return [...blocks.join(`
1228
+
1229
+ `).split(`
1230
+ `), "", ...lines.filter((line) => BUN_TEST_SUMMARY.test(line)).map((line) => line.trim())];
1231
+ };
1232
+ var bunCheck = (lines) => {
1233
+ const text = lines.join(`
1234
+ `);
1235
+ const blocks = text.match(BUN_CHECK_BLOCK);
1236
+ if (blocks === null)
1237
+ return;
1238
+ const errors = blocks.map((block) => {
1239
+ const { file, line, column, code, message } = bunCheckFields(block);
1240
+ return `${file}:${line}:${column} ${code}: ${message}`;
1241
+ });
1242
+ return [...errors, ...lines.filter((line) => BUN_CHECK_SUMMARY.test(line))];
1243
+ };
1244
+ function bunCheckFields(block) {
1245
+ const attributes = Object.fromEntries([...block.slice(0, block.indexOf(`
1246
+ `)).matchAll(BUN_CHECK_ATTRIBUTE)].map((match) => [match[1] ?? "", match[2] ?? ""]));
1247
+ return {
1248
+ file: attributes.file ?? "",
1249
+ line: attributes.line ?? "",
1250
+ column: attributes.column ?? "",
1251
+ code: attributes.code ?? "",
1252
+ message: block.replace(BUN_CHECK_SOURCE, "").split(`
1253
+ `).slice(1, -1).join(`
1254
+ `).trim()
1255
+ };
1256
+ }
1257
+ var tsc = (lines) => {
1258
+ const kept = [];
1259
+ let inError = false;
1260
+ for (const line of lines) {
1261
+ if (TSC_ERROR.test(line)) {
1262
+ inError = true;
1263
+ kept.push(line);
1264
+ } else if (TSC_SUMMARY.test(line)) {
1265
+ inError = false;
1266
+ kept.push(line);
1267
+ } else if (inError && TSC_CONTINUATION.test(line) && !TSC_FRAME.test(line)) {
1268
+ kept.push(line);
1269
+ } else {
1270
+ inError = false;
1271
+ }
1272
+ }
1273
+ return kept.some((line) => TSC_ERROR.test(line)) ? kept : undefined;
1274
+ };
1275
+ var eslint = (lines) => {
1276
+ const kept = [];
1277
+ let file = "";
1278
+ let shown = "";
1279
+ for (const line of lines) {
1280
+ if (ESLINT_PROBLEM.test(line)) {
1281
+ if (file !== shown) {
1282
+ kept.push(file);
1283
+ shown = file;
1284
+ }
1285
+ kept.push(line);
1286
+ } else if (ESLINT_SUMMARY.test(line)) {
1287
+ kept.push(line);
1288
+ } else if (line.trim() !== "") {
1289
+ file = line;
1290
+ }
1291
+ }
1292
+ return kept.some((line) => ESLINT_PROBLEM.test(line)) ? kept : undefined;
1293
+ };
1294
+ var phpstan = (lines) => {
1295
+ const start = lines.findIndex((line) => PHPSTAN_TABLE.test(line));
1296
+ return start === -1 ? undefined : lines.slice(start).filter((line) => !PHPSTAN_NOISE.test(line));
1297
+ };
1298
+ var php = (lines) => {
1299
+ const start = lines.findIndex((line) => PHP_FAILURES.test(line));
1300
+ return start === -1 ? undefined : lines.slice(start);
1301
+ };
1302
+ var vitest = (lines) => {
1303
+ const start = lines.findIndex((line) => VITEST_FAIL_LINE.test(line));
1304
+ return start === -1 ? undefined : lines.slice(start);
1305
+ };
1306
+ var playwright = (lines) => {
1307
+ const start = lines.findIndex((line) => PLAYWRIGHT_FAIL_LINE.test(line));
1308
+ return start === -1 ? undefined : lines.slice(start);
1309
+ };
1310
+ var phpCsFixer = (lines) => {
1311
+ const files = lines.filter((line) => CS_FIXER_LINE.test(line) || CS_FIXER_TOTAL.test(line));
1312
+ return files.some((line) => CS_FIXER_LINE.test(line)) ? files : undefined;
1313
+ };
1314
+ var PARSERS = [bunTest, bunCheck, tsc, eslint, vitest, playwright, phpCsFixer, phpstan, php];
1315
+ function squeeze(lines) {
1316
+ const out = [];
1317
+ for (const line of lines.map((text) => text.trimEnd())) {
1318
+ if (line !== "" || out.at(-1) !== "")
1319
+ out.push(line);
1320
+ }
1321
+ while (out.at(-1) === "")
1322
+ out.pop();
1323
+ return out;
1324
+ }
1325
+ function cut(shown) {
1326
+ return shown.length > MAX_LINES ? [...shown.slice(0, MAX_LINES), `... ${shown.length - MAX_LINES} more lines`].join(`
1327
+ `) : shown.join(`
1328
+ `);
1329
+ }
1330
+ function recognised(lines, parsers) {
1331
+ return parsers.map((parser) => parser(lines)).find((result) => result !== undefined && result.some((line) => line.trim() !== ""));
1332
+ }
1333
+ function failureExcerpt(output) {
1334
+ const lines = stripAnsi(output).split(`
1335
+ `);
1336
+ if (BASH_ECHO.test(lines[0] ?? ""))
1337
+ lines.shift();
1338
+ return cut(squeeze(recognised(lines, PARSERS) ?? lines.slice(-TAIL)));
1339
+ }
1340
+ var LOG_PATTERNS = { BASH_ECHO, DURATION: DURATION2, BOUNDARY, BUN_TEST_SUMMARY, BUN_CHECK_SUMMARY, TSC_CONTINUATION, TSC_FRAME, TSC_SUMMARY, ESLINT_PROBLEM, ESLINT_SUMMARY };
1154
1341
  // ../kit/src/folders.ts
1342
+ import { homedir as homedir5 } from "os";
1343
+ import { join as join7 } from "path";
1344
+ import process17 from "process";
1155
1345
  var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1156
1346
  function ignoredFolders(extra = [], where = {}) {
1157
1347
  const configured = readUserConfig("config", where).ignore;
1158
1348
  const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
1159
1349
  return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
1160
1350
  }
1351
+ function cacheFolder({ home = homedir5(), env = process17.env } = {}) {
1352
+ return env.XDG_CACHE_HOME ?? join7(home, ".cache");
1353
+ }
1161
1354
  // ../kit/src/secrets.ts
1162
1355
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1163
1356
  // ../kit/src/sessions.ts
@@ -1165,21 +1358,133 @@ var {Glob } = globalThis.Bun;
1165
1358
  var SESSION_FILES = new Glob("*.json");
1166
1359
  var ACCOUNT_DIRS = new Glob("*/sessions");
1167
1360
  // package.json
1168
- var version = "0.18.2";
1361
+ var version = "0.20.0";
1169
1362
 
1170
1363
  // src/j.ts
1171
- import process22 from "process";
1364
+ import process25 from "process";
1172
1365
 
1173
1366
  // ../kit/src/picker.ts
1174
1367
  import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
1175
- import { homedir as homedir5 } from "os";
1176
- import { dirname as dirname4, join as join7 } from "path";
1177
- import process19 from "process";
1368
+ import { dirname as dirname4, join as join8 } from "path";
1369
+ import process22 from "process";
1370
+
1371
+ // ../kit/src/picker/line.ts
1372
+ var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
1373
+ var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
1374
+ var FORWARD_KILLS = new Set(["killnext", "killend"]);
1375
+ function isEditKey(key) {
1376
+ return EDIT_KEYS.has(key);
1377
+ }
1378
+ function endsKills(key) {
1379
+ return typeof key !== "object" && !isEditKey(key);
1380
+ }
1381
+ var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
1382
+ var SPACE = /\s/;
1383
+ function isWord(char) {
1384
+ return char !== undefined && WORD_CHARACTER.test(char);
1385
+ }
1386
+ function wordStart(chars, from) {
1387
+ let at = from;
1388
+ while (at > 0 && !isWord(chars[at - 1]))
1389
+ at--;
1390
+ while (at > 0 && isWord(chars[at - 1]))
1391
+ at--;
1392
+ return at;
1393
+ }
1394
+ function wordEnd(chars, from) {
1395
+ let at = from;
1396
+ while (at < chars.length && !isWord(chars[at]))
1397
+ at++;
1398
+ while (at < chars.length && isWord(chars[at]))
1399
+ at++;
1400
+ return at;
1401
+ }
1402
+ function spacedStart(chars, from) {
1403
+ let at = from;
1404
+ while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
1405
+ at--;
1406
+ while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
1407
+ at--;
1408
+ return at;
1409
+ }
1410
+ function cut2(chars, from, to) {
1411
+ return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
1412
+ }
1413
+ function insert(chars, at, text) {
1414
+ const typed = [...text];
1415
+ return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
1416
+ }
1417
+ function editLine(line, key) {
1418
+ const { killed = "", chained = false } = line;
1419
+ const chars = [...line.text];
1420
+ const at = Math.min(Math.max(line.caret, 0), chars.length);
1421
+ const edited = edit(chars, at, key, killed);
1422
+ if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
1423
+ return line.killed === undefined ? edited : { ...edited, killed };
1424
+ const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
1425
+ if (taken === "")
1426
+ return { ...edited, killed, chained };
1427
+ if (!chained)
1428
+ return { ...edited, killed: taken, chained: true };
1429
+ return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
1430
+ }
1431
+ function edit(chars, at, key, killed) {
1432
+ const text = chars.join("");
1433
+ if (typeof key === "object")
1434
+ return insert(chars, at, key.text);
1435
+ switch (key) {
1436
+ case "left":
1437
+ return { text, caret: Math.max(at - 1, 0) };
1438
+ case "right":
1439
+ return { text, caret: Math.min(at + 1, chars.length) };
1440
+ case "wordleft":
1441
+ return { text, caret: wordStart(chars, at) };
1442
+ case "wordright":
1443
+ return { text, caret: wordEnd(chars, at) };
1444
+ case "linestart":
1445
+ return { text, caret: 0 };
1446
+ case "lineend":
1447
+ return { text, caret: chars.length };
1448
+ case "erase":
1449
+ return cut2(chars, Math.max(at - 1, 0), at);
1450
+ case "delete":
1451
+ return cut2(chars, at, Math.min(at + 1, chars.length));
1452
+ case "word":
1453
+ return cut2(chars, spacedStart(chars, at), at);
1454
+ case "killword":
1455
+ return cut2(chars, wordStart(chars, at), at);
1456
+ case "killnext":
1457
+ return cut2(chars, at, wordEnd(chars, at));
1458
+ case "clear":
1459
+ return cut2(chars, 0, at);
1460
+ case "killend":
1461
+ return cut2(chars, at, chars.length);
1462
+ case "yank":
1463
+ return insert(chars, at, killed);
1464
+ }
1465
+ }
1466
+ function visible({ text, caret }, room) {
1467
+ const chars = [...text];
1468
+ const at = Math.min(Math.max(caret, 0), chars.length);
1469
+ const cells = at === chars.length ? [...chars, " "] : chars;
1470
+ const widths = cells.map((char) => Bun.stringWidth(char));
1471
+ const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
1472
+ const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
1473
+ let start = at;
1474
+ let end = at + 1;
1475
+ while (start > 0 && fits(start - 1, end))
1476
+ start--;
1477
+ while (end < cells.length && fits(start, end + 1))
1478
+ end++;
1479
+ const left = start > 0 ? "\u2026" : "";
1480
+ const right = end < cells.length ? "\u2026" : "";
1481
+ return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
1482
+ }
1178
1483
 
1179
1484
  // ../kit/src/picker/score.ts
1180
1485
  var MATCH = 16;
1181
1486
  var CONSECUTIVE = 12;
1182
- var BOUNDARY = 10;
1487
+ var BOUNDARY2 = 10;
1183
1488
  var PREFIX = 8;
1184
1489
  var GAP = 1;
1185
1490
  var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
@@ -1216,7 +1521,7 @@ function fuzzy(query, text) {
1216
1521
  }
1217
1522
  if (haystack[i] !== needle[j])
1218
1523
  continue;
1219
- const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
1524
+ const here = MATCH + (startsWord(text, i) ? BOUNDARY2 : 0) + (i === 0 ? PREFIX : 0);
1220
1525
  if (j === 0) {
1221
1526
  best[0][i] = here - i * GAP;
1222
1527
  continue;
@@ -1260,7 +1565,6 @@ function rank(query, lines) {
1260
1565
  }
1261
1566
 
1262
1567
  // ../kit/src/picker/state.ts
1263
- var ANSI2 = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
1264
1568
  var CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
1265
1569
  var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
1266
1570
  var SGR = /^\x1B\[[0-9;]*m$/;
@@ -1268,7 +1572,6 @@ var RESET = /^\x1B\[0?m$/;
1268
1572
  var COLUMN_GAP = 2;
1269
1573
  var PASTE_START = "\x1B[200~";
1270
1574
  var PASTE_END = "\x1B[201~";
1271
- var LAST_WORD = /\S*\s*$/;
1272
1575
  var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
1273
1576
  var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
1274
1577
  var WHEEL_LINES = 3;
@@ -1291,10 +1594,29 @@ var KEYS = {
1291
1594
  "\n": "enter",
1292
1595
  "\x03": "cancel",
1293
1596
  "\x1B": "cancel",
1597
+ "\x1B[D": "left",
1598
+ "\x1BOD": "left",
1599
+ "\x1B[C": "right",
1600
+ "\x1BOC": "right",
1601
+ "\x1B[1;5D": "wordleft",
1602
+ "\x1B[1;3D": "wordleft",
1603
+ "\x1Bb": "wordleft",
1604
+ "\x1B[1;5C": "wordright",
1605
+ "\x1B[1;3C": "wordright",
1606
+ "\x1Bf": "wordright",
1607
+ "\x01": "linestart",
1608
+ "\x05": "lineend",
1294
1609
  "\x7F": "erase",
1295
- "\b": "erase",
1610
+ "\x1B[3~": "delete",
1611
+ "\b": "killword",
1612
+ "\x1B\x7F": "killword",
1613
+ "\x1B[3;5~": "killnext",
1614
+ "\x1Bd": "killnext",
1296
1615
  "\x15": "clear",
1616
+ "\v": "killend",
1297
1617
  "\x17": "word",
1618
+ "\x19": "yank",
1619
+ "\x1A": "suspend",
1298
1620
  "\t": "tab",
1299
1621
  "\x1F": "help",
1300
1622
  "\x1BOP": "help",
@@ -1316,7 +1638,7 @@ function styled(line) {
1316
1638
  colored ||= active !== "" && flat !== "";
1317
1639
  styles.push(...repeat(active, flat.length));
1318
1640
  }
1319
- for (const found of line.matchAll(ANSI2)) {
1641
+ for (const found of line.matchAll(ANSI)) {
1320
1642
  add(line.slice(last, found.index));
1321
1643
  last = found.index + found[0].length;
1322
1644
  if (SGR.test(found[0]))
@@ -1328,7 +1650,7 @@ function styled(line) {
1328
1650
  function lay(rows, searched) {
1329
1651
  const parsed = rows.map((row) => row.cells.map(styled));
1330
1652
  const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
1331
- return parsed.map((cells) => {
1653
+ return parsed.map((cells, at) => {
1332
1654
  let text = "";
1333
1655
  const styles = [];
1334
1656
  let colored = false;
@@ -1347,7 +1669,7 @@ function lay(rows, searched) {
1347
1669
  styles.push(...repeat("", pad));
1348
1670
  }
1349
1671
  }
1350
- return { text, styles: colored ? styles : undefined, searchable: text.slice(0, searchEnd) };
1672
+ return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
1351
1673
  });
1352
1674
  }
1353
1675
  function parseKeys(input, paste = { active: false }, ctrls = []) {
@@ -1371,7 +1693,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
1371
1693
  });
1372
1694
  }
1373
1695
  function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
1374
- const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
1696
+ const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
1375
1697
  return withRows(state, rows);
1376
1698
  }
1377
1699
  function withRows(state, rows, header = state.header) {
@@ -1381,8 +1703,9 @@ function withRows(state, rows, header = state.header) {
1381
1703
  const matches = rank(state.query, searchable);
1382
1704
  return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
1383
1705
  }
1384
- function withQuery(state, query) {
1385
- return { ...state, query, matches: rank(query, state.searchable), cursor: 0 };
1706
+ function withQuery(state, key) {
1707
+ const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
1708
+ return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
1386
1709
  }
1387
1710
  function move(state, by) {
1388
1711
  return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
@@ -1393,13 +1716,17 @@ function highlighted(state) {
1393
1716
  function press(state, key) {
1394
1717
  if (state.done !== undefined)
1395
1718
  return state;
1719
+ if (state.chained && endsKills(key))
1720
+ state = { ...state, chained: false };
1396
1721
  if (state.help)
1397
1722
  return { ...state, help: false };
1398
1723
  if (typeof key === "object") {
1399
1724
  if ("text" in key)
1400
- return withQuery(state, state.query + key.text);
1725
+ return withQuery(state, key);
1401
1726
  return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
1402
1727
  }
1728
+ if (isEditKey(key))
1729
+ return withQuery(state, key);
1403
1730
  switch (key) {
1404
1731
  case "up":
1405
1732
  return move(state, -1);
@@ -1417,12 +1744,8 @@ function press(state, key) {
1417
1744
  return { ...state, done: "cancel" };
1418
1745
  case "help":
1419
1746
  return { ...state, help: true };
1420
- case "erase":
1421
- return withQuery(state, [...state.query].slice(0, -1).join(""));
1422
- case "clear":
1423
- return withQuery(state, "");
1424
- case "word":
1425
- return withQuery(state, state.query.replace(LAST_WORD, ""));
1747
+ case "suspend":
1748
+ return state;
1426
1749
  case "enter":
1427
1750
  return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
1428
1751
  case "tab": {
@@ -1445,11 +1768,28 @@ function chosen(state) {
1445
1768
 
1446
1769
  // ../kit/src/picker/terminal.ts
1447
1770
  import { openSync as openSync2 } from "fs";
1448
- import process18 from "process";
1771
+ import process21 from "process";
1449
1772
  import tty from "tty";
1450
1773
 
1774
+ // ../kit/src/job.ts
1775
+ import process19 from "process";
1776
+ function stopJob() {
1777
+ process19.kill(0, "SIGTSTP");
1778
+ }
1779
+
1780
+ // ../kit/src/redraw.ts
1781
+ var SYNC_START = "\x1B[?2026h";
1782
+ var SYNC_END = "\x1B[?2026l";
1783
+ function overwrite(lines, columns) {
1784
+ return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
1785
+ `);
1786
+ }
1787
+ function rowsTaken(lines, columns) {
1788
+ return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
1789
+ }
1790
+
1451
1791
  // ../kit/src/picker/preview.ts
1452
- import process17 from "process";
1792
+ import process20 from "process";
1453
1793
 
1454
1794
  // ../kit/src/shell.ts
1455
1795
  var SEPARATORS = new Set([`
@@ -1518,7 +1858,7 @@ async function runPreview(template, line, signal, hidden = []) {
1518
1858
  ${previewCommand(template, line, hidden)}`], { stdin: "ignore", stdout: "pipe", stderr: "ignore", detached: true });
1519
1859
  const stop = () => {
1520
1860
  try {
1521
- process17.kill(-proc.pid, "SIGKILL");
1861
+ process20.kill(-proc.pid, "SIGKILL");
1522
1862
  } catch {
1523
1863
  proc.kill();
1524
1864
  }
@@ -1593,13 +1933,20 @@ function fitStyled(line, width, plain = identity) {
1593
1933
  const { text, styles } = styled(line);
1594
1934
  return fit(text, width, plain, plain, new Set, styles);
1595
1935
  }
1596
- function caretColumn(state, layout) {
1597
- return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
1936
+ function queryShown(state, layout) {
1937
+ return visible({ text: state.query, caret: state.caret }, Math.max(1, layout.listWidth - Bun.stringWidth(state.prompt)));
1938
+ }
1939
+ function caretCell(state, layout) {
1940
+ const shown = queryShown(state, layout);
1941
+ return { column: Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + shown.column + 1), char: shown.at ?? " " };
1598
1942
  }
1599
1943
  function helpLines(state, layout, theme) {
1600
1944
  const lines = [
1601
1945
  "type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end, the wheel move",
1602
- `enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
1946
+ "left, right, ctrl-a, ctrl-e move in the query, ctrl or alt with left or right by a word",
1947
+ "ctrl-w or ctrl-backspace erase a word, ctrl-u back to the start, ctrl-k to the end, del ahead",
1948
+ "ctrl-y puts back what they erased, ctrl-z suspends to the shell",
1949
+ `enter picks${state.multi ? ", tab marks" : ""}, esc or ctrl-c cancels`,
1603
1950
  ...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
1604
1951
  ];
1605
1952
  const title = "keys, any key closes this help";
@@ -1615,7 +1962,9 @@ function listLines(state, layout, theme) {
1615
1962
  const top = Math.max(0, Math.min(state.cursor - Math.floor(rows / 2), state.matches.length - rows));
1616
1963
  const marks = (state.marked.size > 0 ? ` (${state.marked.size} marked)` : "") + (state.status === "" ? "" : ` ${state.status}`);
1617
1964
  const promptWidth = Bun.stringWidth(state.prompt);
1618
- const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
1965
+ const shown = queryShown(state, layout);
1966
+ const text = `${shown.before}${shown.at ?? ""}${shown.after}`;
1967
+ const query = { text, width: Bun.stringWidth(text) };
1619
1968
  const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
1620
1969
  const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks} ctrl-/ keys`, layout.listWidth, theme.label);
1621
1970
  const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
@@ -1648,7 +1997,8 @@ var ESCAPE_WAIT_MS = 30;
1648
1997
  var OPEN = { ctrl: "open" };
1649
1998
  var HIDE_CURSOR = "\x1B[?25l";
1650
1999
  var SHOW_CURSOR = "\x1B[?25h";
1651
- var CARET = "\x1B[7m \x1B[27m";
2000
+ var REVERSE = "\x1B[7m";
2001
+ var REVERSE_END = "\x1B[27m";
1652
2002
  var PASTE_ON = "\x1B[?2004h";
1653
2003
  var PASTE_OFF = "\x1B[?2004l";
1654
2004
  var MOUSE_ON = "\x1B[?1000h\x1B[?1006h";
@@ -1666,7 +2016,7 @@ function openTerminal() {
1666
2016
  return fail("no terminal to read keys from (/dev/tty)");
1667
2017
  }
1668
2018
  const keys = Bun.file("/dev/tty").stream().getReader();
1669
- const out = process18.stderr;
2019
+ const out = process21.stderr;
1670
2020
  let resize;
1671
2021
  async function read(onChunk) {
1672
2022
  const decoder = new TextDecoder;
@@ -1692,6 +2042,11 @@ function openTerminal() {
1692
2042
  out.on("resize", onResize);
1693
2043
  read(onChunk);
1694
2044
  },
2045
+ suspend() {
2046
+ mode.setRawMode(false);
2047
+ stopJob();
2048
+ mode.setRawMode(true);
2049
+ },
1695
2050
  close() {
1696
2051
  if (resize !== undefined)
1697
2052
  out.off("resize", resize);
@@ -1719,14 +2074,14 @@ async function select(rows, settings, terminal = openTerminal()) {
1719
2074
  if (restored)
1720
2075
  return;
1721
2076
  const layout = layoutFor({ columns: terminal.columns, rows: terminal.rows }, settings.height, settings.preview !== undefined, settings.previewPosition);
1722
- let frame = HIDE_CURSOR;
2077
+ let frame = SYNC_START + HIDE_CURSOR;
1723
2078
  if (reserved !== layout.height || clear) {
1724
2079
  frame += CLEAR_BELOW + `
1725
2080
  `.repeat(layout.height - 1) + up(layout.height - 1);
1726
2081
  reserved = layout.height;
1727
2082
  }
1728
- frame += `\r${render(state, layout, theme, preview).map((line) => `\x1B[2K${line}`).join(`
1729
- `)}${up(layout.height - 1)}\r\x1B[${caretColumn(state, layout)}G${CARET}\r`;
2083
+ const caret = caretCell(state, layout);
2084
+ frame += `\r${overwrite(render(state, layout, theme, preview), terminal.columns)}${up(layout.height - 1)}\r\x1B[${caret.column}G${REVERSE}${caret.char}${REVERSE_END}\r${SYNC_END}`;
1730
2085
  terminal.write(frame);
1731
2086
  }
1732
2087
  function pageSize() {
@@ -1768,6 +2123,14 @@ async function select(rows, settings, terminal = openTerminal()) {
1768
2123
  terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
1769
2124
  terminal.close();
1770
2125
  }
2126
+ function suspend() {
2127
+ if (terminal.suspend === undefined)
2128
+ return;
2129
+ terminal.write(`${CLEAR_BELOW}${MOUSE_OFF}${PASTE_OFF}${SHOW_CURSOR}`);
2130
+ terminal.suspend();
2131
+ terminal.write(`${PASTE_ON}${MOUSE_ON}`);
2132
+ draw(true);
2133
+ }
1771
2134
  const stop = () => {
1772
2135
  state = { ...state, done: "cancel" };
1773
2136
  finish?.();
@@ -1801,6 +2164,8 @@ async function select(rows, settings, terminal = openTerminal()) {
1801
2164
  for (let key = pending.shift();key !== undefined && state.done === undefined; key = pending.shift()) {
1802
2165
  if (key === OPEN || typeof key === "object" && "ctrl" in key && key.ctrl === reload?.key)
1803
2166
  await reloadRows();
2167
+ else if (key === "suspend")
2168
+ suspend();
1804
2169
  else
1805
2170
  state = press({ ...state, page: pageSize() }, key);
1806
2171
  }
@@ -1840,9 +2205,9 @@ async function select(rows, settings, terminal = openTerminal()) {
1840
2205
  const ended = new Promise((resolve) => {
1841
2206
  finish = resolve;
1842
2207
  });
1843
- process18.once("exit", restore);
2208
+ process21.once("exit", restore);
1844
2209
  for (const signal of SIGNALS2)
1845
- process18.once(signal, stop);
2210
+ process21.once(signal, stop);
1846
2211
  try {
1847
2212
  terminal.write(`${PASTE_ON}${MOUSE_ON}`);
1848
2213
  terminal.listen(onChunk, () => draw(true));
@@ -1855,8 +2220,8 @@ async function select(rows, settings, terminal = openTerminal()) {
1855
2220
  await ended;
1856
2221
  } finally {
1857
2222
  for (const signal of SIGNALS2)
1858
- process18.off(signal, stop);
1859
- process18.off("exit", restore);
2223
+ process21.off(signal, stop);
2224
+ process21.off("exit", restore);
1860
2225
  restore();
1861
2226
  }
1862
2227
  return state.done === "accept" ? { rows: chosen(state), key: state.key, query: state.query } : undefined;
@@ -1887,7 +2252,7 @@ function heightFor(count) {
1887
2252
  return String(Math.max(15, Math.ceil((count + 4) / 0.6)));
1888
2253
  }
1889
2254
  function historyFile(name) {
1890
- return join7(process19.env.XDG_CACHE_HOME ?? join7(homedir5(), ".cache"), name, "history.json");
2255
+ return join8(cacheFolder(), name, "history.json");
1891
2256
  }
1892
2257
  function history(name) {
1893
2258
  try {
@@ -1898,12 +2263,12 @@ function history(name) {
1898
2263
  }
1899
2264
  }
1900
2265
  function runs(name) {
1901
- return history(name)[process19.cwd()] ?? [];
2266
+ return history(name)[process22.cwd()] ?? [];
1902
2267
  }
1903
2268
  function record(name, run) {
1904
2269
  const all = history(name);
1905
2270
  const file = historyFile(name);
1906
- all[process19.cwd()] = [run, ...(all[process19.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
2271
+ all[process22.cwd()] = [run, ...(all[process22.cwd()] ?? []).filter((earlier) => earlier.id !== run.id)].slice(0, REMEMBERED);
1907
2272
  mkdirSync2(dirname4(file), { recursive: true });
1908
2273
  writeFileSync(file, JSON.stringify(all));
1909
2274
  }
@@ -1927,44 +2292,129 @@ function list(rows) {
1927
2292
  }
1928
2293
 
1929
2294
  // ../kit/src/prompt.ts
1930
- import process20 from "process";
1931
- var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
1932
- function readKeys(input, paste = { active: false }) {
1933
- return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
2295
+ import process23 from "process";
2296
+
2297
+ // ../kit/src/answers.ts
2298
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2 } from "fs";
2299
+ import { dirname as dirname5, join as join9 } from "path";
2300
+ var KEPT = 50;
2301
+ function answersFile() {
2302
+ return join9(cacheFolder(), "kaynooo-cli", "answers.json");
2303
+ }
2304
+ function stored() {
2305
+ try {
2306
+ const parsed = JSON.parse(readFileSync6(answersFile(), "utf-8"));
2307
+ if (typeof parsed !== "object" || parsed === null)
2308
+ return {};
2309
+ return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
2310
+ } catch {
2311
+ return {};
2312
+ }
1934
2313
  }
1935
- async function input2(question, { default: fallback, mask = false, validate, ...settings } = {}) {
1936
- let value = "";
2314
+ function earlierAnswers(key) {
2315
+ return stored()[key] ?? [];
2316
+ }
2317
+ function rememberAnswer(key, answer) {
2318
+ const all = stored();
2319
+ const file = answersFile();
2320
+ all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
2321
+ try {
2322
+ mkdirSync3(dirname5(file), { recursive: true });
2323
+ writeFileSync2(file, JSON.stringify(all));
2324
+ } catch {}
2325
+ }
2326
+
2327
+ // ../kit/src/prompt.ts
2328
+ var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
2329
+ var MAX_LISTED = 12;
2330
+ function readKeys(input, paste = { active: false }) {
2331
+ return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
2332
+ }
2333
+ function roomAfter(question, columns) {
2334
+ return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
2335
+ }
2336
+ function withCaret(colors, line, room, dim = false) {
2337
+ const { before, at, after } = visible(line, room);
2338
+ const tone = dim ? colors.dim : (text) => text;
2339
+ return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
2340
+ }
2341
+ function sharedStart(texts) {
2342
+ const [first = [], ...rest] = texts.map((text) => [...text]);
2343
+ let length = first.length;
2344
+ for (const chars of rest) {
2345
+ const differs = chars.findIndex((char, index) => char !== first[index]);
2346
+ length = Math.min(length, differs === -1 ? chars.length : differs);
2347
+ }
2348
+ return first.slice(0, length).join("");
2349
+ }
2350
+ function listed2(colors, found, columns) {
2351
+ const shared = sharedStart(found);
2352
+ const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
2353
+ const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
2354
+ const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
2355
+ return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
2356
+ }
2357
+ async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
2358
+ let line = { text: "", caret: 0 };
1937
2359
  let invalid;
1938
- const taken = () => value === "" ? fallback ?? "" : value;
2360
+ let completions = [];
2361
+ const remembered = history === undefined || mask ? undefined : history;
2362
+ const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
2363
+ let recalled = -1;
2364
+ let draft = line;
2365
+ const taken = () => line.text === "" ? fallback ?? "" : line.text;
1939
2366
  const shown = () => mask ? "*".repeat([...taken()].length) : taken();
1940
2367
  const accepted = await ask(question, settings, (colors, state, { columns }) => {
1941
2368
  if (state !== "asking")
1942
2369
  return [answer(colors, question, state, shown())];
1943
- const characters = [...shown()];
1944
- const room = Math.max(columns - question.length - 5, 1);
1945
- const tail = characters.length > room ? `\u2026${characters.slice(1 - room).join("")}` : shown();
1946
- const typed = value === "" ? colors.dim(tail) : tail;
1947
- return [`${colors.cyan("?")} ${question} ${typed}${colors.dim("\u2588")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`]];
2370
+ const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
2371
+ return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
1948
2372
  }, (key) => {
1949
2373
  if (key === "cancel")
1950
2374
  return "cancel";
1951
2375
  invalid = undefined;
2376
+ completions = [];
2377
+ if (line.chained === true && endsKills(key))
2378
+ line = { ...line, chained: false };
2379
+ if (key === "tab") {
2380
+ const chars = [...line.text];
2381
+ const before = chars.slice(0, line.caret).join("");
2382
+ const found = complete?.(before) ?? [];
2383
+ const filled = sharedStart(found);
2384
+ if ([...filled].length > [...before].length)
2385
+ line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
2386
+ else
2387
+ completions = found;
2388
+ return;
2389
+ }
1952
2390
  if (key === "enter") {
1953
2391
  invalid = validate?.(taken());
1954
2392
  return invalid === undefined ? "enter" : undefined;
1955
2393
  }
1956
- if (key === "erase")
1957
- value = [...value].slice(0, -1).join("");
1958
- else if (typeof key === "object")
1959
- value += key.text;
2394
+ if (key === "up" || key === "down") {
2395
+ const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
2396
+ if (recalled === -1)
2397
+ draft = line;
2398
+ recalled = to;
2399
+ const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
2400
+ line = { ...shown, killed: line.killed ?? "" };
2401
+ return;
2402
+ }
2403
+ const edit = { home: "linestart", end: "lineend" }[key] ?? key;
2404
+ if (typeof edit === "object" || isEditKey(edit))
2405
+ line = editLine(line, edit);
1960
2406
  return;
1961
2407
  });
1962
- return accepted ? taken() : undefined;
2408
+ if (!accepted)
2409
+ return;
2410
+ if (remembered !== undefined && taken() !== "")
2411
+ rememberAnswer(remembered, taken());
2412
+ return taken();
1963
2413
  }
1964
2414
  function answer(colors, question, state, picked) {
1965
2415
  return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
1966
2416
  }
1967
- async function ask(question, { hint, terminal = process20 }, render, press) {
2417
+ async function ask(question, { hint, terminal = process23 }, render, press) {
1968
2418
  const { stdin, stderr } = terminal;
1969
2419
  if (!isInteractive(terminal))
1970
2420
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
@@ -1974,12 +2424,22 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
1974
2424
  const columns = () => stderr.columns || 80;
1975
2425
  const draw = (state, last = false) => {
1976
2426
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
1977
- stderr.write(`\r\x1B[0J${frame.join(`
1978
- `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
2427
+ const rows = rowsTaken(frame, columns());
2428
+ stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
1979
2429
  current = state;
1980
2430
  };
1981
2431
  const redraw = () => draw(current);
1982
2432
  const paste = { active: false };
2433
+ const stop = terminal.stop ?? (terminal === process23 ? stopJob : undefined);
2434
+ const suspend = () => {
2435
+ if (stop === undefined)
2436
+ return;
2437
+ stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
2438
+ stdin.setRawMode(false);
2439
+ stop();
2440
+ stdin.setRawMode(true);
2441
+ stderr.write("\x1B[?25l\x1B[?2004h");
2442
+ };
1983
2443
  try {
1984
2444
  stderr.on?.("resize", redraw);
1985
2445
  stdin.setRawMode(true);
@@ -1989,6 +2449,10 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
1989
2449
  return await new Promise((resolve) => {
1990
2450
  function onData(data) {
1991
2451
  for (const key of readKeys(data.toString(), paste)) {
2452
+ if (key === "suspend") {
2453
+ suspend();
2454
+ continue;
2455
+ }
1992
2456
  const pressed = press(key);
1993
2457
  if (pressed !== undefined) {
1994
2458
  settle(pressed);
@@ -2020,15 +2484,15 @@ async function ask(question, { hint, terminal = process20 }, render, press) {
2020
2484
  }
2021
2485
 
2022
2486
  // src/job-picker.ts
2023
- import process21 from "process";
2487
+ import process24 from "process";
2024
2488
 
2025
2489
  // src/jobs.ts
2026
- import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync6 } from "fs";
2027
- import { dirname as dirname5, join as join9, resolve as resolvePath } from "path";
2490
+ import { existsSync as existsSync5, readdirSync, readFileSync as readFileSync7 } from "fs";
2491
+ import { dirname as dirname6, join as join11, resolve as resolvePath } from "path";
2028
2492
 
2029
2493
  // src/steps.ts
2030
2494
  import { readdir as readdir2 } from "fs/promises";
2031
- import { join as join8 } from "path";
2495
+ import { join as join10 } from "path";
2032
2496
  var STEP_NAMES = ["check", "typecheck", "lint", "test"];
2033
2497
  var TARGET = /^@?([\w-]+)(?:[ \t][^:=\n]*)?:(?!=)/gm;
2034
2498
  var JUSTFILES = ["justfile", "Justfile", ".justfile"];
@@ -2040,7 +2504,7 @@ var PHPSTAN_CONFIGS = ["phpstan.neon", "phpstan.neon.dist", "phpstan.dist.neon"]
2040
2504
  var PHPUNIT_CONFIGS = ["phpunit.xml", "phpunit.xml.dist", "phpunit.dist.xml"];
2041
2505
  async function readFirst(dir, files) {
2042
2506
  for (const file of files) {
2043
- const handle = Bun.file(join8(dir, file));
2507
+ const handle = Bun.file(join10(dir, file));
2044
2508
  if (await handle.exists())
2045
2509
  return { file, text: await handle.text() };
2046
2510
  }
@@ -2048,7 +2512,7 @@ async function readFirst(dir, files) {
2048
2512
  }
2049
2513
  async function read(dir, ...files) {
2050
2514
  for (const file of files) {
2051
- const handle = Bun.file(join8(dir, file));
2515
+ const handle = Bun.file(join10(dir, file));
2052
2516
  if (await handle.exists())
2053
2517
  return handle.text();
2054
2518
  }
@@ -2108,7 +2572,7 @@ async function candidates(dir, bin) {
2108
2572
  }
2109
2573
  async function firstFile(dir, names) {
2110
2574
  for (const name of names) {
2111
- if (await Bun.file(join8(dir, name)).exists())
2575
+ if (await Bun.file(join10(dir, name)).exists())
2112
2576
  return name;
2113
2577
  }
2114
2578
  return;
@@ -2136,9 +2600,9 @@ async function discoverProjects(dir) {
2136
2600
  for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
2137
2601
  if (!entry.isDirectory() || entry.name.startsWith(".") || ignored.has(entry.name))
2138
2602
  continue;
2139
- const steps = await discover(join8(dir, entry.name));
2603
+ const steps = await discover(join10(dir, entry.name));
2140
2604
  if (steps.length > 0)
2141
- projects.push({ name: entry.name, dir: join8(dir, entry.name), steps });
2605
+ projects.push({ name: entry.name, dir: join10(dir, entry.name), steps });
2142
2606
  }
2143
2607
  return projects;
2144
2608
  }
@@ -2181,12 +2645,12 @@ function list2(dir) {
2181
2645
  }
2182
2646
  }
2183
2647
  function locate(dir, here, names) {
2184
- for (let current = dir;; current = join9(current, "..")) {
2185
- const found = names.find((name) => existsSync5(join9(current, name)));
2648
+ for (let current = dir;; current = join11(current, "..")) {
2649
+ const found = names.find((name) => existsSync5(join11(current, name)));
2186
2650
  if (found !== undefined)
2187
- return join9(current, found);
2651
+ return join11(current, found);
2188
2652
  const absolute = resolvePath(current);
2189
- if (!here || existsSync5(join9(current, ".git")) || dirname5(absolute) === absolute)
2653
+ if (!here || existsSync5(join11(current, ".git")) || dirname6(absolute) === absolute)
2190
2654
  return;
2191
2655
  }
2192
2656
  }
@@ -2216,7 +2680,7 @@ function justFlags(dir, here) {
2216
2680
  if (here)
2217
2681
  return [];
2218
2682
  const file = list2(dir).find((name) => JUSTFILE.test(name));
2219
- return file === undefined ? undefined : ["--justfile", join9(dir, file)];
2683
+ return file === undefined ? undefined : ["--justfile", join11(dir, file)];
2220
2684
  }
2221
2685
  function just(dir, here) {
2222
2686
  const flags = justFlags(dir, here);
@@ -2276,10 +2740,10 @@ function show(source, target) {
2276
2740
  `).trimEnd();
2277
2741
  }
2278
2742
  function make(dir) {
2279
- const file = MAKEFILES.find((name) => existsSync5(join9(dir, name)));
2743
+ const file = MAKEFILES.find((name) => existsSync5(join11(dir, name)));
2280
2744
  if (file === undefined)
2281
2745
  return [];
2282
- const source = readFileSync6(join9(dir, file), "utf-8");
2746
+ const source = readFileSync7(join11(dir, file), "utf-8");
2283
2747
  return build({ kind: "make", tag: "make", runner: ["make"], separated: false, dir }, targets2(source).map((target) => ({ ...target, body: show(source, target.name) })));
2284
2748
  }
2285
2749
  function manager(dir, manifest) {
@@ -2287,11 +2751,11 @@ function manager(dir, manifest) {
2287
2751
  const known = LOCKFILES.find(([, name]) => name === declared);
2288
2752
  if (known !== undefined)
2289
2753
  return known[1];
2290
- for (let current = resolvePath(dir);; current = dirname5(current)) {
2291
- const found = LOCKFILES.find(([file]) => existsSync5(join9(current, file)));
2754
+ for (let current = resolvePath(dir);; current = dirname6(current)) {
2755
+ const found = LOCKFILES.find(([file]) => existsSync5(join11(current, file)));
2292
2756
  if (found !== undefined)
2293
2757
  return found[1];
2294
- if (dirname5(current) === current)
2758
+ if (dirname6(current) === current)
2295
2759
  return "bun";
2296
2760
  }
2297
2761
  }
@@ -2302,38 +2766,38 @@ function packageScripts(dir, here) {
2302
2766
  const file = locate(dir, here, ["package.json"]);
2303
2767
  if (file === undefined)
2304
2768
  return [];
2305
- const manifest = JSON.parse(readFileSync6(file, "utf-8"));
2306
- const tool = manager(dirname5(file), manifest);
2769
+ const manifest = JSON.parse(readFileSync7(file, "utf-8"));
2770
+ const tool = manager(dirname6(file), manifest);
2307
2771
  const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, body: text2(command) }));
2308
- return build({ kind: "package", tag: tool, runner: [tool, "run"], separated: tool === "npm", dir: dirname5(file) }, items);
2772
+ return build({ kind: "package", tag: tool, runner: [tool, "run"], separated: tool === "npm", dir: dirname6(file) }, items);
2309
2773
  }
2310
2774
  function composer(dir, here) {
2311
2775
  const file = locate(dir, here, ["composer.json"]);
2312
2776
  if (file === undefined)
2313
2777
  return [];
2314
- const manifest = JSON.parse(readFileSync6(file, "utf-8"));
2778
+ const manifest = JSON.parse(readFileSync7(file, "utf-8"));
2315
2779
  const descriptions = table2(manifest["scripts-descriptions"]);
2316
2780
  const items = Object.entries(table2(manifest.scripts)).map(([name, command]) => ({ name, doc: field(descriptions, name), body: text2(command) }));
2317
- return build({ kind: "composer", tag: "composer", runner: ["composer", "run"], separated: true, dir: dirname5(file) }, items);
2781
+ return build({ kind: "composer", tag: "composer", runner: ["composer", "run"], separated: true, dir: dirname6(file) }, items);
2318
2782
  }
2319
2783
  function deno(dir, here) {
2320
2784
  const file = locate(dir, here, ["deno.json", "deno.jsonc"]);
2321
2785
  if (file === undefined)
2322
2786
  return [];
2323
- const manifest = Bun.JSONC.parse(readFileSync6(file, "utf-8"));
2787
+ const manifest = Bun.JSONC.parse(readFileSync7(file, "utf-8"));
2324
2788
  const items = Object.entries(table2(manifest.tasks)).map(([name, task]) => ({ name, doc: field(task, "description"), body: field(task, "command") ?? text2(task) }));
2325
- return build({ kind: "deno", tag: "deno", runner: ["deno", "task"], separated: false, dir: dirname5(file) }, items);
2789
+ return build({ kind: "deno", tag: "deno", runner: ["deno", "task"], separated: false, dir: dirname6(file) }, items);
2326
2790
  }
2327
2791
  function taskfile(dir, here) {
2328
2792
  const file = locate(dir, here, TASKFILES);
2329
2793
  if (file === undefined)
2330
2794
  return [];
2331
- const tasks = table2(Bun.YAML.parse(readFileSync6(file, "utf-8"))?.tasks);
2795
+ const tasks = table2(Bun.YAML.parse(readFileSync7(file, "utf-8"))?.tasks);
2332
2796
  const items = Object.entries(tasks).filter(([, task]) => !(task !== null && typeof task === "object" && task.internal === true)).map(([name, task]) => ({ name, doc: field(task, "desc") ?? field(task, "summary"), body: text2(task) }));
2333
- return build({ kind: "task", tag: "task", runner: ["task"], separated: true, dir: dirname5(file) }, items);
2797
+ return build({ kind: "task", tag: "task", runner: ["task"], separated: true, dir: dirname6(file) }, items);
2334
2798
  }
2335
2799
  function mise(dir, here) {
2336
- if (!has("mise") || !here && !MISE_FILES.some((name) => existsSync5(join9(dir, name))))
2800
+ if (!has("mise") || !here && !MISE_FILES.some((name) => existsSync5(join11(dir, name))))
2337
2801
  return [];
2338
2802
  const proc = Bun.spawnSync(["mise", "tasks", "ls", "--json"], { cwd: dir, stderr: "pipe" });
2339
2803
  if (!proc.success)
@@ -2347,15 +2811,15 @@ function pyproject(dir, here) {
2347
2811
  const file = locate(dir, here, ["pyproject.toml"]);
2348
2812
  if (file === undefined)
2349
2813
  return [];
2350
- const manifest = Bun.TOML.parse(readFileSync6(file, "utf-8"));
2814
+ const manifest = Bun.TOML.parse(readFileSync7(file, "utf-8"));
2351
2815
  const tool = table2(manifest.tool);
2352
2816
  const project = table2(manifest.project);
2353
- const uv = locate(dirname5(file), true, ["uv.lock"]) !== undefined;
2817
+ const uv = locate(dirname6(file), true, ["uv.lock"]) !== undefined;
2354
2818
  const poe = Object.entries(table2(table2(tool.poe).tasks)).filter(([name]) => !name.startsWith("_")).map(([name, task]) => ({ name, doc: field(task, "help"), body: field(task, "cmd") ?? field(task, "shell") ?? text2(task) }));
2355
2819
  const entryPoints = Object.entries(table2(project.scripts)).map(([name, target]) => ({ name, body: text2(target) }));
2356
2820
  return [
2357
- ...build({ kind: "poe", tag: "poe", runner: uv ? ["uv", "run", "poe"] : ["poe"], separated: false, dir: dirname5(file) }, poe),
2358
- ...build({ kind: "uv", tag: "uv", runner: ["uv", "run"], separated: false, dir: dirname5(file) }, entryPoints)
2821
+ ...build({ kind: "poe", tag: "poe", runner: uv ? ["uv", "run", "poe"] : ["poe"], separated: false, dir: dirname6(file) }, poe),
2822
+ ...build({ kind: "uv", tag: "uv", runner: ["uv", "run"], separated: false, dir: dirname6(file) }, entryPoints)
2359
2823
  ];
2360
2824
  }
2361
2825
  var READERS = [just, make, packageScripts, composer, deno, taskfile, mise, pyproject];
@@ -2379,12 +2843,12 @@ function readOr(read, fallback) {
2379
2843
  }
2380
2844
  }
2381
2845
  function workspaces() {
2382
- const manifest = readOr(() => JSON.parse(readFileSync6("package.json", "utf-8")), {});
2846
+ const manifest = readOr(() => JSON.parse(readFileSync7("package.json", "utf-8")), {});
2383
2847
  const declared = Array.isArray(manifest.workspaces) ? manifest.workspaces : table2(manifest.workspaces).packages;
2384
- const pnpm = readOr(() => table2(Bun.YAML.parse(readFileSync6("pnpm-workspace.yaml", "utf-8"))).packages, undefined);
2848
+ const pnpm = readOr(() => table2(Bun.YAML.parse(readFileSync7("pnpm-workspace.yaml", "utf-8"))).packages, undefined);
2385
2849
  const patterns = [declared, pnpm].flatMap((value) => Array.isArray(value) ? value.filter((pattern) => typeof pattern === "string") : []);
2386
2850
  const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => new Bun.Glob(pattern.slice(1)));
2387
- return patterns.filter((pattern) => !pattern.startsWith("!")).flatMap((pattern) => [...new Bun.Glob(`${pattern.replace(TRAILING_SLASHES, "")}/package.json`).scanSync({ cwd: "." })].map((file) => dirname5(file))).filter((dir) => !dir.split("/").includes("node_modules") && !excluded.some((glob) => glob.match(dir)));
2851
+ return patterns.filter((pattern) => !pattern.startsWith("!")).flatMap((pattern) => [...new Bun.Glob(`${pattern.replace(TRAILING_SLASHES, "")}/package.json`).scanSync({ cwd: "." })].map((file) => dirname6(file))).filter((dir) => !dir.split("/").includes("node_modules") && !excluded.some((glob) => glob.match(dir)));
2388
2852
  }
2389
2853
  function folders2() {
2390
2854
  return [...new Set([...children(), ...workspaces()])].filter((dir) => dir !== ".");
@@ -2394,7 +2858,7 @@ function guarded(reader, dir, here, isWarned = false) {
2394
2858
  return reader(dir, here);
2395
2859
  } catch (error) {
2396
2860
  if (isWarned)
2397
- warn(`j: skipped ${join9(dir, MANIFEST_OF.get(reader) ?? "a manifest")}, it does not parse (${error instanceof Error ? error.message : String(error)})`);
2861
+ warn(`j: skipped ${join11(dir, MANIFEST_OF.get(reader) ?? "a manifest")}, it does not parse (${error instanceof Error ? error.message : String(error)})`);
2398
2862
  return [];
2399
2863
  }
2400
2864
  }
@@ -2440,7 +2904,7 @@ function labelled(entries) {
2440
2904
  return new Set(entries.map((entry) => entry.tag)).size > 1;
2441
2905
  }
2442
2906
  function row(entry, labels, signed) {
2443
- const colors = paint(process21.stderr);
2907
+ const colors = paint(process24.stderr);
2444
2908
  const keyed = entry.dir === "." ? entry.name : `${colors.dim(`${entry.dir}/`)}${entry.name}`;
2445
2909
  return {
2446
2910
  hidden: [entry.kind, entry.dir, entry.name, id(entry)],
@@ -2454,7 +2918,7 @@ async function pickJob(entries, narrowed = false) {
2454
2918
  prompt: `${[...new Set(entries.map((entry) => entry.tag))].join("/")}> `,
2455
2919
  searched: labels ? 2 : 1,
2456
2920
  ...narrowed ? { height: heightFor(entries.length) } : {},
2457
- preview: `${process21.execPath} ${process21.argv[1]} --show {1} {2} {3}`
2921
+ preview: `${process24.execPath} ${process24.argv[1]} --show {1} {2} {3}`
2458
2922
  });
2459
2923
  return entries.find((candidate) => id(candidate) === picked?.hidden[3]);
2460
2924
  }
@@ -2466,9 +2930,8 @@ j -
2466
2930
  Without a name, picks a recipe, target, script or task of this folder, its parents and its child folders when a terminal is attached, and runs it. The ones run last come first, per folder. Without a terminal it lists them instead.
2467
2931
  \`j -\` runs the last one again with the same arguments, \`j <name> [args...]\` runs without the picker, the words after the name filling the parameters in order and the required ones left being asked for.
2468
2932
  The sources are a Justfile, a Makefile, the scripts of a package.json (through its package manager), composer.json scripts, deno tasks, a Taskfile, mise tasks and a pyproject (poe tasks and entry points).
2469
- A name is the key behind the folder it runs from, \`api/test\`, bare for this folder. A name several entries share offers them, unless it comes qualified by its runner: \`just:check\`, \`bun:api/test\`.
2470
-
2471
- Exits with the code of the command it ran, 1 when there is nothing to run here or nothing by that name.`;
2933
+ A name is the key behind the folder it runs from, \`api/test\`, bare for this folder. A name several entries share offers them, unless it comes qualified by its runner: \`just:check\`, \`bun:api/test\`.`;
2934
+ var EXITS = [["its own", "the code of the command it ran"], [1, "there is nothing to run here or nothing by that name"]];
2472
2935
  var options = {
2473
2936
  json: jsonOption("[{ id, key, runner, dir, name, doc, parameters }]")
2474
2937
  };
@@ -2476,7 +2939,7 @@ function preview(kind, dir, name) {
2476
2939
  const entry = readKind(kind, dir).find((candidate) => candidate.name === name);
2477
2940
  if (entry === undefined)
2478
2941
  return;
2479
- const colors = paint(process22.stdout);
2942
+ const colors = paint(process25.stdout);
2480
2943
  console.log(`${colors.dim(`$ ${dir === "." ? "" : `env -C ${dir} `}`)}${colors.bold([...entry.runner, entry.name].join(" "))}
2481
2944
  `);
2482
2945
  if (entry.body !== undefined)
@@ -2498,7 +2961,7 @@ function completions() {
2498
2961
  return [];
2499
2962
  }
2500
2963
  }
2501
- function listed2(found) {
2964
+ function listed3(found) {
2502
2965
  const labels = labelled(found);
2503
2966
  return byRecency(found, runs("j"), id).map((entry) => ({
2504
2967
  label: [labels ? entry.tag : "", key(entry), signature(entry)].filter(Boolean).join(" "),
@@ -2509,7 +2972,7 @@ function listed2(found) {
2509
2972
  }));
2510
2973
  }
2511
2974
  function listing(found) {
2512
- const colors = paint(process22.stdout);
2975
+ const colors = paint(process25.stdout);
2513
2976
  const labels = labelled(found);
2514
2977
  return table(found.map((entry) => [...labels ? [entry.tag] : [], key(entry), signature(entry), colors.dim(entry.doc ?? "")]));
2515
2978
  }
@@ -2536,7 +2999,7 @@ async function j2(argv) {
2536
2999
  if (found.length === 0)
2537
3000
  fail("nothing to run here: no recipe, target, script or task", 1);
2538
3001
  if (flag === "--list")
2539
- list(listed2(found));
3002
+ list(listed3(found));
2540
3003
  else
2541
3004
  console.log(names(found).map(([name, description]) => `${name} ${description}`).join(`
2542
3005
  `));
@@ -2546,6 +3009,7 @@ async function j2(argv) {
2546
3009
  const args = emitting ? argv.slice(1) : argv;
2547
3010
  const last = args[0] === "-";
2548
3011
  const parsed = last ? { values: {}, positionals: ["-"], rest: args.slice(1) } : parse(args, usage2, options, {
3012
+ exits: EXITS,
2549
3013
  positionals: ["[name]"],
2550
3014
  candidates: { "[name]": completions },
2551
3015
  trailing: true,
@@ -2598,7 +3062,7 @@ async function j2(argv) {
2598
3062
  }
2599
3063
  const answers = [];
2600
3064
  for (const ask of asks) {
2601
- const answer = await input2(ask);
3065
+ const answer = await input2(ask, { history: `j ${id(entry)} ${ask}` });
2602
3066
  if (answer === undefined)
2603
3067
  return 1;
2604
3068
  answers.push(answer);
@@ -2609,4 +3073,4 @@ async function j2(argv) {
2609
3073
  }
2610
3074
 
2611
3075
  // src/j-cli.ts
2612
- process23.exitCode = await runMain({ name: "j", version, run: j2 });
3076
+ process26.exitCode = await runMain({ name: "j", version, run: j2 });