@estebanforge/pi-antigravity-bridge 1.15.0 → 1.15.1
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 +6 -0
- package/package.json +1 -1
- package/src/provider.ts +175 -31
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.15.1] - 2026-11-25
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- A user message typed while a bridge tool round-trip was parked no longer vanishes (Baluard session 2026-11-25 11:54): pi's steering poll delivered it into the transcript, but the continuation pass re-attached to the parked turn without sending any new user event, so the model answered the pre-park work, the queue stayed empty, and the turn ended with the message sitting unanswered. The provider now late-delivers steered messages to the same conversation once the parked turn settles OK, combined with any stranded escalated results in a single prompt (image blocks ride along; the plain no-steer continuation still starts no run). Delivery floor is a per-session dispatch cursor, not the first-pending-toolResult anchor, so a steer from an EARLIER park of a park chain (the normal shape under the approval gate) is still found; a failed or unbindable late start holds both the watermark and the boundary fingerprint at the first undelivered message so the digest re-offers the steer instead of resetting to full history (delivery invariant: claim only what reached agy); the sync handoff contract invalidates on that failure so its checkpoint cannot claim it either; a steer leads the fresh dispatch when the parked turn is already gone (dead handle) instead of an error stop; and an oversized steer is visibly truncated on stream-json instead of silently dropped (issue #2).
|
|
10
|
+
|
|
5
11
|
## [1.15.0] - 2026-11-24
|
|
6
12
|
|
|
7
13
|
### Added
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estebanforge/pi-antigravity-bridge",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.1",
|
|
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
|
@@ -88,6 +88,15 @@ export function _resetObservationalMemoryWarnedForTesting(): void {
|
|
|
88
88
|
* each other's files. */
|
|
89
89
|
const stagedAgentByConversation = new Map<string, string>();
|
|
90
90
|
|
|
91
|
+
/** Per-session mid-park steering cursor: the context length the current turn
|
|
92
|
+
* was dispatched with, and the transcript index past the last steer actually
|
|
93
|
+
* delivered to agy. The moving first-pending-toolResult anchor alone misses
|
|
94
|
+
* a steer that landed during an EARLIER park of a park chain: the anchor
|
|
95
|
+
* moves to the newer park's toolResult, which sits after the steer, and the
|
|
96
|
+
* settle claims it undelivered. Absent (pi restart mid-turn) the provider
|
|
97
|
+
* falls back to the anchor rule. */
|
|
98
|
+
const steerCursors = new Map<string, { dispatchedAt: number; deliveredThrough: number }>();
|
|
99
|
+
|
|
91
100
|
/** Zero-usage helper. agy doesn't expose token counts; pi's cost math gets
|
|
92
101
|
* zeros (we're not billing through this provider). */
|
|
93
102
|
function zeroUsage(): Usage {
|
|
@@ -375,9 +384,9 @@ const ACP_DIGEST_MAX_CHARS = 24_000;
|
|
|
375
384
|
/** stream-json single-prompt silent-drop cap (issue #2, probed 2026-09-30):
|
|
376
385
|
* the CLI drops any prompt past ~25KB with SUCCESS and an empty response,
|
|
377
386
|
* and the dropped turn leaves the conversation permanently unresponsive. */
|
|
378
|
-
const STREAM_JSON_PROMPT_CAP = 25_000;
|
|
387
|
+
export const STREAM_JSON_PROMPT_CAP = 25_000;
|
|
379
388
|
/** Headroom under the cap for the staged-image note and prompt framing. */
|
|
380
|
-
const STREAM_JSON_PROMPT_MARGIN = 4_096;
|
|
389
|
+
export const STREAM_JSON_PROMPT_MARGIN = 4_096;
|
|
381
390
|
|
|
382
391
|
/** Per-engine digest cap. ACP ships the digest as an embeddedContext
|
|
383
392
|
resource block: no prompt cap applies, so the probe-raised cap stands.
|
|
@@ -1364,6 +1373,57 @@ export interface LateToolResult {
|
|
|
1364
1373
|
images?: Array<{ data: string; mimeType: string }>;
|
|
1365
1374
|
}
|
|
1366
1375
|
|
|
1376
|
+
export interface SteeredUserMessage {
|
|
1377
|
+
/** Transcript index of the message; the watermark hold on a failed
|
|
1378
|
+
* delivery claims up to this index. */
|
|
1379
|
+
index: number;
|
|
1380
|
+
text: string;
|
|
1381
|
+
images: Array<{ data: string; mimeType: string }>;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/** User messages pi delivered into the context after the steering floor: pi's
|
|
1385
|
+
* steering poll runs right after tool results, so a message typed while agy
|
|
1386
|
+
* was parked joins the transcript but the continuation pass re-attaches to
|
|
1387
|
+
* the parked turn and sends no new user event (Baluard 2026-11-25: the
|
|
1388
|
+
* message sat in the transcript, agy never saw it, and pi's drained queue
|
|
1389
|
+
* never re-triggered - the turn just ended). The floor is the session's
|
|
1390
|
+
* steering cursor (dispatch length + delivered-through); without one (pi
|
|
1391
|
+
* restart mid-turn) it falls back to the first still-pending toolResult's
|
|
1392
|
+
* index, whose everything-before belongs to the parked turn's dispatched
|
|
1393
|
+
* prompt. Backlog shapes (compaction/branch/bash runs) never count as
|
|
1394
|
+
* steering. Pure; exported for tests. */
|
|
1395
|
+
export function collectSteeredUserMessages(messages: Message[], pendingIds: readonly string[], floor?: number): SteeredUserMessage[] {
|
|
1396
|
+
if (pendingIds.length === 0) return [];
|
|
1397
|
+
let start: number;
|
|
1398
|
+
if (floor !== undefined) {
|
|
1399
|
+
start = floor;
|
|
1400
|
+
} else {
|
|
1401
|
+
const pending = new Set(pendingIds);
|
|
1402
|
+
let anchor = -1;
|
|
1403
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1404
|
+
const m = messages[i];
|
|
1405
|
+
if (m.role !== "toolResult") continue;
|
|
1406
|
+
const id = (m as { toolCallId?: string }).toolCallId;
|
|
1407
|
+
if (id && pending.has(id)) {
|
|
1408
|
+
anchor = i;
|
|
1409
|
+
break;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (anchor < 0) return [];
|
|
1413
|
+
start = anchor + 1;
|
|
1414
|
+
}
|
|
1415
|
+
const out: SteeredUserMessage[] = [];
|
|
1416
|
+
for (let i = start; i < messages.length; i++) {
|
|
1417
|
+
const m = messages[i];
|
|
1418
|
+
if (m.role !== "user") continue;
|
|
1419
|
+
if (isBacklogUserShape(blocksToText(m.content))) continue;
|
|
1420
|
+
const parts = lastMessageParts(m);
|
|
1421
|
+
if (!parts.text && parts.images.length === 0) continue;
|
|
1422
|
+
out.push({ index: i, text: parts.text ?? "", images: parts.images });
|
|
1423
|
+
}
|
|
1424
|
+
return out;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1367
1427
|
/** Frame late tool results so agy treats them as the results its bridge calls
|
|
1368
1428
|
* never received: a park whose round-trip died while the pi tool ran, or an
|
|
1369
1429
|
* escalated result the model never polled. The reason carries the framing. */
|
|
@@ -1668,6 +1728,22 @@ async function runTurnDriver(
|
|
|
1668
1728
|
// agy receives the result via the bridge's MCP HTTP response.
|
|
1669
1729
|
const results = collectToolResults(context.messages, deps.roundTrips.pendingIds);
|
|
1670
1730
|
const isContinuation = results.length > 0;
|
|
1731
|
+
// Scanned before the resolve loop: the pending set must still contain the
|
|
1732
|
+
// parks being resolved. The steering floor is the session's dispatch
|
|
1733
|
+
// cursor when one exists (dispatch length + delivered-through), else the
|
|
1734
|
+
// first-pending-toolResult anchor fallback.
|
|
1735
|
+
const steerCursor = steerCursors.get(key);
|
|
1736
|
+
const steered = ephemeral
|
|
1737
|
+
? []
|
|
1738
|
+
: collectSteeredUserMessages(
|
|
1739
|
+
context.messages,
|
|
1740
|
+
deps.roundTrips.pendingIds,
|
|
1741
|
+
steerCursor ? Math.max(steerCursor.dispatchedAt, steerCursor.deliveredThrough) : undefined,
|
|
1742
|
+
);
|
|
1743
|
+
// Set when a steer leads the dead-turn fallback into a fresh dispatch: the
|
|
1744
|
+
// steer shipped as that dispatch's own prompt, so the post-outcome sweep
|
|
1745
|
+
// must stay off (and its stranded-claim re-sweep with it).
|
|
1746
|
+
let steerLedFresh = false;
|
|
1671
1747
|
// Escalated calls answer through bridge_poll_result, not through an agy
|
|
1672
1748
|
// turn waiting on the park, so note them before resolving.
|
|
1673
1749
|
const escalatedNames = results
|
|
@@ -1798,7 +1874,13 @@ async function runTurnDriver(
|
|
|
1798
1874
|
// Dead turn: claim NOW (single-use). A live turn claims after outcome
|
|
1799
1875
|
// instead — claiming here would eat the post-outcome recovery.
|
|
1800
1876
|
if (!ephemeral) late.push(...collectStranded());
|
|
1801
|
-
|
|
1877
|
+
// A steer with a bound conversation leads the fresh dispatch instead of
|
|
1878
|
+
// stopping quietly: the trailing user run becomes the prompt, so the
|
|
1879
|
+
// message is answered rather than dropped or left to the digest window.
|
|
1880
|
+
// The sweep below must not re-deliver what that dispatch just shipped.
|
|
1881
|
+
const steerCanLead = steered.length > 0 && Boolean(existing?.conversationId);
|
|
1882
|
+
if (isContinuation && late.length === 0 && steerCanLead) steerLedFresh = true;
|
|
1883
|
+
if (isContinuation && late.length === 0 && !steerCanLead) {
|
|
1802
1884
|
if (escalatedNames.length === 0) {
|
|
1803
1885
|
deps.log?.("turn-error", { reason: "tool-result-no-active-turn" }, "warn");
|
|
1804
1886
|
finalize(stream, blocks, "error", "tool result arrived but no antigravity turn is running");
|
|
@@ -1924,6 +2006,14 @@ async function runTurnDriver(
|
|
|
1924
2006
|
// contract, and the settle bypasses the digest store writes. Legacy
|
|
1925
2007
|
// paths (late/strand redelivery, retry-dropped resume, post-compaction
|
|
1926
2008
|
// resume) and the churn latch stay on the digest flow.
|
|
2009
|
+
// A fresh dispatch of the trailing user run opens a new steering window:
|
|
2010
|
+
// everything up to here is the prompt the turn carries, so mid-park
|
|
2011
|
+
// steers must land strictly after this index. Synthetic prompts (late
|
|
2012
|
+
// strands, resume, compaction seeding) do NOT open one - their context
|
|
2013
|
+
// may still hold undelivered steers.
|
|
2014
|
+
if (!resume && !compactionResume && late.length === 0) {
|
|
2015
|
+
steerCursors.set(key, { dispatchedAt: messageCount, deliveredThrough: 0 });
|
|
2016
|
+
}
|
|
1927
2017
|
const handoffRuntime = deps.handoffRuntime;
|
|
1928
2018
|
const syncTurnRequested = config.handoff === "sync" && engine === "acp";
|
|
1929
2019
|
if (
|
|
@@ -2353,38 +2443,89 @@ async function runTurnDriver(
|
|
|
2353
2443
|
// fix: sweep and deliver as a late run in the same conversation. Single
|
|
2354
2444
|
// shot: claims are single-use, so a re-delivered strand cannot reappear
|
|
2355
2445
|
// here; a late run that parks hands recovery to the next pi pass.
|
|
2446
|
+
// A late-start failure must invalidate the sync contract below: its
|
|
2447
|
+
// checkpoint would claim the steer agy never received.
|
|
2448
|
+
let lateStartFailed = false;
|
|
2356
2449
|
if (!ephemeral && isContinuation && outcome.status === "OK" && !outcome.aborted) {
|
|
2357
|
-
const more = collectStranded();
|
|
2358
|
-
|
|
2450
|
+
const more = steerLedFresh ? [] : collectStranded();
|
|
2451
|
+
// Steered messages join the same late run: pi delivered them into the
|
|
2452
|
+
// context while the turn was parked and the reentry pass sent nothing
|
|
2453
|
+
// to agy, so this sweep is the only delivery window left.
|
|
2454
|
+
if (!steerLedFresh && (more.length > 0 || steered.length > 0)) {
|
|
2359
2455
|
const conv = redeliveryConversation ?? outcome.conversationId ?? existing?.conversationId ?? null;
|
|
2360
|
-
|
|
2361
|
-
const
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
timeoutMin: config.turnTimeoutMin,
|
|
2370
|
-
inactivityMin: config.inactivityTimeoutMin,
|
|
2371
|
-
conversationId: conv,
|
|
2372
|
-
prompt: buildLateResultPrompt(more) + stageImageNote(moreImages),
|
|
2373
|
-
images: moreImages.length > 0 ? moreImages : undefined,
|
|
2374
|
-
agent: config.agent ?? (conv ? stagedAgentByConversation.get(conv) : undefined),
|
|
2375
|
-
signal: options?.signal,
|
|
2376
|
-
});
|
|
2377
|
-
if ((await drainTurn(lateHandle)) === "parked") return;
|
|
2378
|
-
outcome = await lateHandle.outcome;
|
|
2379
|
-
} catch (err) {
|
|
2380
|
-
// Release the claims so the next pass can retry the delivery.
|
|
2381
|
-
for (const l of more) if (l.callId) deps.roundTrips.unclaim(l.callId);
|
|
2456
|
+
const steerText = steered.map((s) => s.text).filter(Boolean).join("\n\n");
|
|
2457
|
+
const latePrompt = more.length > 0 ? buildLateResultPrompt(more, steerText || undefined) : steerText;
|
|
2458
|
+
// stream-json silently drops any prompt past the cap (issue #2) and
|
|
2459
|
+
// the dropped turn leaves the conversation unresponsive: slice the
|
|
2460
|
+
// steer visibly instead of killing it.
|
|
2461
|
+
const lateBudget = STREAM_JSON_PROMPT_CAP - STREAM_JSON_PROMPT_MARGIN;
|
|
2462
|
+
let deliveredLatePrompt = latePrompt;
|
|
2463
|
+
if ((deps.engine ?? config.engine) !== "acp" && Buffer.byteLength(latePrompt, "utf8") > lateBudget) {
|
|
2464
|
+
deliveredLatePrompt = `[truncated]\n${Buffer.from(latePrompt, "utf8").subarray(0, Math.max(0, lateBudget - 32)).toString("utf8")}`;
|
|
2382
2465
|
deps.log?.(
|
|
2383
|
-
"turn-
|
|
2384
|
-
{ reason: "
|
|
2385
|
-
"
|
|
2466
|
+
"turn-warning",
|
|
2467
|
+
{ reason: "steer-prompt-truncated", bytes: Buffer.byteLength(latePrompt, "utf8"), budget: lateBudget },
|
|
2468
|
+
"warn",
|
|
2386
2469
|
);
|
|
2387
2470
|
}
|
|
2471
|
+
const moreImages = [...more.flatMap((s) => s.images ?? []), ...steered.flatMap((s) => s.images)];
|
|
2472
|
+
deps.log?.(
|
|
2473
|
+
"steered-redelivery-turn",
|
|
2474
|
+
{ tools: more.map((s) => s.name), steered: steered.length, conversation: conv },
|
|
2475
|
+
"info",
|
|
2476
|
+
);
|
|
2477
|
+
if (!conv) {
|
|
2478
|
+
// Unbindable: a brand-new conversation would answer the steer with
|
|
2479
|
+
// zero context. Release the claims and hold the watermark - the
|
|
2480
|
+
// digest re-offers the steer once a conversation is bound.
|
|
2481
|
+
for (const l of more) if (l.callId) deps.roundTrips.unclaim(l.callId);
|
|
2482
|
+
lateStartFailed = true;
|
|
2483
|
+
if (steered.length > 0) {
|
|
2484
|
+
nextCount = steered[0].index;
|
|
2485
|
+
nextBoundary = boundaryFingerprint(context.messages[steered[0].index - 1]);
|
|
2486
|
+
}
|
|
2487
|
+
deps.log?.("turn-warning", { reason: "steer-redelivery-unbound", steered: steered.length }, "warn");
|
|
2488
|
+
} else {
|
|
2489
|
+
try {
|
|
2490
|
+
const lateHandle = await deps.driver.run({
|
|
2491
|
+
cwd,
|
|
2492
|
+
model: agyModel,
|
|
2493
|
+
effort,
|
|
2494
|
+
mode: config.mode,
|
|
2495
|
+
skipPermissions: config.skipPermissions,
|
|
2496
|
+
timeoutMin: config.turnTimeoutMin,
|
|
2497
|
+
inactivityMin: config.inactivityTimeoutMin,
|
|
2498
|
+
conversationId: conv,
|
|
2499
|
+
prompt: deliveredLatePrompt + stageImageNote(moreImages),
|
|
2500
|
+
images: moreImages.length > 0 ? moreImages : undefined,
|
|
2501
|
+
agent: config.agent ?? (conv ? stagedAgentByConversation.get(conv) : undefined),
|
|
2502
|
+
signal: options?.signal,
|
|
2503
|
+
});
|
|
2504
|
+
// Accepted by agy from here on: a parked late run hands
|
|
2505
|
+
// recovery to the next pass, which must not re-collect it.
|
|
2506
|
+
const cursor = steerCursors.get(key);
|
|
2507
|
+
if (cursor && steered.length > 0) cursor.deliveredThrough = steered[steered.length - 1].index + 1;
|
|
2508
|
+
if ((await drainTurn(lateHandle)) === "parked") return;
|
|
2509
|
+
outcome = await lateHandle.outcome;
|
|
2510
|
+
} catch (err) {
|
|
2511
|
+
// Release the claims so the next pass can retry the delivery.
|
|
2512
|
+
for (const l of more) if (l.callId) deps.roundTrips.unclaim(l.callId);
|
|
2513
|
+
// A steer has no registry to re-arm, only the digest window: hold
|
|
2514
|
+
// the watermark AND the boundary fingerprint at the first
|
|
2515
|
+
// undelivered message, or the next turn reads the mismatched
|
|
2516
|
+
// boundary as a mutated transcript and resets to full history.
|
|
2517
|
+
lateStartFailed = true;
|
|
2518
|
+
if (steered.length > 0) {
|
|
2519
|
+
nextCount = steered[0].index;
|
|
2520
|
+
nextBoundary = boundaryFingerprint(context.messages[steered[0].index - 1]);
|
|
2521
|
+
}
|
|
2522
|
+
deps.log?.(
|
|
2523
|
+
"turn-error",
|
|
2524
|
+
{ reason: "redelivery-start-failed", error: err instanceof Error ? err.message : String(err) },
|
|
2525
|
+
"error",
|
|
2526
|
+
);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2388
2529
|
}
|
|
2389
2530
|
}
|
|
2390
2531
|
// Sync settle: the orchestrator owns the record write (zeroed contract),
|
|
@@ -2411,7 +2552,10 @@ async function runTurnDriver(
|
|
|
2411
2552
|
})();
|
|
2412
2553
|
const result = settleSync.finish(
|
|
2413
2554
|
{
|
|
2414
|
-
|
|
2555
|
+
// A late-start failure leaves the steer undelivered: a terminal
|
|
2556
|
+
// checkpoint would claim it. Invalidate so the next turn re-plans
|
|
2557
|
+
// and the rebuild re-ships the steer as the newest user entry.
|
|
2558
|
+
ok: outcome.status === "OK" && !lateStartFailed,
|
|
2415
2559
|
conversationId: outcome.conversationId ?? null,
|
|
2416
2560
|
aborted: outcome.aborted,
|
|
2417
2561
|
promptAttempted: outcome.promptAttempted,
|