claude_stream_viewer 1.0.16 → 1.0.18

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 (59) hide show
  1. package/README.md +38 -10
  2. package/demo_vhs/claude_stream_viewer.gif +0 -0
  3. package/dist/cli.js +46 -364
  4. package/dist/cli.js.map +1 -1
  5. package/dist/libs/colors.d.ts +15 -0
  6. package/dist/libs/colors.d.ts.map +1 -0
  7. package/dist/libs/colors.js +16 -0
  8. package/dist/libs/colors.js.map +1 -0
  9. package/dist/libs/terminal_output.d.ts +8 -0
  10. package/dist/libs/terminal_output.d.ts.map +1 -0
  11. package/dist/libs/terminal_output.js +13 -0
  12. package/dist/libs/terminal_output.js.map +1 -0
  13. package/dist/log_viewer/log_renderer.d.ts +28 -0
  14. package/dist/log_viewer/log_renderer.d.ts.map +1 -0
  15. package/dist/log_viewer/log_renderer.js +163 -0
  16. package/dist/log_viewer/log_renderer.js.map +1 -0
  17. package/dist/log_viewer/tool_input_formatter.d.ts +31 -0
  18. package/dist/log_viewer/tool_input_formatter.d.ts.map +1 -0
  19. package/dist/log_viewer/tool_input_formatter.js +190 -0
  20. package/dist/log_viewer/tool_input_formatter.js.map +1 -0
  21. package/dist/stats/stats_collector.d.ts +28 -0
  22. package/dist/stats/stats_collector.d.ts.map +1 -0
  23. package/dist/stats/stats_collector.js +165 -0
  24. package/dist/stats/stats_collector.js.map +1 -0
  25. package/dist/stats/stats_renderer.d.ts +13 -0
  26. package/dist/stats/stats_renderer.d.ts.map +1 -0
  27. package/dist/stats/stats_renderer.js +193 -0
  28. package/dist/stats/stats_renderer.js.map +1 -0
  29. package/dist/types/claude_event.d.ts +75 -0
  30. package/dist/types/claude_event.d.ts.map +1 -0
  31. package/dist/types/claude_event.js +2 -0
  32. package/dist/types/claude_event.js.map +1 -0
  33. package/dist/types/stats_report.d.ts +68 -0
  34. package/dist/types/stats_report.d.ts.map +1 -0
  35. package/dist/types/stats_report.js +2 -0
  36. package/dist/types/stats_report.js.map +1 -0
  37. package/package.json +4 -5
  38. package/src/cli.ts +53 -409
  39. package/src/libs/colors.ts +16 -0
  40. package/src/libs/terminal_output.ts +14 -0
  41. package/src/log_viewer/log_renderer.ts +160 -0
  42. package/src/log_viewer/tool_input_formatter.ts +183 -0
  43. package/src/stats/stats_collector.ts +175 -0
  44. package/src/stats/stats_renderer.ts +185 -0
  45. package/src/types/claude_event.ts +74 -0
  46. package/src/types/stats_report.ts +66 -0
  47. package/dist/claude-stream-viewer.d.ts +0 -3
  48. package/dist/claude-stream-viewer.d.ts.map +0 -1
  49. package/dist/claude-stream-viewer.js +0 -100
  50. package/dist/claude-stream-viewer.js.map +0 -1
  51. package/dist/claude_stream_viewer copy.d.ts +0 -3
  52. package/dist/claude_stream_viewer copy.d.ts.map +0 -1
  53. package/dist/claude_stream_viewer copy.js +0 -228
  54. package/dist/claude_stream_viewer copy.js.map +0 -1
  55. package/dist/claude_stream_viewer.d.ts +0 -3
  56. package/dist/claude_stream_viewer.d.ts.map +0 -1
  57. package/dist/claude_stream_viewer.js +0 -155
  58. package/dist/claude_stream_viewer.js.map +0 -1
  59. package/src/claude_stream_viewer copy.ts +0 -287
