ccsniff 1.1.10 → 1.1.11

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +11 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccsniff",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
4
4
  "description": "Watch Claude Code JSONL output files and emit structured events as a Node.js EventEmitter",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -124,17 +124,19 @@ export class JsonlWatcher extends EventEmitter {
124
124
  this.emit('streaming_complete', { conversationId: conv.id, conversation: conv, seq: this._seq(sid), timestamp: Date.now() });
125
125
  }
126
126
 
127
- _push(conv, sid, block, role) {
128
- this.emit('streaming_progress', { conversationId: conv.id, conversation: conv, block, role, seq: this._seq(sid), timestamp: Date.now() });
127
+ _push(conv, sid, block, role, eventTs) {
128
+ const ts = eventTs != null ? eventTs : Date.now();
129
+ this.emit('streaming_progress', { conversationId: conv.id, conversation: conv, block, role, seq: this._seq(sid), timestamp: ts });
129
130
  }
130
131
 
131
132
  _route(conv, sid, e) {
132
133
  if (e.type === 'queue-operation' || e.type === 'last-prompt') return;
134
+ const ets = e.timestamp ? Date.parse(e.timestamp) : null;
133
135
  if (e.type === 'user' && e.isMeta) {
134
136
  this._startStreaming(conv, sid);
135
137
  const content = e.message?.content;
136
138
  const text = typeof content === 'string' ? content : (Array.isArray(content) ? content.filter(b => b?.type === 'text').map(b => b.text).join('') : '');
137
- if (text.trim()) this._push(conv, sid, { type: 'text', text, isMeta: true }, 'user');
139
+ if (text.trim()) this._push(conv, sid, { type: 'text', text, isMeta: true }, 'user', ets);
138
140
  return;
139
141
  }
140
142
 
@@ -147,7 +149,7 @@ export class JsonlWatcher extends EventEmitter {
147
149
  if (e.subtype === 'init') { this._startStreaming(conv, sid); return; }
148
150
  if (e.subtype === 'turn_duration' || e.subtype === 'stop_hook_summary') { this._endStreaming(conv, sid); return; }
149
151
  this._startStreaming(conv, sid);
150
- this._push(conv, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools }, 'system');
152
+ this._push(conv, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools }, 'system', ets);
151
153
  return;
152
154
  }
153
155
 
@@ -158,7 +160,7 @@ export class JsonlWatcher extends EventEmitter {
158
160
  const newBlocks = e.message.content.slice(prev);
159
161
  if (newBlocks.length > 0) {
160
162
  this._emitted.set(key, e.message.content.length);
161
- for (const b of newBlocks) if (b?.type) this._push(conv, sid, b, 'assistant');
163
+ for (const b of newBlocks) if (b?.type) this._push(conv, sid, b, 'assistant', ets);
162
164
  }
163
165
  if (e.message.stop_reason) this._emitted.delete(key);
164
166
  return;
@@ -168,19 +170,19 @@ export class JsonlWatcher extends EventEmitter {
168
170
  this._startStreaming(conv, sid);
169
171
  const content = e.message.content;
170
172
  if (typeof content === 'string') {
171
- if (content.trim()) this._push(conv, sid, { type: 'text', text: content }, 'user');
173
+ if (content.trim()) this._push(conv, sid, { type: 'text', text: content }, 'user', ets);
172
174
  } else if (Array.isArray(content)) {
173
175
  for (const b of content) {
174
176
  if (!b || !b.type) continue;
175
- if (b.type === 'tool_result') this._push(conv, sid, b, 'tool_result');
176
- else this._push(conv, sid, b, 'user');
177
+ if (b.type === 'tool_result') this._push(conv, sid, b, 'tool_result', ets);
178
+ else this._push(conv, sid, b, 'user', ets);
177
179
  }
178
180
  }
179
181
  return;
180
182
  }
181
183
 
182
184
  if (e.type === 'result') {
183
- this._push(conv, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result');
185
+ this._push(conv, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result', ets);
184
186
  this._endStreaming(conv, sid);
185
187
  }
186
188
  }