@kaynooo/cli-wait 0.10.1 → 0.11.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/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  // src/cli.ts
5
5
  import { existsSync as existsSync6 } from "fs";
6
- import process18 from "process";
6
+ import process19 from "process";
7
7
  // ../kit/src/args.ts
8
8
  import process9 from "process";
9
9
  import { parseArgs } from "util";
@@ -782,12 +782,36 @@ function nearestOption(message, options, allowNegative) {
782
782
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
783
783
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
784
784
  }
785
+ // ../kit/src/argv.ts
786
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
787
+ import { resolve as resolve3 } from "path";
788
+ import process10 from "process";
789
+ function commandLine() {
790
+ try {
791
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
792
+ } catch {
793
+ return;
794
+ }
795
+ }
796
+ function realPath(word) {
797
+ try {
798
+ return realpathSync(resolve3(word));
799
+ } catch {
800
+ return;
801
+ }
802
+ }
803
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
804
+ const target = script === undefined ? undefined : realPath(script) ?? script;
805
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
806
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
807
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
808
+ }
785
809
  // ../kit/src/progress.ts
786
- import process11 from "process";
810
+ import process12 from "process";
787
811
 
788
812
  // ../kit/src/process.ts
789
813
  import { constants } from "os";
790
- import process10 from "process";
814
+ import process11 from "process";
791
815
  var KILL_GRACE_MS = 2000;
792
816
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
793
817
  function exitCodeOf(code, signal) {
@@ -809,7 +833,7 @@ function holdSignals(cleanup) {
809
833
  },
810
834
  release: () => {
811
835
  for (const signal of SIGNALS)
812
- process10.off(signal, onSignal);
836
+ process11.off(signal, onSignal);
813
837
  }
814
838
  };
815
839
  function onSignal(signal) {
@@ -822,10 +846,10 @@ function holdSignals(cleanup) {
822
846
  return;
823
847
  held.release();
824
848
  cleanup(signal);
825
- process10.kill(process10.pid, signal);
849
+ process11.kill(process11.pid, signal);
826
850
  }
827
851
  for (const signal of SIGNALS)
828
- process10.on(signal, onSignal);
852
+ process11.on(signal, onSignal);
829
853
  return held;
830
854
  }
831
855
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -839,7 +863,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
839
863
  return;
840
864
  try {
841
865
  if (grouped)
842
- process10.kill(-proc.pid, killing);
866
+ process11.kill(-proc.pid, killing);
843
867
  else
844
868
  proc.kill(killing);
845
869
  } catch {}
@@ -917,7 +941,7 @@ var RESET_STYLE = `${ESC}[0m`;
917
941
  var CTRL_C = 3;
