@estebanforge/pi-antigravity-bridge 1.10.2 → 1.10.4

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,7 +2,17 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [Unreleased]
5
+ ## [1.10.4] - 2026-11-10
6
+
7
+ ### Fixed
8
+
9
+ - **ACP turns no longer report a multiplied context length that fired compaction at a fraction of the real occupancy.** agy's PromptResponse.usage sums input + cacheRead + output over EVERY inference of the prompt (billing totals), and pi reads `Usage.totalTokens` as the live context length, so each tool round-trip re-counted the whole cached prefix: an 18-step turn gauged 107% of the window at ~7% real, and pi's auto-compaction destroyed the session history for no reason (issue #12). The driver keeps the billing fields but replaces the total with the occupancy-shaped value pi expects: the observed `usage_update` occupancy when the server sends it (absent on native agy 1.5.4, probe-calibrated 2026-11-10), otherwise the derived Σinput + Σoutput + ceil(ΣcacheRead / (toolBatches + 1)) where toolBatches counts tool_call batches (a batch opens on the first tool_call after model output and closes on the next output frame, so parallel calls and out-of-order completions cannot inflate the divisor) - exact at one inference (the raw aggregate), and every miscount residual shrinks the divisor, which over-reads, the safe direction; calibrated within +11%..+57% of the real occupancy on live probe turns where the raw aggregate ran +99% (the reported 18-step sessions gauged 107-135% and would land in the low teens). `scripts/probe-acp-usage.mjs` recalibrates the formula against live frames.
10
+
11
+ ## [1.10.3] - 2026-11-10
12
+
13
+ ### Added
14
+
15
+ - **The Antigravity provider dialog and the /agy artifacts and tasks browsers report blocked-on-user-input while open.** Pi 1.5.1 lets overlay dialogs declare a blocked program status (OSC 7501); all three now pass it, so terminal automation watching the session sees pi waiting on input instead of idle. Pi dependency floor moved to ^1.5.1.
6
16
 
7
17
  ## [1.10.2] - 2026-11-09
8
18
 
@@ -28,7 +28,7 @@ import {
28
28
  createWriteToolDefinition,
29
29
  } from "@earendil-works/pi-coding-agent";
30
30
  import { Text } from "@earendil-works/pi-tui";
31
- import { DIALOG_OPTIONS, DialogMenu, type DialogRow } from "@estebanforge/pi-tui-dialogs";
31
+ import { DIALOG_OPTIONS, DialogMenu, dialogBlocked, type DialogRow } from "@estebanforge/pi-tui-dialogs";
32
32
  import {
33
33
  entriesFromRaw,
34
34
  FALLBACK_MODELS,
@@ -1829,7 +1829,7 @@ async function openAgyPicker(ui: ExtensionUIContext, ctx: AgyCommandCtx): Promis
1829
1829
  },
1830
1830
  };
1831
1831
  },
1832
- DIALOG_OPTIONS,
1832
+ { ...DIALOG_OPTIONS, blocked: dialogBlocked("Antigravity provider") },
1833
1833
  );
1834
1834
 
1835
1835
  if (Object.keys(pending).length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estebanforge/pi-antigravity-bridge",
3
- "version": "1.10.2",
3
+ "version": "1.10.4",
4
4
  "description": "Gemini provider for Pi on the Antigravity ACP server (official Google ACP) or the stream-json agy CLI. Use antigravity/* models in Pi. Full /model picker support. Models runs Pi's tools. ToS safe to use.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -46,7 +46,7 @@
46
46
  ]
47
47
  },
48
48
  "peerDependencies": {
49
- "@earendil-works/pi-coding-agent": "^1.5.0"
49
+ "@earendil-works/pi-coding-agent": "^1.5.1"
50
50
  },
51
51
  "peerDependenciesMeta": {
52
52
  "@earendil-works/pi-coding-agent": {
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@estebanforge/pi-ask-shared": "^0.1.4",
58
- "@estebanforge/pi-tui-dialogs": "^0.1.2",
58
+ "@estebanforge/pi-tui-dialogs": "^0.1.3",
59
59
  "@modelcontextprotocol/sdk": "^1.31.0"
60
60
  }
61
61
  }
