@estebanforge/pi-antigravity-bridge 1.10.6 → 1.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.10.7] - 2026-11-15
6
+
7
+ ### Fixed
8
+
9
+ - **Extension Pi tools are no longer silently evicted by `agy acp`'s per-model tool-declaration byte budget.** `agy acp` enforces a per-model declaration cap and keeps only the smallest tools, silently dropping larger extension tools such as `git_commit` and `AskClaude`, and strips any argument not declared under `properties` even when `additionalProperties: true` is set. `tools/list` now exposes only active Pi default tools (`read`, `bash`, `edit`, `write`, `grep`, `find`, `ls`) directly alongside two compact proxy tools: `bridge_tool_info` (lists extension tool names with a 4,000-char description cap and wildcard `["*"]` fallback, returning full descriptions and schemas on demand) and `bridge_call_tool` (accepts `name` plus a stringified JSON object or plain object in `arguments_json` and validates against the active authorized Pi catalog before dispatching). Direct calls by tool name stay authorized so cached schemas from earlier sessions still work while disabled or hidden tools stay blocked.
10
+
5
11
  ## [1.10.6] - 2026-11-13
6
12
 
7
13
  ### Fixed
@@ -99,7 +99,17 @@ import {
99
99
  type SkillLite,
100
100
  } from "../src/skills.js";
101
101
  import { mapAgyToolToNative } from "../src/native-tools.js";
102
- import { bridgedPiTools } from "../src/bridge-catalog.js";
102
+ import {
103
+ CALL_TOOL_NAME,
104
+ TOOL_INFO_TOOL_NAME,
105
+ bridgeCallToolDef,
106
+ bridgeToolInfoDef,
107
+ bridgedPiTools,
108
+ formatBridgeToolInfo,
109
+ parseBridgeCallRequest,
110
+ partitionBridgeTools,
111
+ serializeToolSchema,
112
+ } from "../src/bridge-catalog.js";
103
113
  import { Type } from "typebox";
104
114
  import { patchStatus, restorePatch } from "../src/patch-cleanup.js";
105
115
  import { withDialogLock } from "../src/dialog-lock.js";
