thinkpool-pair 0.7.69 → 0.7.70

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/bridge.mjs +27 -14
  2. package/package.json +1 -1
package/bridge.mjs CHANGED
@@ -462,24 +462,37 @@ const webPeerPresent = () => {
462
462
  // still delivers instead of taking the channel down. capReplayEvents bounds bulk
463
463
  // replays before they reach here; this catches the single-event case + is the alarm.
464
464
  const FRAME_SOFT_LIMIT = 200000
465
+ // Truncate the bulky string fields of ONE event in place (a giant tool_result / cat of
466
+ // a big file / mockup blob). Keeps a head + a marker so the transcript stays readable.
467
+ const truncEventFields = (evt) => {
468
+ if (!evt || typeof evt !== 'object') return
469
+ for (const k of ['text', 'content', 'output', 'stdout', 'stderr', 'input']) {
470
+ const v = evt[k]
471
+ if (typeof v === 'string' && v.length > 20000) {
472
+ evt[k] = v.slice(0, 20000) + `\n…[truncated ${v.length - 20000} bytes — too large to broadcast]`
473
+ }
474
+ }
475
+ }
465
476
  const defendFrame = (event, payload) => {
466
477
  let json
467
478
  try { json = JSON.stringify(payload) } catch { return payload }
468
479
  if (!json || json.length <= FRAME_SOFT_LIMIT) return payload
469
- process.stderr.write(`\n ⚠ oversized ${event} frame: ${json.length}B (term ${String(payload?.term || '?').slice(0, 8)}) — truncating to fit so delivery isn't dropped\n`)
470
- try {
471
- const p = JSON.parse(json)
472
- const evt = p.evt
473
- if (evt && typeof evt === 'object') {
474
- for (const k of ['text', 'content', 'output', 'stdout', 'stderr']) {
475
- if (typeof evt[k] === 'string' && evt[k].length > 20000) {
476
- const orig = evt[k].length
477
- evt[k] = evt[k].slice(0, 20000) + `\n…[truncated ${orig - 20000} bytes — too large to broadcast]`
478
- }
479
- }
480
- }
481
- return p
482
- } catch { return payload }
480
+ process.stderr.write(`\n ⚠ oversized ${event} frame: ${json.length}B (term ${String(payload?.term || '?').slice(0, 8)}) — defanging so Realtime doesn't drop it\n`)
481
+ let p
482
+ try { p = JSON.parse(json) } catch { return payload }
483
+ // single live event (code-event)
484
+ if (p.evt && typeof p.evt === 'object') truncEventFields(p.evt)
485
+ // replay batch (code-replay): truncate each event's bulky fields…
486
+ if (Array.isArray(p.events)) {
487
+ p.events.forEach(truncEventFields)
488
+ // …and if a frame is STILL over the limit (bulk hidden in fields we don't truncate),
489
+ // drop the OLDEST events until it fits — keep the newest so the client's seqHi still
490
+ // advances to current. classifyReplay accepts the resulting seq jump; older events are
491
+ // covered by the DB transcript snapshot.
492
+ let guard = 0
493
+ while (p.events.length > 1 && JSON.stringify(p).length > FRAME_SOFT_LIMIT && guard++ < 10000) p.events.shift()
494
+ }
495
+ return p
483
496
  }
484
497
 
485
498
  const bcast = (event, payload) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thinkpool-pair",
3
- "version": "0.7.69",
3
+ "version": "0.7.70",
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": {