package/src/acp/driver.ts CHANGED
@@ -83,6 +83,20 @@ interface ActiveTurn {
83
83
  thoughtDeltas: number;
84
84
  /** Estimated once, not re-tokenized for every streaming delta. */
85
85
  estimatedInputTokens: number;
86
+ /** Native tool_call batches seen this turn: parallel calls in one
87
+ * inference collapse to one batch. A batch opens on the first tool_call
88
+ * after model output (text/thought) and stays open until the next output
89
+ * frame, so interleaved completions cannot split it. Proxies how many
90
+ * times the model inferred; feeds the PromptResponse.usage context
91
+ * correction (issue #12). */
92
+ toolBatches: number;
93
+ /** True between the first tool_call of an inference and the next model
94
+ * output frame. tool-only inferences keep it open and merge into the
95
+ * previous batch: the divisor shrinks, the total over-reads (safe). */
96
+ toolBatchOpen: boolean;
97
+ /** Last usage_update occupancy this turn. Authoritative over every
98
+ * derived total; native agy 1.5.4 never sends it (probe 2026-11-10). */
99
+ contextUsed: number | undefined;
86
100
  sawResult: boolean;
87
101
  /** True once the prompt RPC was issued. Abort before this point has
88
102
  * nothing to cancel: probing would risk a success-as-noop answer from a
@@ -341,15 +355,20 @@ export class AcpDriver implements TurnDriver {
341
355
  const result = await conn.prompt(turn.sessionId, request.prompt, request.images, request.contextBlock);
342
356
  if (turn.closed) return;
343
357
  turn.sawResult = true;
344
- // When a future server fills ACP PromptResponse.usage, exact counts
345
- // supersede every partial estimate at the end of the turn.
346
- if (result.usage) this.#emit(turn, { type: "usage", usage: result.usage });
358
+ // Exact PromptResponse.usage supersedes every partial estimate, but
359
+ // its total is a billing sum over all inferences, not context (see
360
+ // #derivedContextTokens): correct it before it reaches pi's gauge.
361
+ let settleUsage: AgyUsage | undefined;
362
+ if (result.usage) {
363
+ settleUsage = this.#contextCorrectedUsage(turn, result.usage);
364
+ this.#emit(turn, { type: "usage", usage: settleUsage });
365
+ }
347
366
  const mapped = mapStopReason(result.stopReason);
348
367
  this.#settle(turn, {
349
368
  conversationId: turn.sessionId,
350
369
  status: mapped.status,
351
370
  response: turn.response.text,
352
- usage: result.usage,
371
+ usage: settleUsage,
353
372
  error: mapped.error,
354
373
  finished: true,
355
374
  aborted: mapped.aborted,
@@ -404,6 +423,7 @@ export class AcpDriver implements TurnDriver {
404
423
  if (emit) {
405
424
  turn.textDeltas += 1;
406
425
  turn.textTokens += estimateTokens(emit);
426
+ turn.toolBatchOpen = false;
407
427
  this.#emitLiveEstimate(turn);
408
428
  this.#emit(turn, { type: "text", delta: emit });
409
429
  }
@@ -413,11 +433,29 @@ export class AcpDriver implements TurnDriver {
413
433
  if (!mapped.delta) return;
414
434
  turn.thoughtDeltas += 1;
415
435
  turn.thoughtTokens += estimateTokens(mapped.delta);
436
+ turn.toolBatchOpen = false;
416
437
  this.#emitLiveEstimate(turn);
417
438
  this.#emit(turn, { type: "thought", delta: mapped.delta });
418
439
  return;
419
440
  }
441
+ case "usage": {
442
+ // Occupancy frames are real server data, not the Gate B synthetic:
443
+ // surface them live so pi's gauge tracks the turn (toPiUsage only
444
+ // overwrites the fields the activity carries).
445
+ turn.contextUsed = mapped.used;
446
+ this.#emit(turn, { type: "usage", usage: { total_tokens: mapped.used } });
447
+ return;
448
+ }
420
449
  case "tool_start": {
450
+ // One inference can issue several calls in parallel (and complete
451
+ // them out of order); the divisor must count inference batches, not
452
+ // frames. A batch opens on the first tool_call after model output
453
+ // and only model output closes it, so interleaved completions and
454
+ // duplicate tool_call frames never split or re-open one.
455
+ if (!turn.toolBatchOpen) {
456
+ turn.toolBatches += 1;
457
+ turn.toolBatchOpen = true;
458
+ }
421
459
  const entry = { name: mapped.name, args: mapped.args, diff: mapped.diff, mcpServer: mapped.mcpServer };
422
460
  turn.toolCalls.set(mapped.toolCallId, entry);
423
461
  this.#emit(turn, { type: "tool_start", name: mapped.name, args: mapped.args, mcpServer: mapped.mcpServer, toolCallId: mapped.toolCallId });
@@ -607,8 +645,11 @@ export class AcpDriver implements TurnDriver {
607
645
  textDeltas: 0,
608
646
  thoughtDeltas: 0,
609
647
  estimatedInputTokens: estimateTokens(request.contextBlock?.text ? `${request.prompt}\n${request.contextBlock.text}` : request.prompt),
648
+ toolBatches: 0,
649
+ toolBatchOpen: false,
650
+ contextUsed: undefined,
610
651
  sawResult: false,
611
- promptStarted: false,
652
+ promptStarted: false,
612
653
  aborted: false,
613
654
  abortedBy: null,
614
655
  parks: 0,
@@ -779,7 +820,7 @@ export class AcpDriver implements TurnDriver {
779
820
  // the connection outlives turns and no exact data ever replaces them
780
821
  // on servers without PromptResponse.usage.
781
822
  if (this.#conn?.exactUsageSeen) return undefined;
782
- return synthesizeUsage({
823
+ const usage = synthesizeUsage({
783
824
  mode,
784
825
  prompt: turn.request.prompt,
785
826
  contextText: turn.request.contextBlock?.text,
@@ -789,6 +830,30 @@ export class AcpDriver implements TurnDriver {
789
830
  textDeltas: turn.textDeltas,
790
831
  thoughtDeltas: turn.thoughtDeltas,
791
832
  });
833
+ // Observed occupancy outranks the synthetic gauge guess; the estimate's
834
+ // in/out still feed the status line on servers without PromptResponse.usage.
835
+ if (usage && turn.contextUsed !== undefined) return { ...usage, total_tokens: turn.contextUsed };
836
+ return usage;
837
+ }
838
+
839
+ /** Keep PromptResponse.usage billing fields, replace only the context
840
+ * total. Occupancy frames win; otherwise derive (issue #12, derivation
841
+ * in AGENTS.md). */
842
+ #contextCorrectedUsage(turn: ActiveTurn, usage: AgyUsage): AgyUsage {
843
+ return { ...usage, total_tokens: turn.contextUsed ?? this.#derivedContextTokens(turn, usage) };
844
+ }
845
+
846
+ /** PromptResponse.usage sums input+cacheRead+output over EVERY inference
847
+ * of the prompt, but pi reads Usage.totalTokens as the live context
848
+ * length. Each inference's cacheRead is at least the warm prefix C0, so
849
+ * the batch average lower-bounds C0 and added content reaches the total
850
+ * through the Σinput term; exact at one batch (the raw aggregate). Full
851
+ * derivation in AGENTS.md. */
852
+ #derivedContextTokens(turn: ActiveTurn, usage: AgyUsage): number {
853
+ const input = usage.input_tokens ?? 0;
854
+ const output = usage.output_tokens ?? 0;
855
+ const cacheRead = usage.cache_read_tokens ?? 0;
856
+ return input + output + Math.ceil(cacheRead / (turn.toolBatches + 1));
792
857
  }