@@ -863,16 +873,17 @@ export default async function (pi: ExtensionAPI): Promise<void> {
863
873
  const listTools = () => {
864
874
  // /mcp and pi.setActiveTools() update the same live catalog. ACP gets
865
875
  // this endpoint through session/new or session/load; no global config write.
866
- const tools = getBridgeTools().map((t) => {
867
- let inputSchema: object = { type: "object", properties: {}, additionalProperties: true };
868
- try {
869
- if (t.parameters) inputSchema = JSON.parse(JSON.stringify(t.parameters)) as object;
870
- } catch {
871
- /* keep default schema */
872
- }
873
- return { name: t.name, description: t.description ?? t.name, inputSchema };
874
- });
875
- if (skills.length > 0 && loadConfig().bridgeTools !== "none") {
876
+ const mode = loadConfig().bridgeTools;
877
+ const { direct, proxied } = partitionBridgeTools(getBridgeTools());
878
+ const tools = direct.map((t) => ({
879
+ name: t.name,
880
+ description: t.description ?? t.name,
881
+ inputSchema: serializeToolSchema(t.parameters),
882
+ }));
883
+ if (mode !== "none" && proxied.length > 0) {
884
+ tools.push(bridgeToolInfoDef(proxied), bridgeCallToolDef());
885
+ }
886
+ if (skills.length > 0 && mode !== "none") {
876
887
  tools.push({
877
888
  name: ACTIVATE_SKILL_TOOL_NAME,
878
889
  description: `Activate a pi Agent Skill by name. Catalog:\n${catalogSummary(skills)}`,
@@ -917,19 +928,32 @@ export default async function (pi: ExtensionAPI): Promise<void> {
917
928
  if (view && view.state !== "running") roundTrips.markDelivered(wanted);
918
929
  return Promise.resolve(formatPollAnswer(wanted, view));
919
930
  }
920
- if (name !== ACTIVATE_SKILL_TOOL_NAME) {
921
- // A cached MCP catalog is not authorization. An inactive/hidden tool
922
- // must not get parked into Pi, even if agy retained its old schema.
923
- if (!getBridgeTools().some((tool) => tool.name === name)) {
924
- return Promise.resolve({ content: [{ type: "text", text: `Pi tool ${name} is not active or not exposed to Antigravity` }], isError: true });
925
- }
926
- return roundTrips.onToolCall(callId, name, args, signal).then((r) => {
931
+ if (name === TOOL_INFO_TOOL_NAME) {
932
+ const { proxied } = partitionBridgeTools(getBridgeTools());
933
+ return Promise.resolve(formatBridgeToolInfo(proxied, args.names));
934
+ }
935
+ const dispatchPiTool = (targetName: string, targetArgs: Record<string, unknown>) =>
936
+ roundTrips.onToolCall(callId, targetName, targetArgs, signal).then((r) => {
927
937
  // Early-ack: answer the HTTP request before agy's ~180s client
928
938
  // deadline with a poll handle; pi keeps executing meanwhile.
929
939
  if (!("escalated" in r)) return r;
930
- mcpLog("call-tool-escalated", { name, callId: r.callId });
940
+ mcpLog("call-tool-escalated", { name: targetName, callId: r.callId });
931
941
  return formatEscalatedAck(r);
932
942
  });
943
+ if (name === CALL_TOOL_NAME) {
944
+ const parsed = parseBridgeCallRequest(args, getBridgeTools());
945
+ if (!parsed.ok) {
946
+ return Promise.resolve({ content: [{ type: "text", text: parsed.error }], isError: true });
947
+ }
948
+ return dispatchPiTool(parsed.name, parsed.args);
949
+ }
950
+ if (name !== ACTIVATE_SKILL_TOOL_NAME) {
951
+ // Direct calls by tool name stay authorized so cached schemas from
952
+ // earlier sessions still work, while disabled/hidden tools stay blocked.
953
+ if (!getBridgeTools().some((tool) => tool.name === name)) {
954
+ return Promise.resolve({ content: [{ type: "text", text: `Pi tool ${name} is not active or not exposed to Antigravity` }], isError: true });
955
+ }
956
+ return dispatchPiTool(name, args);
933
957
  }
934
958
  const wanted = typeof args.name === "string" ? args.name : "";
935
959
  const skill = loadConfig().bridgeTools !== "none" ? findSkillByName(skills, wanted) : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estebanforge/pi-antigravity-bridge",
3
- "version": "1.10.6",
3
+ "version": "1.10.7",
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",
@@ -1,4 +1,6 @@
1
1
  import type { BridgeTools } from "./config.js";
2
+ import { POLL_TOOL_NAME } from "./provider.js";
3
+ import { ACTIVATE_SKILL_TOOL_NAME } from "./skills.js";
2
4
 
3
5
  export interface BridgeToolInfo {
4
6
  name: string;
@@ -7,6 +9,37 @@ export interface BridgeToolInfo {
7
9
  sourceInfo?: { source?: string };
8
10
  }
9
11
 
12
+ export const TOOL_INFO_TOOL_NAME = "bridge_tool_info";
13
+ export const CALL_TOOL_NAME = "bridge_call_tool";
14
+ const MAX_DESC_NAMES_CHARS = 4000;
15
+ const MAX_INFO_TOOLS_PER_CALL = 20;
16
+
17
+ /** Pi's seven built-in default tools; only these stay always-loaded when active. */
18
+ const PI_DEFAULT_TOOLS = new Set(["read", "bash", "edit", "write", "grep", "find", "ls"]);
19
+
20
+ const BRIDGE_INTERNAL_TOOLS = new Set([
21
+ "AskAntigravity",
22
+ "antigravity",
23
+ "agy_web_search",
24
+ "agy_read_url",
25
+ POLL_TOOL_NAME,
26
+ ACTIVATE_SKILL_TOOL_NAME,
27
+ TOOL_INFO_TOOL_NAME,
28
+ CALL_TOOL_NAME,
29
+ ]);
30
+
31
+ const DEFAULT_INPUT_SCHEMA: object = { type: "object", properties: {}, additionalProperties: true };
32
+
33
+ /** Serialize a tool's TypeBox/JSON schema safely for MCP exposure. */
34
+ export function serializeToolSchema(parameters?: object): object {
35
+ if (!parameters) return DEFAULT_INPUT_SCHEMA;
36
+ try {
37
+ return JSON.parse(JSON.stringify(parameters)) as object;
38
+ } catch {
39
+ return DEFAULT_INPUT_SCHEMA;
40
+ }
41
+ }
42
+
10
43
  /** The bridge has one live HTTP endpoint. Catalog and dispatch must both use
11
44
  * the CURRENT Pi active set: /mcp and pi.setActiveTools() can change it mid-session.
12
45
  * A stale tools/call must not bypass a disabled Pi tool. */
@@ -19,11 +52,146 @@ export function bridgedPiTools(
19
52
  enabled.has(tool.name) && !hidden.has(tool.name) &&
20
53
  // Never bridge the bridge's own tools. agy has native web tools, so
21
54
  // our quota-burning one-shot wrappers must not tempt it through MCP.
22
- tool.name !== "AskAntigravity" && tool.name !== "antigravity" &&
23
- tool.name !== "agy_web_search" && tool.name !== "agy_read_url" &&
24
- tool.name !== "bridge_poll_result" && tool.name !== "activate_skill" &&
55
+ !BRIDGE_INTERNAL_TOOLS.has(tool.name) &&
25
56
  (mode === "mcp"
26
57
  ? /pi-mcp-adapter/.test(tool.sourceInfo?.source ?? "")
27
58
  : tool.sourceInfo?.source !== "builtin"),
28
59
  );
29
60
  }
61
+
62
+ /** Split authorized bridge tools into always-loaded Pi defaults and proxied extension tools. */
63
+ export function partitionBridgeTools<T extends BridgeToolInfo>(tools: readonly T[]): { direct: T[]; proxied: T[] } {
64
+ const direct: T[] = [];
65
+ const proxied: T[] = [];
66
+ for (const tool of tools) {
67
+ if (PI_DEFAULT_TOOLS.has(tool.name)) direct.push(tool);
68
+ else proxied.push(tool);
69
+ }
70
+ return { direct, proxied };
71
+ }
72
+
73
+ /** Build the bridge_tool_info MCP tool definition listing proxied extension tool names. */
74
+ export function bridgeToolInfoDef(proxied: readonly BridgeToolInfo[]): {
75
+ name: string;
76
+ description: string;
77
+ inputSchema: object;
78
+ } {
79
+ const cleaned = proxied.map((t) => t.name.replace(/[\r\n]+/g, " ").trim()).filter(Boolean);
80
+ let namesText = "";
81
+ let shown = 0;
82
+ for (const n of cleaned) {
83
+ const next = shown === 0 ? n : `${namesText}, ${n}`;
84
+ if (next.length > MAX_DESC_NAMES_CHARS && shown > 0) break;
85
+ namesText = next;
86
+ shown++;
87
+ }
88
+ const remainder = cleaned.length - shown;
89
+ const suffix = remainder > 0 ? `, ... (+${remainder} more; pass names: ["*"] to list all)` : "";
90
+ return {
91
+ name: TOOL_INFO_TOOL_NAME,
92
+ description: `Inspect description and parameter schema for extension Pi tools before calling them via ${CALL_TOOL_NAME}. Pass ["*"] to list all names. Available extension tools (${cleaned.length}): ${namesText}${suffix}`,
93
+ inputSchema: {
94
+ type: "object",
95
+ properties: {
96
+ names: {
97
+ type: "array",
98
+ items: { type: "string" },
99
+ description: 'Exact Pi tool names to inspect (or ["*"] to list all available extension tools).',
100
+ },
101
+ },
102
+ required: ["names"],
103
+ },
104
+ };
105
+ }
106
+
107
+ /** Build the bridge_call_tool MCP tool definition for invoking proxied extension tools. */
108
+ export function bridgeCallToolDef(): { name: string; description: string; inputSchema: object } {
109
+ return {
110
+ name: CALL_TOOL_NAME,
111
+ description: `Invoke an extension Pi tool listed in ${TOOL_INFO_TOOL_NAME}. Inspect its schema with ${TOOL_INFO_TOOL_NAME} first, then pass its exact name and a stringified JSON object in arguments_json.`,
112
+ inputSchema: {
113
+ type: "object",
114
+ properties: {
115
+ name: { type: "string", description: "Exact Pi tool name to invoke." },
116
+ arguments_json: {
117
+ type: "string",
118
+ description: "Stringified JSON object of tool arguments (omit or '{}' if none).",
119
+ },
120
+ },
121
+ required: ["name"],
122
+ },
123
+ };
124
+ }
125
+
126
+ /** Format full descriptions and schemas for requested Pi tools. */
127
+ export function formatBridgeToolInfo(
128
+ authorized: readonly BridgeToolInfo[],
129
+ rawNames: unknown,
130
+ ): { content: Array<{ type: "text"; text: string }>; isError: boolean } {
131
+ const names = Array.isArray(rawNames)
132
+ ? rawNames.filter((n): n is string => typeof n === "string" && n.trim().length > 0).map((n) => n.trim())
133
+ : [];
134
+ if (names.length === 0) {
135
+ return { content: [{ type: "text", text: "Error: names must be a non-empty array of tool names" }], isError: true };
136
+ }
137
+ if (names.includes("*")) {
138
+ const list = authorized.map((t) => t.name).join(", ") || "(none)";
139
+ return {
140
+ content: [{ type: "text", text: `Available extension tools (${authorized.length}): ${list}` }],
141
+ isError: false,
142
+ };
143
+ }
144
+ const capped = names.slice(0, MAX_INFO_TOOLS_PER_CALL);
145
+ const byName = new Map(authorized.map((t) => [t.name, t]));
146
+ const sections: string[] = [];
147
+ const missing: string[] = [];
148
+ for (const name of capped) {
149
+ const tool = byName.get(name);
150
+ if (!tool) {
151
+ missing.push(name);
152
+ continue;
153
+ }
154
+ sections.push(
155
+ `### ${tool.name}\n${tool.description ?? tool.name}\n\nParameters schema:\n${JSON.stringify(serializeToolSchema(tool.parameters), null, 2)}`,
156
+ );
157
+ }
158
+ if (missing.length > 0) sections.push(`Unknown or inactive tools: ${missing.join(", ")}`);
159
+ if (names.length > MAX_INFO_TOOLS_PER_CALL) {
160
+ sections.push(`Note: truncated to first ${MAX_INFO_TOOLS_PER_CALL} requested tools (${names.length} requested).`);
161
+ }
162
+ return {
163
+ content: [{ type: "text", text: sections.join("\n\n---\n\n") }],
164
+ isError: missing.length === capped.length,
165
+ };
166
+ }
167
+
168
+ /** Validate and parse a bridge_call_tool payload against currently authorized Pi tools. */
169
+ export function parseBridgeCallRequest(
170
+ raw: Record<string, unknown>,
171
+ authorized: readonly BridgeToolInfo[],
172
+ ): { ok: true; name: string; args: Record<string, unknown> } | { ok: false; error: string } {
173
+ const name = typeof raw.name === "string" ? raw.name.trim() : "";
174
+ if (!name) return { ok: false, error: "Error: name must be a non-empty string" };
175
+ if (BRIDGE_INTERNAL_TOOLS.has(name) || !authorized.some((t) => t.name === name)) {
176
+ return { ok: false, error: `Pi tool ${name} is not active or not exposed to Antigravity` };
177
+ }
178
+ const rawJson = raw.arguments_json;
179
+ if (rawJson === undefined || rawJson === null || rawJson === "") {
180
+ return { ok: true, name, args: {} };
181
+ }
182
+ if (typeof rawJson === "object" && !Array.isArray(rawJson)) {
183
+ return { ok: true, name, args: rawJson as Record<string, unknown> };
184
+ }
185
+ if (typeof rawJson !== "string") {
186
+ return { ok: false, error: "Error: arguments_json must be a stringified JSON object" };
187
+ }
188
+ try {
189
+ const parsed = JSON.parse(rawJson) as unknown;
190
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
191
+ return { ok: false, error: "Error: arguments_json must decode to a JSON object" };
192
+ }
193
+ return { ok: true, name, args: parsed as Record<string, unknown> };
194
+ } catch (err) {
195
+ return { ok: false, error: `Error: invalid arguments_json (${err instanceof Error ? err.message : String(err)})` };
196
+ }
197
+ }
package/src/provider.ts CHANGED
@@ -179,7 +179,7 @@ export const SYSTEM_PROMPT_END = "[END SYSTEM PROMPT]";
179
179
  * the user's machine must go through the bridge. Rides the systemPrompt
180
180
  * gate: the note ships only when the system prompt ships. */
181
181
  export const TOOL_PRIORITY_NOTE =
182
- "[Tool priority: this conversation runs inside pi, not as a standalone agy session; the user only sees what surfaces in pi. Native interactive tools, for example ask_question, never reach the user. When a Pi Bridge tool covers the same purpose, always use the Pi Bridge tool; for user questions use ask_user_question. Your native file tools such as view_file only read brain artifacts and reject real filesystem paths; for any path on the user's machine use the Pi Bridge tools (read, ls, grep, find, edit, execute). Image files are visible to you: the Pi Bridge read tool returns image files as visible images (png, jpg, webp, gif, bmp), so never claim you cannot view images. When a bridge call answers STILL RUNNING, poll bridge_poll_result before doing other work: until you poll, the result (including any image) stays undelivered to you. Delegate subagent work the same way: when pi's tool list includes a delegation tool (for example subagent, Agent, agent_spawn, agent_wait, or subagent_run), always delegate through it and never through the native invoke_subagent, run_subagent, or manage_subagents; use native ones only if no pi delegation tool is listed, because native subagents run inside agy and are invisible to pi and anything watching it. Long-running bridge calls do not fail: after ~20 seconds the bridge answers STILL RUNNING with a callId; fetch the result with bridge_poll_result and poll until it lands. For work you already know is long, prefer exec_command's session-output pattern or background agents so you keep working while it runs.]";
182
+ "[Tool priority: this conversation runs inside pi, not as a standalone agy session; the user only sees what surfaces in pi. Native interactive tools, for example ask_question, never reach the user. When a Pi Bridge tool covers the same purpose, always use the Pi Bridge tool; for user questions use ask_user_question. Your native file tools such as view_file only read brain artifacts and reject real filesystem paths; for any path on the user's machine use the Pi Bridge tools (read, ls, grep, find, edit, execute). Image files are visible to you: the Pi Bridge read tool returns image files as visible images (png, jpg, webp, gif, bmp), so never claim you cannot view images. Extension Pi tools not declared directly are listed in bridge_tool_info; call bridge_tool_info to inspect their description and schema, then call bridge_call_tool to run them. When a bridge call answers STILL RUNNING, poll bridge_poll_result before doing other work: until you poll, the result (including any image) stays undelivered to you. Delegate subagent work the same way: when pi's tool list includes a delegation tool (for example subagent, Agent, agent_spawn, agent_wait, or subagent_run), always delegate through it and never through the native invoke_subagent, run_subagent, or manage_subagents; use native ones only if no pi delegation tool is listed, because native subagents run inside agy and are invisible to pi and anything watching it. Long-running bridge calls do not fail: after ~20 seconds the bridge answers STILL RUNNING with a callId; fetch the result with bridge_poll_result and poll until it lands. For work you already know is long, prefer exec_command's session-output pattern or background agents so you keep working while it runs.]";
183
183
 
184
184
  /** Assemble the full agy prompt: system prompt block, pi-side digest, user
185
185
  * prompt. Empty parts are dropped. Pure; exported for unit testing.