billion-context-pi 0.1.65 → 0.1.66-pr.362.153

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.
package/dist/index.js CHANGED
@@ -1650,8 +1650,12 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1650
1650
  j2++;
1651
1651
  }
1652
1652
  const companion = messages[j2 + 1];
1653
- if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call") && j2 + 1 > newEndIndex) {
1654
- newEndIndex = j2 + 1;
1653
+ if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call")) {
1654
+ let e = j2 + 1;
1655
+ while (e + 1 < messages.length && messages[e + 1].role === "assistant" && (messages[e + 1].contentType === "text" || messages[e + 1].contentType === "tool-call")) {
1656
+ e++;
1657
+ }
1658
+ if (e > newEndIndex) newEndIndex = e;
1655
1659
  }
1656
1660
  }
1657
1661
  if (msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call")) {
@@ -1667,6 +1671,64 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
1667
1671
  }
1668
1672
  return { startIndex: newStartIndex, endIndex: newEndIndex };
1669
1673
  }
1674
+ function isAssistantAct(msg) {
1675
+ return msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call");
1676
+ }
1677
+ function computeTurnGroups(messages) {
1678
+ const resultIdByCallId = /* @__PURE__ */ new Map();
1679
+ for (const msg of messages) {
1680
+ if (msg.contentType === "tool-result" && typeof msg.toolCallId === "string" && msg.id) {
1681
+ if (!resultIdByCallId.has(msg.toolCallId))
1682
+ resultIdByCallId.set(msg.toolCallId, msg.id);
1683
+ }
1684
+ }
1685
+ const grouped = /* @__PURE__ */ new Set();
1686
+ const groups = [];
1687
+ for (let i = 0; i < messages.length; i++) {
1688
+ const msg = messages[i];
1689
+ if (!msg.id || grouped.has(msg.id)) continue;
1690
+ if (!(msg.contentType === "reasoning" || isAssistantAct(msg))) continue;
1691
+ let reasoningStart = i;
1692
+ if (msg.contentType === "reasoning") {
1693
+ while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
1694
+ reasoningStart--;
1695
+ }
1696
+ } else {
1697
+ let s = i;
1698
+ while (s > 0 && isAssistantAct(messages[s - 1])) s--;
1699
+ reasoningStart = s;
1700
+ while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
1701
+ reasoningStart--;
1702
+ }
1703
+ }
1704
+ const burstStart = (() => {
1705
+ let s = reasoningStart;
1706
+ while (s < messages.length && messages[s].contentType === "reasoning")
1707
+ s++;
1708
+ return s;
1709
+ })();
1710
+ if (burstStart >= messages.length || !isAssistantAct(messages[burstStart])) {
1711
+ continue;
1712
+ }
1713
+ let burstEnd = burstStart;
1714
+ while (burstEnd + 1 < messages.length && isAssistantAct(messages[burstEnd + 1])) {
1715
+ burstEnd++;
1716
+ }
1717
+ const members = /* @__PURE__ */ new Set();
1718
+ for (let k = reasoningStart; k <= burstEnd; k++) {
1719
+ const m2 = messages[k];
1720
+ if (!m2.id) continue;
1721
+ members.add(m2.id);
1722
+ if (m2.role === "assistant" && m2.contentType === "tool-call" && typeof m2.toolCallId === "string") {
1723
+ const rid = resultIdByCallId.get(m2.toolCallId);
1724
+ if (rid) members.add(rid);
1725
+ }
1726
+ }
1727
+ for (const id of members) grouped.add(id);
1728
+ groups.push([...members]);
1729
+ }
1730
+ return groups;
1731
+ }
1670
1732
  function estimateTextTokens(text) {
1671
1733
  return Math.ceil(text.length / 4);
1672
1734
  }
