@estebanforge/pi-antigravity-bridge 1.18.0 → 1.19.0

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,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.19.0] - 2026-12-02
6
+
7
+ ### Added
8
+
9
+ - Steering cut-in for the ACP engine (issue #38): a message the user sends while a bridge tool round-trip is parked now reaches the model at the next tool boundary instead of after the whole turn ends. With a bound conversation and a live turn, the steer rides the parked call's still-open MCP HTTP response as extra content blocks — a `[pi]`-framed text block stating it supersedes the pre-park plan, plus image blocks when the steer carries images — so agy reads it as a mid-turn user message, not tool output. The last non-escalated bridge result of the batch carries; escalated, approval and rt entries have no model-facing response body and keep the end-of-turn delivery, as do dead turns, unbound records and the stream-json engine (byte-identical there). The carry counts as delivered when the HTTP response is written; if the turn fails afterwards, the pre-turn record holds and the digest re-offers the steer, so nothing is lost pi-side. Verified live on agy 1.5.22 with `scripts/smoke-steering.mjs`: a steered round-trip delivered the carried block and the model answered it at the next boundary, with no duplicate delivery. Lean agent sessions are not live-verified for the carrier (the smoke runs the default agent); under lean the block is plain MCP content and should arrive intact.
10
+
11
+ ### Fixed
12
+
13
+ - A steer (or any trailing user run) over a dead parked turn with stranded escalated results shipped twice: once joined into the redelivery prompt, then again through the post-outcome sweep, because `steerLedFresh` required `late` to be empty before trusting the dispatch. The flag now fires only when the dispatch actually carries every collected steer — trailing-run prompt or images, each steer at or after `runStart` — so a steer joined with stranded results ships once, an image-only steer no longer duplicates (prompt-null runs count by images), and a steer stranded before the run's start stays with the sweep as its deliverer, duplicating the in-run one instead of losing the other. The fresh steering window also opens for such dispatches, since the sweep that used to claim the steer stays off. Pinned by the reworked orphaned-escalation redelivery test (4 requests → 3) and new steering cases.
14
+
5
15
  ## [1.18.0] - 2026-12-02
6
16
 
7
17
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estebanforge/pi-antigravity-bridge",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
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",
package/src/provider.ts CHANGED
@@ -1166,6 +1166,15 @@ export class ToolRoundTrips {
1166
1166
  return [...this.#pending.keys()];
1167
1167
  }
1168
1168
 
1169
+ /** True while the call holds an unescalated bridge park: its HTTP response
1170
+ * is still open and can carry extra content blocks (steering carrier).
1171
+ * Escalated entries answered with a poll handle long ago; "rt" and
1172
+ * "approval" entries have no model-facing response body at all. */
1173
+ canCarry(toolCallId: string): boolean {
1174
+ const entry = this.#pending.get(toolCallId);
1175
+ return entry?.kind === "bridge" && entry.escalated !== true;
1176
+ }
1177
+
1169
1178
  /** Call ids whose park already failed (tombstones). */
1170
1179
  get deadIds(): string[] {
1171
1180
  return [...this.#dead.keys()];
@@ -1411,6 +1420,7 @@ export class ToolRoundTrips {
1411
1420
  text: string,
1412
1421
  isError: boolean,
1413
1422
  images: Array<{ data: string; mimeType: string }> = [],
1423
+ steer?: { text: string; images: Array<{ data: string; mimeType: string }> },
1414
1424
  ): boolean {
1415
1425
  const entry = this.#pending.get(toolCallId);
1416
1426
  if (!entry) return false;
@@ -1460,6 +1470,8 @@ export class ToolRoundTrips {
1460
1470
  content: [
1461
1471
  ...images.map((i) => ({ type: "image", data: i.data, mimeType: i.mimeType })),
1462
1472
  { type: "text", text },
1473
+ ...(steer ? steer.images.map((i) => ({ type: "image", data: i.data, mimeType: i.mimeType })) : []),
1474
+ ...(steer ? [{ type: "text", text: buildSteerCarryText(steer.text) }] : []),
1463
1475
  ],
1464
1476
  isError,
1465
1477
  });
@@ -1572,6 +1584,15 @@ export function collectSteeredUserMessages(messages: Message[], pendingIds: read
1572
1584
  return out;
1573
1585
  }
1574
1586
 
1587
+ /** Frame a steer carried inside a tool result so agy reads it as the user's
1588
+ * mid-turn message, not as tool output: it supersedes the pre-park plan.
1589
+ * Image-only steers get the variant so the block never dangles empty. */
1590
+ export function buildSteerCarryText(text: string): string {
1591
+ return text
1592
+ ? `[pi] The user sent this message while the tool ran; it supersedes the current plan. Answer it first:\n${text}`
1593
+ : "[pi] The user sent an image while this tool ran; it supersedes the current plan.";
1594
+ }
1595
+
1575
1596
  /** Frame late tool results so agy treats them as the results its bridge calls
1576
1597
  * never received: a park whose round-trip died while the pi tool ran, or an
1577
1598
  * escalated result the model never polled. The reason carries the framing. */
@@ -1917,16 +1938,16 @@ async function runTurnDriver(
1917
1938
  // cursor when one exists (dispatch length + delivered-through), else the
1918
1939
  // first-pending-toolResult anchor fallback.
1919
1940
  const steerCursor = steerCursors.get(key);
1920
- const steered = ephemeral
1941
+ let steered = ephemeral
1921
1942
  ? []
1922
1943
  : collectSteeredUserMessages(
1923
1944
  context.messages,
1924
1945
  deps.roundTrips.pendingIds,
1925
1946
  steerCursor ? Math.max(steerCursor.dispatchedAt, steerCursor.deliveredThrough) : undefined,
1926
1947
  );
1927
- // Set when a steer leads the dead-turn fallback into a fresh dispatch: the
1928
- // steer shipped as that dispatch's own prompt, so the post-outcome sweep
1929
- // must stay off (and its stranded-claim re-sweep with it).
1948
+ // Set when a steer ships inside the dead-turn dispatch's prompt (its own
1949
+ // trailing run, or joined with late strands): the post-outcome sweep must
1950
+ // stay off (and its stranded-claim re-sweep with it).
1930
1951
  let steerLedFresh = false;
1931
1952
  // Escalated calls answer through bridge_poll_result, not through an agy
1932
1953
  // turn waiting on the park, so note them before resolving.
@@ -1940,8 +1961,55 @@ async function runTurnDriver(
1940
1961
  // text-only: image blocks ride driver.run images instead, so both
1941
1962
  // engines deliver them (ACP native prompt blocks; stream-json staged
1942
1963
  // files).
1943
- for (const r of results)
1944
- deps.roundTrips.resolve(r.toolCallId, r.text, r.isError, r.images);
1964
+ // Steering carrier (issue #38): on ACP a steer that landed while a bridge
1965
+ // park was pending rides that call's still-open HTTP response as extra
1966
+ // content blocks, so the model sees it at its next inference instead of
1967
+ // after the whole turn ends. The last carriable result of the batch
1968
+ // carries; escalated entries settled through the poll registry and dead
1969
+ // turns have no socket to carry on. Needs the record's bound conversation:
1970
+ // on a post-carry failure the held watermark re-offers the steer through
1971
+ // the digest instead of losing it. stream-json keeps late-only delivery.
1972
+ // The carry counts as delivered when the HTTP response is written; a
1973
+ // socket dying right after is not detectable here, and pi's retry-resume
1974
+ // path skips the digest - a steer agy never absorbed is lost in that one
1975
+ // narrow tail. Accepted: verifying absorption would need a protocol
1976
+ // round-trip the bridge does not have.
1977
+ const engine = deps.engine ?? config.engine;
1978
+ const steerText = steered.map((s) => s.text).filter(Boolean).join("\n\n");
1979
+ const steerImages = steered.flatMap((s) => s.images);
1980
+ const willCarrySteer =
1981
+ !ephemeral &&
1982
+ isContinuation &&
1983
+ steered.length > 0 &&
1984
+ engine === "acp" &&
1985
+ Boolean(existing?.conversationId) &&
1986
+ context.messages[context.messages.length - 1]?.role === "user" &&
1987
+ // reentry(), not activeHandle: it is the exact live-turn signal the
1988
+ // continuation branch consults below, so the carry can never ride a
1989
+ // socket the branch is about to declare dead.
1990
+ deps.driver.reentry() !== null;
1991
+ const carrierId = willCarrySteer
1992
+ ? [...results].reverse().find((r) => deps.roundTrips.canCarry(r.toolCallId))?.toolCallId
1993
+ : undefined;
1994
+ let steerCarried = false;
1995
+ for (const r of results) {
1996
+ const settled = deps.roundTrips.resolve(
1997
+ r.toolCallId,
1998
+ r.text,
1999
+ r.isError,
2000
+ r.images,
2001
+ r.toolCallId === carrierId ? { text: steerText, images: steerImages } : undefined,
2002
+ );
2003
+ if (r.toolCallId === carrierId) steerCarried = settled;
2004
+ }
2005
+ if (steerCarried) {
2006
+ // Same accounting as an accepted late run: the cursor must claim the
2007
+ // steer or the next park of the chain would carry it again.
2008
+ const cursor = steerCursors.get(key);
2009
+ if (cursor) cursor.deliveredThrough = steered[steered.length - 1].index + 1;
2010
+ deps.log?.("steer-carried", { callId: carrierId, count: steered.length }, "info");
2011
+ steered = [];
2012
+ }
1945
2013
 
1946
2014
  // Late delivery: a toolResult whose park already failed (the abort/timeout
1947
2015
  // path failed the park while the pi tool kept running). The work is done,
@@ -2086,7 +2154,6 @@ async function runTurnDriver(
2086
2154
  // message is answered rather than dropped or left to the digest window.
2087
2155
  // The sweep below must not re-deliver what that dispatch just shipped.
2088
2156
  const steerCanLead = steered.length > 0 && Boolean(existing?.conversationId);
2089
- if (isContinuation && late.length === 0 && steerCanLead) steerLedFresh = true;
2090
2157
  if (isContinuation && late.length === 0 && !steerCanLead) {
2091
2158
  if (escalatedNames.length === 0) {
2092
2159
  deps.log?.("turn-error", { reason: "tool-result-no-active-turn" }, "warn");
@@ -2129,6 +2196,25 @@ async function runTurnDriver(
2129
2196
  const run = extractTrailingUserRun(context.messages, watermark, boundaryTrusted);
2130
2197
  const userPrompt = run.prompt;
2131
2198
  const images = run.images;
2199
+ // Set only when the steer actually ships inside THIS dispatch: a
2200
+ // trailing user run carries it (own prompt or images, or joined with
2201
+ // late strands by the late-delivery framing). Image-only runs ship with
2202
+ // prompt null, so the run counts by images too. Every collected steer
2203
+ // must sit inside the run - a steer stranded before runStart (watermark
2204
+ // trim, untrusted-boundary fallback) would be lost when the settle
2205
+ // advances the watermark past it, so the sweep stays its deliverer and
2206
+ // the in-run steer duplicates instead (one duplicate beats a loss).
2207
+ // Gating on the run, not on late.length, keeps the sweep off when
2208
+ // stranded results ship beside the steer, and keeps it on for
2209
+ // late-only synthetic dispatches where the sweep is the steer's only
2210
+ // delivery window.
2211
+ if (
2212
+ isContinuation &&
2213
+ steerCanLead &&
2214
+ (run.prompt !== null || run.images.length > 0) &&
2215
+ steered[0].index >= run.runStart
2216
+ )
2217
+ steerLedFresh = true;
2132
2218
  // Resume pass (issue #8): pi's retry dropped the failed attempt from the
2133
2219
  // projected context, so the transcript ends in a toolResult or assistant
2134
2220
  // message and there is no user prompt, no pending park, and nothing
@@ -2177,7 +2263,6 @@ async function runTurnDriver(
2177
2263
  // Post-compaction handoff / compactionResume always ships the digest
2178
2264
  // once even if config.digest is false, because the old agy conversation
2179
2265
  // was rotated and the fresh conversation has no prior history.
2180
- const engine = deps.engine ?? config.engine;
2181
2266
  // A joined run can outgrow the stream-json silent-drop cap on its own
2182
2267
  // (issue #24): the digest budget used to absorb these bytes. Truncate
2183
2268
  // oldest-first, keeping the newest run members; synthetic resume
@@ -2217,8 +2302,10 @@ async function runTurnDriver(
2217
2302
  // everything up to here is the prompt the turn carries, so mid-park
2218
2303
  // steers must land strictly after this index. Synthetic prompts (late
2219
2304
  // strands, resume, compaction seeding) do NOT open one - their context
2220
- // may still hold undelivered steers.
2221
- if (!resume && !compactionResume && late.length === 0) {
2305
+ // may still hold undelivered steers. A steerLedFresh dispatch joins the
2306
+ // steer into its prompt even with strands, so it owns a window too:
2307
+ // the sweep that would normally claim the steer stays off.
2308
+ if ((!resume && !compactionResume && late.length === 0) || steerLedFresh) {
2222
2309
  steerCursors.set(key, { dispatchedAt: messageCount, deliveredThrough: 0 });
2223
2310
  }
2224
2311
  const handoffRuntime = deps.handoffRuntime;