@kaynooo/cli-wait 0.10.0 → 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/README.md CHANGED
@@ -55,3 +55,7 @@ check --slot
55
55
  - `slot ls` is the listing even as a first word, `slot -- ls` being read as `slot ls` because Bun drops a leading `--`: write `slot -n 4 -- ls` for the command.
56
56
  - State lives in `$XDG_RUNTIME_DIR/kaynooo-cli/slot` (`~/.cache/kaynooo-cli/slot` without it), only the user can enter it; `$SLOT_DIR` points elsewhere.
57
57
  - Exit codes: the command's, 2 on a timeout or a usage error.
58
+
59
+ ## Config
60
+
61
+ `~/.config/kaynooo-cli/wait.json` (`$XDG_CONFIG_HOME/kaynooo-cli/` when set) takes positive whole numbers: `tail` (20, the lines of a file kept for a timeout excerpt), `around` (5, the lines kept on each side of a failure line) and `portTimeoutMs` (3000, how long one port probe waits).
package/dist/cli.js CHANGED
@@ -2,14 +2,15 @@
2
2
  // @bun
3
3
 
4
4
  // src/cli.ts
5
- import { existsSync as existsSync5 } from "fs";
6
- import process18 from "process";
5
+ import { existsSync as existsSync6 } from "fs";
6
+ import process19 from "process";
7
7
  // ../kit/src/args.ts
8
8
  import process9 from "process";
9
9
  import { parseArgs } from "util";
10
10
 
11
11
  // ../kit/src/format.ts
12
12
  import process7 from "process";
13
+
13
14
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
14
15
  var N = new Map;
15
16
  var Nt = /\s+\S*$/;
@@ -27,6 +28,7 @@ function ko(t, e, r = "...") {
27
28
  }
28
29
  var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
29
30
  var z = new Map;
31
+
30
32
  // ../kit/src/mode.ts
31
33
  import process2 from "process";
32
34
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -72,7 +74,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
72
74
  return false;
73
75
  return r?.isTTY === true;
74
76
  }
75
- function f2(r, e = []) {
77
+ function f(r, e = []) {
76
78
  let l = "", n = "";
77
79
  for (let t = 0, i = e.length;t < i; t++)
78
80
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
@@ -82,7 +84,7 @@ function f2(r, e = []) {
82
84
  if (Array.isArray(a)) {
83
85
  let s = g.get(i);
84
86
  if (s === undefined)
85
- s = f2(r, [...e, a]), g.set(i, s);
87
+ s = f(r, [...e, a]), g.set(i, s);
86
88
  return s;
87
89
  }
88
90
  if (typeof a === "function")
@@ -91,20 +93,20 @@ function f2(r, e = []) {
91
93
  if (u === undefined) {
92
94
  if (g.size >= 64)
93
95
  g.clear();
94
- u = f2(r, [...e, a(...s)]), g.set(y, u);
96
+ u = f(r, [...e, a(...s)]), g.set(y, u);
95
97
  }
96
98
  return u;
97
99
  };
98
100
  throw Error(`Unknown style: ${String(i)}`);
99
101
  } });
100
102
  }
101
- function Fe2(r = {}) {
102
- return f2(r);
103
+ function Fe(r = {}) {
104
+ return f(r);
103
105
  }
104
- var o2 = Fe2();
106
+ var o = Fe();
105
107
 
106
108
  // ../kit/src/theme.ts
107
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
109
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
108
110
  import { homedir as homedir2 } from "os";
109
111
  import { join as join3, resolve as resolve2 } from "path";
110
112
  import process5 from "process";
@@ -125,6 +127,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
125
127
  }
126
128
 
127
129
  // ../kit/src/user-config.ts
130
+ import { existsSync as existsSync2, readFileSync } from "fs";
128
131
  import { homedir } from "os";
129
132
  import { join as join2 } from "path";
130
133
  import process4 from "process";
@@ -135,6 +138,28 @@ function configBase(where = {}) {
135
138
  function userConfigPath(bin, where = {}) {
136
139
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
137
140
  }
141
+ function userConfigReadPath(bin, legacy = [], where = {}) {
142
+ const current = userConfigPath(bin, where);
143
+ if (existsSync2(current))
144
+ return current;
145
+ const base = configBase(where);
146
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
147
+ }
148
+ function readUserConfig(bin, where = {}, legacy = []) {
149
+ const path = userConfigReadPath(bin, legacy, where);
150
+ if (!existsSync2(path))
151
+ return {};
152
+ try {
153
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
154
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
155
+ } catch {
156
+ return {};
157
+ }
158
+ }
159
+ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
160
+ const value = readUserConfig(bin, where, legacy)[key];
161
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
162
+ }
138
163
 
139
164
  // ../kit/src/theme.ts
140
165
  var ENDS = new Map;
@@ -201,7 +226,7 @@ function readThemeFile(path, warn) {
201
226
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
202
227
  return;
203
228
  }
204
- const parsed = JSON.parse(readFileSync(path, "utf8"));
229
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
205
230
  if (isRecord(parsed))
206
231
  return parsed;
207
232
  warn(`${path} is not a JSON object, theme ignored`);
@@ -267,7 +292,7 @@ function applyFile(theme, file, where, warn) {
267
292
  }
268
293
  }
269
294
  function endsWalk(home) {
270
- return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
295
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
271
296
  }
272
297
  var warned = new Set;
