cliprobe 0.7.1 → 0.8.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 +19 -6
  2. package/dist/cli.js +24 -15
  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
 
@@ -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
package/dist/cli.js CHANGED
@@ -1243,26 +1243,34 @@ function listLabels$1(kinds) {
1243
1243
  const labels = kinds.map((k) => CONTROL_LABELS[k]);
1244
1244
  return labels.length <= 1 ? labels[0] ?? "" : `${labels.slice(0, -1).join(", ")} and ${labels.at(-1) ?? ""}`;
1245
1245
  }
1246
+ /**
1247
+ * Escape sequences (cursor, erase, mode, hyperlink, title, other OSC) in a pipe fail: no
1248
+ * real tool in the censuses printed one there except by mistake. A carriage-return redraw
1249
+ * alone only warns, because some tools draw a progress meter on stderr by design (curl).
1250
+ */
1246
1251
  function judgePipeEscapes(r) {
1247
1252
  if (r.spawnError) return {
1248
1253
  verdict: "error",
1249
1254
  reason: `could not start: ${r.spawnError}`
1250
1255
  };
1251
1256
  const stdout = r.stdout.toString("utf8");
1252
- const outHits = findControls(stdout);
1253
- const errHits = findControls(r.stderr);
1254
- const first = outHits[0] ? {
1257
+ const hits = [...findControls(stdout).map((hit) => ({
1255
1258
  stream: "stdout",
1256
- hit: outHits[0]
1257
- } : errHits[0] && {
1259
+ hit
1260
+ })), ...findControls(r.stderr).map((hit) => ({
1258
1261
  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
- };
1262
+ hit
1263
+ }))];
1264
+ const escape = hits.find((h) => h.hit.kind !== "redraw");
1265
+ const first = escape ?? hits[0];
1266
+ if (first) {
1267
+ const kinds = [...new Set(hits.map((h) => h.hit.kind))];
1268
+ return {
1269
+ verdict: escape ? "fail" : "warn",
1270
+ 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",
1271
+ evidence: `${first.stream} line ${first.hit.line}: ${first.hit.text}`
1272
+ };
1273
+ }
1266
1274
  if (!stdout && !r.stderr) return r.timedOut ? {
1267
1275
  verdict: "skip",
1268
1276
  reason: `${stillRunning(r.durationMs)} and printed nothing so far`
@@ -1916,9 +1924,10 @@ Checks:
1916
1924
  color Runs the command into a pipe, then under a terminal, then under
1917
1925
  a terminal with NO_COLOR=1. Fails if color codes reach a pipe;
1918
1926
  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.
1927
+ pipe-escapes Runs the command into a pipe. Fails if cursor movement, erase,
1928
+ mode switch, hyperlink or window title codes (spinners,
1929
+ progress bars, prompts) reach stdout or stderr; warns if only
1930
+ carriage returns redraw a line, as a progress meter does.
1922
1931
  stdin Runs the command with stdin as an open pipe nobody writes to,
1923
1932
  as agents and CI runners often leave it. Fails if --version or
1924
1933
  --help waits for input; for your own probes, warns if it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliprobe",
3
- "version": "0.7.1",
3
+ "version": "0.8.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": {