@@ -2381,6 +2443,42 @@ function applySingleRange(input) {
2381
2443
  )} from compression range (recent/last-user zone).`
2382
2444
  );
2383
2445
  }
2446
+ {
2447
+ const reasoningIds = /* @__PURE__ */ new Set();
2448
+ const callIds = /* @__PURE__ */ new Set();
2449
+ for (const m2 of input.messages) {
2450
+ if (!m2.id) continue;
2451
+ if (m2.contentType === "reasoning") reasoningIds.add(m2.id);
2452
+ if (m2.role === "assistant" && m2.contentType === "tool-call") callIds.add(m2.id);
2453
+ }
2454
+ const withdrawIds = /* @__PURE__ */ new Set();
2455
+ let splitTurnCount = 0;
2456
+ for (const group of computeTurnGroups(input.messages)) {
2457
+ const foldHasReasoning = group.some(
2458
+ (id) => effectiveMessageIds.has(id) && reasoningIds.has(id)
2459
+ );
2460
+ if (!foldHasReasoning) continue;
2461
+ const keptHasCall = group.some(
2462
+ (id) => !effectiveMessageIds.has(id) && callIds.has(id)
2463
+ );
2464
+ if (!keptHasCall) continue;
2465
+ splitTurnCount++;
2466
+ for (const id of group) withdrawIds.add(id);
2467
+ }
2468
+ if (withdrawIds.size > 0) {
2469
+ for (const id of withdrawIds) effectiveMessageIds.delete(id);
2470
+ const beforeWithdraw = filteredIds.length;
2471
+ filteredIds = filteredIds.filter((id) => !withdrawIds.has(id));
2472
+ if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
2473
+ throw new Error(
2474
+ `Range would split ${splitTurnCount} turn(s) at the protected-zone boundary: a visible tool-call must keep its reasoning run (strict-echo providers reject a rebuilt request that lost it). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
2475
+ );
2476
+ }
2477
+ warnings.push(
2478
+ `Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitTurnCount} turn(s) intact (visible tool-call would lose its reasoning run).`
2479
+ );
2480
+ }
2481
+ }
2384
2482
  if (!isBlockBoundary && filteredIds.length === 0 && consumedBlockIds.length > 0) {
2385
2483
  const first = consumedBlockIds[0];
2386
2484
  const last = consumedBlockIds[consumedBlockIds.length - 1];
@@ -16867,7 +16965,7 @@ async function statusReport(runtime, ctx) {
16867
16965
  const sentTokens = estimateTokens(coreMessages, coveredIds, imageTokens) + systemPromptTokens;
16868
16966
  const viewSentTokens = adjustedTokenCount(runtime.core, coreMessages, state, config, sentTokens, imageTokens, systemPromptTokens);
16869
16967
  const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: anchorStale ? viewSentTokens : Math.max(viewSentTokens, realUsage?.tokens ?? 0) });
16870
- const versionStr = "0.1.65" ? `billion-context-pi@${"0.1.65"}` : void 0;
16968
+ const versionStr = "0.1.66" ? `billion-context-pi@${"0.1.66"}` : void 0;
16871
16969
  let text = buildStatusPanel({
16872
16970
  version: versionStr,
16873
16971
  tokenCount: sessionTokens,
@@ -17565,7 +17663,7 @@ async function autoInstallLatest(latest, extDirOverride) {
17565
17663
  "--no-fund",
17566
17664
  "--no-save"
17567
17665
  ];
17568
- const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.65";
17666
+ const prevVersion = (await readPackageJson(join11(extDir, "package.json")))?.version ?? "0.1.66";
17569
17667
  const { code, stderr } = await runNpmImpl(installArgs(latest), { cwd: npmDir, timeout: 6e4 });
17570
17668
  if (code !== 0) {
17571
17669
  logWarn("update", {
@@ -17583,7 +17681,7 @@ async function autoInstallLatest(latest, extDirOverride) {
17583
17681
  }
17584
17682
  const verify = await verifyInstall(npmDir, latest);
17585
17683
  if (!verify.ok) {
17586
- const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.65";
17684
+ const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.66";
17587
17685
  logWarn("update", { event: "auto-install-verify-failed", latest, reason: verify.reason, rollbackTo });
17588
17686
  const rb = await runNpmImpl(installArgs(rollbackTo), { cwd: npmDir, timeout: 6e4 });
17589
17687
  logInfo("update", { event: "rollback", from: latest, to: rollbackTo, ok: rb.code === 0 });
@@ -17658,7 +17756,7 @@ async function checkForUpdate(autoUpdate, notify) {
17658
17756
  }
17659
17757
  const latest = await fetchLatestVersion(tag);
17660
17758
  if (!latest) return;
17661
- const current = runtimeVersion ?? "0.1.65";
17759
+ const current = runtimeVersion ?? "0.1.66";
17662
17760
  const hasUpdate = isVersionNewer(latest, current);
17663
17761
  debug.event("update-check", {
17664
17762
  current,
@@ -17836,7 +17934,7 @@ function wireSessionLifecycle(pi, runtime, standDownIfProxied) {
17836
17934
  setDelegatePolicy(DEFAULT_DELEGATE_POLICY);
17837
17935
  const sid = ctx.sessionManager.getSessionId();
17838
17936
  const modelInfo = ctx.model;
17839
- logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.65" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
17937
+ logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.66" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
17840
17938
  try {
17841
17939
  await runtime.reloadConfig(ctx.cwd);
17842
17940
  const delegateCfg = resolveDelegate(runtime.adapter);