claude_stream_viewer 1.0.10 → 1.0.12
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 +64 -0
- package/dist/claude_stream_viewer.js +30 -13
- package/dist/claude_stream_viewer.js.map +1 -1
- package/package.json +1 -1
- package/src/claude_stream_viewer.ts +37 -15
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# claude_stream_viewer
|
|
2
|
+
|
|
3
|
+
Pretty-prints [Claude Code](https://claude.com/claude-code) `stream-json` events from stdin with colorized output. Drop it at the end of a `claude --output-format stream-json` pipe to read the stream as a human instead of as raw JSON.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20+
|
|
8
|
+
- An upstream process emitting [Claude Code stream-json events](https://docs.claude.com/en/docs/claude-code/sdk) (typically the `claude` CLI run with `--output-format stream-json`)
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g claude_stream_viewer
|
|
14
|
+
# or run on demand without installing
|
|
15
|
+
npx claude_stream_viewer
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Pipe any source of stream-json events into the viewer:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
claude --output-format stream-json --verbose --include-partial-messages \
|
|
24
|
+
--permission-mode auto -p "explain quantum computing like I'm 5" \
|
|
25
|
+
| npx claude_stream_viewer
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The viewer reads one JSON event per line from stdin and writes a colorized, human-readable rendering to stdout. It exits when stdin closes, printing `[stream ended]`.
|
|
29
|
+
|
|
30
|
+
### What it renders
|
|
31
|
+
|
|
32
|
+
| Event | Output |
|
|
33
|
+
|------------------------------------|------------------------------------------------------------------|
|
|
34
|
+
| `text_delta` (inside `stream_event`) | streamed inline as plain text — the assistant's reply |
|
|
35
|
+
| `tool_use` | `=== TOOL USE ===` header followed by the event JSON |
|
|
36
|
+
| Other `stream_event` types | `=== EVENT: <type> ===` header followed by the event JSON |
|
|
37
|
+
| Legacy `message_delta` | streamed inline as plain text |
|
|
38
|
+
| Final assistant message | `=== FINAL MESSAGE ===` header followed by each content block |
|
|
39
|
+
| Anything else | `=== UNKNOWN EVENT ===` header followed by the raw JSON |
|
|
40
|
+
|
|
41
|
+
Malformed lines are reported on stderr (`Invalid JSON: …`) without aborting the stream.
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
| Flag | Description | Default |
|
|
46
|
+
|--------------|----------------------------|---------|
|
|
47
|
+
| `--no-color` | Disable colored output | colored |
|
|
48
|
+
| `--version` | Print the package version | — |
|
|
49
|
+
| `--help` | Print usage help | — |
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cd packages/claude_stream_viewer
|
|
55
|
+
npm install
|
|
56
|
+
npm run dev # tsx ./src/claude_stream_viewer.ts
|
|
57
|
+
npm run build # compile TypeScript → dist/
|
|
58
|
+
npm run typecheck # type-check without emitting
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Output
|
|
62
|
+
|
|
63
|
+
- Rendered events are written to **stdout**.
|
|
64
|
+
- Parse errors and processing errors are written to **stderr**; the process keeps reading.
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Reads Claude API stream-json events line-by-line from stdin and pretty-prints
|
|
3
3
|
// them with colorized output. Designed to wrap an upstream `claude --stream-json`
|
|
4
|
-
// pipe, e.g. `claude … | claude_stream_viewer`.
|
|
4
|
+
// pipe, e.g. `claude … | npx claude_stream_viewer`.
|
|
5
|
+
// Usage:
|
|
6
|
+
// claude --stream-json | npx claude_stream_viewer
|
|
7
|
+
//
|
|
8
|
+
// claude --output-format stream-json --verbose --include-partial-messages --permission-mode auto -p "explain quantum computing like I'm 5" | npx claude_stream_viewer
|
|
5
9
|
import Readline from 'node:readline';
|
|
6
|
-
import
|
|
10
|
+
import Fs from 'node:fs';
|
|
11
|
+
import * as Commander from 'commander';
|
|
7
12
|
import Chalk from 'chalk';
|
|
13
|
+
import Path from 'node:path';
|
|
14
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
|
8
15
|
const colors = {
|
|
9
16
|
text: Chalk.white,
|
|
10
17
|
tool: Chalk.cyan,
|
|
@@ -19,16 +26,6 @@ const colors = {
|
|
|
19
26
|
///////////////////////////////////////////////////////////////////////////////
|
|
20
27
|
///////////////////////////////////////////////////////////////////////////////
|
|
21
28
|
class MainHelper {
|
|
22
|
-
static parseCliOptions() {
|
|
23
|
-
const program = new Command();
|
|
24
|
-
program
|
|
25
|
-
.name('claude_stream_viewer')
|
|
26
|
-
.description('Pretty-prints Claude API stream-json events from stdin with colorized output.')
|
|
27
|
-
.version('1.0.9')
|
|
28
|
-
.option('--no-color', 'disable colored output')
|
|
29
|
-
.parse(process.argv);
|
|
30
|
-
return program.opts();
|
|
31
|
-
}
|
|
32
29
|
static printText(text) {
|
|
33
30
|
process.stdout.write(colors.text(text));
|
|
34
31
|
}
|
|
@@ -101,7 +98,27 @@ class MainHelper {
|
|
|
101
98
|
///////////////////////////////////////////////////////////////////////////////
|
|
102
99
|
///////////////////////////////////////////////////////////////////////////////
|
|
103
100
|
async function main() {
|
|
104
|
-
const
|
|
101
|
+
const packageJsonPath = Path.join(__dirname, '..', 'package.json');
|
|
102
|
+
const packageJson = JSON.parse(await Fs.promises.readFile(packageJsonPath, 'utf-8'));
|
|
103
|
+
const packageVersion = packageJson.version ?? 'unknown';
|
|
104
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
105
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
106
|
+
//
|
|
107
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
108
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
109
|
+
const program = new Commander.Command();
|
|
110
|
+
program
|
|
111
|
+
.name('claude_stream_viewer')
|
|
112
|
+
.description('Pretty-prints Claude API stream-json events from stdin with colorized output.')
|
|
113
|
+
.version(packageVersion)
|
|
114
|
+
.option('--no-color', 'disable colored output')
|
|
115
|
+
.parse(process.argv);
|
|
116
|
+
const options = program.opts();
|
|
117
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
118
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
119
|
+
//
|
|
120
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
121
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
105
122
|
if (options.color === false) {
|
|
106
123
|
Chalk.level = 0;
|
|
107
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude_stream_viewer.js","sourceRoot":"","sources":["../src/claude_stream_viewer.ts"],"names":[],"mappings":";AAEA,gFAAgF;AAChF,kFAAkF;AAClF,
|
|
1
|
+
{"version":3,"file":"claude_stream_viewer.js","sourceRoot":"","sources":["../src/claude_stream_viewer.ts"],"names":[],"mappings":";AAEA,gFAAgF;AAChF,kFAAkF;AAClF,oDAAoD;AACpD,SAAS;AACT,oDAAoD;AACpD,EAAE;AACF,sKAAsK;AAGtK,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;AA6BzD,MAAM,MAAM,GAAG;IACd,IAAI,EAAE,KAAK,CAAC,KAAK;IACjB,IAAI,EAAE,KAAK,CAAC,IAAI;IAChB,MAAM,EAAE,KAAK,CAAC,IAAI;IAClB,KAAK,EAAE,KAAK,CAAC,GAAG;IAChB,IAAI,EAAE,KAAK,CAAC,GAAG;IACf,M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AAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC5B,sEAAsE;QACtE,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,OAAO;QAE/B,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,UAAU,CAAC,YAAY,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;YAC/C,OAAO,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,+EAA+E;AAC/E,GAAG;AACH,+EAA+E;AAC/E,+EAA+E;AAE/E,MAAM,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,11 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
// Reads Claude API stream-json events line-by-line from stdin and pretty-prints
|
|
4
4
|
// them with colorized output. Designed to wrap an upstream `claude --stream-json`
|
|
5
|
-
// pipe, e.g. `claude … | claude_stream_viewer`.
|
|
5
|
+
// pipe, e.g. `claude … | npx claude_stream_viewer`.
|
|
6
|
+
// Usage:
|
|
7
|
+
// claude --stream-json | npx claude_stream_viewer
|
|
8
|
+
//
|
|
9
|
+
// claude --output-format stream-json --verbose --include-partial-messages --permission-mode auto -p "explain quantum computing like I'm 5" | npx claude_stream_viewer
|
|
10
|
+
|
|
6
11
|
|
|
7
12
|
import Readline from 'node:readline';
|
|
8
|
-
import
|
|
13
|
+
import Fs from 'node:fs';
|
|
14
|
+
import * as Commander from 'commander';
|
|
9
15
|
import Chalk from 'chalk';
|
|
16
|
+
import Path from 'node:path';
|
|
17
|
+
|
|
18
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
|
10
19
|
|
|
11
20
|
type CliOptions = {
|
|
12
21
|
color: boolean;
|
|
@@ -51,18 +60,6 @@ const colors = {
|
|
|
51
60
|
///////////////////////////////////////////////////////////////////////////////
|
|
52
61
|
|
|
53
62
|
class MainHelper {
|
|
54
|
-
static parseCliOptions(): CliOptions {
|
|
55
|
-
const program = new Command();
|
|
56
|
-
program
|
|
57
|
-
.name('claude_stream_viewer')
|
|
58
|
-
.description('Pretty-prints Claude API stream-json events from stdin with colorized output.')
|
|
59
|
-
.version('1.0.9')
|
|
60
|
-
.option('--no-color', 'disable colored output')
|
|
61
|
-
.parse(process.argv);
|
|
62
|
-
|
|
63
|
-
return program.opts<CliOptions>();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
63
|
static printText(text: string) {
|
|
67
64
|
process.stdout.write(colors.text(text));
|
|
68
65
|
}
|
|
@@ -146,7 +143,32 @@ class MainHelper {
|
|
|
146
143
|
///////////////////////////////////////////////////////////////////////////////
|
|
147
144
|
|
|
148
145
|
async function main(): Promise<void> {
|
|
149
|
-
|
|
146
|
+
|
|
147
|
+
const packageJsonPath = Path.join(__dirname, '..', 'package.json');
|
|
148
|
+
const packageJson: object = JSON.parse(await Fs.promises.readFile(packageJsonPath, 'utf-8'))
|
|
149
|
+
const packageVersion = (packageJson as { version?: string }).version ?? 'unknown';
|
|
150
|
+
|
|
151
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
152
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
153
|
+
//
|
|
154
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
155
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
156
|
+
|
|
157
|
+
const program = new Commander.Command();
|
|
158
|
+
program
|
|
159
|
+
.name('claude_stream_viewer')
|
|
160
|
+
.description('Pretty-prints Claude API stream-json events from stdin with colorized output.')
|
|
161
|
+
.version(packageVersion)
|
|
162
|
+
.option('--no-color', 'disable colored output')
|
|
163
|
+
.parse(process.argv);
|
|
164
|
+
|
|
165
|
+
const options = program.opts<CliOptions>();
|
|
166
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
167
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
168
|
+
//
|
|
169
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
170
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
171
|
+
|
|
150
172
|
if (options.color === false) {
|
|
151
173
|
Chalk.level = 0;
|
|
152
174
|
}
|