thinkpool-pair 0.7.12 → 0.7.13

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/claude-session.mjs +31 -1
  2. package/package.json +1 -1
@@ -127,6 +127,15 @@ export function startClaudeSession({ cwd, model, resume, mode: initialMode = 'de
127
127
  const alwaysAllow = new Set() // tool:risk signatures the user chose "don't ask again" for
128
128
  const toolStart = new Map() // tool_use id → start time, for the duration badge
129
129
  let effort = null // active reasoning effort for the turn (from the hook input)
130
+ // Live token count for the thinking indicator — mirrors Claude Code's
131
+ // "↓ N tokens": the turn's billed OUTPUT tokens (thinking is billed as
132
+ // output, so this is the full count, not just the reasoning estimate). A
133
+ // tool-using turn emits several assistant messages; message_delta carries
134
+ // the running output_tokens for the CURRENT message, so we fold finished
135
+ // messages into turnBaseOut and add the live message's count on top. Reset
136
+ // per turn on `result`.
137
+ let turnBaseOut = 0 // output tokens from completed messages this turn
138
+ let curMsgOut = 0 // latest output_tokens for the in-flight message
130
139
 
131
140
  const emit = (evt) => { try { onEvent?.(evt) } catch { /* never let a consumer throw into the loop */ } }
132
141
 
@@ -286,7 +295,11 @@ export function startClaudeSession({ cwd, model, resume, mode: initialMode = 'de
286
295
  // model reasons, surfaced as the indicator's ↓ N tokens. Coarse,
287
296
  // emitted during extended thinking; not a per-token stream.
288
297
  if (m.subtype === 'thinking_tokens') {
289
- emit({ kind: 'thinking_tokens', tokens: m.estimated_tokens, delta: m.estimated_tokens_delta })
298
+ // The reasoning-phase estimate (smooth, but approximate). Only
299
+ // surface it BEFORE real output streams — once message_delta gives
300
+ // us authoritative output_tokens (which already include thinking),
301
+ // that supersedes the estimate so the count never jumps backwards.
302
+ if (turnBaseOut + curMsgOut === 0) emit({ kind: 'thinking_tokens', tokens: m.estimated_tokens, delta: m.estimated_tokens_delta })
290
303
  break
291
304
  }
292
305
  if (m.session_id) sessionId = m.session_id
@@ -312,8 +325,25 @@ export function startClaudeSession({ cwd, model, resume, mode: initialMode = 'de
312
325
  }
313
326
  }
314
327
  break
328
+ case 'stream_event': {
329
+ // Live output-token progress for the thinking indicator. message_delta
330
+ // carries the running output_tokens for the current assistant message;
331
+ // message_start opens a new one (fold the finished message into the
332
+ // turn base first). Authoritative + monotonic within a turn.
333
+ const ev = m.event
334
+ if (ev?.type === 'message_start') {
335
+ turnBaseOut += curMsgOut
336
+ curMsgOut = ev.message?.usage?.output_tokens || 0
337
+ emit({ kind: 'thinking_tokens', tokens: turnBaseOut + curMsgOut })
338
+ } else if (ev?.type === 'message_delta' && ev.usage) {
339
+ curMsgOut = ev.usage.output_tokens ?? curMsgOut
340
+ emit({ kind: 'thinking_tokens', tokens: turnBaseOut + curMsgOut })
341
+ }
342
+ break
343
+ }
315
344
  case 'result':
316
345
  if (m.session_id) sessionId = m.session_id
346
+ turnBaseOut = 0; curMsgOut = 0 // reset the live token count for the next turn
317
347
  emit({ kind: 'result', subtype: m.subtype, sessionId, costUsd: m.total_cost_usd, usage: m.usage, numTurns: m.num_turns })
318
348
  // Surface a usage/context meter (chrome, not a transcript line). The
319
349
  // context window % comes from the control request; cost is cumulative.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinkpool-pair",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "description": "Share a local coding-agent CLI (Claude Code, Codex, Gemini, Aider, …) into a ThinkPool Code room, live.",
5
5
  "type": "module",
6
6
  "bin": {