793
858
 
794
859
  #log(msg: string, data?: unknown): void {
package/src/acp/events.ts CHANGED
@@ -34,6 +34,7 @@ export interface AcpEditDiff {
34
34
  export type MappedUpdate =
35
35
  | { kind: "text"; delta: string }
36
36
  | { kind: "thought"; delta: string }
37
+ | { kind: "usage"; used: number }
37
38
  | { kind: "tool_start"; toolCallId: string; name: string; args: Record<string, unknown>; diff?: AcpEditDiff; mcpServer?: string }
38
39
  | { kind: "tool_done"; toolCallId: string; output?: string; diff?: AcpEditDiff; mcpServer?: string }
39
40
  | { kind: "tool_error"; toolCallId: string; message: string; mcpServer?: string }
@@ -52,6 +53,14 @@ export function mapUpdate(update: unknown): MappedUpdate {
52
53
  return { kind: "thought", delta: chunkText(u.content) };
53
54
  case "user_message_chunk":
54
55
  return { kind: "replay_user" };
56
+ case "usage_update": {
57
+ // Context-window occupancy after one inference. Absent on native agy
58
+ // 1.5.4 (probe 2026-11-10); other ACP runtimes send it per inference.
59
+ const used = u.used;
60
+ return typeof used === "number" && Number.isSafeInteger(used) && used > 0
61
+ ? { kind: "usage", used }
62
+ : null;
63
+ }
55
64
  case "tool_call": {
56
65
  const id = stringField(u.toolCallId);
57
66
  if (!id) return null;
@@ -9,6 +9,7 @@
9
9
  import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
10
10
  import { DynamicBorder } from "@earendil-works/pi-coding-agent";
11
11
  import { Container, type SelectItem, SelectList, Spacer, Text } from "@earendil-works/pi-tui";
12
+ import { dialogBlocked } from "@estebanforge/pi-tui-dialogs";
12
13
  import type { AgyArtifact } from "./artifacts.js";
13
14
 
14
15
  export type ArtifactsBrowserAction =
@@ -82,5 +83,6 @@ export async function showArtifactsBrowser(
82
83
  }, {
83
84
  overlay: true,
84
85
  overlayOptions: { anchor: "center" as const, width: 84, maxHeight: "85%" as const, margin: 1 },
86
+ blocked: dialogBlocked(`Antigravity artifacts (${artifacts.length})`),
85
87
  });
86
88
  }
package/src/tasks-ui.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
9
9
  import { DynamicBorder } from "@earendil-works/pi-coding-agent";
10
10
  import { Container, type SelectItem, SelectList, Spacer, Text } from "@earendil-works/pi-tui";
11
+ import { dialogBlocked } from "@estebanforge/pi-tui-dialogs";
11
12
  import type { AgyTask } from "./tasks.js";
12
13
 
13
14
  export type TasksBrowserAction = { type: "rescan" } | { type: "close" };
@@ -84,5 +85,6 @@ export async function showTasksBrowser(
84
85
  }, {
85
86
  overlay: true,
86
87
  overlayOptions: { anchor: "center" as const, width: 72, maxHeight: "85%" as const, margin: 1 },
88
+ blocked: dialogBlocked(`Antigravity tasks (${tasks.length})`),
87
89
  });
88
90
  }