@estebanforge/pi-antigravity-bridge 1.10.5 → 1.10.6
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 +7 -0
- package/README.md +2 -2
- package/extensions/index.ts +90 -6
- package/package.json +1 -1
- package/src/acp/connection.ts +3 -3
- package/src/acp/home.ts +58 -12
- package/src/agy-version.ts +147 -0
- package/src/driver.ts +69 -6
- package/src/mcp-registration.ts +23 -4
- package/src/sysprompt-agent.ts +18 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.10.6] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **stream-json sessions get the same cross-session MCP isolation ACP already had.** Every pi session wrote a `pi-bridge-<pid>` entry into the global `~/.gemini/config/mcp_config.json`, and agy hot-reloads the watched config, so ANY agy on the machine could discover and call ANY session's bridge: `tools/list` ignores turn state, so a foreign call hit an idle provider (fail-closed "no active antigravity turn") or parked inside another session's live turn (issue #14; thanks @leofranjav for the report and the `--gemini_dir` spike that proved the flag). The stream-json driver now stages a per-session MCP home - the global servers minus every foreign bridge, plus this session's own entry written ENABLED straight into the staged copy, because the delegation-suppression marker protects foreign readers of the global file and must never disable our own home - and spawns agy with the undocumented top-level `--gemini_dir <home>` flag. A quota-free capability probe (one `--gemini_dir <tmp> --version` spawn, memoized per binary) gates the path: flag refusal, probe timeout, or spawn failure falls back to the legacy global registration plus suppression with a one-time warning (the toast names which), a version above the live-verified floor (1.5.8) still isolates but logs an unverified-version notice (a parse probe cannot detect a flag that is accepted but ignored), and an `AGY_AGENTS_ROOT` sandbox override skips even the probe and keeps the legacy path (carriers stage outside the home's live agents view). If staging itself fails, the global registration is restored so the bridge stays reachable, and a bridge enabled after the home was staged writes its own entry straight into the staged copy. The home is removed only after the child's process GROUP is confirmed dead - leader death is not group death, and late agy subprocess writes would recreate a removed home; the session-start sweep accepts both engine prefixes, and a recycle restages so the next process picks up a fresh global-config snapshot. ACP behavior is unchanged. The stream-json driver now also honors `AGY_BIN` for its spawn (previously it always ran PATH `agy`; the probe, doctor, and ask-tool already resolved the override, so with it set the probe tested a different binary than the one that ran). Applies from the next pi process start. Live-verified 2026-11-13 on agy 1.5.8: a real agy turn under a staged home discovered the staged own entry, authenticated with the bridge token, and completed a full MCP `tools/call` round-trip while the global config stayed byte-identical.
|
|
10
|
+
- **stream-json carrier sessions have their write/edit/command tools back.** The staged system-prompt agent (`pi-bridge-sys-*`, the G10 carrier that keeps pi's system prompt off the ~25KB prompt-line cap) omitted the `tools:` frontmatter key on the assumption that omission keeps agy's full default toolset. agy reads an omitted `tools:` as a small read-only default set instead (official migrate-agent-settings guidance: always declare it), so carrier sessions could not `write_file`, `edit_file`, or `run_command` and reported only inspection tools (issue #13). The carrier now declares the productive toolset (`read_file`, `edit_file`, `write_file`, `run_command`, `manage_task`, `search_web`) in block style, the same shape the web delegates already prove agy parses; agy appends the resource/MCP tools itself, so bridge G9 round-trips are unaffected. Three tools that rode the broken read-only default (`generate_image`, `send_message`, `schedule`) are now undeclared: the first is marginal for a provider session (images ride the bridge), the latter two are subagent machinery the carrier masks anyway. Only the carrier changes - the web delegates keep their search-only `tools:` sandbox and the ask-tool reviewer keeps stripping everything, both intentional. Applies from the next pi process start: staged carriers are per-process dirs and old ones are pruned by the pid sweep; a conversation resumed across that restart gets the new agent name and the driver recycles on the drift.
|
|
11
|
+
|
|
5
12
|
## [1.10.5] - 2026-11-13
|
|
6
13
|
|
|
7
14
|
### Changed
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ The bridge starts a localhost MCP server inside pi's process. The exposed catalo
|
|
|
42
42
|
|
|
43
43
|
**Long calls don't die.** agy's MCP client abandons a `tools/call` request at a flat ~180s, which used to kill any pi tool that ran longer (a long peer review, a build, a commit preview waiting for you). A call still running after ~20 seconds now settles its HTTP request with a `STILL RUNNING` answer carrying a `callId` while pi keeps executing; agy fetches the result through the bridge-local `bridge_poll_result` tool and polls until it lands. Delegation-shaped tools (pi subagent/delegation tools, e.g. `subagent_run`, `agent_spawn`) hold the synchronous window 120s instead (issue #6: orchestrators expect a plain result across the 30-120s subagent range, and 120s stays under the 180s wall); `escalateLongTools` in config.json adds custom names. Escalated calls get their own 30-minute budget, so human-gated tools can take as long as the human takes. Fast calls stay fully synchronous and never see any of this. If a park does fail (abort, timeout, recycle), the late result is re-routed to agy as a follow-up prompt in the same conversation instead of being lost. If pi retries a failed turn and drops the attempt from the projected context (pi core `_omitRecoveryAttempt`), leaving a toolResult or assistant tail with no live turn, the provider re-opens the bound conversation with a synthetic resume prompt instead of the unretryable "No user message" hard error (issue #8); a first-ever turn that parks binds its conversation at park time, so a retry-dropped tail has a conversation to resume into unless the park produced no conversation id or the later failure proved the conversation dead. Consecutive polls render as ONE ♊︎-marked counted line (`♊︎ bridge_poll_result Poll git_commit (x30)`) instead of one entry per poll, with a live muted status counter while a run is open.
|
|
44
44
|
|
|
45
|
-
**Session isolation.**
|
|
45
|
+
**Session isolation.** Both engines keep their agy in a private MCP home with every global `pi-bridge` and `pi-bridge-<pid>` entry filtered out (issue #14): ACP via per-session `mcpServers`, stream-json via the top-level `--gemini_dir` flag, which a quota-free capability probe verifies per agy version. If the running CLI refuses the flag or the home cannot be staged, stream-json falls back to the legacy global per-pid registration plus the delegation suppression machinery, with a one-time warning. The home shares CLI credentials, settings, and conversation state without inheriting another pi session's bridge.
|
|
46
46
|
|
|
47
47
|
**Recursion safety.** Only the provider's agy receives the extra `--add-dir`. `AskAntigravity` is also filtered from the exposed tool list. Its delegated `agy -p` spawns with just the workspace, and for the whole delegated run the bridge hides its global per-pid entries: disabled before the spawn, released only on process close or error - agy watches the config and hot-reloads MCP servers on file changes, so a mid-run re-enable would poke the live delegation back into pi. A cross-process marker (`suppression.json` in the bridge's extensions-data dir) coordinates concurrent delegations: entries come back only when no live delegation remains, a session starting mid-delegation registers its own entry disabled, and the session-start heal re-enables only once the last delegator is gone (dead entries pruned by pid liveness with a 24h age bound). The inner agy therefore sees no bridge and cannot re-enter pi. Foreign servers in the global config are never touched.
|
|
48
48
|
|
|
@@ -119,7 +119,7 @@ If `agy models` fails at load (binary missing, auth not done, network stall), a
|
|
|
119
119
|
| `webTools` | `off` (no web tools), `on` (register `agy_web_search` + `agy_read_url` as Pi tools, usable by ANY provider's model). Each call spawns a one-shot search-only `agy` agent (plan mode, bridge MCP inheritance off), gates the answer on an observed native `search_web`/`read_url_content` step, and spends Antigravity quota. Off by default: Antigravity sessions already have native web tools on both engines; these serve other providers | `off` |
|
|
120
120
|
| `bridgeTools` | `none` (bridge off), `all` (every non-builtin tool, incl. other `Ask*` delegations), `mcp` (pi-mcp-adapter tools + skills bridge only) | `all` |
|
|
121
121
|
| `digest` | `off` (stable prompts; agy's prompt cache hits) or `on` (inject a delta of pi-side context - compaction summaries, other-provider turns - into each agy prompt; the delta changes every turn, so agy re-bills the full context). Enable for mixed-provider sessions where agy must see pi-side context | `off` |
|
|
122
|
-
| `systemPrompt` | `on` (send pi's system prompt - operating instructions plus the global agent-dir `AGENTS.md` and ancestor `AGENTS.md`/`CLAUDE.md` - to the first prompt of each new agy conversation, plus a tool-priority note: Pi Bridge tools win over agy's native interactive ones, which never reach the user. Delivery: stream-json stages it as an agy agent file via `--agent`, off the prompt line - the CLI silently drops single prompts past a ~25KB cap and the dropped turn kills the conversation; the carrier declares `subagent: false` + `agents: []` so the native subagent tools stay masked (ACP carries no agent file, so its natives remain and the tool-priority note steers the model to pi delegation). ACP prepends it to the first prompt) or `off` (agy-native behavior) | `on` |
|
|
122
|
+
| `systemPrompt` | `on` (send pi's system prompt - operating instructions plus the global agent-dir `AGENTS.md` and ancestor `AGENTS.md`/`CLAUDE.md` - to the first prompt of each new agy conversation, plus a tool-priority note: Pi Bridge tools win over agy's native interactive ones, which never reach the user. Delivery: stream-json stages it as an agy agent file via `--agent`, off the prompt line - the CLI silently drops single prompts past a ~25KB cap and the dropped turn kills the conversation; the carrier declares the productive toolset explicitly (omitting `tools:` reads as a read-only set upstream, issue #13) plus `subagent: false` + `agents: []` so the native subagent tools stay masked (ACP carries no agent file, so its natives remain and the tool-priority note steers the model to pi delegation). ACP prepends it to the first prompt) or `off` (agy-native behavior) | `on` |
|
|
123
123
|
| `turnTimeoutMin` | Overall cap on ONE agy turn, minutes, both engines. Parked time (pi-tool round-trips, escalated calls, human-gated approvals) does not count against it on either engine: the cap pauses with remaining-budget semantics and resumes on unpark. When it fires, the bridge kills the agy process mid-task ("ACP turn exceeded the 10m deadline" / "agy exceeded the 10m turn timeout") - it is a bridge cap, not a Google server limit. Default is TTY-aware: `0` (no cap) on an interactive pi - you are the backstop with Esc; `20` headless, where nobody can abort and one runaway turn blocks the serialized turn queue. Opt into a gate with 1-1440 (free type via `config.json` or `/agy timeout <1-1440|off>`, or the `/agy` picker's preset list); `0` disables explicitly; anything else falls back to the TTY-aware default. The 5m inactivity stall guard always still bounds a hung server | `0` TTY / `20` headless |
|
|
124
124
|
| `inactivityTimeoutMin` | Silence cap, minutes, both engines: no stream-json stdout / no ACP session/update for this long fails the turn as a stall. `0` disables the guard. Parks (bridge calls, escalated calls, ACP permission dialogs) pause it; agy-native long steps such as builds do not. A false kill costs the whole turn, and on stream-json a stall kill with no result frame clears the conversation binding. Keep `5`; use `2`-`3` only when native steps are known to be short; do not use `1` | `5` |
|
|
125
125
|
|
package/extensions/index.ts
CHANGED
|
@@ -59,7 +59,7 @@ import { detectPermissionGateExtensions, resolveGateMode } from "../src/approval
|
|
|
59
59
|
import { hookScriptSource, removeGateHooks, stageGateHooks, sweepWorkspaceGateGroups } from "../src/approval-hook.js";
|
|
60
60
|
import { StreamDriver } from "../src/driver.js";
|
|
61
61
|
import { AcpDriver } from "../src/acp/driver.js";
|
|
62
|
-
import {
|
|
62
|
+
import { removeStagedAgyHome, stageAgyHome, sweepStagedAgyHomes, writeOwnBridgeEntry } from "../src/acp/home.js";
|
|
63
63
|
import { cleanupManagedAcpInstall } from "../src/acp/setup.js";
|
|
64
64
|
import { agyAuthenticationMessage } from "../src/agy-install.js";
|
|
65
65
|
import { createAgySetupOffer } from "../src/agy-setup.js";
|
|
@@ -67,7 +67,7 @@ import { ensureQueuedMessagesDefaults } from "../src/queued-messages.js";
|
|
|
67
67
|
import type { TurnDriver, TurnOutcome } from "../src/driver-types.js";
|
|
68
68
|
import { CONFIG_PATH, loadConfig, logsDir, MAX_TURN_CAP_MIN, parseCapMinutes, removeLegacyAcpBin, saveConfig, type AgyMode, type BridgeTools, type Engine, type ThinkingTier } from "../src/config.js";
|
|
69
69
|
import { agyMissingMessage, ENGINE_SETTINGS_ROW_ID, engineSettingsRow, isAgyInstalled, savedEngineMessage, showEnginePicker, shouldOfferEnginePicker } from "../src/engine-picker.js";
|
|
70
|
-
import { agyVersionVerdict, checkAgyCliVersion, describeAgyVersionCheck, MIN_AGY_ACP_VERSION, MIN_AGY_VERSION } from "../src/agy-version.js";
|
|
70
|
+
import { agyVersionVerdict, checkAgyCliVersion, describeAgyVersionCheck, MIN_AGY_ACP_VERSION, MIN_AGY_VERSION, MIN_GEMINI_DIR_VERSION, probeGeminiDirFlag, resolveStreamHomeMode } from "../src/agy-version.js";
|
|
71
71
|
import { isValidAgyAgentName, listAgyAgents } from "../src/agents.js";
|
|
72
72
|
import { formatSubagentRoster, SubagentRoster } from "../src/subagent-roster.js";
|
|
73
73
|
import { spawn } from "node:child_process";
|
|
@@ -245,6 +245,67 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
245
245
|
const level = failed ? "warn" : msg === "turn-start" ? "info" : "debug";
|
|
246
246
|
fileLog.log(msg, data, level);
|
|
247
247
|
};
|
|
248
|
+
// --- Isolated stream-json MCP home (issue #14) ----------------------------
|
|
249
|
+
// ACP has isolated its MCP view since the private-home work. stream-json
|
|
250
|
+
// spawned against the GLOBAL config, where every session's pi-bridge-<pid>
|
|
251
|
+
// entry is visible to every agy on the machine - and agy hot-reloads the
|
|
252
|
+
// watched config, so the ask-tool suppression dances cannot protect
|
|
253
|
+
// long-lived provider sessions. When the CLI parses --gemini_dir, each
|
|
254
|
+
// stream-json child gets a staged home instead: the global servers minus
|
|
255
|
+
// every foreign bridge, plus this session's own entry (enabled - the
|
|
256
|
+
// suppression marker never applies to our own home, a private-home agy
|
|
257
|
+
// does not read the global file at all).
|
|
258
|
+
const agentsRootOverride = Boolean(process.env.AGY_AGENTS_ROOT);
|
|
259
|
+
// The override must gate the PROBE too, not just staging: carriers stage
|
|
260
|
+
// under AGY_AGENTS_ROOT, outside the home's live agents view.
|
|
261
|
+
const streamHomeProbe = engine === "stream-json" && !agentsRootOverride ? await probeGeminiDirFlag(binary) : undefined;
|
|
262
|
+
const homeMode = resolveStreamHomeMode({ engine, agentsRootOverride, probe: streamHomeProbe });
|
|
263
|
+
const streamHome: { isolated: boolean; path: string | undefined; fallbackReason?: string } = {
|
|
264
|
+
isolated: homeMode === "isolated",
|
|
265
|
+
path: undefined,
|
|
266
|
+
};
|
|
267
|
+
if (homeMode === "isolated") {
|
|
268
|
+
if (streamHomeProbe?.unverifiedVersion) {
|
|
269
|
+
fileLog.log("gemini-dir-unverified", { version: streamHomeProbe.version, verifiedFloor: MIN_GEMINI_DIR_VERSION }, "info");
|
|
270
|
+
}
|
|
271
|
+
streamDriver.stagedHome = () => {
|
|
272
|
+
if (streamHome.path) return streamHome.path;
|
|
273
|
+
try {
|
|
274
|
+
streamHome.path = stageAgyHome({
|
|
275
|
+
prefix: "agy-home",
|
|
276
|
+
ownBridge: mcpHandle
|
|
277
|
+
? { pid: process.pid, port: mcpHandle.port, token: mcpHandle.token, tokenHeader: TOKEN_HEADER }
|
|
278
|
+
: undefined,
|
|
279
|
+
});
|
|
280
|
+
} catch (err) {
|
|
281
|
+
fileLog.log("stream-home-stage-failed", { error: String(err) }, "warn");
|
|
282
|
+
// The per-pid --add-dir config is not the stream-json delivery
|
|
283
|
+
// path; restore the global registration so the bridge stays
|
|
284
|
+
// reachable when the staged home is unusable.
|
|
285
|
+
if (mcpHandle) {
|
|
286
|
+
registerBridgeServer({ pid: process.pid, port: mcpHandle.port, token: mcpHandle.token, tokenHeader: TOKEN_HEADER });
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
return streamHome.path;
|
|
291
|
+
};
|
|
292
|
+
streamDriver.releaseStagedHome = (home) => {
|
|
293
|
+
if (streamHome.path === home) streamHome.path = undefined;
|
|
294
|
+
removeStagedAgyHome(home);
|
|
295
|
+
};
|
|
296
|
+
} else if (homeMode === "override-skip") {
|
|
297
|
+
fileLog.log("stream-home-skipped", { reason: "AGY_AGENTS_ROOT override" }, "info");
|
|
298
|
+
} else if (engine === "stream-json") {
|
|
299
|
+
const version = streamHomeProbe?.version ?? "unknown";
|
|
300
|
+
const why =
|
|
301
|
+
streamHomeProbe?.detail === "timeout"
|
|
302
|
+
? `the agy --gemini_dir probe timed out (agy ${version})`
|
|
303
|
+
: streamHomeProbe?.detail === "spawn-failure"
|
|
304
|
+
? `the agy --gemini_dir probe failed to run (agy ${version})`
|
|
305
|
+
: `agy ${version} refused --gemini_dir`;
|
|
306
|
+
streamHome.fallbackReason = why;
|
|
307
|
+
fileLog.log("gemini-dir-refused", { version, detail: streamHomeProbe?.detail ?? "refused" }, "warn");
|
|
308
|
+
}
|
|
248
309
|
const acpLog = (msg: string, data?: unknown): void => {
|
|
249
310
|
const expectedExit =
|
|
250
311
|
msg === "connection-exited" &&
|
|
@@ -573,6 +634,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
573
634
|
acpDriver,
|
|
574
635
|
engine,
|
|
575
636
|
getMcpPort: () => mcpHandle?.port ?? null,
|
|
637
|
+
streamIsolated: streamHome.isolated,
|
|
576
638
|
bridgeTools: getBridgeTools,
|
|
577
639
|
hiddenBridgeTools,
|
|
578
640
|
fileLog,
|
|
@@ -789,7 +851,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
789
851
|
// Sweep crashed sessions even when the bridge is disabled.
|
|
790
852
|
sweepStaleBridgeServers();
|
|
791
853
|
sweepStaleBridgeDirs();
|
|
792
|
-
|
|
854
|
+
sweepStagedAgyHomes();
|
|
793
855
|
// Start the bridge unless the user turned it off. No patch gate, no
|
|
794
856
|
// consent flow: calls route through pi's normal toolUse loop.
|
|
795
857
|
const bridgeMode: BridgeTools = loadConfig().bridgeTools;
|
|
@@ -900,15 +962,32 @@ export default async function (pi: ExtensionAPI): Promise<void> {
|
|
|
900
962
|
// session must not leave dead-pid entries or stuck suppression flags
|
|
901
963
|
// for the next one.
|
|
902
964
|
healBridgeSuppression();
|
|
903
|
-
// ACP supplies the bridge per-session (session/new | session/load)
|
|
904
|
-
//
|
|
905
|
-
|
|
965
|
+
// ACP supplies the bridge per-session (session/new | session/load).
|
|
966
|
+
// stream-json skips the global file entirely when the isolated home
|
|
967
|
+
// is active (issue #14): this session's bridge rides the staged
|
|
968
|
+
// config instead, so no other agy on the machine can see or call it.
|
|
969
|
+
if (engine === "stream-json" && !streamHome.isolated) {
|
|
906
970
|
registerBridgeServer({
|
|
907
971
|
pid: process.pid,
|
|
908
972
|
port: r.handle.port,
|
|
909
973
|
token: r.handle.token,
|
|
910
974
|
tokenHeader: TOKEN_HEADER,
|
|
911
975
|
});
|
|
976
|
+
} else if (streamHome.path) {
|
|
977
|
+
// Bridge enabled after the home was staged without one: refresh
|
|
978
|
+
// the staged copy directly. agy reads the home once at spawn;
|
|
979
|
+
// the running child sees it on its next start.
|
|
980
|
+
try {
|
|
981
|
+
writeOwnBridgeEntry(streamHome.path, { pid: process.pid, port: r.handle.port, token: r.handle.token, tokenHeader: TOKEN_HEADER });
|
|
982
|
+
} catch (err) {
|
|
983
|
+
fileLog.log("stream-home-entry-failed", { error: String(err) }, "warn");
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (streamHome.fallbackReason) {
|
|
987
|
+
// Isolation degraded to the legacy global path: say so once.
|
|
988
|
+
const msg = `[antigravity-bridge] ${streamHome.fallbackReason}; using the global MCP registration (issue #14 isolation unavailable).`;
|
|
989
|
+
if (ctx.hasUI) ctx.ui.notify(msg, "warning");
|
|
990
|
+
else console.error(msg);
|
|
912
991
|
}
|
|
913
992
|
// --- Approval gate (docs/TODO.md 2.5) ------------------------------
|
|
914
993
|
// agy native tool calls pass through a pi-side approval: a PreToolUse
|
|
@@ -1062,6 +1141,9 @@ interface AgyCommandCtx {
|
|
|
1062
1141
|
/** Engine latched at extension load (see the provider wiring note). */
|
|
1063
1142
|
engine: Engine;
|
|
1064
1143
|
getMcpPort: () => number | null;
|
|
1144
|
+
/** stream-json MCP-home isolation state (issue #14): false when the CLI
|
|
1145
|
+
* refused --gemini_dir or a sandbox override kept the legacy path. */
|
|
1146
|
+
streamIsolated: boolean;
|
|
1065
1147
|
bridgeTools: () => Array<{ name: string }>;
|
|
1066
1148
|
hiddenBridgeTools: Set<string>;
|
|
1067
1149
|
/** Daily file logger (src/daily-log.ts); command + doctor surfacing. */
|
|
@@ -1275,6 +1357,8 @@ function registerAgyCommand(pi: ExtensionAPI, ctx: AgyCommandCtx): void {
|
|
|
1275
1357
|
for (const entry of snap.lifecycle.slice(-5)) lines.push(` ${entry}`);
|
|
1276
1358
|
}
|
|
1277
1359
|
if (engine === "acp") lines.push(" acp transport: agy acp (shared CLI authentication, isolated MCP home)");
|
|
1360
|
+
if (engine === "stream-json" && ctx.streamIsolated) lines.push(" stream transport: agy stream-json (shared CLI authentication, isolated MCP home)");
|
|
1361
|
+
if (engine === "stream-json" && !ctx.streamIsolated) lines.push(" stream transport: agy stream-json (shared CLI authentication, GLOBAL MCP registration: isolation unavailable)");
|
|
1278
1362
|
const retiredAuth = path.join(os.homedir(), ".gemini", "antigravity-acp");
|
|
1279
1363
|
if (fs.existsSync(retiredAuth)) lines.push(` retired auth: ${retiredAuth} is unused; remove it manually when no longer needed`);
|
|
1280
1364
|
// The config surface lives here too, so doctor is the ONE status
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estebanforge/pi-antigravity-bridge",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.6",
|
|
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
|
@@ -19,7 +19,7 @@ import { frameCarriesUsage } from "./events.js";
|
|
|
19
19
|
import type { AgyUsage } from "../driver-types.js";
|
|
20
20
|
import { redactText } from "../redact.js";
|
|
21
21
|
import { JsonRpcResponseError, JsonRpcSession } from "./jsonrpc.js";
|
|
22
|
-
import {
|
|
22
|
+
import { removeStagedAgyHome, stageAgyHome } from "./home.js";
|
|
23
23
|
|
|
24
24
|
export interface AcpMcpServer {
|
|
25
25
|
name: string;
|
|
@@ -167,7 +167,7 @@ export class AcpConnection {
|
|
|
167
167
|
if (this.#child) return;
|
|
168
168
|
const args = [...(this.#opts.binArgs ?? [])];
|
|
169
169
|
if (this.#opts.isolateHome) {
|
|
170
|
-
this.#stagedHome =
|
|
170
|
+
this.#stagedHome = stageAgyHome(typeof this.#opts.isolateHome === "object" ? this.#opts.isolateHome : {});
|
|
171
171
|
args.push("--gemini-dir", this.#stagedHome);
|
|
172
172
|
}
|
|
173
173
|
let child: ChildProcess;
|
|
@@ -550,7 +550,7 @@ export class AcpConnection {
|
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
#releaseHome(): void {
|
|
553
|
-
if (this.#stagedHome)
|
|
553
|
+
if (this.#stagedHome) removeStagedAgyHome(this.#stagedHome);
|
|
554
554
|
this.#stagedHome = undefined;
|
|
555
555
|
}
|
|
556
556
|
}
|
package/src/acp/home.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isPidAlive } from "../mcp-server.js";
|
|
5
|
-
import { readGlobalMcpConfig } from "../mcp-registration.js";
|
|
5
|
+
import { bridgeServerEntry, bridgeServerName, readGlobalMcpConfig } from "../mcp-registration.js";
|
|
6
6
|
|
|
7
7
|
function record(value: unknown, label: string): Record<string, unknown> {
|
|
8
8
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must contain a JSON object`);
|
|
@@ -13,12 +13,31 @@ function linkDirectory(source: string, target: string): void {
|
|
|
13
13
|
fs.symlinkSync(source, target, "junction");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/** Staging root for isolated agy homes. The directory name predates the
|
|
17
|
+
* stream-json engine adopting homes; renaming it would strand existing
|
|
18
|
+
* installs' unswept dirs, so both engines stage under it. */
|
|
19
|
+
export function agyHomeStagingDir(): string {
|
|
17
20
|
return path.join(os.homedir(), ".pi", "agent", "antigravity-bridge", "acp-homes");
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
export interface StageAgyHomeOptions {
|
|
24
|
+
geminiHome?: string;
|
|
25
|
+
parentDir?: string;
|
|
26
|
+
/** Dir-name prefix: "acp-home" (ACP engine, default) or "agy-home"
|
|
27
|
+
* (stream-json). The sweep accepts both. */
|
|
28
|
+
prefix?: string;
|
|
29
|
+
/** This session's bridge entry, written ENABLED straight into the staged
|
|
30
|
+
* config (issue #14). Never ride the suppression marker here: the marker
|
|
31
|
+
* hides bridges from an agy reading the GLOBAL config, and a private-home
|
|
32
|
+
* agy never reads global - a marker-disabled own entry would break G9
|
|
33
|
+
* silently inside our own home. Omit when the bridge is off. */
|
|
34
|
+
ownBridge?: { pid: number; port: number; token: string; tokenHeader: string };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Isolate a spawned agy from per-pid bridge entries in the global MCP
|
|
38
|
+
* config: the staged home carries the global servers minus every
|
|
39
|
+
* pi-bridge-*, plus (optionally) exactly this session's bridge entry. */
|
|
40
|
+
export function stageAgyHome(opts: StageAgyHomeOptions = {}): string {
|
|
22
41
|
const geminiHome = opts.geminiHome ?? path.join(os.homedir(), ".gemini");
|
|
23
42
|
const globalConfigDir = path.join(geminiHome, "config");
|
|
24
43
|
const globalMcpPath = path.join(globalConfigDir, "mcp_config.json");
|
|
@@ -33,11 +52,17 @@ export function stageAcpHome(opts: { geminiHome?: string; parentDir?: string } =
|
|
|
33
52
|
}
|
|
34
53
|
}
|
|
35
54
|
const servers = record(config.mcpServers ?? {}, `${globalMcpPath} mcpServers`);
|
|
36
|
-
const filtered = Object.fromEntries(
|
|
55
|
+
const filtered: Record<string, unknown> = Object.fromEntries(
|
|
56
|
+
Object.entries(servers).filter(([name]) => !/^pi-bridge(?:-\d+)?$/.test(name)),
|
|
57
|
+
);
|
|
58
|
+
if (opts.ownBridge) {
|
|
59
|
+
filtered[bridgeServerName(opts.ownBridge.pid)] = bridgeServerEntry({ ...opts.ownBridge, disabled: false });
|
|
60
|
+
}
|
|
37
61
|
|
|
38
|
-
const parentDir = opts.parentDir ??
|
|
62
|
+
const parentDir = opts.parentDir ?? agyHomeStagingDir();
|
|
63
|
+
const prefix = opts.prefix ?? "acp-home";
|
|
39
64
|
fs.mkdirSync(parentDir, { recursive: true, mode: 0o700 });
|
|
40
|
-
const staged = fs.mkdtempSync(path.join(parentDir,
|
|
65
|
+
const staged = fs.mkdtempSync(path.join(parentDir, `${prefix}-${process.pid}-`));
|
|
41
66
|
try {
|
|
42
67
|
fs.mkdirSync(path.join(staged, "config"), { mode: 0o700 });
|
|
43
68
|
fs.writeFileSync(path.join(staged, "config", "mcp_config.json"), JSON.stringify({ ...config, mcpServers: filtered }), { mode: 0o600 });
|
|
@@ -71,7 +96,11 @@ export function stageAcpHome(opts: { geminiHome?: string; parentDir?: string } =
|
|
|
71
96
|
}
|
|
72
97
|
}
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
/** Sweep staged homes whose owning pi process died. Accepts both engine
|
|
100
|
+
* prefixes; a home staged by the CURRENT process is skipped (it may be in
|
|
101
|
+
* use by a live driver - process-exit leftovers are the next start's
|
|
102
|
+
* problem). */
|
|
103
|
+
export function sweepStagedAgyHomes(baseDir: string = agyHomeStagingDir(), alive: (pid: number) => boolean = isPidAlive): void {
|
|
75
104
|
let entries: string[];
|
|
76
105
|
try {
|
|
77
106
|
entries = fs.readdirSync(baseDir);
|
|
@@ -79,16 +108,33 @@ export function sweepStaleAcpHomes(baseDir: string = acpHomeStagingDir(), alive:
|
|
|
79
108
|
return;
|
|
80
109
|
}
|
|
81
110
|
for (const name of entries) {
|
|
82
|
-
const match = /^acp-home-(\d+)-/.exec(name);
|
|
111
|
+
const match = /^(?:acp|agy)-home-(\d+)-/.exec(name);
|
|
83
112
|
if (!match) continue;
|
|
84
113
|
const pid = Number(match[1]);
|
|
85
114
|
if (pid === process.pid || alive(pid)) continue;
|
|
86
|
-
|
|
115
|
+
removeStagedAgyHome(path.join(baseDir, name));
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
118
|
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
/** Add or refresh this session's own bridge entry in an ALREADY-STAGED
|
|
120
|
+
* home (the bridge was enabled after the first spawn staged the home
|
|
121
|
+
* without one). Single-writer file (our pid owns the session), plain
|
|
122
|
+
* write is fine. */
|
|
123
|
+
export function writeOwnBridgeEntry(staged: string, entry: { pid: number; port: number; token: string; tokenHeader: string }): void {
|
|
124
|
+
const cfgPath = path.join(staged, "config", "mcp_config.json");
|
|
125
|
+
const cfg = record(readGlobalMcpConfig(cfgPath), cfgPath);
|
|
126
|
+
const servers = record(cfg.mcpServers ?? {}, `${cfgPath} mcpServers`);
|
|
127
|
+
servers[bridgeServerName(entry.pid)] = bridgeServerEntry({ ...entry, disabled: false });
|
|
128
|
+
// Same-dir tmp + rename: agy watches config dirs, so a truncated
|
|
129
|
+
// mid-write read must be impossible (issue #14 review round 3).
|
|
130
|
+
const tmp = `${cfgPath}.tmp-${process.pid}`;
|
|
131
|
+
fs.writeFileSync(tmp, JSON.stringify({ ...cfg, mcpServers: servers }), { mode: 0o600 });
|
|
132
|
+
fs.renameSync(tmp, cfgPath);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function removeStagedAgyHome(staged: string): void {
|
|
136
|
+
const base = path.basename(staged);
|
|
137
|
+
if (!base.startsWith("acp-home-") && !base.startsWith("agy-home-")) return;
|
|
92
138
|
try {
|
|
93
139
|
if (!fs.lstatSync(staged).isDirectory()) return;
|
|
94
140
|
fs.rmSync(staged, { recursive: true, force: true });
|
package/src/agy-version.ts
CHANGED
|
@@ -11,11 +11,21 @@
|
|
|
11
11
|
// floor because older CLI releases do not ship the subcommand.
|
|
12
12
|
|
|
13
13
|
import { spawn } from "node:child_process";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
14
17
|
|
|
15
18
|
/** Floor for the stream-json CLI. Matches the protocol grammar our driver
|
|
16
19
|
* and the event mapping rely on; older agy predates verified fields. */
|
|
17
20
|
export const MIN_AGY_VERSION = "1.1.22";
|
|
18
21
|
export const MIN_AGY_ACP_VERSION = "1.5.3";
|
|
22
|
+
/** Highest agy release where the top-level --gemini_dir flag was
|
|
23
|
+
* live-verified to isolate MCP discovery (issue #14 work, 2026-11-13).
|
|
24
|
+
* The flag is undocumented upstream and may change shape in future
|
|
25
|
+
* releases; the parse probe catches removal, but a flag that parses yet is
|
|
26
|
+
* IGNORED cannot be probed without quota - versions above this floor warn
|
|
27
|
+
* so a silent G9 tool drop gets noticed. */
|
|
28
|
+
export const MIN_GEMINI_DIR_VERSION = "1.5.8";
|
|
19
29
|
|
|
20
30
|
const VERSION_TIMEOUT_MS = 5_000;
|
|
21
31
|
|
|
@@ -119,6 +129,143 @@ export function resetAgyVersionCache(): void {
|
|
|
119
129
|
checkCache.clear();
|
|
120
130
|
}
|
|
121
131
|
|
|
132
|
+
// --- --gemini_dir capability probe (issue #14) -------------------------------
|
|
133
|
+
|
|
134
|
+
export interface GeminiDirProbe {
|
|
135
|
+
/** True when the running agy parses --gemini_dir on the default run path
|
|
136
|
+
* (the stream-json spawn shape). Refusal means fall back to global MCP
|
|
137
|
+
* registration plus the suppression machinery. */
|
|
138
|
+
supported: boolean;
|
|
139
|
+
version?: string;
|
|
140
|
+
/** Supported but the version is above MIN_GEMINI_DIR_VERSION (or
|
|
141
|
+
* unreadable): the parse probe cannot detect a flag that is accepted but
|
|
142
|
+
* ignored, so the caller should warn once. */
|
|
143
|
+
unverifiedVersion: boolean;
|
|
144
|
+
/** Why the probe said no (absent when supported). Distinguishes an agy
|
|
145
|
+
* that refuses the flag from one the probe could not run at all. */
|
|
146
|
+
detail?: "refused" | "timeout" | "spawn-failure";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** How the stream-json engine should deliver MCP (issue #14). */
|
|
150
|
+
export type StreamHomeMode = "isolated" | "override-skip" | "legacy";
|
|
151
|
+
|
|
152
|
+
/** Decide the stream-json MCP-home mode BEFORE any probe spawn. The
|
|
153
|
+
* AGY_AGENTS_ROOT sandbox override wins over everything: carriers stage
|
|
154
|
+
* outside the staged home's live agents view, so isolation would silently
|
|
155
|
+
* drop the system-prompt carrier regardless of what the probe says. */
|
|
156
|
+
export function resolveStreamHomeMode(input: {
|
|
157
|
+
engine: string;
|
|
158
|
+
agentsRootOverride: boolean;
|
|
159
|
+
probe: GeminiDirProbe | undefined;
|
|
160
|
+
}): StreamHomeMode {
|
|
161
|
+
if (input.engine !== "stream-json") return "legacy";
|
|
162
|
+
if (input.agentsRootOverride) return "override-skip";
|
|
163
|
+
return input.probe?.supported ? "isolated" : "legacy";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ProbeGeminiDirOptions {
|
|
167
|
+
/** Parent dir for the probe home (tests inject an unwritable root). */
|
|
168
|
+
tmpRoot?: string;
|
|
169
|
+
/** Probe watchdog budget (tests shrink the 5s default). */
|
|
170
|
+
watchdogMs?: number;
|
|
171
|
+
/** Extra env for the spawned probe (tests select fixture behaviors). */
|
|
172
|
+
env?: Record<string, string>;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const probeCache = new Map<string, Promise<GeminiDirProbe>>();
|
|
176
|
+
|
|
177
|
+
/** One spawn answers BOTH questions: `agy --gemini_dir <tmp> --version`
|
|
178
|
+
* prints the version when the flag parses, and a Go flag-package refusal
|
|
179
|
+
* ("flag provided but not defined", nonzero exit, empty stdout) when it
|
|
180
|
+
* does not. The default run path parses the underscore form; the acp
|
|
181
|
+
* subcommand takes the hyphen form (both live-verified 2026-11-13 on agy
|
|
182
|
+
* 1.5.8). Memoized per binary until resetGeminiDirProbeCache. */
|
|
183
|
+
export function probeGeminiDirFlag(binary: string = "agy", opts: ProbeGeminiDirOptions = {}): Promise<GeminiDirProbe> {
|
|
184
|
+
const cached = probeCache.get(binary);
|
|
185
|
+
if (cached) return cached;
|
|
186
|
+
const run = new Promise<GeminiDirProbe>((resolve) => {
|
|
187
|
+
let tmp: string;
|
|
188
|
+
try {
|
|
189
|
+
tmp = fs.mkdtempSync(path.join(opts.tmpRoot ?? os.tmpdir(), "agy-geminidir-probe-"));
|
|
190
|
+
} catch {
|
|
191
|
+
// Cannot even stage the probe home: the flag is unproven, fall back.
|
|
192
|
+
resolve({ supported: false, unverifiedVersion: false, detail: "spawn-failure" });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
let out = "";
|
|
196
|
+
let err = "";
|
|
197
|
+
let code: number | null = null;
|
|
198
|
+
let done = false;
|
|
199
|
+
const finish = () => {
|
|
200
|
+
if (done) return;
|
|
201
|
+
done = true;
|
|
202
|
+
clearTimeout(watchdog);
|
|
203
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
204
|
+
// Exit 0 wins: a CLI can print arbitrary warnings (including text
|
|
205
|
+
// that happens to contain "not defined") on a successful probe.
|
|
206
|
+
if (code === 0) {
|
|
207
|
+
const verdict = agyVersionVerdict(out);
|
|
208
|
+
if (verdict.status === "development") {
|
|
209
|
+
resolve({ supported: true, version: "dev", unverifiedVersion: true });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const version = verdict.version;
|
|
213
|
+
resolve({
|
|
214
|
+
supported: true,
|
|
215
|
+
version,
|
|
216
|
+
unverifiedVersion:
|
|
217
|
+
!version || compareVersionTuples(version, MIN_GEMINI_DIR_VERSION) > 0,
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const detail: NonNullable<GeminiDirProbe["detail"]> = /not defined/.test(err)
|
|
222
|
+
? "refused"
|
|
223
|
+
: code === null
|
|
224
|
+
? "timeout"
|
|
225
|
+
: "spawn-failure";
|
|
226
|
+
resolve({ supported: false, unverifiedVersion: false, detail });
|
|
227
|
+
};
|
|
228
|
+
let proc: ReturnType<typeof spawn>;
|
|
229
|
+
try {
|
|
230
|
+
proc = spawn(binary, ["--gemini_dir", tmp, "--version"], {
|
|
231
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
232
|
+
shell: false,
|
|
233
|
+
env: opts.env ? { ...process.env, ...opts.env } : process.env,
|
|
234
|
+
});
|
|
235
|
+
} catch {
|
|
236
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
237
|
+
resolve({ supported: false, unverifiedVersion: false, detail: "spawn-failure" });
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
proc.stdout?.setEncoding("utf8");
|
|
241
|
+
proc.stderr?.setEncoding("utf8");
|
|
242
|
+
proc.stdout?.on("data", (d: string) => (out = (out + d).slice(0, 4096)));
|
|
243
|
+
proc.stderr?.on("data", (d: string) => (err = (err + d).slice(0, 4096)));
|
|
244
|
+
proc.on("error", () => {
|
|
245
|
+
code = code ?? -1;
|
|
246
|
+
finish();
|
|
247
|
+
});
|
|
248
|
+
proc.on("close", (c) => {
|
|
249
|
+
code = c;
|
|
250
|
+
finish();
|
|
251
|
+
});
|
|
252
|
+
const watchdog = setTimeout(() => {
|
|
253
|
+
try {
|
|
254
|
+
proc.kill("SIGKILL");
|
|
255
|
+
} catch {
|
|
256
|
+
/* already gone */
|
|
257
|
+
}
|
|
258
|
+
}, opts.watchdogMs ?? 5_000);
|
|
259
|
+
});
|
|
260
|
+
probeCache.set(binary, run);
|
|
261
|
+
return run;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Test seam: drop the memoized gemini_dir probes. */
|
|
265
|
+
export function resetGeminiDirProbeCache(): void {
|
|
266
|
+
probeCache.clear();
|
|
267
|
+
}
|
|
268
|
+
|
|
122
269
|
/** One-line doctor rendering. */
|
|
123
270
|
export function describeAgyVersionCheck(check: AgyVersionCheck): string {
|
|
124
271
|
switch (check.status) {
|
package/src/driver.ts
CHANGED
|
@@ -101,6 +101,32 @@ function effectiveSkipPermissions(mode: DriverTurnRequest["mode"], skipPermissio
|
|
|
101
101
|
return mode !== "plan" && skipPermissions;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** Wait until the child's process GROUP is gone (POSIX) or return
|
|
105
|
+
* immediately on win32, where the driver does not use detached groups.
|
|
106
|
+
* Leader death alone is not enough: agy's own subprocesses can outlive it
|
|
107
|
+
* and late writes would recreate a removed home dir. Bounded by budgetMs;
|
|
108
|
+
* false means stragglers may remain (the startup sweep is the backstop). */
|
|
109
|
+
export function waitForPidGroupExit(pid: number | undefined, budgetMs = 2_000): Promise<boolean> {
|
|
110
|
+
if (!pid || process.platform === "win32") return Promise.resolve(true);
|
|
111
|
+
const deadline = Date.now() + budgetMs;
|
|
112
|
+
return new Promise<boolean>((resolve) => {
|
|
113
|
+
const tick = () => {
|
|
114
|
+
try {
|
|
115
|
+
process.kill(-pid, 0);
|
|
116
|
+
} catch {
|
|
117
|
+
resolve(true);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (Date.now() >= deadline) {
|
|
121
|
+
resolve(false);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
setTimeout(tick, 50);
|
|
125
|
+
};
|
|
126
|
+
tick();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
104
130
|
function emit(turn: ActiveTurn, activity: DriverActivity): void {
|
|
105
131
|
if (turn.closed) return;
|
|
106
132
|
if (turn.wake.length > 0) turn.wake.shift()!();
|
|
@@ -183,6 +209,8 @@ export function shouldFlipToCumulative(accumulated: string, next: string): boole
|
|
|
183
209
|
export class StreamDriver implements TurnDriver {
|
|
184
210
|
#state: DriverState = "idle";
|
|
185
211
|
#child: ChildProcess | undefined;
|
|
212
|
+
#lastChildPid: number | undefined;
|
|
213
|
+
#stagedHomePath: string | undefined;
|
|
186
214
|
#generation = 0;
|
|
187
215
|
#profile: DriverProfile | undefined;
|
|
188
216
|
#boundConversation: string | undefined;
|
|
@@ -197,6 +225,15 @@ export class StreamDriver implements TurnDriver {
|
|
|
197
225
|
/** Optional external lifecycle sink (the extension's daily file log).
|
|
198
226
|
* Fire-and-forget: the ring buffer stays the source for /agy doctor. */
|
|
199
227
|
log?: (msg: string, data?: unknown) => void;
|
|
228
|
+
/** Optional isolated-MCP-home wiring (issue #14). stagedHome() is
|
|
229
|
+
* consulted before every spawn: a path means the child runs with
|
|
230
|
+
* --gemini_dir <path> (top-level underscore form; the acp subcommand
|
|
231
|
+
* takes the hyphen form). releaseStagedHome() is awaited in close() AFTER
|
|
232
|
+
* the child's process group is confirmed dead - deliberately NOT in the
|
|
233
|
+
* child exit handler, which is generation-guarded and never fires on the
|
|
234
|
+
* close/recycle paths. */
|
|
235
|
+
stagedHome?: () => string | undefined;
|
|
236
|
+
releaseStagedHome?: (home: string, childPid: number | undefined) => Promise<void> | void;
|
|
200
237
|
#onTurnEnd: ((outcome: TurnOutcome) => void) | undefined;
|
|
201
238
|
#stats = {
|
|
202
239
|
spawns: 0,
|
|
@@ -414,7 +451,14 @@ export class StreamDriver implements TurnDriver {
|
|
|
414
451
|
|
|
415
452
|
ensureQueuedMessagesInFile(defaultCliSettingsPath());
|
|
416
453
|
|
|
454
|
+
// Issue #14: an isolated home means this child sees no foreign bridge
|
|
455
|
+
// registrations at all. Consulted per spawn so a post-recycle restage
|
|
456
|
+
// picks up a fresh global-config snapshot.
|
|
457
|
+
const home = this.stagedHome?.();
|
|
458
|
+
this.#stagedHomePath = home;
|
|
459
|
+
|
|
417
460
|
const args: string[] = ["--add-dir", request.cwd];
|
|
461
|
+
if (home) args.push("--gemini_dir", home);
|
|
418
462
|
// The bridge dir carries .agents/mcp_config.json (tool bridge) and, when
|
|
419
463
|
// the approval gate is on, .agents/hooks.json (gate staging). Only this
|
|
420
464
|
// session's agy ever gets it: standalone IDE/CLI sessions in the
|
|
@@ -435,13 +479,21 @@ export class StreamDriver implements TurnDriver {
|
|
|
435
479
|
"--disable-slash-commands",
|
|
436
480
|
);
|
|
437
481
|
|
|
438
|
-
|
|
482
|
+
// AGY_BIN is the repo-wide binary override (probe, doctor, ask-tool);
|
|
483
|
+
// the driver ignoring it made the --gemini_dir probe test a different
|
|
484
|
+
// binary than the one that actually spawns (issue #14 review round 3).
|
|
485
|
+
const bin = process.env.AGY_BIN || "agy";
|
|
486
|
+
const child = spawn(bin, args, {
|
|
439
487
|
cwd: request.cwd,
|
|
440
488
|
stdio: ["pipe", "pipe", "pipe"],
|
|
441
489
|
detached: process.platform !== "win32",
|
|
442
490
|
windowsHide: true,
|
|
443
491
|
});
|
|
444
492
|
this.#child = child;
|
|
493
|
+
// Kept past #killChild: close() must wait on THIS pid even after the
|
|
494
|
+
// child exited (or was deadline-killed), so late stragglers in the
|
|
495
|
+
// process group cannot write into a home we are about to remove.
|
|
496
|
+
this.#lastChildPid = child.pid;
|
|
445
497
|
this.#stdoutBuf = "";
|
|
446
498
|
this.#stats.spawns += 1;
|
|
447
499
|
// Pipe write failures surface asynchronously as stream 'error' events;
|
|
@@ -787,10 +839,6 @@ export class StreamDriver implements TurnDriver {
|
|
|
787
839
|
|
|
788
840
|
async close(reason: "recycle" | "shutdown", cause?: string): Promise<void> {
|
|
789
841
|
const child = this.#child;
|
|
790
|
-
if (!child) {
|
|
791
|
-
this.#state = reason === "shutdown" ? "dead" : "idle";
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
842
|
if (reason === "recycle" && cause) {
|
|
795
843
|
this.#stats.recycles += 1;
|
|
796
844
|
this.#stats.lastRecycleReason = cause;
|
|
@@ -801,8 +849,23 @@ export class StreamDriver implements TurnDriver {
|
|
|
801
849
|
if (turn && !turn.closed) {
|
|
802
850
|
this.#failTurn(turn, `agy driver ${reason === "recycle" ? "recycled" : "shut down"} mid-turn${cause ? ` (${cause})` : ""}`);
|
|
803
851
|
}
|
|
804
|
-
|
|
852
|
+
// Home disposal must NOT be gated on a live child: the child can exit
|
|
853
|
+
// (or be deadline-killed) well before close runs, and an early return
|
|
854
|
+
// would strand the staged home with its stale own entry (issue #14
|
|
855
|
+
// review round 2, blocker 2).
|
|
856
|
+
const home = this.#stagedHomePath;
|
|
857
|
+
const homePid = child?.pid ?? this.#lastChildPid;
|
|
858
|
+
if (child) this.#killChild();
|
|
805
859
|
this.#state = reason === "shutdown" ? "dead" : "idle";
|
|
860
|
+
if (home && this.releaseStagedHome) {
|
|
861
|
+
// Leader death is not group death: agy's own subprocesses can
|
|
862
|
+
// outlive it and late writes would recreate a removed home dir
|
|
863
|
+
// (issue #14 reporter's shutdown trap). Wait for the group, then
|
|
864
|
+
// dispose; the session-start sweep is the backstop for stragglers.
|
|
865
|
+
await waitForPidGroupExit(homePid);
|
|
866
|
+
this.#stagedHomePath = undefined;
|
|
867
|
+
await this.releaseStagedHome(home, homePid);
|
|
868
|
+
}
|
|
806
869
|
}
|
|
807
870
|
|
|
808
871
|
#killChild(): void {
|
package/src/mcp-registration.ts
CHANGED
|
@@ -75,6 +75,24 @@ function writeConfig(file: string, config: McpConfig): void {
|
|
|
75
75
|
fs.renameSync(tmp, file);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/** The canonical mcp_config.json entry shape for a bridge server. Single
|
|
79
|
+
* source for BOTH registration paths: the global per-pid entry
|
|
80
|
+
* (registerBridgeServer, marker-driven disabled flag) and the isolated-home
|
|
81
|
+
* own entry (always enabled - a private-home agy never reads global, so the
|
|
82
|
+
* marker never applies there, issue #14). */
|
|
83
|
+
export function bridgeServerEntry(entry: {
|
|
84
|
+
port: number;
|
|
85
|
+
token: string;
|
|
86
|
+
tokenHeader: string;
|
|
87
|
+
disabled?: boolean;
|
|
88
|
+
}): BridgeServerEntry {
|
|
89
|
+
return {
|
|
90
|
+
disabled: entry.disabled ?? false,
|
|
91
|
+
headers: { [entry.tokenHeader]: entry.token },
|
|
92
|
+
serverUrl: `http://127.0.0.1:${entry.port}/mcp`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
78
96
|
/** Register (or refresh) the bridge's per-pid server entry. Foreign servers
|
|
79
97
|
* in the file are preserved.
|
|
80
98
|
*
|
|
@@ -95,11 +113,12 @@ export function registerBridgeServer(
|
|
|
95
113
|
const disabled = hasLiveDelegator(marker, opts.isAlive ?? pidAlive, (opts.now ?? Date.now)());
|
|
96
114
|
const read = readConfig(configPath);
|
|
97
115
|
if (!read.ok) return { wrote: false, disabled, reason: read.reason };
|
|
98
|
-
read.config.mcpServers[bridgeServerName(entry.pid)] = {
|
|
116
|
+
read.config.mcpServers[bridgeServerName(entry.pid)] = bridgeServerEntry({
|
|
117
|
+
port: entry.port,
|
|
118
|
+
token: entry.token,
|
|
119
|
+
tokenHeader: entry.tokenHeader,
|
|
99
120
|
disabled,
|
|
100
|
-
|
|
101
|
-
serverUrl: `http://127.0.0.1:${entry.port}/mcp`,
|
|
102
|
-
} satisfies BridgeServerEntry;
|
|
121
|
+
});
|
|
103
122
|
writeConfig(configPath, read.config);
|
|
104
123
|
return { wrote: true, disabled };
|
|
105
124
|
}
|
package/src/sysprompt-agent.ts
CHANGED
|
@@ -10,12 +10,15 @@
|
|
|
10
10
|
// files from disk, off the prompt line, so the cap never applies.
|
|
11
11
|
//
|
|
12
12
|
// Frontmatter keeps agy's DEFAULTS on purpose (no excludeDefaultComponents,
|
|
13
|
-
// no
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
13
|
+
// no inheritMcp override): provider sessions need the bridge MCP config for
|
|
14
|
+
// G9 round-trips. Two deliberate exceptions. The tools list: omitting tools
|
|
15
|
+
// reads as "read-only defaults" upstream, not "all tools", which stripped
|
|
16
|
+
// write/edit/command from carrier sessions (issue #13; agy appends the
|
|
17
|
+
// resource/MCP tools itself, so G9 round-trips ride call_mcp_tool
|
|
18
|
+
// regardless). The subagent keys: agent-file presence already suppresses
|
|
19
|
+
// agy's native subagent tools (probed 2026-10-20, issue #7), and declaring
|
|
20
|
+
// it makes the suppression explicit instead of relying on the accident
|
|
21
|
+
// (whether the keys themselves mask, apart from presence, is unattributed).
|
|
19
22
|
// Contrast the ask-tool reviewer agent, which strips everything for
|
|
20
23
|
// sandboxing.
|
|
21
24
|
//
|
|
@@ -56,6 +59,15 @@ export function syspromptAgentMd(name: string, body: string): string {
|
|
|
56
59
|
"model: inherit",
|
|
57
60
|
"subagent: false",
|
|
58
61
|
"agents: []",
|
|
62
|
+
"tools:",
|
|
63
|
+
// Block style, not flow: the web delegates (web-tools.ts) prove agy
|
|
64
|
+
// parses this shape; flow style is only proven in the issue report.
|
|
65
|
+
" - read_file",
|
|
66
|
+
" - edit_file",
|
|
67
|
+
" - write_file",
|
|
68
|
+
" - run_command",
|
|
69
|
+
" - manage_task",
|
|
70
|
+
" - search_web",
|
|
59
71
|
"---",
|
|
60
72
|
"",
|
|
61
73
|
body,
|