Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): hide Antigravity's lookups of its own tool descriptions

Elian Doran2578a943eb96
diff --git a/apps/server/src/services/llm/providers/acp_agent.ts b/apps/server/src/services/llm/providers/acp_agent.ts
index 9825445fe2..a51490ec75 100644
--- a/apps/server/src/services/llm/providers/acp_agent.ts
+++ b/apps/server/src/services/llm/providers/acp_agent.ts
@@ -181,6 +181,15 @@ export abstract class AcpAgentProvider implements LlmProvider {
return denyPermission(request, this.logLabel);
}
+ /**
+ * Whether a tool call is the agent's own bookkeeping rather than work the
+ * user asked for, and so stays out of the chat. Display only: the call has
+ * already passed the permission policy.
+ */
+ protected isInternalToolCall(_update: AcpToolCallUpdate): boolean {
+ return false;
+ }
+
/** Map a failure to an actionable message. */
protected describeFailure(error: unknown): string {
return describeError(error);
@@ -299,7 +308,7 @@ export abstract class AcpAgentProvider implements LlmProvider {
wakeup?.();
};
- const collector = createUpdateCollector(emit);
+ const collector = createUpdateCollector(emit, update => this.isInternalToolCall(update));
let client: AcpClient | undefined;
let sessionId: string | undefined;
let assistantText = "";
@@ -577,8 +586,10 @@ export function denyPermission(request: AcpPermissionRequest, logLabel: string):
* Create the session/update collector: maps ACP updates to LlmStreamChunks and
* pushes them through `emit`. `muted` suppresses the replay flood during
* session/load; `sessionId` filters stray updates from other sessions.
+ * `isHidden` keeps a tool call, and with it every update for that call, out
+ * of the chat.
*/
-export function createUpdateCollector(emit: (chunk: LlmStreamChunk) => void) {
+export function createUpdateCollector(emit: (chunk: LlmStreamChunk) => void, isHidden?: (update: AcpToolCallUpdate) => boolean) {
// toolCallId → display name, for labelling results; also the guard that
// only this turn's tool calls produce result chunks.
const toolNamesById = new Map<string, string>();
@@ -611,8 +622,8 @@ export function createUpdateCollector(emit: (chunk: LlmStreamChunk) => void) {
break;
}
case "tool_call": {
- if (!update.toolCallId || toolNamesById.has(update.toolCallId)) {
- break; // malformed or a re-announcement of a known call
+ if (!update.toolCallId || toolNamesById.has(update.toolCallId) || isHidden?.(update)) {
+ break; // malformed, a re-announcement of a known call, or hidden
}
const mcpTool = mcpToolName(update._meta);
const toolName = mcpTool ?? (update.title || "tool");
@@ -699,16 +710,21 @@ type AcpContentBlock =
interface AcpSessionUpdate {
sessionId: string;
- update?: {
- sessionUpdate: string;
- content?: AcpContentBlock | { type: string; content?: AcpContentBlock; [key: string]: unknown };
- toolCallId?: string;
- title?: string;
- status?: string;
- rawInput?: unknown;
- rawOutput?: unknown;
- [key: string]: unknown;
- };
+ update?: AcpToolCallUpdate;
+}
+
+/** One `session/update` payload; the fields listed are those of tool calls. */
+export interface AcpToolCallUpdate {
+ sessionUpdate: string;
+ content?: AcpContentBlock | { type: string; content?: AcpContentBlock; [key: string]: unknown };
+ toolCallId?: string;
+ title?: string;
+ status?: string;
+ /** Files the call touches. */
+ locations?: { path?: string }[];
+ rawInput?: unknown;
+ rawOutput?: unknown;
+ [key: string]: unknown;
}
function rememberSession(sessionsByChatNote: Map<string, SessionEntry>, chatNoteId: string, entry: SessionEntry) {
diff --git a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
index 98539443cf..daed92d34b 100644
--- a/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
+++ b/apps/server/src/services/llm/providers/antigravity_agent.spec.ts
@@ -36,14 +36,18 @@ class FakeAcpClient {
static lastStart: { binary: string; opts: { args?: string[]; env?: Record<string, string>; cwd: string } } | undefined;
static signedIn = true;
static availableModels: unknown[] = [];
+ /** The session/update payloads the agent streams while answering session/prompt. */
+ static promptUpdates: Record<string, unknown>[] = [];
requests: { method: string; params: unknown }[] = [];
onAgentRequest?: (method: string, params: unknown) => unknown;
+ onNotification?: (method: string, params: unknown) => void;
- static start(binary: string, opts: { args?: string[]; env?: Record<string, string>; cwd: string; onAgentRequest?: (m: string, p: unknown) => unknown }) {
+ static start(binary: string, opts: { args?: string[]; env?: Record<string, string>; cwd: string; onAgentRequest?: (m: string, p: unknown) => unknown; onNotification?: (m: string, p: unknown) => void }) {
FakeAcpClient.lastStart = { binary, opts };
FakeAcpClient.current = new FakeAcpClient();
FakeAcpClient.current.onAgentRequest = opts.onAgentRequest;
+ FakeAcpClient.current.onNotification = opts.onNotification;
return FakeAcpClient.current;
}
@@ -56,7 +60,12 @@ class FakeAcpClient {
if (!FakeAcpClient.signedIn) throw SIGN_IN_REQUIRED;
return { sessionId: "sess-1", models: { currentModelId: "gemini-3.7-flash-high", availableModels: FakeAcpClient.availableModels } } as T;
}
- if (method === "session/prompt") return { stopReason: "end_turn" } as T;
+ if (method === "session/prompt") {
+ for (const update of FakeAcpClient.promptUpdates) {
+ this.onNotification?.("session/update", { sessionId: "sess-1", update });
+ }
+ return { stopReason: "end_turn" } as T;
+ }
return {} as T;
}
@@ -102,6 +111,7 @@ beforeEach(() => {
FakeAcpClient.lastStart = undefined;
FakeAcpClient.signedIn = true;
FakeAcpClient.availableModels = REMOTE_MODELS;
+ FakeAcpClient.promptUpdates = [];
});
describe("decideAntigravityPermission", () => {
@@ -216,6 +226,31 @@ describe("tool call updates from agy_acp_server", () => {
});
});
+describe("AntigravityAgentProvider tool calls", () => {
+ // Shapes captured from agy_acp_server 1.1.1.
+ const MCP_DIR = path.join(DATA_DIR, "antigravity-agent", "home", "antigravity-acp", "brain", "06ada25b", "mcp", "trilium");
+ const TOKEN_FILE = path.join(DATA_DIR, "antigravity-agent", "home", "antigravity-acp", "acp_token.json");
+
+ it("hides the agent's reads of its own tool descriptions, and nothing else", async () => {
+ FakeAcpClient.promptUpdates = [
+ // Listing the tool descriptions: hidden, and so is its completion.
+ { sessionUpdate: "tool_call", toolCallId: "06ada25b:2", title: "Running list_directory", kind: "search", status: "in_progress", locations: [{ path: MCP_DIR }], rawInput: { directory_path: MCP_DIR } },
+ { sessionUpdate: "tool_call_update", toolCallId: "06ada25b:2", status: "completed", rawOutput: "List trilium MCP tools" },
+ // Reading one that does not exist, which the agent never completes: hidden, so it cannot end up "stopped".
+ { sessionUpdate: "tool_call", toolCallId: "call_257368", title: "Running view_file", kind: "read", status: "in_progress", rawInput: { AbsolutePath: path.join(MCP_DIR, "instructions.md") } },
+ // Its own sign-in token lives in its home too, and a read of it stays visible.
+ { sessionUpdate: "tool_call", toolCallId: "call_token", title: "Running view_file", kind: "read", status: "in_progress", locations: [{ path: TOKEN_FILE }], rawInput: { AbsolutePath: TOKEN_FILE } },
+ { sessionUpdate: "tool_call_update", toolCallId: "call_token", status: "completed", rawOutput: "Read token" },
+ // A note tool.
+ { sessionUpdate: "tool_call", toolCallId: "cf21", title: "trilium_search_icons", kind: "other", status: "pending", rawInput: { arguments: { query: "font" } }, _meta: { mcp: { tool: "search_icons", server: "trilium" }, is_mcp_tool_call: true } },
+ { sessionUpdate: "tool_call_update", toolCallId: "cf21", status: "completed", rawOutput: "Search icons" }
+ ];
+
+ const chunks = await collect(new AntigravityAgentProvider().chatChunks([{ role: "user", content: "hi" }], { enableNoteTools: true }));
+ expect(chunks.filter(c => c.type === "tool_use" || c.type === "tool_result").map(c => c.toolCallId)).toEqual(["call_token", "call_token", "cf21", "cf21"]);
+ });
+});
+
describe("buildAntigravityModelList", () => {
it("leads with the server's own default and keeps the server's order and names", () => {
expect(buildAntigravityModelList({ availableModels: [{ modelId: "gemini-x" }, { modelId: "default" }, { modelId: "" }] })).toEqual([
diff --git a/apps/server/src/services/llm/providers/antigravity_agent.ts b/apps/server/src/services/llm/providers/antigravity_agent.ts
index a5106e499f..c7fc1df1e7 100644
--- a/apps/server/src/services/llm/providers/antigravity_agent.ts
+++ b/apps/server/src/services/llm/providers/antigravity_agent.ts
@@ -21,7 +21,7 @@ import { existsSync } from "fs";
import path from "path";
import dataDirs from "../../data_dir.js";
-import { AcpAgentProvider, type AcpLaunchSpec, type AcpNewSessionParams, type AcpPermissionOutcome, type AcpPermissionRequest, type AcpSessionModelState, denyPermission, describeError, NOTE_TOOLS_MCP_SERVER_NAME } from "./acp_agent.js";
+import { AcpAgentProvider, type AcpLaunchSpec, type AcpNewSessionParams, type AcpPermissionOutcome, type AcpPermissionRequest, type AcpSessionModelState, type AcpToolCallUpdate, denyPermission, describeError, NOTE_TOOLS_MCP_SERVER_NAME } from "./acp_agent.js";
import { type AcpClient, AcpError } from "./acp_client.js";
import { resolveAntigravityBinaryPath } from "./antigravity_binary.js";
@@ -83,7 +83,7 @@ export class AntigravityAgentProvider extends AcpAgentProvider {
binary,
// The ACP registry launches the Linux build with an empty `--uid=`.
args: process.platform === "linux" ? ["--uid="] : [],
- env: buildAntigravityEnv(path.resolve(dataDirs.TRILIUM_DATA_DIR, "antigravity-agent", "home"))
+ env: buildAntigravityEnv(agentHome())
};
}
@@ -97,6 +97,16 @@ export class AntigravityAgentProvider extends AcpAgentProvider {
return decideAntigravityPermission(request, this.logLabel);
}
+ /**
+ * The agent writes a description of every MCP tool to
+ * `<home>/antigravity-acp/brain/<session>/mcp/<server>/<tool>.json` and reads
+ * them with its own file tools before calling one. Those reads are how it
+ * looks a tool up, not work on the user's behalf.
+ */
+ protected isInternalToolCall(update: AcpToolCallUpdate): boolean {
+ return isToolDescriptionAccess(update, agentHome());
+ }
+
/**
* Open a session, signing in first when the server has no saved sign-in and
* the user is on the add-provider screen to complete it. The server opens
@@ -169,6 +179,25 @@ export function buildAntigravityModelList(remote: AcpSessionModelState): ModelIn
return [...AVAILABLE_MODELS, ...models];
}
+/**
+ * Whether a built-in tool call only touches the agent's tool descriptions:
+ * every path it names lies under `<home>/antigravity-acp/brain/<session>/mcp/`.
+ * Anything else in the home, such as the sign-in token, does not qualify.
+ */
+export function isToolDescriptionAccess(update: AcpToolCallUpdate, home: string): boolean {
+ if (update._meta && (update._meta as { is_mcp_tool_call?: unknown }).is_mcp_tool_call === true) {
+ return false;
+ }
+ const paths = [
+ ...(update.locations ?? []).map(location => location.path),
+ ...Object.values(typeof update.rawInput === "object" && update.rawInput !== null ? update.rawInput : {})
+ ].filter((value): value is string => typeof value === "string" && path.isAbsolute(value));
+ return paths.length > 0 && paths.every(candidate => {
+ const segments = path.relative(home, path.resolve(candidate)).split(path.sep);
+ return segments[0] === "antigravity-acp" && segments[1] === "brain" && segments[3] === "mcp";
+ });
+}
+
/**
* The environment the server runs in. `GEMINI_HOME` gives it a home of
* Trilium's own. On Linux, `SSL_CERT_FILE` points it at the system CA bundle
@@ -197,6 +226,11 @@ function pickTitleModel(models: ModelInfo[]): string | undefined {
return models.find(m => /flash-low$/.test(m.id))?.id;
}
+/** The server's home, `GEMINI_HOME`: its sign-in, sessions and tool descriptions. */
+function agentHome(): string {
+ return path.resolve(dataDirs.TRILIUM_DATA_DIR, "antigravity-agent", "home");
+}
+
function isSignInRequired(error: unknown): boolean {
return error instanceof AcpError && error.code === -32000 && /authentication required/i.test(error.message);
}