@estebanforge/pi-antigravity-bridge 1.13.2 → 1.14.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 +30 -0
- package/extensions/index.ts +123 -68
- package/package.json +1 -1
- package/src/acp/connection.ts +16 -4
- package/src/acp/driver.ts +23 -7
- package/src/ask-tool.ts +2 -2
- package/src/atomic-write.ts +41 -0
- package/src/config.ts +59 -40
- package/src/driver-types.ts +8 -0
- package/src/mcp-registration.ts +3 -8
- package/src/mcp-server.ts +54 -23
- package/src/native-tools.ts +2 -0
- package/src/provider.ts +162 -16
- package/src/runtime.ts +310 -0
- package/src/sessions.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.14.0] - 2026-11-24
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- One oversized tool result no longer erases earlier turns from the context digest (#25): tool-result bodies are capped per part (head + tail with an elision marker) before the delta budget is spent, so a single >8KB read/bash result can no longer starve the mid-session handoff.
|
|
10
|
+
- Assistant tool calls now render into the digest (`[tool call: name(args)]`, args capped and redacted) instead of vanishing with their text blocks; a turn carrying only tool calls ships too, where it used to be skipped entirely (#25).
|
|
11
|
+
- A config.json saved before the digest-default flip no longer silently keeps the digest off (#25): `migrateStaleDigestDefault` at session start flips the stale `digest: false` to the shipped ON default once, writes a `digestMigrated` marker so later deliberate `/agy digest off` survives, and respects `AGY_DIGEST`. One-time ambiguity window: an `/agy digest off` chosen between the flip commit and this release migrates to ON once (the toast explains how to keep it off).
|
|
12
|
+
- A bound turn whose digest build fails the stream-json byte cap no longer permanently loses that delta (#25 follow-up): the settle write holds the watermark when nothing shipped, so the window re-offers on the next turn (the re-offer re-includes the prior turn's user prompt, which already reached the conversation as that turn's prompt - a small duplicate, never a loss); partial renders (budget cut old turns) still advance and now log the skipped span (`digest` event, AGY_DEBUG-visible) for cap-deciding data.
|
|
13
|
+
- An ACP `session/load` failure that silently falls back to a fresh agy conversation no longer ships a blind turn (#25): bound turns carry an as-if-fresh fallback variant (system prompt gate open, full `bound: false` digest) that the driver swaps in at the load-failure point; the variant honors the same `/agy digest off` and `/agy system-prompt off` choices as the normal turn, and with both off no variant is built at all. stream-json cannot detect its stale-id drop, so the fallback is ACP-only.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- ACP digest cap raised 8k to 24k chars after a live probe (scripts/probe-acp-context.mjs): a 120k-char embeddedContext block shipped and the model recalled needle strings at both block extremities exactly (end needle on the digest turn; start needle again on a bound follow-up with no block re-sent, proving the block persists server-side), so 24k is transport-safe and shrinks the newest-first partial-render hole. stream-json keeps its 8k inline clamp under the ~25KB prompt cap.
|
|
18
|
+
- AskAntigravity model param description now names the configured default (gemini-4-hydrogen) and the Gemini 4 lines. Removed the legacy flash/pro examples: callers read them as the house default, hard-coded `model: "flash"`, and skipped the hydrogen default entirely (flash resolves to the deprecated 3.x era).
|
|
19
|
+
|
|
20
|
+
## [1.13.3] - 2026-11-23
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **Multiple sessions in one process now share one bridge runtime instead of clobbering each other's provider and `process.pid` artifacts.** Subagent or multi-session spawns in the same JS realm previously overwrote the global provider registration and deleted `agy-mcp-<pid>`, `approval-hook-<pid>.js`, and global `mcp_config.json` entries on child shutdown while the parent was still running. A shared realm runtime (`src/runtime.ts`, `Symbol.for`-branded to survive `/reload`) now owns one `SessionStore`, routes `streamSimple` by live `options.sessionId` (failing closed when multiple sessions are active and unmatched), serves one MCP listener with per-session route tokens (`addRoute`), isolates per-factory `activeUi` and lazy `conversationId` attribution, stages gate hooks idempotently per `session_start`, and tears down per-realm artifacts (including keep-alive sockets) in a `try/finally` only when the last session leaves.
|
|
25
|
+
|
|
26
|
+
- **The approval gate no longer lets `skipPermissions` auto-allow `session/request_permission` on ACP turns.** Staged gate hooks do not stop `agy`'s own permission path, so a gate-active turn with `skipPermissions` previously bypassed the gate; when the gate is active, `approvals.mode` and the permission dialog now decide (`allow` answers allow, `deny`/headless denies, otherwise the dialog prompts). Permission log events also include the tool kind, redacted title, `toolCallId`, and field names.
|
|
27
|
+
- **`SessionStore.flush()` now drains queued session-binding writes on `session_shutdown`.** Headless/print runs exiting right after the final bind can no longer drop the last `sessions.json` update before the process exits.
|
|
28
|
+
- **`read_file` steps on stream-json now re-execute as native `read` calls.** Matches `agy` 1.5.14's rename of `view_file` (same `Path`/`StartLine`/`EndLine` shape; unknown keys still fall back to the wrapper).
|
|
29
|
+
- **The stream-json `mcp_config.json` and suppression-marker writes are now symlink-safe too.** The same dotfiles hazard as `config.json`: `mcp-registration.ts` wrote `~/.gemini/config/mcp_config.json` (register, disable flip, unregister, stale sweep) and `suppression.json` (delegation markers) via temp + rename over the raw path, so a symlinked file was silently replaced by a regular file on the first write. Both now go through a shared `writeJsonAtomic` helper (extracted from `config.ts`, one implementation for every bridge config writer) with the same resolution rules: the rename lands in the link target, a dangling link is written through, hard errors fail visibly. Per-file modes are unchanged (`0600` file, `0700` data dir).
|
|
30
|
+
- **`saveConfig` no longer replaces a symlinked config with a regular file.** The atomic write (temp + rename over the path) swapped a dotfiles-managed config symlink for a plain file on the first unrelated save. `writeConfigJson` now resolves the real target first and renames through it, so the link survives: a missing regular file falls back to the raw path (fresh install), a dangling symlink resolves through the link to its not-yet-existing target, and hard errors (EACCES, a link loop) fail the write visibly instead of falling back and replacing the link. This also backs `removeLegacyAcpBin`, whose explicit resolution it replaces.
|
|
31
|
+
- **`readOnly` now accepts the JSON numbers `0`/`1` the README already promised (issue #23 review).** The file-path parser handled only booleans and strings, so a hand-edited `"readOnly": 0` warned and failed closed to ON - the opposite of what the user wrote, while the warning text itself listed `1/0` as recognized spellings. The literal grammar (booleans, the numbers `0`/`1`, the `on`/`off` vocabulary) now lives in one shared helper used by the boolean parser, the readOnly path, and `saveConfig`; unrecognized values keep failing closed to ON with a warning.
|
|
32
|
+
- **`saveConfig` no longer collapses a hand-edited `acp.sessionRetryOnTimeout` to `false` on unrelated saves (issue #23 review).** The strict `=== true` pass-through discarded the boolish spellings `loadConfig` accepts (`"on"`, `"true"`, `"1"`, the numbers): any unrelated `/agy` toggle rewrote them to `false`. Saves now normalize through the same literal grammar; junk falls back to the default, an explicit patch still wins, `AGY_ACP_SESSION_RETRY` still never bakes into the file, and junk is rewritten (its doctor warning with it) on the first unrelated save - the same trade `sessionTimeoutMs` and `engine` already make.
|
|
33
|
+
- **`saveConfig` no longer invents `turnTimeoutMin: 0` on files that omit the key (issue #23 review).** The `0` in `DEFAULTS` is a load-time placeholder (the real cap resolves per TTY state), but the defaults spread persisted it, and `parseCapMinutes` reads an explicit `0` as "cap disabled" - so one unrelated save silently uncapped future headless turns on installs that never configured a cap. The key is now written only when the file or the patch carries it. Installs already carrying a `0` from an earlier save keep it: a stored `0` is indistinguishable from a deliberate "cap off", so the fix only stops new placeholder writes.
|
|
34
|
+
|
|
5
35
|
## [1.13.2] - 2026-11-22
|
|
6
36
|
|
|
7
37
|
### Fixed
|
package/extensions/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
toPiModel,
|
|
37
37
|
type AgyModelEntry,
|
|
38
38
|
} from "../src/models.js";
|
|
39
|
-
import { SessionStore } from "../src/sessions.js";
|
|
39
|
+
import type { SessionStore } from "../src/sessions.js";
|
|
40
40
|
import {
|
|
41
41
|
APPROVAL_PARK_MS,
|
|
42
42
|
POLL_TOOL_NAME,
|
|
@@ -68,7 +68,7 @@ import { agyAuthenticationMessage } from "../src/agy-install.js";
|
|
|
68
68
|
import { createAgySetupOffer } from "../src/agy-setup.js";
|
|
69
69
|
import { ensureQueuedMessagesDefaults } from "../src/queued-messages.js";
|
|
70
70
|
import type { TurnDriver, TurnOutcome } from "../src/driver-types.js";
|
|
71
|
-
import { configPath, configWarningsMessage, loadConfig, logsDir, MAX_TURN_CAP_MIN, parseCapMinutes, removeLegacyAcpBin, saveConfig, type AcpConfig, type AgyMode, type BridgeTools, type Engine, type ThinkingTier } from "../src/config.js";
|
|
71
|
+
import { configPath, configWarningsMessage, loadConfig, logsDir, MAX_TURN_CAP_MIN, migrateStaleDigestDefault, parseCapMinutes, removeLegacyAcpBin, saveConfig, type AcpConfig, type AgyMode, type BridgeTools, type Engine, type ThinkingTier } from "../src/config.js";
|
|
72
72
|
import { agyMissingMessage, ENGINE_SETTINGS_ROW_ID, engineSettingsRow, isAgyInstalled, savedEngineMessage, showEnginePicker, shouldOfferEnginePicker } from "../src/engine-picker.js";
|
|
73
73
|
import { agyVersionVerdict, agyUpdateMessage, checkAgyCliVersion, describeAgyVersionCheck, MIN_AGY_ACP_VERSION, MIN_AGY_VERSION, MIN_GEMINI_DIR_VERSION, probeGeminiDirFlag, resolveStreamHomeMode } from "../src/agy-version.js";
|
|
74
74
|
import { isValidAgyAgentName, listAgyAgents } from "../src/agents.js";
|
|
@@ -85,13 +85,19 @@ import { redactText } from "../src/redact.js";
|
|
|
85
85
|
import { createDailyLogger, type DailyLogger } from "../src/daily-log.js";
|
|
86
86
|
import { registerAskAntigravityTool, toolModelsFromRaw } from "../src/ask-tool.js";
|
|
87
87
|
import { registerWebTools } from "../src/web-tools.js";
|
|
88
|
-
import { bridgeMcpConfigDir,
|
|
88
|
+
import { bridgeMcpConfigDir, sweepStaleBridgeDirs, TOKEN_HEADER } from "../src/mcp-server.js";
|
|
89
89
|
import {
|
|
90
90
|
registerBridgeServer,
|
|
91
91
|
healBridgeSuppression,
|
|
92
92
|
sweepStaleBridgeServers,
|
|
93
|
-
unregisterBridgeServer,
|
|
94
93
|
} from "../src/mcp-registration.js";
|
|
94
|
+
import {
|
|
95
|
+
approvalHookScriptPath,
|
|
96
|
+
bridgeRealm,
|
|
97
|
+
liveSessionId,
|
|
98
|
+
type BridgeEndpoint,
|
|
99
|
+
type RealmSession,
|
|
100
|
+
} from "../src/runtime.js";
|
|
95
101
|
import {
|
|
96
102
|
ACTIVATE_SKILL_TOOL_NAME,
|
|
97
103
|
activateSkillSchema,
|
|
@@ -117,15 +123,14 @@ import { Type } from "typebox";
|
|
|
117
123
|
import { patchStatus, restorePatch } from "../src/patch-cleanup.js";
|
|
118
124
|
import { withDialogLock } from "../src/dialog-lock.js";
|
|
119
125
|
|
|
120
|
-
// Last UI seen (session_start / /agy commands). Module scope: both the
|
|
121
|
-
// default export and registerAgyCommand assign it.
|
|
122
|
-
let activeUi: ExtensionUIContext | null = null;
|
|
123
|
-
|
|
124
126
|
function resolveAgyBinary(): string {
|
|
125
127
|
return process.env.AGY_BIN || "agy";
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
export default async function (pi: ExtensionAPI): Promise<void> {
|
|
131
|
+
// Per-factory UI reference so child session_shutdown never clears the
|
|
132
|
+
// parent's UI context.
|
|
133
|
+
let activeUi: ExtensionUIContext | null = null;
|
|
129
134
|
ensureQueuedMessagesDefaults({ onlyIfDirExists: true });
|
|
130
135
|
|
|
131
136
|
// Claim the AskAntigravity tool for this process. pi-ask-antigravity (if also
|
|
@@ -210,18 +215,23 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
210
215
|
"info",
|
|
211
216
|
);
|
|
212
217
|
|
|
213
|
-
const
|
|
218
|
+
const realm = bridgeRealm();
|
|
219
|
+
const store = realm.store;
|
|
214
220
|
// MCP bridge handle, declared early: the ACP engine reads the bridge port
|
|
215
221
|
// at session/new / session/load time.
|
|
216
|
-
let mcpHandle:
|
|
222
|
+
let mcpHandle: BridgeEndpoint | null = null;
|
|
223
|
+
let currentSessionManager: unknown;
|
|
224
|
+
let lastConversationId: string | undefined;
|
|
225
|
+
let realmSession: RealmSession | null = null;
|
|
217
226
|
// Session-only visibility overrides; never change either application's MCP config.
|
|
218
227
|
const hiddenBridgeTools = new Set<string>();
|
|
219
228
|
const getBridgeTools = () => bridgedPiTools(pi.getAllTools(), pi.getActiveTools(), loadConfig().bridgeTools, hiddenBridgeTools);
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
let
|
|
229
|
+
// Staged gate hooks do not stop agy's own request_permission path, so when
|
|
230
|
+
// true the ACP driver stops letting skipPermissions auto-allow it.
|
|
231
|
+
let gateActive = false;
|
|
223
232
|
let managedAcpCleanupRan = false;
|
|
224
233
|
let legacyConfigCleanupRan = false;
|
|
234
|
+
let digestMigrationRan = false;
|
|
225
235
|
let legacyConfigCleanupFailed = false;
|
|
226
236
|
let legacyEnvAcpWarningShown = false;
|
|
227
237
|
let legacyFileAcpWarningShown = false;
|
|
@@ -298,7 +308,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
298
308
|
// path; restore the global registration so the bridge stays
|
|
299
309
|
// reachable when the staged home is unusable.
|
|
300
310
|
if (mcpHandle) {
|
|
301
|
-
registerBridgeServer({ pid: process.pid, port: mcpHandle.port, token: mcpHandle.
|
|
311
|
+
registerBridgeServer({ pid: process.pid, port: mcpHandle.port, token: mcpHandle.realmToken, tokenHeader: TOKEN_HEADER });
|
|
302
312
|
}
|
|
303
313
|
return undefined;
|
|
304
314
|
}
|
|
@@ -338,11 +348,14 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
338
348
|
usageEstimate: () => loadConfig().acp.usageEstimate,
|
|
339
349
|
sessionOpTimeoutMs: () => loadConfig().acp.sessionTimeoutMs,
|
|
340
350
|
sessionRetryOnTimeout: () => loadConfig().acp.sessionRetryOnTimeout,
|
|
341
|
-
// ACP request_permission parity with the approval gate:
|
|
342
|
-
// turns auto-allow in the driver
|
|
343
|
-
//
|
|
344
|
-
//
|
|
351
|
+
// ACP request_permission parity with the approval gate: with the gate
|
|
352
|
+
// off, skipPermissions turns auto-allow in the driver. With the gate
|
|
353
|
+
// staged (gateActive) skipPermissions never applies, because the hook
|
|
354
|
+
// does not stop agy's own permission path: approvals.mode allow
|
|
355
|
+
// answers allow, deny answers deny, everything else opens a dialog
|
|
356
|
+
// (esc and headless deny fail-closed) under the shared dialog lock.
|
|
345
357
|
permissionPolicy: () => (loadConfig().approvals.mode === "allow" ? "auto" : "deny"),
|
|
358
|
+
gateActive: () => gateActive,
|
|
346
359
|
onPermissionRequest: async (req) => {
|
|
347
360
|
const ui = activeUi;
|
|
348
361
|
if (loadConfig().approvals.mode === "deny" || !ui) return undefined;
|
|
@@ -506,7 +519,10 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
506
519
|
// Stamp live escalations with the ended turn's conversation: the park
|
|
507
520
|
// pass returns before the provider's store.set, so a first-turn park
|
|
508
521
|
// has no other record of where its result must be re-delivered.
|
|
509
|
-
if (outcome.conversationId)
|
|
522
|
+
if (outcome.conversationId) {
|
|
523
|
+
lastConversationId = outcome.conversationId;
|
|
524
|
+
roundTrips.stampConversation(outcome.conversationId);
|
|
525
|
+
}
|
|
510
526
|
};
|
|
511
527
|
streamDriver.onTurnEnd = onTurnEnd;
|
|
512
528
|
acpDriver.onTurnEnd = onTurnEnd;
|
|
@@ -604,6 +620,9 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
604
620
|
fileLog.log("background-watch-sweep-error", { error: err instanceof Error ? err.message : String(err) }, "warn");
|
|
605
621
|
}
|
|
606
622
|
});
|
|
623
|
+
// Bindings must reach disk before the host exits (headless/print modes
|
|
624
|
+
// exit right after session_shutdown).
|
|
625
|
+
pi.on("session_shutdown", () => store.flush());
|
|
607
626
|
// Session keys whose bound agy conversation was rotated on session_compact
|
|
608
627
|
// so the next turn starts a fresh backend conversation and ships the
|
|
609
628
|
// compaction summary once (even when config.digest is disabled).
|
|
@@ -671,6 +690,16 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
671
690
|
log: fileLog.log.bind(fileLog),
|
|
672
691
|
});
|
|
673
692
|
|
|
693
|
+
const joinRealm = () =>
|
|
694
|
+
realm.join({
|
|
695
|
+
sessionId: () => liveSessionId(currentSessionManager),
|
|
696
|
+
streamSimple,
|
|
697
|
+
hasActiveTurn: () => (engine === "acp" ? acpDriver.activeHandle !== null : streamDriver.activeHandle !== null),
|
|
698
|
+
conversationId: () =>
|
|
699
|
+
(engine === "acp" ? acpDriver.snapshot().conversationId : streamDriver.snapshot().conversationId)
|
|
700
|
+
?? lastConversationId,
|
|
701
|
+
});
|
|
702
|
+
|
|
674
703
|
pi.registerProvider("antigravity", {
|
|
675
704
|
name: "Antigravity (agy)",
|
|
676
705
|
baseUrl: "agy-bridge://antigravity",
|
|
@@ -687,7 +716,10 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
687
716
|
contextWindow: m.contextWindow,
|
|
688
717
|
maxTokens: m.maxTokens,
|
|
689
718
|
})),
|
|
690
|
-
|
|
719
|
+
// pi-ai's provider registry is process-global and every session's factory
|
|
720
|
+
// call registers again: register the realm's stable dispatcher so each
|
|
721
|
+
// call routes to its own session's streamSimple.
|
|
722
|
+
streamSimple: realm.streamSimple,
|
|
691
723
|
});
|
|
692
724
|
|
|
693
725
|
registerAgyCommand(pi, {
|
|
@@ -705,6 +737,9 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
705
737
|
roster,
|
|
706
738
|
pendingCompactionHandoff,
|
|
707
739
|
checkAgySetup,
|
|
740
|
+
setActiveUi: (ui) => {
|
|
741
|
+
activeUi = ui;
|
|
742
|
+
},
|
|
708
743
|
});
|
|
709
744
|
|
|
710
745
|
// AskAntigravity tool: one-shot delegation to agy (ported from
|
|
@@ -791,6 +826,8 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
791
826
|
// normal toolUse loop (native cards, permissions, hooks) - no patch, no
|
|
792
827
|
// privileged API. Started on session_start, torn down on session_shutdown.
|
|
793
828
|
pi.on("session_start", async (event, ctx) => {
|
|
829
|
+
currentSessionManager = ctx.sessionManager;
|
|
830
|
+
realmSession ??= joinRealm();
|
|
794
831
|
if (ctx.hasUI) activeUi = ctx.ui;
|
|
795
832
|
// First-run engine picker: ask once, on the first interactive start,
|
|
796
833
|
// which turn engine to use. Skipped headless (ctx.mode !== "tui"),
|
|
@@ -832,6 +869,25 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
832
869
|
fileLog.log("legacy-acp-config-cleanup", { error: String(err) }, "error");
|
|
833
870
|
}
|
|
834
871
|
}
|
|
872
|
+
// One-time digest-default migration (issue #25): a config saved before
|
|
873
|
+
// the default flip carries digest:false as a bare default, silently
|
|
874
|
+
// keeping mid-session context handoffs off. Best-effort like the
|
|
875
|
+
// cleanup above: a failure must never block session_start.
|
|
876
|
+
if (!digestMigrationRan) {
|
|
877
|
+
digestMigrationRan = true;
|
|
878
|
+
try {
|
|
879
|
+
const migrated = migrateStaleDigestDefault().migrated;
|
|
880
|
+
fileLog.log("digest-default-migration", { migrated }, migrated ? "info" : "debug");
|
|
881
|
+
if (migrated && ctx.hasUI) {
|
|
882
|
+
ctx.ui.notify(
|
|
883
|
+
"digest was still off from an older default; enabled it (keeps context visible on model switches). Keep it off with /agy digest off.",
|
|
884
|
+
"info",
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
} catch (err) {
|
|
888
|
+
fileLog.log("digest-default-migration", { error: String(err) }, "warn");
|
|
889
|
+
}
|
|
890
|
+
}
|
|
835
891
|
if (!legacyEnvAcpWarningShown && process.env.AGY_ACP_BIN?.trim()) {
|
|
836
892
|
legacyEnvAcpWarningShown = true;
|
|
837
893
|
const msg = "AGY_ACP_BIN is set but no longer used; turns run \"agy acp\" from the CLI. Remove it from your shell config, then start a new terminal.";
|
|
@@ -1032,13 +1088,13 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1032
1088
|
isError: !skill,
|
|
1033
1089
|
});
|
|
1034
1090
|
};
|
|
1035
|
-
const r = await
|
|
1091
|
+
const r = await realmSession.attachBridge(
|
|
1036
1092
|
{
|
|
1037
1093
|
listTools,
|
|
1038
1094
|
onToolCall: bridgeOnToolCall,
|
|
1039
1095
|
onApproval: (ticket, payload) => roundTrips.onApproval(ticket, payload),
|
|
1040
1096
|
},
|
|
1041
|
-
|
|
1097
|
+
mcpLog,
|
|
1042
1098
|
);
|
|
1043
1099
|
if (r.ok && r.handle) {
|
|
1044
1100
|
mcpHandle = r.handle;
|
|
@@ -1049,18 +1105,20 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1049
1105
|
// Global-config hygiene runs on BOTH engines: a crashed stream-json
|
|
1050
1106
|
// session must not leave dead-pid entries or stuck suppression flags
|
|
1051
1107
|
// for the next one.
|
|
1052
|
-
healBridgeSuppression();
|
|
1108
|
+
if (r.first) healBridgeSuppression();
|
|
1053
1109
|
// ACP supplies the bridge per-session (session/new | session/load).
|
|
1054
1110
|
// stream-json skips the global file entirely when the isolated home
|
|
1055
1111
|
// is active (issue #14): this session's bridge rides the staged
|
|
1056
1112
|
// config instead, so no other agy on the machine can see or call it.
|
|
1057
1113
|
if (engine === "stream-json" && !streamHome.isolated) {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1114
|
+
if (r.first) {
|
|
1115
|
+
registerBridgeServer({
|
|
1116
|
+
pid: process.pid,
|
|
1117
|
+
port: r.handle.port,
|
|
1118
|
+
token: r.handle.realmToken,
|
|
1119
|
+
tokenHeader: TOKEN_HEADER,
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1064
1122
|
} else if (streamHome.path) {
|
|
1065
1123
|
// Bridge enabled after the home was staged without one: refresh
|
|
1066
1124
|
// the staged copy directly. agy reads the home once at spawn;
|
|
@@ -1085,6 +1143,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1085
1143
|
{
|
|
1086
1144
|
const cfg = loadConfig();
|
|
1087
1145
|
const mode = resolveGateMode(cfg.approvals.gateMode, detectPermissionGateExtensions());
|
|
1146
|
+
gateActive = mode !== "off";
|
|
1088
1147
|
if (mode !== "off" && engine === "acp") {
|
|
1089
1148
|
// Staged-home hook delivery is probe-verified on agy 1.5.12
|
|
1090
1149
|
// only (issue #18); older ACP builds may not honor it. Warn
|
|
@@ -1105,34 +1164,35 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1105
1164
|
// Staging now lives in the session-private add-dir; sweep groups left
|
|
1106
1165
|
// behind by dead sessions from the old scheme. Live sessions' and
|
|
1107
1166
|
// foreign groups are never touched.
|
|
1108
|
-
|
|
1109
|
-
|
|
1167
|
+
if (r.first) {
|
|
1168
|
+
const sweptLegacy = sweepWorkspaceGateGroups(process.cwd());
|
|
1169
|
+
if (sweptLegacy > 0) fileLog.log("approval-workspace-swept", { swept: sweptLegacy }, "info");
|
|
1170
|
+
}
|
|
1110
1171
|
if (mode === "off") {
|
|
1111
|
-
// Gate off: drop this session's private hooks file.
|
|
1112
|
-
// own their own per-pid files; nothing shared to preserve.
|
|
1172
|
+
// Gate off: drop this session's private hooks file.
|
|
1113
1173
|
const unstaged = removeGateHooks();
|
|
1114
1174
|
if (unstaged.wrote) fileLog.log("approval-unstaged", unstaged, "info");
|
|
1115
1175
|
} else {
|
|
1116
|
-
// Script: per-
|
|
1117
|
-
// embedded (peer review 2026-09-07).
|
|
1118
|
-
|
|
1176
|
+
// Script: per-realm file; 0600 because the realm token is
|
|
1177
|
+
// embedded (peer review 2026-09-07). Re-stage idempotently so
|
|
1178
|
+
// a partial failure on an earlier session never leaves the
|
|
1179
|
+
// gate un-staged while gateActive is true.
|
|
1180
|
+
const scriptPath = approvalHookScriptPath();
|
|
1119
1181
|
fs.mkdirSync(path.dirname(scriptPath), { recursive: true, mode: 0o700 });
|
|
1120
1182
|
fs.writeFileSync(
|
|
1121
1183
|
scriptPath,
|
|
1122
1184
|
hookScriptSource({
|
|
1123
1185
|
port: r.handle.port,
|
|
1124
|
-
token: r.handle.
|
|
1186
|
+
token: r.handle.realmToken,
|
|
1125
1187
|
deadlineMs: APPROVAL_PARK_MS,
|
|
1126
1188
|
}),
|
|
1127
1189
|
{ mode: 0o600 },
|
|
1128
1190
|
);
|
|
1129
|
-
|
|
1130
|
-
//
|
|
1131
|
-
// into the bridge add-dir that ONLY this session's agy receives.
|
|
1132
|
-
// Standalone sessions in the workspace never load it.
|
|
1191
|
+
// Private per-realm staging (issue #5 isolation): the gate group goes
|
|
1192
|
+
// into the bridge add-dir that ONLY this process's agy receives.
|
|
1133
1193
|
const staged = stageGateHooks(bridgeMcpConfigDir(), {
|
|
1134
1194
|
port: r.handle.port,
|
|
1135
|
-
token: r.handle.
|
|
1195
|
+
token: r.handle.realmToken,
|
|
1136
1196
|
scriptPath,
|
|
1137
1197
|
parkBudgetMs: APPROVAL_PARK_MS,
|
|
1138
1198
|
});
|
|
@@ -1198,31 +1258,25 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
1198
1258
|
activeUi = null;
|
|
1199
1259
|
const h = mcpHandle;
|
|
1200
1260
|
mcpHandle = null;
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
try {
|
|
1221
|
-
fs.rmSync(gateScriptPath, { force: true });
|
|
1222
|
-
} catch {
|
|
1223
|
-
/* best effort */
|
|
1224
|
-
}
|
|
1225
|
-
gateScriptPath = null;
|
|
1261
|
+
try {
|
|
1262
|
+
// "recycle", NOT "shutdown": pi fires session_shutdown on /new, /resume
|
|
1263
|
+
// and /fork (docs/extensions.md session lifecycle), not only on process
|
|
1264
|
+
// exit. The drivers are process-lifetime singletons; closing them with
|
|
1265
|
+
// "shutdown" latched them permanently and every later turn failed with
|
|
1266
|
+
// "ACP driver is shut down." (regression 2026-09-07). Recycle kills the
|
|
1267
|
+
// connection now; the next turn respawns it. event.reason is
|
|
1268
|
+
// deliberately ignored: recycle is correct even on real process exit
|
|
1269
|
+
// ("quit") - the connection kill is identical and nothing runs after.
|
|
1270
|
+
await streamDriver.close("recycle", "session shutdown");
|
|
1271
|
+
await acpDriver.close("recycle", "session shutdown");
|
|
1272
|
+
roundTrips.failAll(FAIL_REASON_SHUTDOWN);
|
|
1273
|
+
await h?.close();
|
|
1274
|
+
hiddenBridgeTools.clear();
|
|
1275
|
+
} finally {
|
|
1276
|
+
// Leaving the realm revokes this session's route; only the last session
|
|
1277
|
+
// to leave tears down the shared listener and per-realm artifacts.
|
|
1278
|
+
await realmSession?.leave();
|
|
1279
|
+
realmSession = null;
|
|
1226
1280
|
}
|
|
1227
1281
|
});
|
|
1228
1282
|
}
|
|
@@ -1249,6 +1303,7 @@ interface AgyCommandCtx {
|
|
|
1249
1303
|
roster: SubagentRoster;
|
|
1250
1304
|
pendingCompactionHandoff: Set<string>;
|
|
1251
1305
|
checkAgySetup: (ctx: { ui: ExtensionUIContext; mode: string }, engine: Engine, explicit?: boolean) => Promise<void>;
|
|
1306
|
+
setActiveUi: (ui: ExtensionUIContext) => void;
|
|
1252
1307
|
}
|
|
1253
1308
|
|
|
1254
1309
|
interface PendingConfig {
|
|
@@ -1315,7 +1370,7 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
1315
1370
|
"Antigravity provider: doctor (health + settings), settings picker, clear sessions. Usage: /agy [doctor|auth|auth-manual|engine stream-json|acp|mode plan|accept-edits|readonly on|off|permissions on|off|ask on|off|model <alias>|thinking low|medium|high|agent <name|off>|subagents|quota|artifacts [open <n|name>]|tasks [tail <id>]|bridge all|mcp|none|tools [hide|show <name>|reset]|web on|off|digest on|off|system-prompt on|off|timeout <1-1440|off>|patch-cleanup|clear]",
|
|
1316
1371
|
handler: async (args, cmdCtx: ExtensionCommandContext) => {
|
|
1317
1372
|
const ui = cmdCtx.ui;
|
|
1318
|
-
if (ui)
|
|
1373
|
+
if (ui) ctx.setActiveUi(ui);
|
|
1319
1374
|
const mode = cmdCtx.mode;
|
|
1320
1375
|
const sub = (args ?? "").trim().split(/\s+/)[0]?.toLowerCase();
|
|
1321
1376
|
const val = (args ?? "").trim().split(/\s+/)[1]?.toLowerCase();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estebanforge/pi-antigravity-bridge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.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/acp/connection.ts
CHANGED
|
@@ -102,6 +102,18 @@ export interface AcpPermissionRequest {
|
|
|
102
102
|
|
|
103
103
|
export type AcpPermissionHandler = (req: AcpPermissionRequest) => Promise<string | null | undefined>;
|
|
104
104
|
|
|
105
|
+
/** Tool identity of a permission request for the log: kind, redacted title,
|
|
106
|
+
* toolCallId and field names only (no raw input, so no file contents). */
|
|
107
|
+
function permissionToolIdentity(params: AcpPermissionRequest | undefined): Record<string, string | string[]> {
|
|
108
|
+
const tc = params?.toolCall;
|
|
109
|
+
const out: Record<string, string | string[]> = {};
|
|
110
|
+
if (tc && typeof tc === "object") out.fields = Object.keys(tc);
|
|
111
|
+
if (typeof tc?.kind === "string") out.kind = tc.kind;
|
|
112
|
+
if (typeof tc?.title === "string") out.title = redactText(tc.title).slice(0, 200);
|
|
113
|
+
if (typeof tc?.toolCallId === "string") out.toolCallId = tc.toolCallId;
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
|
|
106
118
|
export class AcpConnection {
|
|
107
119
|
#opts: AcpConnectionOptions;
|
|
@@ -421,12 +433,12 @@ export class AcpConnection {
|
|
|
421
433
|
const policy = this.#opts.permissions?.() ?? "deny";
|
|
422
434
|
if (policy === "auto") {
|
|
423
435
|
const chosen = (allow ?? options[0])?.optionId;
|
|
424
|
-
this.#opts.log("permission", { optionId: chosen, policy });
|
|
436
|
+
this.#opts.log("permission", { optionId: chosen, policy, tool: permissionToolIdentity(params) });
|
|
425
437
|
return Promise.resolve({ outcome: { outcome: "selected", optionId: chosen } });
|
|
426
438
|
}
|
|
427
439
|
const handler = this.#opts.onPermissionRequest;
|
|
428
440
|
if (!handler) {
|
|
429
|
-
this.#opts.log("permission", { optionId: denyId, policy });
|
|
441
|
+
this.#opts.log("permission", { optionId: denyId, policy, tool: permissionToolIdentity(params) });
|
|
430
442
|
return Promise.resolve(
|
|
431
443
|
denyId !== undefined
|
|
432
444
|
? { outcome: { outcome: "selected", optionId: denyId } }
|
|
@@ -438,7 +450,7 @@ export class AcpConnection {
|
|
|
438
450
|
const memKey = params?.toolCall?.title ? `${params.toolCall.kind ?? ""}|${params.toolCall.title}` : undefined;
|
|
439
451
|
const remembered = memKey !== undefined ? this.#permissionMemory.get(memKey) : undefined;
|
|
440
452
|
if (remembered !== undefined && options.some((o) => o.optionId === remembered)) {
|
|
441
|
-
this.#opts.log("permission", { optionId: remembered, policy: "memory" });
|
|
453
|
+
this.#opts.log("permission", { optionId: remembered, policy: "memory", tool: permissionToolIdentity(params) });
|
|
442
454
|
return Promise.resolve({ outcome: { outcome: "selected", optionId: remembered } });
|
|
443
455
|
}
|
|
444
456
|
const parkMs = this.#opts.permissionParkMs ?? PERMISSION_PARK_MS;
|
|
@@ -452,7 +464,7 @@ export class AcpConnection {
|
|
|
452
464
|
settled = true;
|
|
453
465
|
if (timer) clearTimeout(timer);
|
|
454
466
|
this.#permissionPending.delete(settleCancel);
|
|
455
|
-
this.#opts.log("permission", { optionId, policy: why });
|
|
467
|
+
this.#opts.log("permission", { optionId, policy: why, tool: permissionToolIdentity(params) });
|
|
456
468
|
// undefined optionId (no reject option on the table) cancels
|
|
457
469
|
// instead of selecting nothing.
|
|
458
470
|
resolve(
|
package/src/acp/driver.ts
CHANGED
|
@@ -59,10 +59,14 @@ export interface AcpDriverOptions {
|
|
|
59
59
|
onPermissionRequest?: AcpPermissionHandler;
|
|
60
60
|
/** Park budget for one permission dialog (tests shrink it). */
|
|
61
61
|
permissionParkMs?: number;
|
|
62
|
-
/** Standing policy consulted when the turn is not skipPermissions
|
|
63
|
-
* "auto" answers the first
|
|
64
|
-
* the human handler or
|
|
62
|
+
/** Standing policy consulted when the turn is not skipPermissions, or
|
|
63
|
+
* skipPermissions is overridden by gateActive: "auto" answers the first
|
|
64
|
+
* allow option synchronously, "deny" consults the human handler or
|
|
65
|
+
* fail-closes. Default deny. */
|
|
65
66
|
permissionPolicy?: () => "auto" | "deny";
|
|
67
|
+
/** True while the approval gate is staged: staged hooks do not stop
|
|
68
|
+
* agy's own request_permission path, so skipPermissions must not bypass it. */
|
|
69
|
+
gateActive?: () => boolean;
|
|
66
70
|
/** Timeout in ms for session/new, session/load, set_config_option, and
|
|
67
71
|
* session/close. Defaults to AcpConnection's 20000ms. */
|
|
68
72
|
sessionOpTimeoutMs?: number | (() => number);
|
|
@@ -289,7 +293,10 @@ export class AcpDriver implements TurnDriver {
|
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
async #executeTurn(turn: ActiveTurn): Promise<void> {
|
|
292
|
-
|
|
296
|
+
// Reassigned when a load failure applies the request's fresh-mode
|
|
297
|
+
// fallback (issue #25): everything after session setup must read the
|
|
298
|
+
// swapped variant.
|
|
299
|
+
let request = turn.request;
|
|
293
300
|
const conn = await this.#ensureConnection(request);
|
|
294
301
|
let reused = false;
|
|
295
302
|
|
|
@@ -336,6 +343,14 @@ export class AcpDriver implements TurnDriver {
|
|
|
336
343
|
this.#failTurn(turn, `ACP session failed: ${describe(err2)}`);
|
|
337
344
|
return;
|
|
338
345
|
}
|
|
346
|
+
if (request.fallback) {
|
|
347
|
+
// The recreated conversation holds nothing: swap in the as-if-
|
|
348
|
+
// fresh variant the provider prebuilt (system prompt + full
|
|
349
|
+
// digest) instead of shipping the bound-mode prompt blind.
|
|
350
|
+
this.#log("session-load-fallback-applied", { sessionId: request.conversationId });
|
|
351
|
+
request = { ...request, prompt: request.fallback.prompt, contextBlock: request.fallback.contextBlock };
|
|
352
|
+
turn.request = request;
|
|
353
|
+
}
|
|
339
354
|
} else {
|
|
340
355
|
this.#failTurn(turn, `ACP session failed: ${describe(err)}`);
|
|
341
356
|
return;
|
|
@@ -626,11 +641,12 @@ export class AcpDriver implements TurnDriver {
|
|
|
626
641
|
cwd: request.cwd,
|
|
627
642
|
mcpServers: this.#opts.mcpServers,
|
|
628
643
|
log: (msg, data) => this.#log(msg, data),
|
|
629
|
-
// Fail-closed permissions: skipPermissions answers allow
|
|
630
|
-
//
|
|
644
|
+
// Fail-closed permissions: skipPermissions answers allow unless the
|
|
645
|
+
// approval gate is active; then (and for non-skip turns) a standing
|
|
646
|
+
// policy decides (approvals.mode allow widens to auto), everything
|
|
631
647
|
// else goes to the human handler or denies.
|
|
632
648
|
permissions: () =>
|
|
633
|
-
this.#active?.request.skipPermissions
|
|
649
|
+
this.#active?.request.skipPermissions && !this.#opts.gateActive?.()
|
|
634
650
|
? "auto"
|
|
635
651
|
: (this.#opts.permissionPolicy?.() ?? "deny"),
|
|
636
652
|
onPermissionRequest: this.#opts.onPermissionRequest
|
package/src/ask-tool.ts
CHANGED
|
@@ -64,7 +64,7 @@ COMPACT OUTPUT (param: digest): when true, the prompt is prefixed to request com
|
|
|
64
64
|
THINKING LEVEL (params: thinking, effort - SYNONYMS for one knob):
|
|
65
65
|
- pi calls it thinking, agy calls it effort. Same thing. Pass ONE of the two.
|
|
66
66
|
- Values (pi vocabulary): minimal|low|medium|high|xhigh|max. Clamped to agy's low|medium|high; unknown values fall back to low. "peer review on high thinking" -> thinking: "high".
|
|
67
|
-
- An explicit level beats a tier embedded in model ("
|
|
67
|
+
- An explicit level beats a tier embedded in model ("gemini-4-carbon-high") and the configured default. Omit both for the configured default.`;
|
|
68
68
|
|
|
69
69
|
// Delegations legitimately run long (research, review, analysis); a short
|
|
70
70
|
// default kills the run mid-task and the caller re-pays the whole prompt.
|
|
@@ -669,7 +669,7 @@ export async function registerAskAntigravityTool(
|
|
|
669
669
|
model: Type.Optional(
|
|
670
670
|
Type.String({
|
|
671
671
|
description:
|
|
672
|
-
"Model alias or exact id.
|
|
672
|
+
"Model alias or exact id. Omit for the configured default (gemini-4-hydrogen, fast all-rounder). Gemini 4 lines: 'gemini-4-hydrogen' (default), 'gemini-4-neon' (more capable), 'gemini-4-carbon' (most capable). Tier via suffix: 'gemini-4-carbon-high'. Legacy 'flash'/'pro' resolve to the deprecated 3.x era.",
|
|
673
673
|
}),
|
|
674
674
|
),
|
|
675
675
|
thinking: Type.Optional(
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export interface AtomicJsonWriteOptions {
|
|
5
|
+
/** File mode for the written file. Default 0600: these files carry secrets. */
|
|
6
|
+
mode?: number;
|
|
7
|
+
/** Mode for directories created on the way to the file. Default: process umask. */
|
|
8
|
+
dirMode?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Atomic JSON write (temp + rename) for every shared config file. The
|
|
12
|
+
* rename goes through the symlink-resolved target so a dotfiles-managed
|
|
13
|
+
* link survives: an existing file resolves to its real path, a dangling
|
|
14
|
+
* link resolves one hop (the missing target is created through the link),
|
|
15
|
+
* a vanished non-link falls back to the raw path (fresh install), and any
|
|
16
|
+
* other resolution error (EACCES, a link loop) throws instead of silently
|
|
17
|
+
* replacing a link. The temp file lives in the target's directory so the
|
|
18
|
+
* rename never crosses devices. */
|
|
19
|
+
export function writeJsonAtomic(file: string, value: unknown, opts: AtomicJsonWriteOptions = {}): void {
|
|
20
|
+
let target = file;
|
|
21
|
+
try {
|
|
22
|
+
target = fs.realpathSync(file);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if ((err as NodeJS.ErrnoException).code !== "ENOENT") throw err;
|
|
25
|
+
const st = fs.lstatSync(file, { throwIfNoEntry: false });
|
|
26
|
+
if (st?.isSymbolicLink()) target = path.resolve(path.dirname(file), fs.readlinkSync(file));
|
|
27
|
+
}
|
|
28
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: opts.dirMode });
|
|
29
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
30
|
+
try {
|
|
31
|
+
fs.writeFileSync(tmp, JSON.stringify(value, null, 2) + "\n", { mode: opts.mode ?? 0o600 });
|
|
32
|
+
fs.renameSync(tmp, target);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
try {
|
|
35
|
+
fs.unlinkSync(tmp);
|
|
36
|
+
} catch {
|
|
37
|
+
/* nothing to clean */
|
|
38
|
+
}
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|