918
942
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
919
943
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
920
- function liveRegion(render, stream = process11.stderr, env = process11.env) {
944
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
921
945
  if (!takesControlCodes(stream, env))
922
946
  return { redraw: () => {
923
947
  return;
@@ -964,11 +988,11 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
964
988
  clear();
965
989
  restore();
966
990
  release();
967
- process11.off("exit", onExit);
991
+ process12.off("exit", onExit);
968
992
  signals.release();
969
993
  }
970
994
  timer.unref();
971
- process11.on("exit", onExit);
995
+ process12.on("exit", onExit);
972
996
  return {
973
997
  redraw: draw,
974
998
  print: (text) => {
@@ -1007,14 +1031,14 @@ function cutToWidth(line, width) {
1007
1031
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1008
1032
  }
1009
1033
  function swallowInput() {
1010
- const input = process11.stdin;
1034
+ const input = process12.stdin;
1011
1035
  if (!input.isTTY)
1012
1036
  return () => {
1013
1037
  return;
1014
1038
  };
1015
1039
  const onData = (data) => {
1016
1040
  if (data.includes(CTRL_C))
1017
- process11.kill(process11.pid, "SIGINT");
1041
+ process12.kill(process12.pid, "SIGINT");
1018
1042
  };
1019
1043
  input.setRawMode(true);
1020
1044
  input.on("data", onData);
@@ -1030,7 +1054,7 @@ function swallowInput() {
1030
1054
  };
1031
1055
  }
1032
1056
  function interceptOutput(clear) {
1033
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
1057
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1034
1058
  const wrapped = targets.map(([target, name]) => {
1035
1059
  const original = Reflect.get(target, name);
1036
1060
  const wrapper = (...args) => {
@@ -1048,33 +1072,33 @@ function interceptOutput(clear) {
1048
1072
  };
1049
1073
  }
1050
1074
  // ../kit/src/cli.ts
1051
- import { readFileSync as readFileSync3, realpathSync } from "fs";
1075
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1052
1076
  import { dirname as dirname3, join as join6 } from "path";
1053
- import process14 from "process";
1077
+ import process15 from "process";
1054
1078
 
1055
1079
  // ../kit/src/usage.ts
1056
1080
  import { appendFileSync, mkdirSync } from "fs";
1057
1081
  import { homedir as homedir4 } from "os";
1058
1082
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1059
- import process13 from "process";
1083
+ import process14 from "process";
1060
1084
 
1061
1085
  // ../kit/src/logs.ts
1062
1086
  import { lstatSync, openSync } from "fs";
1063
1087
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
1064
1088
  import { homedir as homedir3, tmpdir } from "os";
1065
1089
  import { join as join4 } from "path";
1066
- import process12 from "process";
1090
+ import process13 from "process";
1067
1091
  var DAY_MS = 24 * 60 * 60 * 1000;
1068
1092
  var CLI_FOLDER = "kaynooo-cli";
1069
1093
  function isPrivateDirectory(path) {
1070
1094
  try {
1071
1095
  const info = lstatSync(path, { throwIfNoEntry: false });
1072
- return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1096
+ return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1073
1097
  } catch {
1074
1098
  return false;
1075
1099
  }
1076
1100
  }
1077
- async function privateLogDirectory(name, env = process12.env) {
1101
+ async function privateLogDirectory(name, env = process13.env) {
1078
1102
  const runtime = env.XDG_RUNTIME_DIR;
1079
1103
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1080
1104
  const path = join4(base, name);
@@ -1094,14 +1118,14 @@ var usageError;
1094
1118
  function noteUsageError(message) {
1095
1119
  usageError = message;
1096
1120
  }
1097
- function stateHome(env = process13.env) {
1121
+ function stateHome(env = process14.env) {
1098
1122
  const dir = env.XDG_STATE_HOME;
1099
1123
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1100
1124
  }
1101
- function usagePath(env = process13.env) {
1125
+ function usagePath(env = process14.env) {
1102
1126
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1103
1127
  }
1104
- function usageRecorded(env = process13.env) {
1128
+ function usageRecorded(env = process14.env) {
1105
1129
  const off = env.KAYNOOO_CLI_NO_USAGE;
1106
1130
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1107
1131
  }
@@ -1115,7 +1139,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1115
1139
  usageError = undefined;
1116
1140
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1117
1141
  }
1118
- function recordUsage(entry, env = process13.env) {
1142
+ function recordUsage(entry, env = process14.env) {
1119
1143
  if (!usageRecorded(env))
1120
1144
  return;
1121
1145
  try {
@@ -1133,8 +1157,8 @@ var LEVEL_OPTIONS = {
1133
1157
  };
1134
1158
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1135
1159
  function printError(prefix, message, hint, cause) {
1136
- const colors = paint(process14.stderr);
1137
- const styled = takesControlCodes(process14.stderr);
1160
+ const colors = paint(process15.stderr);
1161
+ const styled = takesControlCodes(process15.stderr);
1138
1162
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1139
1163
  const under = (label, text, tint) => text === undefined ? "" : `
1140
1164
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1178,24 +1202,24 @@ function candidateLine(candidate) {
1178
1202
  }
1179
1203
  function positionalBeingTyped(before, { options, positionals }) {
1180
1204
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1181
- let index = 0;
1205
+ const typed = [];
1182
1206
  let at = 0;
1183
1207
  while (at < before.length) {
1184
1208
  const word = before[at];
1185
1209
  if (word === "--") {
1186
- index += before.length - at - 1;
1210
+ typed.push(...before.slice(at + 1));
1187
1211
  break;
1188
1212
  }
1189
1213
  if (!word.startsWith("-"))
1190
- index++;
1214
+ typed.push(word);
1191
1215
  else if (takesValue(word))
1192
1216
  at++;
1193
1217
  at++;
1194
1218
  }
1195
1219
  const last = positionals.at(-1);
1196
- if (index < positionals.length)
1197
- return positionals[index];
1198
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1220
+ if (typed.length < positionals.length)
1221
+ return { name: positionals[typed.length], typed };
1222
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1199
1223
  }
1200
1224
  async function leafCandidates(run, words) {
1201
1225
  const completing = await completingOf(run);
@@ -1203,12 +1227,12 @@ async function leafCandidates(run, words) {
1203
1227
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1204
1228
  const flag = words.at(-2);
1205
1229
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1230
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1206
1231
  if (option?.type === "string") {
1207
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1232
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1208
1233
  return values === undefined ? [FILES] : values.map(candidateLine);
1209
1234
  }
1210
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1211
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1235
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1212
1236
  return values === undefined ? [FILES] : values.map(candidateLine);
1213
1237
  }
1214
1238
  async function printCandidates(found) {
@@ -1217,9 +1241,13 @@ async function printCandidates(found) {
1217
1241
  return 0;
1218
1242
  }
1219
1243
  function packageVersion(entry = Bun.main) {
1220
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1244
+ let resolved = entry;
1245
+ try {
1246
+ resolved = realpathSync2(entry);
1247
+ } catch {}
1248
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1221
1249
  try {
1222
- const { version } = JSON.parse(readFileSync3(join6(dir, "package.json"), "utf8"));
1250
+ const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1223
1251
  if (typeof version === "string")
1224
1252
  return version;
1225
1253
  } catch {}
@@ -1227,7 +1255,7 @@ function packageVersion(entry = Bun.main) {
1227
1255
  return "0.0.0";
1228
1256
  }
1229
1257
  }
1230
- async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1258
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1231
1259
  if (argv[0] === COMPLETE)
1232
1260
  return printCandidates(leafCandidates(run, argv.slice(1)));
1233
1261
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1254,15 +1282,15 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
1254
1282
  // ../kit/src/sessions.ts
1255
1283
  import { homedir as homedir5 } from "os";
1256
1284
  import { join as join7 } from "path";
1257
- import process15 from "process";
1285
+ import process16 from "process";
1258
1286
  var {Glob } = globalThis.Bun;
1259
1287
  var SESSION_FILES = new Glob("*.json");
1260
1288
  var ACCOUNT_DIRS = new Glob("*/sessions");
1261
1289
  async function sessionDirs() {
1262
1290
  const home = homedir5();
1263
1291
  const dirs = new Set([join7(home, ".claude", "sessions")]);
1264
- if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1265
- dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
1292
+ if (process16.env.CLAUDE_CONFIG_DIR !== undefined)
1293
+ dirs.add(join7(process16.env.CLAUDE_CONFIG_DIR, "sessions"));
1266
1294
  try {
1267
1295
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1268
1296
  dirs.add(dir);
@@ -1308,7 +1336,7 @@ async function liveSessions() {
1308
1336
  }
1309
1337
  async function currentSession(sessions) {
1310
1338
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1311
- let pid = process15.ppid;
1339
+ let pid = process16.ppid;
1312
1340
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1313
1341
  const session = byPid.get(pid);
1314
1342
  if (session !== undefined)
@@ -1445,9 +1473,9 @@ async function urlCheck(url, timeout) {
1445
1473
  }
1446
1474
 
1447
1475
  // src/task.ts
1448
- import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync4, statSync as statSync3 } from "fs";
1476
+ import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
1449
1477
  import { join as join8 } from "path";
1450
- import process17 from "process";
1478
+ import process18 from "process";
1451
1479
  var EXITED = /(?:^|\n)\[exited with code (-?\d+)\]\n*$/;
1452
1480
  var FAILURE = /\(fail\)|\berror:/i;
1453
1481
  var TASK_ID = /^[\w-]+$/;
@@ -1455,9 +1483,9 @@ var TAIL_BYTES = 256;
1455
1483
  var LONGEST_FAILURES = 30;
1456
1484
  var CARRIAGE_RETURN2 = /\r$/;
1457
1485
  function tasksRoot(env) {
1458
- return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process17.getuid?.() ?? 0}`);
1486
+ return join8(env.CLAUDE_CODE_TMPDIR ?? env.TMPDIR ?? "/tmp", `claude-${process18.getuid?.() ?? 0}`);
1459
1487
  }
1460
- function taskFile(task, env = process17.env) {
1488
+ function taskFile(task, env = process18.env) {
1461
1489
  if (task.includes("/") || task.endsWith(".output"))
1462
1490
  return task;
1463
1491
  if (!TASK_ID.test(task))
@@ -1490,7 +1518,7 @@ async function taskEnd(path, lines) {
1490
1518
  }
1491
1519
  function pidAlive(pid) {
1492
1520
  try {
1493
- process17.kill(pid, 0);
1521
+ process18.kill(pid, 0);
1494
1522
  } catch (error) {
1495
1523
  return error.code === "EPERM";
1496
1524
  }
@@ -1498,7 +1526,7 @@ function pidAlive(pid) {
1498
1526
  }
1499
1527
  function isZombie(pid) {
1500
1528
  try {
1501
- const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
1529
+ const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
1502
1530
  return stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3) === "Z";
1503
1531
  } catch {
1504
1532
  return false;
@@ -1581,7 +1609,7 @@ async function waitTask(args) {
1581
1609
  const lines = wholeNumber(values.lines, "lines", 20);
1582
1610
  const timeout = duration(values.timeout, "timeout", 5 * 60000);
1583
1611
  const started = Date.now();
1584
- const { dim } = paint(process18.stderr);
1612
+ const { dim } = paint(process19.stderr);
1585
1613
  const region = values.quiet === true ? undefined : liveRegion((spinner) => [`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now() - started))}`]);
1586
1614
  let code;
1587
1615
  try {
@@ -1652,7 +1680,7 @@ ${USAGE}`);
1652
1680
  let isPidLeft = pid !== undefined;
1653
1681
  let cmdLeft = values.cmd === undefined ? undefined : "not run yet";
1654
1682
  let cmdRanAt = 0;
1655
- const { dim } = paint(process18.stderr);
1683
+ const { dim } = paint(process19.stderr);
1656
1684
  const region = values.quiet === true ? undefined : liveRegion((spinner) => {
1657
1685
  const waited = dim(formatElapsed(Date.now() - started));
1658
1686
  const left = [
@@ -1743,4 +1771,4 @@ ${numbered(event.excerpt, event.line)}`);
1743
1771
  last lines of ${watch?.path}:
1744
1772
  ${numbered(lines)}`}`);
1745
1773
  }
1746
- process18.exitCode = await runMain({ name: "waitfor", run: main });
1774
+ process19.exitCode = await runMain({ name: "waitfor", run: main });
package/dist/slot-cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // @bun
3
3
 
4
4
  // src/slot-cli.ts
5
- import process19 from "process";
5
+ import process20 from "process";
6
6
  // ../kit/src/args.ts
7
7
  import process9 from "process";
8
8
  import { parseArgs } from "util";
@@ -781,12 +781,36 @@ function nearestOption(message, options, allowNegative) {
781
781
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
782
782
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
783
783
  }
784
+ // ../kit/src/argv.ts
785
+ import { readFileSync as readFileSync3, realpathSync } from "fs";
786
+ import { resolve as resolve3 } from "path";
787
+ import process10 from "process";
788
+ function commandLine() {
789
+ try {
790
+ return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
791
+ } catch {
792
+ return;
793
+ }
794
+ }
795
+ function realPath(word) {
796
+ try {
797
+ return realpathSync(resolve3(word));
798
+ } catch {
799
+ return;
800
+ }
801
+ }
802
+ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
803
+ const target = script === undefined ? undefined : realPath(script) ?? script;
804
+ const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
805
+ const after = at === -1 ? [] : cmdline.slice(at + 1);
806
+ return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
807
+ }
784
808
  // ../kit/src/progress.ts
785
- import process11 from "process";
809
+ import process12 from "process";
786
810
 
787
811
  // ../kit/src/process.ts
788
812
  import { constants } from "os";
789
- import process10 from "process";
813
+ import process11 from "process";
790
814
  var KILL_GRACE_MS = 2000;
791
815
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
792
816
  function exitCodeOf(code, signal) {
@@ -808,7 +832,7 @@ function holdSignals(cleanup) {
808
832
  },
809
833
  release: () => {
810
834
  for (const signal of SIGNALS)
811
- process10.off(signal, onSignal);
835
+ process11.off(signal, onSignal);
812
836
  }
813
837
  };
814
838
  function onSignal(signal) {
@@ -821,10 +845,10 @@ function holdSignals(cleanup) {
821
845
  return;
822
846
  held.release();
823
847
  cleanup(signal);
824
- process10.kill(process10.pid, signal);
848
+ process11.kill(process11.pid, signal);
825
849
  }
826
850
  for (const signal of SIGNALS)
827
- process10.on(signal, onSignal);
851
+ process11.on(signal, onSignal);
828
852
  return held;
829
853
  }
830
854
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -838,7 +862,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
838
862
  return;
839
863
  try {
840
864
  if (grouped)
841
- process10.kill(-proc.pid, killing);
865
+ process11.kill(-proc.pid, killing);
842
866
  else
843
867
  proc.kill(killing);
844
868
  } catch {}
@@ -916,7 +940,7 @@ var RESET_STYLE = `${ESC}[0m`;
916
940
  var CTRL_C = 3;
917
941
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
918
942
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
919
- function liveRegion(render, stream = process11.stderr, env = process11.env) {
943
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
920
944
  if (!takesControlCodes(stream, env))
921
945
  return { redraw: () => {
922
946
  return;
@@ -963,11 +987,11 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
963
987
  clear();
964
988
  restore();
965
989
  release();
966
- process11.off("exit", onExit);
990
+ process12.off("exit", onExit);
967
991
  signals.release();
968
992
  }
969
993
  timer.unref();
970
- process11.on("exit", onExit);
994
+ process12.on("exit", onExit);
971
995
  return {
972
996
  redraw: draw,
973
997
  print: (text) => {
@@ -1006,14 +1030,14 @@ function cutToWidth(line, width) {
1006
1030
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
1007
1031
  }
1008
1032
  function swallowInput() {
1009
- const input = process11.stdin;
1033
+ const input = process12.stdin;
1010
1034
  if (!input.isTTY)
1011
1035
  return () => {
1012
1036
  return;
1013
1037
  };
1014
1038
  const onData = (data) => {
1015
1039
  if (data.includes(CTRL_C))
1016
- process11.kill(process11.pid, "SIGINT");
1040
+ process12.kill(process12.pid, "SIGINT");
1017
1041
  };
1018
1042
  input.setRawMode(true);
1019
1043
  input.on("data", onData);
@@ -1029,7 +1053,7 @@ function swallowInput() {
1029
1053
  };
1030
1054
  }
1031
1055
  function interceptOutput(clear) {
1032
- const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process11.stdout, "write"], [process11.stderr, "write"]];
1056
+ const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
1033
1057
  const wrapped = targets.map(([target, name]) => {
1034
1058
  const original = Reflect.get(target, name);
1035
1059
  const wrapper = (...args) => {
@@ -1047,33 +1071,33 @@ function interceptOutput(clear) {
1047
1071
  };
1048
1072
  }
1049
1073
  // ../kit/src/cli.ts
1050
- import { readFileSync as readFileSync3, realpathSync } from "fs";
1074
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1051
1075
  import { dirname as dirname3, join as join6 } from "path";
1052
- import process14 from "process";
1076
+ import process15 from "process";
1053
1077
 
1054
1078
  // ../kit/src/usage.ts
1055
1079
  import { appendFileSync, mkdirSync } from "fs";
1056
1080
  import { homedir as homedir4 } from "os";
1057
1081
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1058
- import process13 from "process";
1082
+ import process14 from "process";
1059
1083
 
1060
1084
  // ../kit/src/logs.ts
1061
1085
  import { lstatSync, openSync } from "fs";
1062
1086
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
1063
1087
  import { homedir as homedir3, tmpdir } from "os";
1064
1088
  import { join as join4 } from "path";
1065
- import process12 from "process";
1089
+ import process13 from "process";
1066
1090
  var DAY_MS = 24 * 60 * 60 * 1000;
1067
1091
  var CLI_FOLDER = "kaynooo-cli";
1068
1092
  function isPrivateDirectory(path) {
1069
1093
  try {
1070
1094
  const info = lstatSync(path, { throwIfNoEntry: false });
1071
- return info !== undefined && info.isDirectory() && info.uid === (process12.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1095
+ return info !== undefined && info.isDirectory() && info.uid === (process13.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
1072
1096
  } catch {
1073
1097
  return false;
1074
1098
  }
1075
1099
  }
1076
- async function privateLogDirectory(name, env = process12.env) {
1100
+ async function privateLogDirectory(name, env = process13.env) {
1077
1101
  const runtime = env.XDG_RUNTIME_DIR;
1078
1102
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1079
1103
  const path = join4(base, name);
@@ -1093,14 +1117,14 @@ var usageError;
1093
1117
  function noteUsageError(message) {
1094
1118
  usageError = message;
1095
1119
  }
1096
- function stateHome(env = process13.env) {
1120
+ function stateHome(env = process14.env) {
1097
1121
  const dir = env.XDG_STATE_HOME;
1098
1122
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1099
1123
  }
1100
- function usagePath(env = process13.env) {
1124
+ function usagePath(env = process14.env) {
1101
1125
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1102
1126
  }
1103
- function usageRecorded(env = process13.env) {
1127
+ function usageRecorded(env = process14.env) {
1104
1128
  const off = env.KAYNOOO_CLI_NO_USAGE;
1105
1129
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1106
1130
  }
@@ -1114,7 +1138,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1114
1138
  usageError = undefined;
1115
1139
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1116
1140
  }
1117
- function recordUsage(entry, env = process13.env) {
1141
+ function recordUsage(entry, env = process14.env) {
1118
1142
  if (!usageRecorded(env))
1119
1143
  return;
1120
1144
  try {
@@ -1132,8 +1156,8 @@ var LEVEL_OPTIONS = {
1132
1156
  };
1133
1157
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1134
1158
  function printError(prefix, message, hint, cause) {
1135
- const colors = paint(process14.stderr);
1136
- const styled = takesControlCodes(process14.stderr);
1159
+ const colors = paint(process15.stderr);
1160
+ const styled = takesControlCodes(process15.stderr);
1137
1161
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1138
1162
  const under = (label, text, tint) => text === undefined ? "" : `
1139
1163
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1177,24 +1201,24 @@ function candidateLine(candidate) {
1177
1201
  }
1178
1202
  function positionalBeingTyped(before, { options, positionals }) {
1179
1203
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1180
- let index = 0;
1204
+ const typed = [];
1181
1205
  let at = 0;
1182
1206
  while (at < before.length) {
1183
1207
  const word = before[at];
1184
1208
  if (word === "--") {
1185
- index += before.length - at - 1;
1209
+ typed.push(...before.slice(at + 1));
1186
1210
  break;
1187
1211
  }
1188
1212
  if (!word.startsWith("-"))
1189
- index++;
1213
+ typed.push(word);
1190
1214
  else if (takesValue(word))
1191
1215
  at++;
1192
1216
  at++;
1193
1217
  }
1194
1218
  const last = positionals.at(-1);
1195
- if (index < positionals.length)
1196
- return positionals[index];
1197
- return last?.replace("]", "").endsWith("...") === true ? last : undefined;
1219
+ if (typed.length < positionals.length)
1220
+ return { name: positionals[typed.length], typed };
1221
+ return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
1198
1222
  }
1199
1223
  async function leafCandidates(run, words) {
1200
1224
  const completing = await completingOf(run);
@@ -1202,12 +1226,12 @@ async function leafCandidates(run, words) {
1202
1226
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1203
1227
  const flag = words.at(-2);
1204
1228
  const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
1229
+ const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
1205
1230
  if (option?.type === "string") {
1206
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1231
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1207
1232
  return values === undefined ? [FILES] : values.map(candidateLine);
1208
1233
  }
1209
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1210
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1234
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1211
1235
  return values === undefined ? [FILES] : values.map(candidateLine);
1212
1236
  }
1213
1237
  async function printCandidates(found) {
@@ -1216,9 +1240,13 @@ async function printCandidates(found) {
1216
1240
  return 0;
1217
1241
  }
1218
1242
  function packageVersion(entry = Bun.main) {
1219
- for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
1243
+ let resolved = entry;
1244
+ try {
1245
+ resolved = realpathSync2(entry);
1246
+ } catch {}
1247
+ for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
1220
1248
  try {
1221
- const { version } = JSON.parse(readFileSync3(join6(dir, "package.json"), "utf8"));
1249
+ const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1222
1250
  if (typeof version === "string")
1223
1251
  return version;
1224
1252
  } catch {}
@@ -1226,7 +1254,7 @@ function packageVersion(entry = Bun.main) {
1226
1254
  return "0.0.0";
1227
1255
  }
1228
1256
  }
1229
- async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1257
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1230
1258
  if (argv[0] === COMPLETE)
1231
1259
  return printCandidates(leafCandidates(run, argv.slice(1)));
1232
1260
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1253,15 +1281,15 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
1253
1281
  // ../kit/src/sessions.ts
1254
1282
  import { homedir as homedir5 } from "os";
1255
1283
  import { join as join7 } from "path";
1256
- import process15 from "process";
1284
+ import process16 from "process";
1257
1285
  var {Glob } = globalThis.Bun;
1258
1286
  var SESSION_FILES = new Glob("*.json");
1259
1287
  var ACCOUNT_DIRS = new Glob("*/sessions");
1260
1288
  async function sessionDirs() {
1261
1289
  const home = homedir5();
1262
1290
  const dirs = new Set([join7(home, ".claude", "sessions")]);
1263
- if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1264
- dirs.add(join7(process15.env.CLAUDE_CONFIG_DIR, "sessions"));
1291
+ if (process16.env.CLAUDE_CONFIG_DIR !== undefined)
1292
+ dirs.add(join7(process16.env.CLAUDE_CONFIG_DIR, "sessions"));
1265
1293
  try {
1266
1294
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1267
1295
  dirs.add(dir);
@@ -1307,7 +1335,7 @@ async function liveSessions() {
1307
1335
  }
1308
1336
  async function currentSession(sessions) {
1309
1337
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1310
- let pid = process15.ppid;
1338
+ let pid = process16.ppid;
1311
1339
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1312
1340
  const session = byPid.get(pid);
1313
1341
  if (session !== undefined)
@@ -1320,20 +1348,20 @@ async function currentSession(sessions) {
1320
1348
  return;
1321
1349
  }
1322
1350
  // src/slot.ts
1323
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync4, rmSync } from "fs";
1351
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync5, rmSync } from "fs";
1324
1352
  import { availableParallelism } from "os";
1325
1353
  import { join as join8 } from "path";
1326
- import process18 from "process";
1354
+ import process19 from "process";
1327
1355
 
1328
1356
  // src/flock.ts
1329
1357
  import { closeSync, constants as constants2, ftruncateSync, openSync as openSync2, writeSync } from "fs";
1330
- import process17 from "process";
1358
+ import process18 from "process";
1331
1359
  import { dlopen, FFIType } from "bun:ffi";
1332
1360
  var LOCK_EX = 2;
1333
1361
  var LOCK_NB = 4;
1334
1362
  var flock;
1335
1363
  function native() {
1336
- flock ??= dlopen(process17.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1364
+ flock ??= dlopen(process18.platform === "darwin" ? "libSystem.B.dylib" : "libc.so.6", { flock: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 } }).symbols.flock;
1337
1365
  return flock;
1338
1366
  }
1339
1367
  function tryLock(path) {
@@ -1377,14 +1405,14 @@ function defaultSlots() {
1377
1405
  return Math.max(1, Math.floor(availableParallelism() / 2));
1378
1406
  }
1379
1407
  async function stateDir() {
1380
- const dir = process18.env.SLOT_DIR ?? await privateLogDirectory("slot");
1408
+ const dir = process19.env.SLOT_DIR ?? await privateLogDirectory("slot");
1381
1409
  for (const sub of ["slots", "locks", "waiters"])
1382
1410
  mkdirSync2(join8(dir, sub), { recursive: true, mode: 448 });
1383
1411
  return dir;
1384
1412
  }
1385
1413
  function readHolder(path) {
1386
1414
  try {
1387
- const holder = JSON.parse(readFileSync4(path, "utf8"));
1415
+ const holder = JSON.parse(readFileSync5(path, "utf8"));
1388
1416
  return typeof holder.pid === "number" && typeof holder.command === "string" ? { pid: holder.pid, command: holder.command, cwd: holder.cwd ?? "", since: holder.since ?? 0, ...holder.session === undefined ? {} : { session: holder.session }, ...holder.resource === undefined ? {} : { resource: holder.resource } } : undefined;
1389
1417
  } catch {
1390
1418
  return;
@@ -1419,7 +1447,7 @@ function waitingLine(dir, wanted) {
1419
1447
  }
1420
1448
  async function holderOf(command) {
1421
1449
  const session = await currentSession(await liveSessions());
1422
- return { pid: process18.pid, command: command.join(" "), cwd: process18.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1450
+ return { pid: process19.pid, command: command.join(" "), cwd: process19.cwd(), since: Date.now(), ...session === undefined ? {} : { session: session.name } };
1423
1451
  }
1424
1452
  var waiterCount = 0;
1425
1453
  async function acquire(dir, resources, holder, deadline, timeoutMs) {
@@ -1445,7 +1473,7 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1445
1473
  held.release();
1446
1474
  const resource = busy.kind === "lock" ? `lock ${busy.name}` : "slot";
1447
1475
  if (waiter === undefined) {
1448
- const path = join8(dir, "waiters", `${process18.pid}-${waiterCount++}`);
1476
+ const path = join8(dir, "waiters", `${process19.pid}-${waiterCount++}`);
1449
1477
  const held = tryLock(path);
1450
1478
  if (held !== undefined) {
1451
1479
  writeHeld(held, JSON.stringify({ ...holder, resource }));
@@ -1486,7 +1514,7 @@ ${RUN_USAGE}`);
1486
1514
  const count = wholeNumber(values.slots, "slots", defaultSlots());
1487
1515
  const timeoutMs = duration(values.timeout, "timeout", Number.POSITIVE_INFINITY);
1488
1516
  const deadline = Date.now() + timeoutMs;
1489
- const holding = new Set((process18.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1517
+ const holding = new Set((process19.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1490
1518
  const wanted = [...locks.filter((name) => !holding.has(`lock:${name}`)).map((name) => ({ kind: "lock", name, count })), ...values["no-slot"] === true || holding.has("slot") ? [] : [{ kind: "slot", name: "", count }]];
1491
1519
  const signals = holdSignals(() => {
1492
1520
  return;
@@ -1501,7 +1529,7 @@ ${RUN_USAGE}`);
1501
1529
  const tokens = new Set([...holding, ...locks.map((name) => `lock:${name}`), ...wanted.some((resource) => resource.kind === "slot") ? ["slot"] : []]);
1502
1530
  let child;
1503
1531
  try {
1504
- child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process18.env, [HOLDING]: [...tokens].join(",") } });
1532
+ child = Bun.spawn(rest, { stdio: ["inherit", "inherit", "inherit"], env: { ...process19.env, [HOLDING]: [...tokens].join(",") } });
1505
1533
  } catch (error) {
1506
1534
  fail(`cannot run ${rest[0]}: ${error instanceof Error ? error.message : String(error)}`, 127);
1507
1535
  }
@@ -1544,11 +1572,11 @@ async function listSlots(args) {
1544
1572
  printJson({ slots: count, busy, entries });
1545
1573
  return 0;
1546
1574
  }
1547
- console.log(paint(process18.stdout).bold(`slots: ${busy} of ${count} busy`));
1575
+ console.log(paint(process19.stdout).bold(`slots: ${busy} of ${count} busy`));
1548
1576
  if (entries.length > 0)
1549
- console.log(table(entries.map((entry) => [badge(entry.state, process18.stdout), entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1577
+ console.log(table(entries.map((entry) => [badge(entry.state, process19.stdout), entry.resource, entry.session ?? `pid ${entry.pid}`, truncate(entry.command, COMMAND_WIDTH), entry.since === 0 ? "?" : formatAge(entry.since)])));
1550
1578
  return 0;
1551
1579
  }
1552
1580
 
1553
1581
  // src/slot-cli.ts
1554
- process19.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });
1582
+ process20.exitCode = await runMain({ name: "slot", run: async (args) => args[0] === "ls" ? listSlots(args.slice(1)) : runSlotted(args) });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-wait",
3
3
  "type": "module",
4
- "version": "0.10.1",
4
+ "version": "0.11.0",
5
5
  "description": "waitfor and slot: waits for a log line, a listening port or a URL answering, and queues heavy commands behind machine-wide slots and named locks, for Claude Code, instead of sleep and polling loops.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -38,6 +38,6 @@
38
38
  "waitfor": "$npm_execpath src/cli.ts"
39
39
  },
40
40
  "devDependencies": {
41
- "@kaynooo/cli-kit": "0.37.0"
41
+ "@kaynooo/cli-kit": "0.38.2"
42
42
  }
43
43
  }