273
298
  function warnOnce(message) {
@@ -323,7 +348,7 @@ function takesControlCodes(stream, env = process6.env) {
323
348
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
324
349
  }
325
350
  function paint(stream, env = process6.env) {
326
- return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
351
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
327
352
  }
328
353
  function marked(mark, text, stream, detail, env = process6.env) {
329
354
  const colors = paint(stream, env);
@@ -757,12 +782,36 @@ function nearestOption(message, options, allowNegative) {
757
782
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
758
783
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
759
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
+ }
760
809
  // ../kit/src/progress.ts
761
- import process11 from "process";
810
+ import process12 from "process";
762
811
 
763
812
  // ../kit/src/process.ts
764
813
  import { constants } from "os";
765
- import process10 from "process";
814
+ import process11 from "process";
766
815
  var KILL_GRACE_MS = 2000;
767
816
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
768
817
  function exitCodeOf(code, signal) {
@@ -784,7 +833,7 @@ function holdSignals(cleanup) {
784
833
  },
785
834
  release: () => {
786
835
  for (const signal of SIGNALS)
787
- process10.off(signal, onSignal);
836
+ process11.off(signal, onSignal);
788
837
  }
789
838
  };
790
839
  function onSignal(signal) {
@@ -797,10 +846,10 @@ function holdSignals(cleanup) {
797
846
  return;
798
847
  held.release();
799
848
  cleanup(signal);
800
- process10.kill(process10.pid, signal);
849
+ process11.kill(process11.pid, signal);
801
850
  }
802
851
  for (const signal of SIGNALS)
803
- process10.on(signal, onSignal);
852
+ process11.on(signal, onSignal);
804
853
  return held;
805
854
  }
806
855
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -814,7 +863,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
814
863
  return;
815
864
  try {
816
865
  if (grouped)
817
- process10.kill(-proc.pid, killing);
866
+ process11.kill(-proc.pid, killing);
818
867
  else
819
868
  proc.kill(killing);
820
869
  } catch {}
@@ -885,15 +934,14 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
885
934
  // ../kit/src/progress.ts
886
935
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
887
936
  var FRAME_MS = 200;
888
- var CLEAR_LINE = "\r\x1B[2K";
889
- var LINE_UP = "\x1B[1A\x1B[2K";
937
+ var CLEAR_BELOW = "\r\x1B[J";
890
938
  var ESC = String.fromCharCode(27);
891
939
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
892
940
  var RESET_STYLE = `${ESC}[0m`;
893
941
  var CTRL_C = 3;
894
942
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
895
943
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
896
- function liveRegion(render, stream = process11.stderr, env = process11.env) {
944
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
897
945
  if (!takesControlCodes(stream, env))
898
946
  return { redraw: () => {
899
947
  return;
@@ -903,13 +951,15 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
903
951
  } };
904
952
  const write = stream.write.bind(stream);
905
953
  let frame = 0;
906
- let drawn = [];
907
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
908
- const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
954
+ let drawn = false;
955
+ const columns = () => {
956
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
957
+ return now === undefined || now === 0 ? 80 : now;
958
+ };
909
959
  const clear = () => {
910
- if (drawn.length > 0)
911
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
912
- drawn = [];
960
+ if (drawn)
961
+ write(CLEAR_BELOW);
962
+ drawn = false;
913
963
  };
914
964
  const draw = () => {
915
965
  const width = columns() - 1;
@@ -919,9 +969,9 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
919
969
  clear();
920
970
  return;
921
971
  }
922
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
923
- `)}`);
924
- drawn = lines.map((line) => Bun.stringWidth(line));
972
+ write(`${CLEAR_BELOW}${lines.join(`
973
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
974
+ drawn = true;
925
975
  };
926
976
  const timer = setInterval(draw, FRAME_MS);
927
977
  stream.on?.("resize", draw);
@@ -938,11 +988,11 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
938
988
  clear();
939
989
  restore();
940
990
  release();
941
- process11.off("exit", onExit);
991
+ process12.off("exit", onExit);
942
992
  signals.release();
943
993
  }
944
994
  timer.unref();
945
- process11.on("exit", onExit);
995
+ process12.on("exit", onExit);
946
996
  return {
947
997
  redraw: draw,
948
998
  print: (text) => {
@@ -981,14 +1031,14 @@ function cutToWidth(line, width) {
981
1031
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
982
1032
  }
983
1033
  function swallowInput() {
984
- const input = process11.stdin;
1034
+ const input = process12.stdin;
985
1035
  if (!input.isTTY)
986
1036
  return () => {
987
1037
  return;
988
1038
  };
989
1039
  const onData = (data) => {
990
1040
  if (data.includes(CTRL_C))
991
- process11.kill(process11.pid, "SIGINT");
1041
+ process12.kill(process12.pid, "SIGINT");
992
1042
  };
993
1043
  input.setRawMode(true);
994
1044
  input.on("data", onData);
@@ -1004,7 +1054,7 @@ function swallowInput() {
1004
1054
  };
1005
1055
  }
1006
1056
  function interceptOutput(clear) {
1007
- 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"]];
1008
1058
  const wrapped = targets.map(([target, name]) => {
1009
1059
  const original = Reflect.get(target, name);
1010
1060
  const wrapper = (...args) => {
@@ -1022,33 +1072,33 @@ function interceptOutput(clear) {
1022
1072
  };
1023
1073
  }
1024
1074
  // ../kit/src/cli.ts
1025
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1075
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1026
1076
  import { dirname as dirname3, join as join6 } from "path";
1027
- import process14 from "process";
1077
+ import process15 from "process";
1028
1078
 
1029
1079
  // ../kit/src/usage.ts
1030
1080
  import { appendFileSync, mkdirSync } from "fs";
1031
1081
  import { homedir as homedir4 } from "os";
1032
1082
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1033
- import process13 from "process";
1083
+ import process14 from "process";
1034
1084
 
1035
1085
  // ../kit/src/logs.ts
1036
1086
  import { lstatSync, openSync } from "fs";
1037
1087
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
1038
1088
  import { homedir as homedir3, tmpdir } from "os";
1039
1089
  import { join as join4 } from "path";
1040
- import process12 from "process";
1090
+ import process13 from "process";
1041
1091
  var DAY_MS = 24 * 60 * 60 * 1000;
1042
1092
  var CLI_FOLDER = "kaynooo-cli";
1043
1093
  function isPrivateDirectory(path) {
1044
1094
  try {
1045
1095
  const info = lstatSync(path, { throwIfNoEntry: false });
1046
- 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;
1047
1097
  } catch {
1048
1098
  return false;
1049
1099
  }
1050
1100
  }
1051
- async function privateLogDirectory(name, env = process12.env) {
1101
+ async function privateLogDirectory(name, env = process13.env) {
1052
1102
  const runtime = env.XDG_RUNTIME_DIR;
1053
1103
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1054
1104
  const path = join4(base, name);
@@ -1068,14 +1118,14 @@ var usageError;
1068
1118
  function noteUsageError(message) {
1069
1119
  usageError = message;
1070
1120
  }
1071
- function stateHome(env = process13.env) {
1121
+ function stateHome(env = process14.env) {
1072
1122
  const dir = env.XDG_STATE_HOME;
1073
1123
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1074
1124
  }
1075
- function usagePath(env = process13.env) {
1125
+ function usagePath(env = process14.env) {
1076
1126
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1077
1127
  }
1078
- function usageRecorded(env = process13.env) {
1128
+ function usageRecorded(env = process14.env) {
1079
1129
  const off = env.KAYNOOO_CLI_NO_USAGE;
1080
1130
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1081
1131
  }
@@ -1089,7 +1139,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1089
1139
  usageError = undefined;
1090
1140
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1091
1141
  }
1092
- function recordUsage(entry, env = process13.env) {
1142
+ function recordUsage(entry, env = process14.env) {
1093
1143
  if (!usageRecorded(env))
1094
1144
  return;
1095
1145
  try {
@@ -1107,8 +1157,8 @@ var LEVEL_OPTIONS = {
1107
1157
  };
1108
1158
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1109
1159
  function printError(prefix, message, hint, cause) {
1110
- const colors = paint(process14.stderr);
1111
- const styled = takesControlCodes(process14.stderr);
1160
+ const colors = paint(process15.stderr);
1161
+ const styled = takesControlCodes(process15.stderr);
1112
1162
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1113
1163
  const under = (label, text, tint) => text === undefined ? "" : `
1114
1164
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1152,24 +1202,24 @@ function candidateLine(candidate) {
1152
1202
  }
1153
1203
  function positionalBeingTyped(before, { options, positionals }) {
1154
1204
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1155
- let index = 0;
1205
+ const typed = [];
1156
1206
  let at = 0;
1157
1207
  while (at < before.length) {
1158
1208
  const word = before[at];
1159
1209
  if (word === "--") {
1160
- index += before.length - at - 1;
1210
+ typed.push(...before.slice(at + 1));
1161
1211
  break;
1162
1212
  }
1163
1213
  if (!word.startsWith("-"))
1164
- index++;
1214
+ typed.push(word);
1165
1215
  else if (takesValue(word))
1166
1216
  at++;
1167
1217
  at++;
1168
1218
  }
1169
1219
  const last = positionals.at(-1);
1170
- if (index < positionals.length)
1171
- return positionals[index];
1172
- 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 };
1173
1223
  }
1174
1224
  async function leafCandidates(run, words) {
1175
1225
  const completing = await completingOf(run);
@@ -1177,12 +1227,12 @@ async function leafCandidates(run, words) {
1177
1227
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1178
1228
  const flag = words.at(-2);
1179
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);
1180
1231
  if (option?.type === "string") {
1181
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1232
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1182
1233
  return values === undefined ? [FILES] : values.map(candidateLine);
1183
1234
  }
1184
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1185
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1235
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1186
1236
  return values === undefined ? [FILES] : values.map(candidateLine);
1187
1237
  }
1188
1238
  async function printCandidates(found) {
@@ -1191,9 +1241,13 @@ async function printCandidates(found) {
1191
1241
  return 0;
1192
1242
  }
1193
1243
  function packageVersion(entry = Bun.main) {
1194
- 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)) {
1195
1249
  try {
1196
- const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1250
+ const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1197
1251
  if (typeof version === "string")
1198
1252
  return version;
1199
1253
  } catch {}
@@ -1201,7 +1255,7 @@ function packageVersion(entry = Bun.main) {
1201
1255
  return "0.0.0";
1202
1256
  }
1203
1257
  }
1204
- async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1258
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1205
1259
  if (argv[0] === COMPLETE)
1206
1260
  return printCandidates(leafCandidates(run, argv.slice(1)));
1207
1261
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1228,15 +1282,15 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
1228
1282
  // ../kit/src/sessions.ts
1229
1283
  import { homedir as homedir5 } from "os";
1230
1284
  import { join as join7 } from "path";
1231
- import process15 from "process";
1285
+ import process16 from "process";
1232
1286
  var {Glob } = globalThis.Bun;
1233
1287
  var SESSION_FILES = new Glob("*.json");
1234
1288
  var ACCOUNT_DIRS = new Glob("*/sessions");
1235
1289
  async function sessionDirs() {
1236
1290
  const home = homedir5();
1237
1291
  const dirs = new Set([join7(home, ".claude", "sessions")]);
1238
- if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1239
- 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"));
1240
1294
  try {
1241
1295
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1242
1296
  dirs.add(dir);
@@ -1282,7 +1336,7 @@ async function liveSessions() {
1282
1336
  }
1283
1337
  async function currentSession(sessions) {
1284
1338
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1285
- let pid = process15.ppid;
1339
+ let pid = process16.ppid;
1286
1340
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1287
1341
  const session = byPid.get(pid);
1288
1342
  if (session !== undefined)
@@ -1295,13 +1349,13 @@ async function currentSession(sessions) {
1295
1349
  return;
1296
1350
  }
1297
1351
  // src/conditions.ts
1298
- import { existsSync as existsSync3, statSync as statSync2 } from "fs";
1299
- var TAIL = 20;
1300
- var AROUND = 5;
1352
+ import { existsSync as existsSync4, statSync as statSync2 } from "fs";
1353
+ var TAIL = configuredNumber("wait", "tail", 20);
1354
+ var AROUND = configuredNumber("wait", "around", 5);
1301
1355
  var CARRIAGE_RETURN = /\r$/;
1302
1356
  var SLICE_BYTES = 1024 * 1024;
1303
1357
  var MAX_LINE = 1e4;
1304
- var PORT_TIMEOUT_MS = 3000;
1358
+ var PORT_TIMEOUT_MS = configuredNumber("wait", "portTimeoutMs", 3000);
1305
1359
 
1306
1360
  class FileWatch {
1307
1361
  path;
@@ -1327,7 +1381,7 @@ class FileWatch {
1327
1381
  return this.failure !== undefined;
1328
1382
  }
1329
1383
  get exists() {
1330
- return existsSync3(this.path);
1384
+ return existsSync4(this.path);
1331
1385
  }
1332
1386
  async poll() {
1333
1387
  const events = [];
@@ -1361,7 +1415,7 @@ class FileWatch {
1361
1415
  return this.recent;
1362
1416
  }
1363
1417
  async nextLines() {
1364
- if (!existsSync3(this.path))
1418
+ if (!existsSync4(this.path))
1365
1419
  return;
1366
1420
  const { size, dev, ino } = statSync2(this.path);
1367
1421
  const replaced = this.identity !== undefined && (this.identity.dev !== dev || this.identity.ino !== ino);
@@ -1419,9 +1473,9 @@ async function urlCheck(url, timeout) {
1419
1473
  }
1420
1474
 
1421
1475
  // src/task.ts
1422
- import { existsSync as existsSync4, lstatSync as lstatSync2, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
1476
+ import { existsSync as existsSync5, lstatSync as lstatSync2, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
1423
1477
  import { join as join8 } from "path";
1424
- import process17 from "process";
1478
+ import process18 from "process";
1425
1479
  var EXITED = /(?:^|\n)\[exited with code (-?\d+)\]\n*$/;
1426
1480
  var FAILURE = /\(fail\)|\berror:/i;
1427
1481
  var TASK_ID = /^[\w-]+$/;
@@ -1429,29 +1483,29 @@ var TAIL_BYTES = 256;
1429
1483
  var LONGEST_FAILURES = 30;
1430
1484
  var CARRIAGE_RETURN2 = /\r$/;
1431
1485
  function tasksRoot(env) {
1432
- 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}`);
1433
1487
  }
1434
- function taskFile(task, env = process17.env) {
1488
+ function taskFile(task, env = process18.env) {
1435
1489
  if (task.includes("/") || task.endsWith(".output"))
1436
1490
  return task;
1437
1491
  if (!TASK_ID.test(task))
1438
1492
  return;
1439
1493
  const root = tasksRoot(env);
1440
- const found = existsSync4(root) ? [...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({ cwd: root, onlyFiles: false })] : [];
1494
+ const found = existsSync5(root) ? [...new Bun.Glob(`*/*/tasks/${task}.output`).scanSync({ cwd: root, onlyFiles: false })] : [];
1441
1495
  return found.length === 0 ? undefined : join8(root, found[0] ?? "");
1442
1496
  }
1443
1497
  function isTranscript(path) {
1444
- return existsSync4(path) && lstatSync2(path).isSymbolicLink() && path.endsWith(".output");
1498
+ return existsSync5(path) && lstatSync2(path).isSymbolicLink() && path.endsWith(".output");
1445
1499
  }
1446
1500
  async function exitCode(path) {
1447
- if (!existsSync4(path))
1501
+ if (!existsSync5(path))
1448
1502
  return;
1449
1503
  const size = statSync3(path).size;
1450
1504
  const found = EXITED.exec(await Bun.file(path).slice(Math.max(0, size - TAIL_BYTES), size).text());
1451
1505
  return found === null ? undefined : Number(found[1]);
1452
1506
  }
1453
1507
  async function taskEnd(path, lines) {
1454
- if (!existsSync4(path))
1508
+ if (!existsSync5(path))
1455
1509
  return { failures: [], tail: [] };
1456
1510
  const text = (await Bun.file(path).text()).replace(EXITED, "");
1457
1511
  const all = text.split(`
@@ -1464,7 +1518,7 @@ async function taskEnd(path, lines) {
1464
1518
  }
1465
1519
  function pidAlive(pid) {
1466
1520
  try {
1467
- process17.kill(pid, 0);
1521
+ process18.kill(pid, 0);
1468
1522
  } catch (error) {
1469
1523
  return error.code === "EPERM";
1470
1524
  }
@@ -1472,7 +1526,7 @@ function pidAlive(pid) {
1472
1526
  }
1473
1527
  function isZombie(pid) {
1474
1528
  try {
1475
- const stat = readFileSync3(`/proc/${pid}/stat`, "utf8");
1529
+ const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
1476
1530
  return stat.slice(stat.lastIndexOf(")") + 2, stat.lastIndexOf(")") + 3) === "Z";
1477
1531
  } catch {
1478
1532
  return false;
@@ -1548,14 +1602,14 @@ async function waitTask(args) {
1548
1602
  const path = taskFile(task);
1549
1603
  if (path === undefined)
1550
1604
  fail(`no background task ${task}: give the id a background Bash call returned, or the path of its .output file`);
1551
- if (!existsSync5(path))
1605
+ if (!existsSync6(path))
1552
1606
  fail(`no output file ${path}: ${task} is no background task of this machine`);
1553
1607
  if (isTranscript(path))
1554
1608
  fail(`${task} is a subagent, whose end its notification reports: waitfor task waits on a background Bash task`);
1555
1609
  const lines = wholeNumber(values.lines, "lines", 20);
1556
1610
  const timeout = duration(values.timeout, "timeout", 5 * 60000);
1557
1611
  const started = Date.now();
1558
- const { dim } = paint(process18.stderr);
1612
+ const { dim } = paint(process19.stderr);
1559
1613
  const region = values.quiet === true ? undefined : liveRegion((spinner) => [`${spinner} task ${task}: still running ${dim(formatElapsed(Date.now() - started))}`]);
1560
1614
  let code;
1561
1615
  try {
@@ -1626,7 +1680,7 @@ ${USAGE}`);
1626
1680
  let isPidLeft = pid !== undefined;
1627
1681
  let cmdLeft = values.cmd === undefined ? undefined : "not run yet";
1628
1682
  let cmdRanAt = 0;
1629
- const { dim } = paint(process18.stderr);
1683
+ const { dim } = paint(process19.stderr);
1630
1684
  const region = values.quiet === true ? undefined : liveRegion((spinner) => {
1631
1685
  const waited = dim(formatElapsed(Date.now() - started));
1632
1686
  const left = [
@@ -1717,4 +1771,4 @@ ${numbered(event.excerpt, event.line)}`);
1717
1771
  last lines of ${watch?.path}:
1718
1772
  ${numbered(lines)}`}`);
1719
1773
  }
1720
- process18.exitCode = await runMain({ name: "waitfor", run: main });
1774
+ process19.exitCode = await runMain({ name: "waitfor", run: main });
package/dist/slot-cli.js CHANGED
@@ -2,13 +2,14 @@
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";
9
9
 
10
10
  // ../kit/src/format.ts
11
11
  import process7 from "process";
12
+
12
13
  // ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
13
14
  var N = new Map;
14
15
  var Nt = /\s+\S*$/;
@@ -26,6 +27,7 @@ function ko(t, e, r = "...") {
26
27
  }
27
28
  var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
28
29
  var z = new Map;
30
+
29
31
  // ../kit/src/mode.ts
30
32
  import process2 from "process";
31
33
  var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
@@ -71,7 +73,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
71
73
  return false;
72
74
  return r?.isTTY === true;
73
75
  }
74
- function f2(r, e = []) {
76
+ function f(r, e = []) {
75
77
  let l = "", n = "";
76
78
  for (let t = 0, i = e.length;t < i; t++)
77
79
  l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
@@ -81,7 +83,7 @@ function f2(r, e = []) {
81
83
  if (Array.isArray(a)) {
82
84
  let s = g.get(i);
83
85
  if (s === undefined)
84
- s = f2(r, [...e, a]), g.set(i, s);
86
+ s = f(r, [...e, a]), g.set(i, s);
85
87
  return s;
86
88
  }
87
89
  if (typeof a === "function")
@@ -90,20 +92,20 @@ function f2(r, e = []) {
90
92
  if (u === undefined) {
91
93
  if (g.size >= 64)
92
94
  g.clear();
93
- u = f2(r, [...e, a(...s)]), g.set(y, u);
95
+ u = f(r, [...e, a(...s)]), g.set(y, u);
94
96
  }
95
97
  return u;
96
98
  };
97
99
  throw Error(`Unknown style: ${String(i)}`);
98
100
  } });
99
101
  }
100
- function Fe2(r = {}) {
101
- return f2(r);
102
+ function Fe(r = {}) {
103
+ return f(r);
102
104
  }
103
- var o2 = Fe2();
105
+ var o = Fe();
104
106
 
105
107
  // ../kit/src/theme.ts
106
- import { existsSync as existsSync2, readFileSync, statSync } from "fs";
108
+ import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
107
109
  import { homedir as homedir2 } from "os";
108
110
  import { join as join3, resolve as resolve2 } from "path";
109
111
  import process5 from "process";
@@ -124,6 +126,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
124
126
  }
125
127
 
126
128
  // ../kit/src/user-config.ts
129
+ import { existsSync as existsSync2, readFileSync } from "fs";
127
130
  import { homedir } from "os";
128
131
  import { join as join2 } from "path";
129
132
  import process4 from "process";
@@ -134,6 +137,28 @@ function configBase(where = {}) {
134
137
  function userConfigPath(bin, where = {}) {
135
138
  return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
136
139
  }
140
+ function userConfigReadPath(bin, legacy = [], where = {}) {
141
+ const current = userConfigPath(bin, where);
142
+ if (existsSync2(current))
143
+ return current;
144
+ const base = configBase(where);
145
+ return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
146
+ }
147
+ function readUserConfig(bin, where = {}, legacy = []) {
148
+ const path = userConfigReadPath(bin, legacy, where);
149
+ if (!existsSync2(path))
150
+ return {};
151
+ try {
152
+ const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
153
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
154
+ } catch {
155
+ return {};
156
+ }
157
+ }
158
+ function configuredNumber(bin, key, fallback, where = {}, legacy = []) {
159
+ const value = readUserConfig(bin, where, legacy)[key];
160
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
161
+ }
137
162
 
138
163
  // ../kit/src/theme.ts
139
164
  var ENDS = new Map;
@@ -200,7 +225,7 @@ function readThemeFile(path, warn) {
200
225
  warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
201
226
  return;
202
227
  }
203
- const parsed = JSON.parse(readFileSync(path, "utf8"));
228
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
204
229
  if (isRecord(parsed))
205
230
  return parsed;
206
231
  warn(`${path} is not a JSON object, theme ignored`);
@@ -266,7 +291,7 @@ function applyFile(theme, file, where, warn) {
266
291
  }
267
292
  }
268
293
  function endsWalk(home) {
269
- return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
294
+ return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
270
295
  }
271
296
  var warned = new Set;
272
297
  function warnOnce(message) {
@@ -322,7 +347,7 @@ function takesControlCodes(stream, env = process6.env) {
322
347
  return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
323
348
  }
324
349
  function paint(stream, env = process6.env) {
325
- return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
350
+ return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
326
351
  }
327
352
  function marked(mark, text, stream, detail, env = process6.env) {
328
353
  const colors = paint(stream, env);
@@ -756,12 +781,36 @@ function nearestOption(message, options, allowNegative) {
756
781
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
757
782
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
758
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
+ }
759
808
  // ../kit/src/progress.ts
760
- import process11 from "process";
809
+ import process12 from "process";
761
810
 
762
811
  // ../kit/src/process.ts
763
812
  import { constants } from "os";
764
- import process10 from "process";
813
+ import process11 from "process";
765
814
  var KILL_GRACE_MS = 2000;
766
815
  var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
767
816
  function exitCodeOf(code, signal) {
@@ -783,7 +832,7 @@ function holdSignals(cleanup) {
783
832
  },
784
833
  release: () => {
785
834
  for (const signal of SIGNALS)
786
- process10.off(signal, onSignal);
835
+ process11.off(signal, onSignal);
787
836
  }
788
837
  };
789
838
  function onSignal(signal) {
@@ -796,10 +845,10 @@ function holdSignals(cleanup) {
796
845
  return;
797
846
  held.release();
798
847
  cleanup(signal);
799
- process10.kill(process10.pid, signal);
848
+ process11.kill(process11.pid, signal);
800
849
  }
801
850
  for (const signal of SIGNALS)
802
- process10.on(signal, onSignal);
851
+ process11.on(signal, onSignal);
803
852
  return held;
804
853
  }
805
854
  async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
@@ -813,7 +862,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
813
862
  return;
814
863
  try {
815
864
  if (grouped)
816
- process10.kill(-proc.pid, killing);
865
+ process11.kill(-proc.pid, killing);
817
866
  else
818
867
  proc.kill(killing);
819
868
  } catch {}
@@ -884,15 +933,14 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
884
933
  // ../kit/src/progress.ts
885
934
  var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
886
935
  var FRAME_MS = 200;
887
- var CLEAR_LINE = "\r\x1B[2K";
888
- var LINE_UP = "\x1B[1A\x1B[2K";
936
+ var CLEAR_BELOW = "\r\x1B[J";
889
937
  var ESC = String.fromCharCode(27);
890
938
  var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
891
939
  var RESET_STYLE = `${ESC}[0m`;
892
940
  var CTRL_C = 3;
893
941
  var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
894
942
  var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
895
- function liveRegion(render, stream = process11.stderr, env = process11.env) {
943
+ function liveRegion(render, stream = process12.stderr, env = process12.env) {
896
944
  if (!takesControlCodes(stream, env))
897
945
  return { redraw: () => {
898
946
  return;
@@ -902,13 +950,15 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
902
950
  } };
903
951
  const write = stream.write.bind(stream);
904
952
  let frame = 0;
905
- let drawn = [];
906
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
907
- const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
953
+ let drawn = false;
954
+ const columns = () => {
955
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
956
+ return now === undefined || now === 0 ? 80 : now;
957
+ };
908
958
  const clear = () => {
909
- if (drawn.length > 0)
910
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
911
- drawn = [];
959
+ if (drawn)
960
+ write(CLEAR_BELOW);
961
+ drawn = false;
912
962
  };
913
963
  const draw = () => {
914
964
  const width = columns() - 1;
@@ -918,9 +968,9 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
918
968
  clear();
919
969
  return;
920
970
  }
921
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
922
- `)}`);
923
- drawn = lines.map((line) => Bun.stringWidth(line));
971
+ write(`${CLEAR_BELOW}${lines.join(`
972
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
973
+ drawn = true;
924
974
  };
925
975
  const timer = setInterval(draw, FRAME_MS);
926
976
  stream.on?.("resize", draw);
@@ -937,11 +987,11 @@ function liveRegion(render, stream = process11.stderr, env = process11.env) {
937
987
  clear();
938
988
  restore();
939
989
  release();
940
- process11.off("exit", onExit);
990
+ process12.off("exit", onExit);
941
991
  signals.release();
942
992
  }
943
993
  timer.unref();
944
- process11.on("exit", onExit);
994
+ process12.on("exit", onExit);
945
995
  return {
946
996
  redraw: draw,
947
997
  print: (text) => {
@@ -980,14 +1030,14 @@ function cutToWidth(line, width) {
980
1030
  return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
981
1031
  }
982
1032
  function swallowInput() {
983
- const input = process11.stdin;
1033
+ const input = process12.stdin;
984
1034
  if (!input.isTTY)
985
1035
  return () => {
986
1036
  return;
987
1037
  };
988
1038
  const onData = (data) => {
989
1039
  if (data.includes(CTRL_C))
990
- process11.kill(process11.pid, "SIGINT");
1040
+ process12.kill(process12.pid, "SIGINT");
991
1041
  };
992
1042
  input.setRawMode(true);
993
1043
  input.on("data", onData);
@@ -1003,7 +1053,7 @@ function swallowInput() {
1003
1053
  };
1004
1054
  }
1005
1055
  function interceptOutput(clear) {
1006
- 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"]];
1007
1057
  const wrapped = targets.map(([target, name]) => {
1008
1058
  const original = Reflect.get(target, name);
1009
1059
  const wrapper = (...args) => {
@@ -1021,33 +1071,33 @@ function interceptOutput(clear) {
1021
1071
  };
1022
1072
  }
1023
1073
  // ../kit/src/cli.ts
1024
- import { readFileSync as readFileSync2, realpathSync } from "fs";
1074
+ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
1025
1075
  import { dirname as dirname3, join as join6 } from "path";
1026
- import process14 from "process";
1076
+ import process15 from "process";
1027
1077
 
1028
1078
  // ../kit/src/usage.ts
1029
1079
  import { appendFileSync, mkdirSync } from "fs";
1030
1080
  import { homedir as homedir4 } from "os";
1031
1081
  import { dirname as dirname2, isAbsolute, join as join5 } from "path";
1032
- import process13 from "process";
1082
+ import process14 from "process";
1033
1083
 
1034
1084
  // ../kit/src/logs.ts
1035
1085
  import { lstatSync, openSync } from "fs";
1036
1086
  import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
1037
1087
  import { homedir as homedir3, tmpdir } from "os";
1038
1088
  import { join as join4 } from "path";
1039
- import process12 from "process";
1089
+ import process13 from "process";
1040
1090
  var DAY_MS = 24 * 60 * 60 * 1000;
1041
1091
  var CLI_FOLDER = "kaynooo-cli";
1042
1092
  function isPrivateDirectory(path) {
1043
1093
  try {
1044
1094
  const info = lstatSync(path, { throwIfNoEntry: false });
1045
- 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;
1046
1096
  } catch {
1047
1097
  return false;
1048
1098
  }
1049
1099
  }
1050
- async function privateLogDirectory(name, env = process12.env) {
1100
+ async function privateLogDirectory(name, env = process13.env) {
1051
1101
  const runtime = env.XDG_RUNTIME_DIR;
1052
1102
  const base = runtime === undefined || runtime === "" ? join4(homedir3(), ".cache", CLI_FOLDER) : join4(runtime, CLI_FOLDER);
1053
1103
  const path = join4(base, name);
@@ -1067,14 +1117,14 @@ var usageError;
1067
1117
  function noteUsageError(message) {
1068
1118
  usageError = message;
1069
1119
  }
1070
- function stateHome(env = process13.env) {
1120
+ function stateHome(env = process14.env) {
1071
1121
  const dir = env.XDG_STATE_HOME;
1072
1122
  return dir !== undefined && isAbsolute(dir) ? dir : join5(homedir4(), ".local", "state");
1073
1123
  }
1074
- function usagePath(env = process13.env) {
1124
+ function usagePath(env = process14.env) {
1075
1125
  return join5(stateHome(env), CLI_FOLDER, "usage.jsonl");
1076
1126
  }
1077
- function usageRecorded(env = process13.env) {
1127
+ function usageRecorded(env = process14.env) {
1078
1128
  const off = env.KAYNOOO_CLI_NO_USAGE;
1079
1129
  return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
1080
1130
  }
@@ -1088,7 +1138,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
1088
1138
  usageError = undefined;
1089
1139
  return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
1090
1140
  }
1091
- function recordUsage(entry, env = process13.env) {
1141
+ function recordUsage(entry, env = process14.env) {
1092
1142
  if (!usageRecorded(env))
1093
1143
  return;
1094
1144
  try {
@@ -1106,8 +1156,8 @@ var LEVEL_OPTIONS = {
1106
1156
  };
1107
1157
  var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
1108
1158
  function printError(prefix, message, hint, cause) {
1109
- const colors = paint(process14.stderr);
1110
- const styled = takesControlCodes(process14.stderr);
1159
+ const colors = paint(process15.stderr);
1160
+ const styled = takesControlCodes(process15.stderr);
1111
1161
  const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
1112
1162
  const under = (label, text, tint) => text === undefined ? "" : `
1113
1163
  ${styled ? tint(label) : `${label}:`} ${text}`;
@@ -1151,24 +1201,24 @@ function candidateLine(candidate) {
1151
1201
  }
1152
1202
  function positionalBeingTyped(before, { options, positionals }) {
1153
1203
  const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
1154
- let index = 0;
1204
+ const typed = [];
1155
1205
  let at = 0;
1156
1206
  while (at < before.length) {
1157
1207
  const word = before[at];
1158
1208
  if (word === "--") {
1159
- index += before.length - at - 1;
1209
+ typed.push(...before.slice(at + 1));
1160
1210
  break;
1161
1211
  }
1162
1212
  if (!word.startsWith("-"))
1163
- index++;
1213
+ typed.push(word);
1164
1214
  else if (takesValue(word))
1165
1215
  at++;
1166
1216
  at++;
1167
1217
  }
1168
1218
  const last = positionals.at(-1);
1169
- if (index < positionals.length)
1170
- return positionals[index];
1171
- 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 };
1172
1222
  }
1173
1223
  async function leafCandidates(run, words) {
1174
1224
  const completing = await completingOf(run);
@@ -1176,12 +1226,12 @@ async function leafCandidates(run, words) {
1176
1226
  return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
1177
1227
  const flag = words.at(-2);
1178
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);
1179
1230
  if (option?.type === "string") {
1180
- const values = option.choices === undefined ? await option.candidates?.() : option.choices;
1231
+ const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
1181
1232
  return values === undefined ? [FILES] : values.map(candidateLine);
1182
1233
  }
1183
- const name = positionalBeingTyped(words.slice(0, -1), completing);
1184
- const values = name === undefined ? undefined : await completing.candidates[name]?.();
1234
+ const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
1185
1235
  return values === undefined ? [FILES] : values.map(candidateLine);
1186
1236
  }
1187
1237
  async function printCandidates(found) {
@@ -1190,9 +1240,13 @@ async function printCandidates(found) {
1190
1240
  return 0;
1191
1241
  }
1192
1242
  function packageVersion(entry = Bun.main) {
1193
- 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)) {
1194
1248
  try {
1195
- const { version } = JSON.parse(readFileSync2(join6(dir, "package.json"), "utf8"));
1249
+ const { version } = JSON.parse(readFileSync4(join6(dir, "package.json"), "utf8"));
1196
1250
  if (typeof version === "string")
1197
1251
  return version;
1198
1252
  } catch {}
@@ -1200,7 +1254,7 @@ function packageVersion(entry = Bun.main) {
1200
1254
  return "0.0.0";
1201
1255
  }
1202
1256
  }
1203
- async function runMain({ name, version, run, redact, usage }, argv = process14.argv.slice(2)) {
1257
+ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
1204
1258
  if (argv[0] === COMPLETE)
1205
1259
  return printCandidates(leafCandidates(run, argv.slice(1)));
1206
1260
  if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
@@ -1227,15 +1281,15 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
1227
1281
  // ../kit/src/sessions.ts
1228
1282
  import { homedir as homedir5 } from "os";
1229
1283
  import { join as join7 } from "path";
1230
- import process15 from "process";
1284
+ import process16 from "process";
1231
1285
  var {Glob } = globalThis.Bun;
1232
1286
  var SESSION_FILES = new Glob("*.json");
1233
1287
  var ACCOUNT_DIRS = new Glob("*/sessions");
1234
1288
  async function sessionDirs() {
1235
1289
  const home = homedir5();
1236
1290
  const dirs = new Set([join7(home, ".claude", "sessions")]);
1237
- if (process15.env.CLAUDE_CONFIG_DIR !== undefined)
1238
- 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"));
1239
1293
  try {
1240
1294
  for await (const dir of ACCOUNT_DIRS.scan({ cwd: join7(home, ".claude-accounts"), onlyFiles: false, absolute: true }))
1241
1295
  dirs.add(dir);
@@ -1281,7 +1335,7 @@ async function liveSessions() {
1281
1335
  }
1282
1336
  async function currentSession(sessions) {
1283
1337
  const byPid = new Map(sessions.map((session) => [session.pid, session]));
1284
- let pid = process15.ppid;
1338
+ let pid = process16.ppid;
1285
1339
  for (let depth = 0;depth < 32 && pid > 1; depth++) {
1286
1340
  const session = byPid.get(pid);
1287
1341
  if (session !== undefined)
@@ -1294,20 +1348,20 @@ async function currentSession(sessions) {
1294
1348
  return;
1295
1349
  }
1296
1350
  // src/slot.ts
1297
- import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync3, rmSync } from "fs";
1351
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readdirSync, readFileSync as readFileSync5, rmSync } from "fs";
1298
1352
  import { availableParallelism } from "os";
1299
1353
  import { join as join8 } from "path";
1300
- import process18 from "process";
1354
+ import process19 from "process";
1301
1355
 
1302
1356
  // src/flock.ts
1303
1357
  import { closeSync, constants as constants2, ftruncateSync, openSync as openSync2, writeSync } from "fs";
1304
- import process17 from "process";
1358
+ import process18 from "process";
1305
1359
  import { dlopen, FFIType } from "bun:ffi";
1306
1360
  var LOCK_EX = 2;
1307
1361
  var LOCK_NB = 4;
1308
1362
  var flock;
1309
1363
  function native() {
1310
- 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;
1311
1365
  return flock;
1312
1366
  }
1313
1367
  function tryLock(path) {
@@ -1351,14 +1405,14 @@ function defaultSlots() {
1351
1405
  return Math.max(1, Math.floor(availableParallelism() / 2));
1352
1406
  }
1353
1407
  async function stateDir() {
1354
- const dir = process18.env.SLOT_DIR ?? await privateLogDirectory("slot");
1408
+ const dir = process19.env.SLOT_DIR ?? await privateLogDirectory("slot");
1355
1409
  for (const sub of ["slots", "locks", "waiters"])
1356
1410
  mkdirSync2(join8(dir, sub), { recursive: true, mode: 448 });
1357
1411
  return dir;
1358
1412
  }
1359
1413
  function readHolder(path) {
1360
1414
  try {
1361
- const holder = JSON.parse(readFileSync3(path, "utf8"));
1415
+ const holder = JSON.parse(readFileSync5(path, "utf8"));
1362
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;
1363
1417
  } catch {
1364
1418
  return;
@@ -1393,7 +1447,7 @@ function waitingLine(dir, wanted) {
1393
1447
  }
1394
1448
  async function holderOf(command) {
1395
1449
  const session = await currentSession(await liveSessions());
1396
- 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 } };
1397
1451
  }
1398
1452
  var waiterCount = 0;
1399
1453
  async function acquire(dir, resources, holder, deadline, timeoutMs) {
@@ -1419,7 +1473,7 @@ async function acquire(dir, resources, holder, deadline, timeoutMs) {
1419
1473
  held.release();
1420
1474
  const resource = busy.kind === "lock" ? `lock ${busy.name}` : "slot";
1421
1475
  if (waiter === undefined) {
1422
- const path = join8(dir, "waiters", `${process18.pid}-${waiterCount++}`);
1476
+ const path = join8(dir, "waiters", `${process19.pid}-${waiterCount++}`);
1423
1477
  const held = tryLock(path);
1424
1478
  if (held !== undefined) {
1425
1479
  writeHeld(held, JSON.stringify({ ...holder, resource }));
@@ -1460,7 +1514,7 @@ ${RUN_USAGE}`);
1460
1514
  const count = wholeNumber(values.slots, "slots", defaultSlots());
1461
1515
  const timeoutMs = duration(values.timeout, "timeout", Number.POSITIVE_INFINITY);
1462
1516
  const deadline = Date.now() + timeoutMs;
1463
- const holding = new Set((process18.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1517
+ const holding = new Set((process19.env[HOLDING] ?? "").split(",").filter((token) => token !== ""));
1464
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 }]];
1465
1519
  const signals = holdSignals(() => {
1466
1520
  return;
@@ -1475,7 +1529,7 @@ ${RUN_USAGE}`);
1475
1529
  const tokens = new Set([...holding, ...locks.map((name) => `lock:${name}`), ...wanted.some((resource) => resource.kind === "slot") ? ["slot"] : []]);
1476
1530
  let child;
1477
1531
  try {
1478
- 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(",") } });
1479
1533
  } catch (error) {
1480
1534
  fail(`cannot run ${rest[0]}: ${error instanceof Error ? error.message : String(error)}`, 127);
1481
1535
  }
@@ -1491,7 +1545,7 @@ ${RUN_USAGE}`);
1491
1545
  function scan(dir, state, kind) {
1492
1546
  const folder = join8(dir, kind);
1493
1547
  const entries = [];
1494
- for (const name of existsSync3(folder) ? readdirSync(folder) : []) {
1548
+ for (const name of existsSync4(folder) ? readdirSync(folder) : []) {
1495
1549
  const path = join8(folder, name);
1496
1550
  const probe = tryLock(path);
1497
1551
  if (probe !== undefined) {
@@ -1518,11 +1572,11 @@ async function listSlots(args) {
1518
1572
  printJson({ slots: count, busy, entries });
1519
1573
  return 0;
1520
1574
  }
1521
- console.log(paint(process18.stdout).bold(`slots: ${busy} of ${count} busy`));
1575
+ console.log(paint(process19.stdout).bold(`slots: ${busy} of ${count} busy`));
1522
1576
  if (entries.length > 0)
1523
- 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)])));
1524
1578
  return 0;
1525
1579
  }
1526
1580
 
1527
1581
  // src/slot-cli.ts
1528
- 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.0",
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.36.0"
41
+ "@kaynooo/cli-kit": "0.38.2"
42
42
  }
43
43
  }