cliprobe 0.0.0-stage → 0.1.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -2
  3. package/dist/cli.js +1247 -0
  4. package/package.json +88 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Khaled Saeed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,159 @@
1
- # Temporary Holding Version
1
+ # cliprobe
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Black-box tests any command-line program for terminal-edge bugs: the ones that only show up when output is piped, cut short, or read by a script or an AI agent.
4
+
5
+ ```sh
6
+ npx cliprobe -- esbuild
7
+ ```
8
+
9
+ ```
10
+ cliprobe 0.1.0: closed-pipe, color, ctrl-c, control-chars checks for esbuild
11
+
12
+ closed-pipe
13
+ FAIL esbuild --version crashed when stdout was closed (exit 0 -> 1)
14
+ Error: Command failed: .../esbuild --version (at node_modules/esbuild/bin/esbuild:222:28)
15
+ FAIL esbuild --help crashed when stdout was closed (exit 0 -> 1)
16
+ Error: Command failed: .../esbuild --help (at node_modules/esbuild/bin/esbuild:222:28)
17
+
18
+ color
19
+ PASS esbuild --version no color in a pipe or in a terminal
20
+ PASS esbuild --help colors only in a terminal, and NO_COLOR turns it off
21
+
22
+ ctrl-c
23
+ SKIP esbuild needs probe args that keep it running, such as a watch or serve command
24
+
25
+ control-chars
26
+ SKIP esbuild no {fixture} in the arguments; put it where the command takes a path, e.g. ls {fixture}
27
+
28
+ 2 failed, 0 warned, 2 passed, 2 skipped
29
+ ```
30
+
31
+ ## Why
32
+
33
+ When a program's output goes into a reader that stops early (`| head`, `grep -q`, a closed agent pipe), its next write to stdout fails. A well-behaved program exits quietly. Many Node.js CLIs instead crash with `Error: write EPIPE`, a stack trace, and exit code 1. That breaks scripts running under `set -o pipefail` and confuses agents that read stderr.
34
+
35
+ In a census of the 100 most-downloaded npm packages that ship a command (119 commands, run offline in a throwaway container), **9 crashed this way every time**: esbuild, browserslist, update-browserslist-db, autoprefixer, husky, tsconfck, ts-jest, rolldown, and tsx on `--version`. The best-known existing CLI auditor rated the first 8 as passing its SIGPIPE check. The same census found two commands that print color codes into a pipe (`giget --help`, `tsx --help`), and no false failures: every `FAIL` reproduced by hand. (A census of `--help` and `--version` can't exercise ctrl-c or control-chars, which need a command that keeps running or takes a path; their fixtures and real-tool tests are in `test/`.)
36
+
37
+ The other checks cover the rest of what goes wrong between a program and the thing reading it: color codes leaking into logs and agent transcripts, Ctrl-C that is ignored or ends in a stack trace, and file names that can send escape sequences to your terminal.
38
+
39
+ ## Usage
40
+
41
+ ```sh
42
+ npx cliprobe -- <command> # probes "<command> --version" and "<command> --help"
43
+ npx cliprobe -- <command> [args...] # probes exactly this invocation
44
+ npx cliprobe -- node ./dist/cli.js list # test your own CLI before publishing
45
+ npx cliprobe --json -- <command> # machine-readable results
46
+ npx cliprobe -- ls {fixture} # {fixture}: a directory of hostile file names
47
+ npx cliprobe --check startup,baseline -- node ./dist/cli.js # info checks, only when named
48
+ ```
49
+
50
+ | Option | Meaning |
51
+ | ----------------- | -------------------------------------------------------- |
52
+ | `--check <name>` | Run only this check; repeat it or use commas for several |
53
+ | `--json` | Print results as JSON, including the checks that ran |
54
+ | `--timeout <ms>` | Kill a probe after this long (default 15000) |
55
+ | `-h`, `--help` | Show help |
56
+ | `-v`, `--version` | Show the version |
57
+
58
+ Exit codes: `0` no failures, `1` a check failed, `2` usage error or the command could not run. That makes it usable as a CI gate.
59
+
60
+ ## Checks
61
+
62
+ A default run does the four checks below: closed-pipe, color, ctrl-c and control-chars. Each one reports evidence, never a score. Two info checks, startup and baseline, run only when you name them with `--check`.
63
+
64
+ **closed-pipe**. cliprobe runs the command twice: once normally, then with stdout set to a pipe whose reading end is already closed, so the first write fails every time, even for fast native programs. Results:
65
+
66
+ | Verdict | Meaning |
67
+ | ------- | ------------------------------------------------------------------------------ |
68
+ | `PASS` | Exited quietly, or was stopped by SIGPIPE (the Unix convention) |
69
+ | `FAIL` | Printed an EPIPE error or stack trace and changed its exit code, or hung |
70
+ | `WARN` | Printed a write error but kept its exit code |
71
+ | `SKIP` | Wrote nothing to stdout for this invocation, so pass args that print something |
72
+
73
+ **color**. cliprobe runs the command up to three times: into a pipe, under a real terminal (a pseudo-terminal through the system's `script` command, 80×24), and under a terminal with `NO_COLOR=1`. Every run gets `TERM=xterm-256color` and no `CI` variable, so a program can't pass just because the terminal type looks colorless, and color libraries that force color in CI don't fail it. Color codes in piped output end up in log files and agent transcripts as `\x1b[31m` noise. Results:
74
+
75
+ | Verdict | Meaning |
76
+ | ------- | -------------------------------------------------------------------------------------------- |
77
+ | `PASS` | No color in a pipe; in a terminal, either no color at all or color that `NO_COLOR` turns off |
78
+ | `FAIL` | Printed color or style codes (bold counts, a bare reset doesn't) to stdout in a pipe |
79
+ | `WARN` | Printed color to stderr in a pipe, or kept printing color under `NO_COLOR` |
80
+ | `SKIP` | Printed nothing, waited for input in a terminal, or no usable `script` (BusyBox) |
81
+
82
+ Many classic tools (git, BSD `ls` and `grep`) color correctly but don't implement [`NO_COLOR`](https://no-color.org), so they get a `WARN`, never a `FAIL`. Probe a command that prints color in normal use: almost no CLI colors its `--help`.
83
+
84
+ **ctrl-c**. 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:
85
+
86
+ | Verdict | Meaning |
87
+ | ------- | ---------------------------------------------------------------------------------------------- |
88
+ | `PASS` | Stopped by SIGINT, exited 130 (the convention), or exited with another failure code |
89
+ | `FAIL` | Still running 3 seconds later, or printed a stack trace or traceback after the Ctrl-C |
90
+ | `WARN` | Exited 0, so a script or an agent can't tell the work was interrupted |
91
+ | `SKIP` | Finished before the Ctrl-C, as `--version` and `--help` do: probe a command that keeps running |
92
+
93
+ 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.
94
+
95
+ **control-chars**. Put `{fixture}` in the arguments where your command takes a path, for example `npx cliprobe -- ls {fixture}` or `npx cliprobe -- node ./dist/cli.js scan --dir={fixture}`. cliprobe replaces it with a temporary directory of file names holding escape sequences (one sets the window title, one clears the screen), a C1 control character, a carriage return, a newline and a bidirectional override. It runs the command under a terminal and looks for those characters, unescaped, in what reaches it. A file name that can clear someone's screen or retitle their window is a terminal injection, the same bug class as the `ls`/`find` escaping that GNU coreutils added years ago. Reports show `{fixture}`, never the temporary path, and the directory is removed afterwards. Results:
96
+
97
+ | Verdict | Meaning |
98
+ | ------- | ----------------------------------------------------------------------------------------------------------- |
99
+ | `PASS` | Escaped or replaced the control characters (a raw bidi override is mentioned, not judged) |
100
+ | `FAIL` | Sent an escape sequence from a file name to the terminal unescaped |
101
+ | `WARN` | Printed a C1 control, carriage return or newline from a file name unescaped, which can hide or forge output |
102
+ | `SKIP` | No `{fixture}` in the arguments, the command never printed the file names, or no usable `script` |
103
+
104
+ Only the terminal run is judged. Into a pipe, `ls` and `find` print names exactly, by design; that is recorded in the JSON (`pipeRaw`) but doesn't affect the verdict. BSD `find` on macOS fails this check: unlike GNU `find`, it prints names raw even to a terminal.
105
+
106
+ ### Info checks
107
+
108
+ These report an observation with the verdict `INFO` and never fail. They run only when named, for example `--check startup,baseline`. With probe args, those args are treated as the program: `npx cliprobe --check baseline -- node ./dist/cli.js` probes `node ./dist/cli.js --version`, and so on.
109
+
110
+ **startup**. The median wall time over 5 runs, after one warm-up, of `<command> --version`, or of the probe exactly as given. It's skipped if that invocation exits non-zero.
111
+
112
+ **baseline**. Appends `--version`, `--help` and `--cliprobe-unknown-flag` to the probe and describes what scripts and agents rely on: one version line on stdout, help on stdout with exit 0, and a non-zero exit with the message on stderr for a flag the program doesn't know. A program that ignores unknown flags will run its default action (it's stopped after 5 seconds), which is why baseline never runs unless you ask for it.
113
+
114
+ ## Fixing a failure in a Node.js CLI
115
+
116
+ **closed-pipe:** handle `EPIPE` on stdout once, near your entry point:
117
+
118
+ ```js
119
+ process.stdout.on('error', (error) => {
120
+ if (error.code === 'EPIPE') process.exit(0);
121
+ throw error;
122
+ });
123
+ ```
124
+
125
+ **color:** decide once, from the stream you write to:
126
+
127
+ ```js
128
+ const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
129
+ ```
130
+
131
+ `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.
132
+
133
+ **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:
134
+
135
+ ```js
136
+ process.once('SIGINT', async () => {
137
+ await cleanUp();
138
+ process.exit(130);
139
+ });
140
+ ```
141
+
142
+ **control-chars:** escape names (and any other text you didn't write) before printing them for a person. `JSON.stringify` alone isn't enough: it leaves C1 controls and bidi overrides raw.
143
+
144
+ ```js
145
+ const shown = name.replace(
146
+ /[\x00-\x1f\x7f-\x9f]/g,
147
+ (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, '0')}`
148
+ );
149
+ ```
150
+
151
+ Also escape U+2028, U+2029 and the bidi controls (U+202A to U+202E, U+2066 to U+2069) if names may come from untrusted sources.
152
+
153
+ ## Safety
154
+
155
+ cliprobe runs the target in your current directory without a shell, with stdin closed, 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`; only the baseline check, when you name it, adds an unknown flag. It kills each run's whole process group on timeout, including under a pseudo-terminal. macOS and Linux only for now.
156
+
157
+ ## License
158
+
159
+ MIT