openzoo 0.48.57 → 0.48.58

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/lib/proxy.js +24 -3
  2. package/package.json +1 -1
package/lib/proxy.js CHANGED
@@ -411,10 +411,31 @@ async function spillTranscript(body, log, req) {
411
411
  // for a bug rather than for coherence. 6 turns still covers "what did I just
412
412
  // do" — the case retrieval cannot answer, because the model does not know to
413
413
  // query for it — and hands the rest back as saving.
414
+ // COUNT CONVERSATION TURNS, NOT MESSAGES.
415
+ //
416
+ // A tool round trip is TWO messages (assistant tool_call + tool result), so a
417
+ // floor of 6 messages is three tool calls and nothing else — the agent loses
418
+ // the human turn that started the run and every decision it made along the
419
+ // way. OBSERVED: "it's when he calls a bunch of tools, he gets lost."
420
+ //
421
+ // So the floor is measured in user/assistant turns and tool traffic rides
422
+ // along for free. A tool-heavy stretch therefore widens the window instead of
423
+ // consuming it, which is the opposite of the old behaviour and the whole
424
+ // point: what the agent needs verbatim is what it DID, and doing things is
425
+ // exactly what fills the window with tool messages.
414
426
  const minTurns = Number(process.env.OPENZOO_TAIL_MIN_TURNS || 6);
415
- if (msgs.length - cut < minTurns) {
416
- for (let i = Math.max(firstSpillable + 1, msgs.length - minTurns); i > firstSpillable; i--) {
417
- if (severable(i)) { cut = i; break; }
427
+ const realTurns = (from) => {
428
+ let n = 0;
429
+ for (let i = from; i < msgs.length; i++) {
430
+ const r = msgs[i]?.role;
431
+ if (r === 'user' || r === 'assistant') n += 1;
432
+ }
433
+ return n;
434
+ };
435
+ if (realTurns(cut) < minTurns) {
436
+ for (let i = cut - 1; i > firstSpillable; i--) {
437
+ if (severable(i) && realTurns(i) >= minTurns) { cut = i; break; }
438
+ if (i === firstSpillable + 1) { if (severable(i)) cut = i; break; }
418
439
  }
419
440
  }
420
441
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzoo",
3
- "version": "0.48.57",
3
+ "version": "0.48.58",
4
4
  "description": "Local x402-paying proxy + MCP server for openzoo.fun — point any OpenAI-compatible harness (Cursor, Claude Code, aider, SDKs) at localhost and it pays per call from a local burner wallet. Solana and Base rails live; Robinhood experimental.",
5
5
  "license": "MIT",
6
6
  "type": "module",