pi-antigravity-bridge 0.1.17 → 0.1.18

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.18] - 2026-11-28
6
+
7
+ ### Fixed
8
+
9
+ - 修复 Gemini 4 Neon 和 Carbon 恢复长会话后容易立刻压缩,导致 Pi 上下文占用反复大幅跳变的问题。
10
+
5
11
  ## [0.1.17] - 2026-11-28
6
12
 
7
13
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-antigravity-bridge",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Google Antigravity CLI (agy acp) agent backend bridge for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -183,19 +183,22 @@ export interface DiscoveredCatalogSnapshot {
183
183
  modelEfforts: Record<string, EffortSuffix[]>;
184
184
  }
185
185
 
186
- /** 运行时从 usage_update.size 动态观测到的真实窗口上限表 */
186
+ /** 运行时从 usage_update.size 观测到的后端容量,可能大于原生 Checkpointer 水位。 */
187
187
  const runtimeObservedWindows = new Map<string, number>();
188
188
 
189
- /** 更新某模型在当前账号下实时回报的真实有效上下文窗口 */
190
- export function recordObservedContextWindow(modelId: string, size: number | undefined): boolean {
189
+ export function normalizeReportedContextWindow(size: number | undefined): number | undefined {
191
190
  if (typeof size !== "number" || !Number.isFinite(size) || size < 16_000) {
192
- return false;
191
+ return undefined;
193
192
  }
194
- const rounded = Math.floor(size);
195
- if (runtimeObservedWindows.get(modelId) === rounded) {
193
+ return Math.floor(size);
194
+ }
195
+
196
+ export function recordObservedContextWindow(modelId: string, size: number | undefined): boolean {
197
+ const window = normalizeReportedContextWindow(size);
198
+ if (window === undefined || runtimeObservedWindows.get(modelId) === window) {
196
199
  return false;
197
200
  }
198
- runtimeObservedWindows.set(modelId, rounded);
201
+ runtimeObservedWindows.set(modelId, window);
199
202
  return true;
200
203
  }
201
204
 
@@ -203,6 +206,16 @@ export function getObservedContextWindow(modelId: string): number | undefined {
203
206
  return runtimeObservedWindows.get(modelId);
204
207
  }
205
208
 
209
+ /** 以已核实的 AGY 原生 Checkpointer 水位规划回放和 Pi 自动压缩。 */
210
+ export function resolveAgyContextWindow(modelId: string, capacity: number): number {
211
+ const lower = modelId.toLowerCase();
212
+ const baseId = splitEffortSuffix(lower)?.baseId ?? lower;
213
+ if (baseId === "gemini-4-neon" || baseId === "gemini-4-carbon") {
214
+ return Math.min(capacity, 512_000);
215
+ }
216
+ return capacity;
217
+ }
218
+
206
219
  /** 按模型家族推断默认上下文窗口与最大输出 Token 规格 */
207
220
  export function inferModelSpecs(modelId: string): {
208
221
  contextWindow: number;
@@ -232,7 +245,7 @@ export function inferModelSpecs(modelId: string): {
232
245
  lower.includes("orchestrator")
233
246
  ) {
234
247
  return {
235
- contextWindow: observed ?? 1_048_576,
248
+ contextWindow: resolveAgyContextWindow(modelId, observed ?? 1_048_576),
236
249
  maxTokens: 65_536,
237
250
  supportsImage: true,
238
251
  };
@@ -426,11 +439,11 @@ export function readCachedCatalog(env: NodeJS.ProcessEnv = process.env): Discove
426
439
  if (!fs.existsSync(cachePath)) return undefined;
427
440
  const raw = JSON.parse(fs.readFileSync(cachePath, "utf8")) as DiscoveredCatalogSnapshot;
428
441
  if (raw?.version === 1 && Array.isArray(raw.models) && raw.models.length > 0) {
429
- // 应用最新观测到的窗口校准,并为旧版零费用缓存自动补全 Pi 内置目录参考定价
442
+ // 应用最新观测的容量与 Checkpointer 水位,并为旧版零费用缓存补全参考定价。
430
443
  const calibrated = raw.models.map((m) => ({
431
444
  ...m,
432
445
  cost: hasNonZeroModelCost(m.cost) ? m.cost : resolveBuiltinModelCost(m.id, m.name),
433
- contextWindow: getObservedContextWindow(m.id) ?? m.contextWindow,
446
+ contextWindow: resolveAgyContextWindow(m.id, getObservedContextWindow(m.id) ?? m.contextWindow),
434
447
  }));
435
448
  return { ...raw, models: calibrated };
436
449
  }
@@ -34,8 +34,10 @@ import type {
34
34
  } from "../acp/protocol.ts";
35
35
  import {
36
36
  ANTIGRAVITY_PROVIDER_ID,
37
+ normalizeReportedContextWindow,
37
38
  recordObservedContextWindow,
38
39
  removeEmptyProbeSessionFiles,
40
+ resolveAgyContextWindow,
39
41
  resolveSessionModelSelection,
40
42
  } from "../catalog/model-discovery.ts";
41
43
  import {
@@ -734,21 +736,22 @@ export class TurnCoordinator {
734
736
  }
735
737
  ledger.usedTokens = update.used;
736
738
  }
737
- if (typeof update.size === "number") {
738
- ledger.windowSize = update.size;
739
+ const reportedSize = normalizeReportedContextWindow(update.size);
740
+ if (reportedSize !== undefined) {
741
+ ledger.windowSize = reportedSize;
739
742
  const activeModel = this.activeContext?.model;
740
743
  const targetModelId =
741
744
  ledger.lastSelectedModelId ??
742
745
  (activeModel?.provider === ANTIGRAVITY_PROVIDER_ID ? activeModel.id : undefined);
743
746
  if (targetModelId) {
744
- recordObservedContextWindow(targetModelId, update.size);
747
+ recordObservedContextWindow(targetModelId, reportedSize);
745
748
  }
746
749
  if (
747
750
  activeModel &&
748
751
  activeModel.provider === ANTIGRAVITY_PROVIDER_ID &&
749
752
  (!ledger.lastSelectedModelId || activeModel.id === ledger.lastSelectedModelId)
750
753
  ) {
751
- activeModel.contextWindow = update.size;
754
+ activeModel.contextWindow = resolveAgyContextWindow(activeModel.id, reportedSize);
752
755
  }
753
756
  }
754
757
  updateAntigravityStatusBar(
@@ -885,6 +888,8 @@ export class TurnCoordinator {
885
888
  context: TranscriptContext,
886
889
  options?: SimpleStreamOptions,
887
890
  ): Promise<void> {
891
+ // 兼容仍携带旧目录容量的模型对象,在规划重放前应用 Checkpointer 水位。
892
+ model.contextWindow = resolveAgyContextWindow(model.id, model.contextWindow);
888
893
  const piSessionKey = this.resolveCurrentPiSessionKey(options?.sessionId);
889
894
  const primaryLedger = this.ledgers.get(piSessionKey);
890
895
  const hasBusyPrimary = Boolean(
@@ -3022,9 +3027,9 @@ export class TurnCoordinator {
3022
3027
  if (item.kind === "prompt_done") {
3023
3028
  this.mirrorBroker.completePendingCallsImplicitly(ledger.agySessionId);
3024
3029
 
3025
- if (ledger.windowSize) {
3030
+ if (ledger.windowSize !== undefined) {
3026
3031
  recordObservedContextWindow(model.id, ledger.windowSize);
3027
- model.contextWindow = ledger.windowSize;
3032
+ model.contextWindow = resolveAgyContextWindow(model.id, ledger.windowSize);
3028
3033
  }
3029
3034
 
3030
3035
  if (item.response.stopReason === "cancelled") {