cliprobe 0.7.1 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +26 -11
  2. package/dist/cli.js +33 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -196,13 +196,14 @@ Many classic tools (git, BSD `ls` and `grep`) color correctly but don't implemen
196
196
 
197
197
  cliprobe runs the command into a pipe, with the same environment as the color check, and looks at stdout and stderr for terminal control codes that only make sense on a screen: cursor movement, line and screen erases, mode switches such as hiding the cursor, hyperlinks (OSC 8), window titles, and carriage returns that redraw a line. Spinners and progress bars are the usual source. In a pipe they turn logs and agent transcripts into `\r\x1b[2K` noise. Results:
198
198
 
199
- | Verdict | Meaning |
200
- | ------- | -------------------------------------------------------------------------- |
201
- | `PASS` | None of those codes reached the pipe (color is the color check's business) |
202
- | `WARN` | One or more reached stdout or stderr; the reason lists which kinds |
203
- | `SKIP` | Printed nothing |
199
+ | Verdict | Meaning |
200
+ | ------- | --------------------------------------------------------------------------------- |
201
+ | `PASS` | None of those codes reached the pipe (color is the color check's business) |
202
+ | `FAIL` | An escape sequence reached stdout or stderr; the reason lists which kinds |
203
+ | `WARN` | Only carriage returns reached the pipe, redrawing a line as a progress meter does |
204
+ | `SKIP` | Printed nothing |
204
205
 
205
- It only warns for now, never fails. In the census of the top 100 npm CLIs, no `--help` or `--version` printed any of these codes, which says nothing about their spinners: probe a command that does real work, such as an install or a build. With `{fixture}` in the args, the hostile file names themselves are left to the control-chars check: a lister that prints them raw into a pipe, as `ls` does, isn't warned about.
206
+ A carriage-return redraw only warns because some tools draw a progress meter on stderr into a pipe by design: curl does, unless you pass `-s`. Before this check could fail, it ran on 78 commands doing real work (builds, linters, test runners, scaffolders, package managers and system tools) and 38 watch modes and dev servers, offline in a throwaway container. Every escape sequence it found was a real bug, such as a prompt hiding the cursor in a pipe (`changeset init`), `mocha --watch` hiding the cursor and `tsc --watch` clearing the screen; none was a false failure. Probe a command that does real work, such as an install or a build: `--help` and `--version` rarely draw spinners. With `{fixture}` in the args, the hostile file names themselves are left to the control-chars check: a lister that prints them raw into a pipe, as `ls` does, passes. If the codes come from data you passed in (a file you `cat`), they are yours, not the program's.
206
207
 
207
208
  ### stdin
208
209
 
@@ -219,7 +220,7 @@ In the census of the top 100 npm CLIs, 9 of 238 `--help` and `--version` runs fa
219
220
 
220
221
  ### ctrl-c
221
222
 
222
- cliprobe lets the command run for 1 second, then sends SIGINT to its process group, which is what a terminal does when you press Ctrl-C, and gives it 3 seconds to exit. Results:
223
+ cliprobe lets the command run for 1 second, then sends SIGINT to its process group, which is what a terminal does when you press Ctrl-C, and gives it 3 seconds to exit. stdin is left open, as a terminal leaves it, so a server that stops at the end of stdin (`esbuild --serve`) keeps running until the Ctrl-C. Results:
223
224
 
224
225
  | Verdict | Meaning |
225
226
  | ------- | ---------------------------------------------------------------------------------------------- |
@@ -228,7 +229,7 @@ cliprobe lets the command run for 1 second, then sends SIGINT to its process gro
228
229
  | `WARN` | Exited 0, so a script or an agent can't tell the work was interrupted |
229
230
  | `SKIP` | Finished before the Ctrl-C, as `--version` and `--help` do: probe a command that keeps running |
230
231
 
231
- A stack trace printed before the Ctrl-C doesn't count. Python's default `KeyboardInterrupt` traceback is the classic failure here, so `python3 -c 'import time; time.sleep(30)'` fails.
232
+ A stack trace printed before the Ctrl-C doesn't count. Python's default `KeyboardInterrupt` traceback is the classic failure here, so `python3 -c 'import time; time.sleep(30)'` fails. Across 42 watch modes, dev servers and long tasks run offline (vite, webpack, tsc, jest, Next.js, Nuxt, Astro, wrangler, nodemon and more), every one stopped within 60 ms of the Ctrl-C, whether it came after 1, 3 or 6 seconds, so the timing rarely matters. 13 of them exit 0 on purpose, among them `tsc --watch`, webpack, `next dev` and `nuxt dev`: that is a warn, not a fail.
232
233
 
233
234
  ### restore
234
235
 
@@ -282,6 +283,18 @@ const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
282
283
 
283
284
  `util.styleText` makes that decision for you on Node 22.13 and later (its `validateStream` option, on by default), and most color libraries check `isTTY` already, but some turn color on whenever `TERM` allows it or `CI` is set.
284
285
 
286
+ **pipe-escapes:** draw spinners, progress bars and prompts only when the stream is a terminal, and print plain lines otherwise:
287
+
288
+ ```js
289
+ if (process.stderr.isTTY) {
290
+ startSpinner(); // frames, \r and cursor codes only on a terminal
291
+ } else {
292
+ console.error('building...'); // one plain line per step in a pipe
293
+ }
294
+ ```
295
+
296
+ Most spinner libraries check `isTTY` already. Prompt libraries may not, so check `process.stdin.isTTY` before asking anything (see stdin below).
297
+
285
298
  **stdin:** look at your arguments before reading stdin, so `--help` and `--version` answer at once, and only prompt when stdin is a terminal:
286
299
 
287
300
  ```js
@@ -289,15 +302,17 @@ if (process.stdin.isTTY) askTheQuestion();
289
302
  else useTheDefault(); // or fail with a message saying which flag to pass
290
303
  ```
291
304
 
292
- **ctrl-c:** Node's default already does the right thing, dying by SIGINT. If you add a handler to clean up, finish by exiting 130 rather than 0, and don't throw from it:
305
+ **ctrl-c:** Node's default already does the right thing, dying by SIGINT. If you add a handler to clean up, finish by dying the same way, and don't throw from it:
293
306
 
294
307
  ```js
295
308
  process.once('SIGINT', async () => {
296
309
  await cleanUp();
297
- process.exit(130);
310
+ process.kill(process.pid, 'SIGINT'); // the handler is gone, so this ends the process
298
311
  });
299
312
  ```
300
313
 
314
+ That matters to the shell that started you: bash stops a script on Ctrl-C only when the program died by the signal. After an exit with 130 or 0, the script carries on to its next command; 130 at least stops `&&` chains and `set -e`, which 0 doesn't.
315
+
301
316
  **restore:** switch every mode back off on the way out, including after Ctrl-C. Node runs `exit` handlers on `process.exit()` but not when a signal kills it, so turn SIGINT into an exit, and in raw mode, where Ctrl-C arrives as the key `\x03`, exit on that key too:
302
317
 
303
318
  ```js
@@ -319,7 +334,7 @@ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+
319
334
 
320
335
  ## Safety
321
336
 
322
- cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin check also uses a pipe that it never writes to), a temporary `HOME`, and a minimal environment (no tokens from your shell). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal. It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command, which Alpine ships in `util-linux-misc`. Windows isn't supported yet.
337
+ cliprobe runs the target in your current directory without a shell, with stdin closed (`/dev/null`; the stdin and ctrl-c checks use a pipe that they never write to), a temporary `HOME`, and a minimal environment (no tokens from your shell). It still executes the program, so only probe programs you trust. By default cliprobe passes only the arguments you give, or `--version` and `--help`, or none with `--bare`; only the baseline check, when you name it, adds an unknown flag. The only input it ever sends is Ctrl-C, from the ctrl-c and restore checks, to probes you write. It kills each run's whole process group on timeout, including under a pseudo-terminal. It runs on macOS and Linux, including Alpine; the terminal checks need the `script` command, which Alpine ships in `util-linux-misc`. Windows isn't supported yet.
323
338
 
324
339
  ## Contributing
325
340
 
package/dist/cli.js CHANGED
@@ -1197,7 +1197,8 @@ async function ctrlC(command, args) {
1197
1197
  signal: {
1198
1198
  name: "SIGINT",
1199
1199
  afterMs: CTRL_C_DELAY_MS
1200
- }
1200
+ },
1201
+ stdin: "open"
1201
1202
  });
1202
1203
  const sent = r.signalSentMs;
1203
1204
  return {
@@ -1243,26 +1244,34 @@ function listLabels$1(kinds) {
1243
1244
  const labels = kinds.map((k) => CONTROL_LABELS[k]);
1244
1245
  return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
1245
1246
  }
1247
+ /**
1248
+ * Escape sequences (cursor, erase, mode, hyperlink, title, other OSC) in a pipe fail: no
1249
+ * real tool in the censuses printed one there except by mistake. A carriage-return redraw
1250
+ * alone only warns, because some tools draw a progress meter on stderr by design (curl).
1251
+ */
1246
1252
  function judgePipeEscapes(r) {
1247
1253
  if (r.spawnError) return {
1248
1254
  verdict: "error",
1249
1255
  reason: `could not start: ${r.spawnError}`
1250
1256
  };
1251
1257
  const stdout = r.stdout.toString("utf8");
1252
- const outHits = findControls(stdout);
1253
- const errHits = findControls(r.stderr);
1254
- const first = outHits[0] ? {
1258
+ const hits = [...findControls(stdout).map((hit) => ({
1255
1259
  stream: "stdout",
1256
- hit: outHits[0]
1257
- } : errHits[0] && {
1260
+ hit
1261
+ })), ...findControls(r.stderr).map((hit) => ({
1258
1262
  stream: "stderr",
1259
- hit: errHits[0]
1260
- };
1261
- if (first) return {
1262
- verdict: "warn",
1263
- reason: `printed terminal control codes into a pipe: ${listLabels$1([.../* @__PURE__ */ new Set([...kindsOf(outHits), ...kindsOf(errHits)])])}`,
1264
- evidence: `${first.stream} line ${first.hit.line}: ${first.hit.text}`
1265
- };
1263
+ hit
1264
+ }))];
1265
+ const escape = hits.find((h) => h.hit.kind !== "redraw");
1266
+ const first = escape ?? hits[0];
1267
+ if (first) {
1268
+ const kinds = [...new Set(hits.map((h) => h.hit.kind))];
1269
+ return {
1270
+ verdict: escape ? "fail" : "warn",
1271
+ reason: escape ? `printed terminal control codes into a pipe: ${listLabels$1(kinds)}` : "redrew lines with carriage returns in a pipe, as a progress meter does",
1272
+ evidence: `${first.stream} line ${first.hit.line}: ${first.hit.text}`
1273
+ };
1274
+ }
1266
1275
  if (!stdout && !r.stderr) return r.timedOut ? {
1267
1276
  verdict: "skip",
1268
1277
  reason: `${stillRunning(r.durationMs)} and printed nothing so far`
@@ -1916,17 +1925,19 @@ Checks:
1916
1925
  color Runs the command into a pipe, then under a terminal, then under
1917
1926
  a terminal with NO_COLOR=1. Fails if color codes reach a pipe;
1918
1927
  warns if color goes to a piped stderr or NO_COLOR is ignored.
1919
- pipe-escapes Runs the command into a pipe and warns if cursor movement,
1920
- erase, hyperlink, window title or carriage-return redraw
1921
- codes (spinners, progress bars) reach stdout or stderr.
1928
+ pipe-escapes Runs the command into a pipe. Fails if cursor movement, erase,
1929
+ mode switch, hyperlink or window title codes (spinners,
1930
+ progress bars, prompts) reach stdout or stderr; warns if only
1931
+ carriage returns redraw a line, as a progress meter does.
1922
1932
  stdin Runs the command with stdin as an open pipe nobody writes to,
1923
1933
  as agents and CI runners often leave it. Fails if --version or
1924
1934
  --help waits for input; for your own probes, warns if it
1925
1935
  prompts and skips if it reads stdin like a filter.
1926
- ctrl-c Sends Ctrl-C (SIGINT) after 1 s. Fails if the command is still
1927
- running 3 s later or prints a stack trace; warns if it exits 0.
1928
- Skipped when the command finishes first, so probe a command
1929
- that keeps running (a watcher, a server, a long task).
1936
+ ctrl-c Sends Ctrl-C (SIGINT) after 1 s, with stdin left open as in a
1937
+ terminal. Fails if the command is still running 3 s later or
1938
+ prints a stack trace; warns if it exits 0. Skipped when the
1939
+ command finishes first, so probe a command that keeps running
1940
+ (a watcher, a server, a long task).
1930
1941
  restore Runs the command under a terminal and, for your own probes,
1931
1942
  types Ctrl-C after 1 s, as a person would. Warns if it leaves
1932
1943
  the cursor hidden, the alternate screen, mouse or focus
@@ -1964,8 +1975,8 @@ Options:
1964
1975
 
1965
1976
  Exit codes: 0 no failures, 1 a check failed, 2 usage error or could not run.
1966
1977
  Runs the target in the current directory without a shell, with stdin closed
1967
- (the stdin check uses a pipe it never writes to), a temporary HOME and a
1968
- minimal environment. Only run programs you trust.`;
1978
+ (the stdin and ctrl-c checks use a pipe they never write to), a temporary HOME
1979
+ and a minimal environment. Only run programs you trust.`;
1969
1980
  // src/cli/program.ts
1970
1981
  /** 0 no failures, 1 a check failed, 2 nothing could be judged because something could not run. */
1971
1982
  function exitCodeFor(results) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "description": "Black-box test any command-line program for terminal-edge bugs: crashes on a closed pipe (| head), color and control codes leaking into pipes, hangs waiting on stdin, broken Ctrl-C handling, a terminal left broken after Ctrl-C, and control characters from file names reaching your terminal.",
5
5
  "type": "module",
6
6
  "bin": {