@@ -0,0 +1,13 @@
1
+ import { colors } from './colors.js';
2
+ /** Builds the colorized string primitives shared by the log and stats renderers. */
3
+ export class TerminalOutput {
4
+ /** Returns a colorized `=== LABEL ===` section header, preceded by a blank line. */
5
+ static header(label) {
6
+ return colors.header(`\n=== ${label} ===`);
7
+ }
8
+ /** Returns a dimmed, pretty-printed (2-space) JSON rendering of `obj`. */
9
+ static json(obj) {
10
+ return colors.json(JSON.stringify(obj, null, 2));
11
+ }
12
+ }
13
+ //# sourceMappingURL=terminal_output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminal_output.js","sourceRoot":"","sources":["../../src/libs/terminal_output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,oFAAoF;AACpF,MAAM,OAAO,cAAc;IAC1B,oFAAoF;IACpF,MAAM,CAAC,MAAM,CAAC,KAAa;QAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,SAAS,KAAK,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,0EAA0E;IAC1E,MAAM,CAAC,IAAI,CAAC,GAAY;QACvB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;CACD"}
@@ -0,0 +1,28 @@
1
+ import type { ClaudeEvent } from '../types/claude_event.js';
2
+ /**
3
+ * Renders consolidated stream events to stdout as a colorized, human-readable
4
+ * log.
5
+ *
6
+ * Holds per-stream state (a `tool_use_id` → tool-name map used to label tool
7
+ * results), so a fresh instance should be created per stream.
8
+ */
9
+ export declare class LogRenderer {
10
+ private toolNamesById;
11
+ /**
12
+ * Renders a single event to stdout. `stream_event` envelopes are skipped and
13
+ * unrecognized event types are dumped as raw JSON under a generic header.
14
+ */
15
+ render(event: ClaudeEvent): void;
16
+ private printHeader;
17
+ private printJSON;
18
+ private renderSystem;
19
+ private renderAssistant;
20
+ private renderAssistantBlock;
21
+ private renderToolUse;
22
+ private renderUser;
23
+ private renderToolResult;
24
+ private static toolResultToText;
25
+ private renderRateLimit;
26
+ private renderResult;
27
+ }
28
+ //# sourceMappingURL=log_renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_renderer.d.ts","sourceRoot":"","sources":["../../src/log_viewer/log_renderer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAA2B,MAAM,0BAA0B,CAAC;AAKrF;;;;;;GAMG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,aAAa,CAA6B;IAElD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW;IAYzB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAM/B,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,YAAY;CAWpB"}
@@ -0,0 +1,163 @@
1
+ import { colors } from '../libs/colors.js';
2
+ import { TerminalOutput } from '../libs/terminal_output.js';
3
+ import { ToolInputFormatter } from './tool_input_formatter.js';
4
+ /** Tool results longer than this many lines are truncated in the log. */
5
+ const MAX_TOOL_RESULT_LINES = 40;
6
+ /**
7
+ * Renders consolidated stream events to stdout as a colorized, human-readable
8
+ * log.
9
+ *
10
+ * Holds per-stream state (a `tool_use_id` → tool-name map used to label tool
11
+ * results), so a fresh instance should be created per stream.
12
+ */
13
+ export class LogRenderer {
14
+ constructor() {
15
+ this.toolNamesById = new Map();
16
+ }
17
+ /**
18
+ * Renders a single event to stdout. `stream_event` envelopes are skipped and
19
+ * unrecognized event types are dumped as raw JSON under a generic header.
20
+ */
21
+ render(event) {
22
+ const type = event.type;
23
+ if (type === 'stream_event')
24
+ return;
25
+ if (type === 'system')
26
+ return this.renderSystem(event);
27
+ if (type === 'assistant')
28
+ return this.renderAssistant(event);
29
+ if (type === 'user')
30
+ return this.renderUser(event);
31
+ if (type === 'rate_limit_event')
32
+ return this.renderRateLimit(event);
33
+ if (type === 'result')
34
+ return this.renderResult(event);
35
+ this.printHeader(`${type ?? 'unknown'}`);
36
+ this.printJSON(event);
37
+ }
38
+ printHeader(label) {
39
+ console.log(TerminalOutput.header(label));
40
+ }
41
+ printJSON(obj) {
42
+ console.log(TerminalOutput.json(obj));
43
+ }
44
+ renderSystem(event) {
45
+ if (event.subtype !== 'init') {
46
+ this.printHeader(`SYSTEM: ${event.subtype ?? 'unknown'}`);
47
+ this.printJSON(event);
48
+ return;
49
+ }
50
+ this.printHeader('SESSION');
51
+ const sessionPrefix = event.session_id !== undefined ? event.session_id.slice(0, 8) : 'unknown';
52
+ const toolsCount = event.tools !== undefined ? event.tools.length : 0;
53
+ console.log(colors.system(`model: ${event.model ?? 'unknown'}`));
54
+ console.log(colors.system(`cwd: ${event.cwd ?? 'unknown'}`));
55
+ console.log(colors.system(`tools: ${toolsCount}`));
56
+ console.log(colors.system(`session: ${sessionPrefix}`));
57
+ if (event.claude_code_version !== undefined) {
58
+ console.log(colors.system(`claude-code: v${event.claude_code_version}`));
59
+ }
60
+ }
61
+ renderAssistant(event) {
62
+ const content = event.message?.content;
63
+ if (content === undefined)
64
+ return;
65
+ for (const block of content) {
66
+ this.renderAssistantBlock(block);
67
+ }
68
+ }
69
+ renderAssistantBlock(block) {
70
+ if (block.type === 'thinking') {
71
+ console.log(colors.system('\n--- thinking ---'));
72
+ console.log(colors.thinking(block.thinking ?? ''));
73
+ return;
74
+ }
75
+ if (block.type === 'text') {
76
+ console.log(colors.text(`\n${block.text ?? ''}`));
77
+ return;
78
+ }
79
+ if (block.type === 'tool_use') {
80
+ this.renderToolUse(block);
81
+ return;
82
+ }
83
+ console.log(colors.system(`\n[assistant block: ${block.type ?? 'unknown'}]`));
84
+ this.printJSON(block);
85
+ }
86
+ renderToolUse(block) {
87
+ const name = block.name ?? 'tool';
88
+ if (block.id !== undefined) {
89
+ this.toolNamesById.set(block.id, name);
90
+ }
91
+ console.log(colors.tool(`\n→ ${name}`));
92
+ const rawInput = block.input;
93
+ const input = (rawInput !== null && typeof rawInput === 'object')
94
+ ? rawInput
95
+ : {};
96
+ const bodyLines = ToolInputFormatter.format(name, input);
97
+ for (const line of bodyLines) {
98
+ console.log(` ${line}`);
99
+ }
100
+ }
101
+ renderUser(event) {
102
+ const content = event.message?.content;
103
+ if (content === undefined)
104
+ return;
105
+ for (const block of content) {
106
+ if (block.type === 'tool_result') {
107
+ this.renderToolResult(block);
108
+ continue;
109
+ }
110
+ console.log(colors.system(`\n[user block: ${block.type ?? 'unknown'}]`));
111
+ this.printJSON(block);
112
+ }
113
+ }
114
+ renderToolResult(block) {
115
+ const toolName = block.tool_use_id !== undefined
116
+ ? this.toolNamesById.get(block.tool_use_id) ?? block.tool_use_id.slice(0, 12)
117
+ : 'unknown';
118
+ const isError = block.is_error === true;
119
+ const label = isError ? `← ${toolName} ERROR` : `← ${toolName} result`;
120
+ console.log(colors.tool(`\n${label}`));
121
+ const text = LogRenderer.toolResultToText(block.content);
122
+ const lines = text.split('\n');
123
+ const colorFn = isError ? colors.error : colors.text;
124
+ if (lines.length <= MAX_TOOL_RESULT_LINES) {
125
+ console.log(colorFn(text));
126
+ return;
127
+ }
128
+ const head = lines.slice(0, MAX_TOOL_RESULT_LINES).join('\n');
129
+ const moreCount = lines.length - MAX_TOOL_RESULT_LINES;
130
+ console.log(colorFn(head));
131
+ console.log(colors.system(`… (truncated, ${moreCount} more lines)`));
132
+ }
133
+ static toolResultToText(content) {
134
+ if (content === undefined)
135
+ return '';
136
+ if (typeof content === 'string')
137
+ return content;
138
+ return content.map((b) => b.text ?? '').join('');
139
+ }
140
+ renderRateLimit(event) {
141
+ const status = event.rate_limit_info?.status ?? 'unknown';
142
+ console.log(colors.system(`\n[rate_limit] ${status}`));
143
+ }
144
+ renderResult(event) {
145
+ this.printHeader('RESULT');
146
+ if (event.terminal_reason !== undefined)
147
+ console.log(colors.system(`terminal_reason: ${event.terminal_reason}`));
148
+ if (event.stop_reason !== undefined)
149
+ console.log(colors.system(`stop_reason: ${event.stop_reason}`));
150
+ if (event.is_error === true)
151
+ console.log(colors.error('is_error: true'));
152
+ const denials = event.permission_denials;
153
+ if (denials !== undefined && denials.length > 0)
154
+ console.log(colors.system(`permission_denials: ${denials.length}`));
155
+ if (event.num_turns !== undefined)
156
+ console.log(colors.system(`turns: ${event.num_turns}`));
157
+ if (event.duration_ms !== undefined)
158
+ console.log(colors.system(`duration: ${(event.duration_ms / 1000).toFixed(2)}s`));
159
+ if (event.total_cost_usd !== undefined)
160
+ console.log(colors.system(`cost: $${event.total_cost_usd.toFixed(4)}`));
161
+ }
162
+ }
163
+ //# sourceMappingURL=log_renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log_renderer.js","sourceRoot":"","sources":["../../src/log_viewer/log_renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,yEAAyE;AACzE,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IAAxB;QACS,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IA+InD,CAAC;IA7IA;;;OAGG;IACH,MAAM,CAAC,KAAkB;QACxB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IAAI,IAAI,KAAK,cAAc;YAAE,OAAO;QACpC,IAAI,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7D,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACnD,IAAI,IAAI,KAAK,kBAAkB;YAAE,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACvD,IAAI,CAAC,WAAW,CAAC,GAAG,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAEO,WAAW,CAAC,KAAa;QAChC,OAAO,CAAC,GAAG,CAAC,cAAc,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AE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC3F,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACvH,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjH,CAAC;CACD"}
@@ -0,0 +1,31 @@
1
+ import type { ToolInput } from '../types/claude_event.js';
2
+ /**
3
+ * Renders a `tool_use` block's input into compact, human-readable lines — one
4
+ * dedicated formatter per known tool (Bash, Read, Grep, …).
5
+ */
6
+ export declare class ToolInputFormatter {
7
+ /**
8
+ * Formats a tool's input into display lines, dispatched by tool name.
9
+ * Unrecognized tools fall back to a pretty-printed JSON dump.
10
+ *
11
+ * @param name Tool name from the `tool_use` block.
12
+ * @param input Raw tool input object.
13
+ * @returns Colorized lines to print beneath the tool header.
14
+ */
15
+ static format(name: string, input: ToolInput): string[];
16
+ private static formatBashInput;
17
+ private static formatReadInput;
18
+ private static formatWriteInput;
19
+ private static formatEditInput;
20
+ private static formatGrepInput;
21
+ private static formatGlobInput;
22
+ private static formatTodoWriteInput;
23
+ private static formatWebFetchInput;
24
+ private static formatWebSearchInput;
25
+ private static formatTaskInput;
26
+ private static formatFallbackInput;
27
+ private static readString;
28
+ private static readNumber;
29
+ private static readBoolean;
30
+ }
31
+ //# sourceMappingURL=tool_input_formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool_input_formatter.d.ts","sourceRoot":"","sources":["../../src/log_viewer/tool_input_formatter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;;GAGG;AACH,qBAAa,kBAAkB;IAC9B;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE;IAcvD,OAAO,CAAC,MAAM,CAAC,eAAe;IAe9B,OAAO,CAAC,MAAM,CAAC,eAAe;IAa9B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B,OAAO,CAAC,MAAM,CAAC,eAAe;IAS9B,OAAO,CAAC,MAAM,CAAC,eAAe;IAqB9B,OAAO,CAAC,MAAM,CAAC,eAAe;IAO9B,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAoBnC,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAUlC,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAgBnC,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAKlC,OAAO,CAAC,MAAM,CAAC,UAAU;IAKzB,OAAO,CAAC,MAAM,CAAC,UAAU;IAKzB,OAAO,CAAC,MAAM,CAAC,WAAW;CAI1B"}
@@ -0,0 +1,190 @@
1
+ import { colors } from '../libs/colors.js';
2
+ /**
3
+ * Renders a `tool_use` block's input into compact, human-readable lines — one
4
+ * dedicated formatter per known tool (Bash, Read, Grep, …).
5
+ */
6
+ export class ToolInputFormatter {
7
+ /**
8
+ * Formats a tool's input into display lines, dispatched by tool name.
9
+ * Unrecognized tools fall back to a pretty-printed JSON dump.
10
+ *
11
+ * @param name Tool name from the `tool_use` block.
12
+ * @param input Raw tool input object.
13
+ * @returns Colorized lines to print beneath the tool header.
14
+ */
15
+ static format(name, input) {
16
+ if (name === 'Bash')
17
+ return ToolInputFormatter.formatBashInput(input);
18
+ if (name === 'Read')
19
+ return ToolInputFormatter.formatReadInput(input);
20
+ if (name === 'Write')
21
+ return ToolInputFormatter.formatWriteInput(input);
22
+ if (name === 'Edit')
23
+ return ToolInputFormatter.formatEditInput(input);
24
+ if (name === 'Grep')
25
+ return ToolInputFormatter.formatGrepInput(input);
26
+ if (name === 'Glob')
27
+ return ToolInputFormatter.formatGlobInput(input);
28
+ if (name === 'TodoWrite')
29
+ return ToolInputFormatter.formatTodoWriteInput(input);
30
+ if (name === 'WebFetch')
31
+ return ToolInputFormatter.formatWebFetchInput(input);
32
+ if (name === 'WebSearch')
33
+ return ToolInputFormatter.formatWebSearchInput(input);
34
+ if (name === 'Task' || name === 'Agent')
35
+ return ToolInputFormatter.formatTaskInput(input);
36
+ return ToolInputFormatter.formatFallbackInput(input);
37
+ }
38
+ static formatBashInput(input) {
39
+ const command = ToolInputFormatter.readString(input, 'command') ?? '';
40
+ const description = ToolInputFormatter.readString(input, 'description');
41
+ const lines = [];
42
+ const cmdLines = command.split('\n');
43
+ lines.push(colors.text(`$ ${cmdLines[0] ?? ''}`));
44
+ for (let i = 1; i < cmdLines.length; i++) {
45
+ lines.push(colors.text(cmdLines[i]));
46
+ }
47
+ if (description !== undefined) {
48
+ lines.push(colors.system(`# ${description}`));
49
+ }
50
+ return lines;
51
+ }
52
+ static formatReadInput(input) {
53
+ const filePath = ToolInputFormatter.readString(input, 'file_path') ?? '';
54
+ const offset = ToolInputFormatter.readNumber(input, 'offset');
55
+ const limit = ToolInputFormatter.readNumber(input, 'limit');
56
+ let suffix = '';
57
+ if (offset !== undefined && limit !== undefined) {
58
+ suffix = `:${offset}-${offset + limit - 1}`;
59
+ }
60
+ else if (offset !== undefined) {
61
+ suffix = `:${offset}+`;
62
+ }
63
+ return [colors.text(`${filePath}${suffix}`)];
64
+ }
65
+ static formatWriteInput(input) {
66
+ const filePath = ToolInputFormatter.readString(input, 'file_path') ?? '';
67
+ return [colors.text(filePath)];
68
+ }
69
+ static formatEditInput(input) {
70
+ const filePath = ToolInputFormatter.readString(input, 'file_path') ?? '';
71
+ const lines = [colors.text(filePath)];
72
+ if (ToolInputFormatter.readBoolean(input, 'replace_all') === true) {
73
+ lines.push(colors.system('replace_all=true'));
74
+ }
75
+ return lines;
76
+ }
77
+ static formatGrepInput(input) {
78
+ const pattern = ToolInputFormatter.readString(input, 'pattern') ?? '';
79
+ const path = ToolInputFormatter.readString(input, 'path');
80
+ const head = path !== undefined ? `"${pattern}" in ${path}` : `"${pattern}"`;
81
+ const flags = [];
82
+ const outputMode = ToolInputFormatter.readString(input, 'output_mode');
83
+ if (outputMode !== undefined)
84
+ flags.push(`output_mode=${outputMode}`);
85
+ if (ToolInputFormatter.readBoolean(input, '-n') === true)
86
+ flags.push('-n');
87
+ if (ToolInputFormatter.readBoolean(input, '-i') === true)
88
+ flags.push('-i');
89
+ const headLimit = ToolInputFormatter.readNumber(input, 'head_limit');
90
+ if (headLimit !== undefined)
91
+ flags.push(`head_limit=${headLimit}`);
92
+ const glob = ToolInputFormatter.readString(input, 'glob');
93
+ if (glob !== undefined)
94
+ flags.push(`glob=${glob}`);
95
+ const fileType = ToolInputFormatter.readString(input, 'type');
96
+ if (fileType !== undefined)
97
+ flags.push(`type=${fileType}`);
98
+ if (flags.length === 0) {
99
+ return [colors.text(head)];
100
+ }
101
+ return [`${colors.text(head)} ${colors.system(`(${flags.join(', ')})`)}`];
102
+ }
103
+ static formatGlobInput(input) {
104
+ const pattern = ToolInputFormatter.readString(input, 'pattern') ?? '';
105
+ const path = ToolInputFormatter.readString(input, 'path');
106
+ const text = path !== undefined ? `${pattern} in ${path}` : pattern;
107
+ return [colors.text(text)];
108
+ }
109
+ static formatTodoWriteInput(input) {
110
+ const todos = input['todos'];
111
+ if (Array.isArray(todos) === false) {
112
+ return [colors.system('(no todos)')];
113
+ }
114
+ return todos.map((todo) => {
115
+ if (typeof todo !== 'object' || todo === null) {
116
+ return colors.text(String(todo));
117
+ }
118
+ const t = todo;
119
+ const status = typeof t['status'] === 'string' ? t['status'] : '?';
120
+ const content = typeof t['content'] === 'string' ? t['content'] : '';
121
+ let mark = '?';
122
+ if (status === 'pending')
123
+ mark = ' ';
124
+ else if (status === 'in_progress')
125
+ mark = '~';
126
+ else if (status === 'completed')
127
+ mark = 'x';
128
+ return colors.text(`[${mark}] ${content}`);
129
+ });
130
+ }
131
+ static formatWebFetchInput(input) {
132
+ const url = ToolInputFormatter.readString(input, 'url') ?? '';
133
+ const prompt = ToolInputFormatter.readString(input, 'prompt');
134
+ const lines = [colors.text(url)];
135
+ if (prompt !== undefined) {
136
+ lines.push(colors.system(`prompt: ${prompt}`));
137
+ }
138
+ return lines;
139
+ }
140
+ static formatWebSearchInput(input) {
141
+ const query = ToolInputFormatter.readString(input, 'query') ?? '';
142
+ const flags = [];
143
+ const allowed = input['allowed_domains'];
144
+ if (Array.isArray(allowed) && allowed.length > 0) {
145
+ flags.push(`allowed_domains=[${allowed.map((d) => String(d)).join(', ')}]`);
146
+ }
147
+ const blocked = input['blocked_domains'];
148
+ if (Array.isArray(blocked) && blocked.length > 0) {
149
+ flags.push(`blocked_domains=[${blocked.map((d) => String(d)).join(', ')}]`);
150
+ }
151
+ const head = colors.text(`"${query}"`);
152
+ if (flags.length === 0)
153
+ return [head];
154
+ return [`${head} ${colors.system(`(${flags.join(', ')})`)}`];
155
+ }
156
+ static formatTaskInput(input) {
157
+ const description = ToolInputFormatter.readString(input, 'description') ?? '';
158
+ const subagentType = ToolInputFormatter.readString(input, 'subagent_type') ?? 'agent';
159
+ const prompt = ToolInputFormatter.readString(input, 'prompt');
160
+ const lines = [colors.text(`[${subagentType}] ${description}`)];
161
+ if (prompt !== undefined) {
162
+ const PROMPT_PREVIEW_LIMIT = 200;
163
+ if (prompt.length <= PROMPT_PREVIEW_LIMIT) {
164
+ lines.push(colors.system(`prompt: ${prompt}`));
165
+ }
166
+ else {
167
+ const head = prompt.slice(0, PROMPT_PREVIEW_LIMIT);
168
+ lines.push(colors.system(`prompt: ${head}… (${prompt.length} chars)`));
169
+ }
170
+ }
171
+ return lines;
172
+ }
173
+ static formatFallbackInput(input) {
174
+ const json = JSON.stringify(input, null, 2);
175
+ return json.split('\n').map((line) => colors.json(line));
176
+ }
177
+ static readString(input, key) {
178
+ const value = input[key];
179
+ return typeof value === 'string' ? value : undefined;
180
+ }
181
+ static readNumber(input, key) {
182
+ const value = input[key];
183
+ return typeof value === 'number' ? value : undefined;
184
+ }
185
+ static readBoolean(input, key) {
186
+ const value = input[key];
187
+ return typeof value === 'boolean' ? value : undefined;
188
+ }
189
+ }
190
+ //# sourceMappingURL=tool_input_formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool_input_formatter.js","sourceRoot":"","sources":["../../src/log_viewer/tool_input_formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,KAAgB;QAC3C,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,kBAAkB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACxE,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,kBAAkB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAChF,IAAI,IAAI,KAAK,UAAU;YAAE,OAAO,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AC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,KAAgB,EAAE,GAAW;QACtD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,KAAgB,EAAE,GAAW;QACvD,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,CAAC;CACD"}
@@ -0,0 +1,28 @@
1
+ import type { ClaudeEvent } from '../types/claude_event.js';
2
+ import type { StatsReport } from '../types/stats_report.js';
3
+ /**
4
+ * Accumulates per-stream statistics — tool-call counts, tool-result errors, and
5
+ * peak prompt size — and captures the `result` event, then assembles a
6
+ * {@link StatsReport}. A fresh instance should be created per stream.
7
+ */
8
+ export declare class StatsCollector {
9
+ private toolUseCounts;
10
+ private toolResultCount;
11
+ private toolResultErrorCount;
12
+ private peakPromptTokens;
13
+ private resultEvent;
14
+ /** Feeds one event into the accumulators; call for every event in the stream. */
15
+ track(event: ClaudeEvent): void;
16
+ private trackPromptSize;
17
+ private trackToolUses;
18
+ private trackToolResults;
19
+ /**
20
+ * Builds the final {@link StatsReport} from the captured `result` event and
21
+ * the tracked accumulators. Call once, after the stream closes.
22
+ */
23
+ buildReport(): StatsReport;
24
+ private static buildByModel;
25
+ private static maxContextWindow;
26
+ private static round1;
27
+ }
28
+ //# sourceMappingURL=stats_collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stats_collector.d.ts","sourceRoot":"","sources":["../../src/stats/stats_collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,0BAA0B,CAAC;AACxE,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEzE;;;;GAIG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,WAAW,CAA0B;IAE7C,iFAAiF;IACjF,KAAK,CAAC,KAAK,EAAE,WAAW;IAgBxB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,gBAAgB;IAcxB;;;OAGG;IACH,WAAW,IAAI,WAAW;IA4E1B,OAAO,CAAC,MAAM,CAAC,YAAY;IAY3B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAY/B,OAAO,CAAC,MAAM,CAAC,MAAM;CAGrB"}