@devries-cameron20 / t3code Mirror · read-only / commits / d530ef339b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(acp): classify web search by title and omit fake filename results (#38106)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Helmi Pradita committed Nov 19, 2026 at 13:23 UTC d530ef339b29a4644bb3d087d053ba17a51ae9a2
3 files changed +184 -16
apps/server/scripts/acp-mock-agent.ts
+64
@@ -1268,6 +1268,33 @@ const program = Effect.gen(function* () {
1268 status: "completed",
1269 rawInput: { query: "TODO", path: "apps/web" },
1270 },
1271 + {
1272 + sessionUpdate: "tool_call_update",
1273 + toolCallId: "structured-search-explicit-location",
1274 + title: "Grep",
1275 + kind: "search",
1276 + status: "completed",
1277 + rawInput: { query: " README.md " },
1278 + locations: [{ path: "README.md" }],
1279 + rawOutput: "# Title",
1280 + },
1281 + {
1282 + sessionUpdate: "tool_call_update",
1283 + toolCallId: "structured-search-query-only",
1284 + title: "Grep",
1285 + kind: "search",
1286 + status: "completed",
1287 + rawInput: { query: "TODO" },
1288 + rawOutput: "src/a.ts: TODO",
1289 + },
1290 + {
1291 + sessionUpdate: "tool_call_update",
1292 + toolCallId: "structured-search-query-no-output",
1293 + title: "Grep",
1294 + kind: "search",
1295 + status: "completed",
1296 + rawInput: { query: "FIXME" },
1297 + },
1298 // Grok backend searches: the query only arrives in the completed rawOutput.
1299 {
1300 sessionUpdate: "tool_call_update",
@@ -1332,6 +1359,43 @@ const program = Effect.gen(function* () {
1359 rawInput: { command: "cat probe.txt" },
1360 rawOutput: { commandLine: "cat probe.txt", exitCode: 0, combinedOutput: "after\n" },
1361 },
1362 + {
1363 + sessionUpdate: "tool_call_update",
1364 + toolCallId: "antigravity-web-search",
1365 + title: "Web search",
1366 + kind: "search",
1367 + status: "completed",
1368 + rawInput: { query: " top story on Hacker News today " },
1369 + rawOutput:
1370 + "Sources:\n<https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGYNzfz>.",
1371 + },
1372 + {
1373 + sessionUpdate: "tool_call_update",
1374 + toolCallId: "antigravity-run-search-web",
1375 + title: "Running search_web",
1376 + kind: "search",
1377 + status: "completed",
1378 + rawInput: { query: "top story on Hacker News today" },
1379 + },
1380 + {
1381 + sessionUpdate: "tool_call_update",
1382 + toolCallId: "antigravity-web-search-streamed",
1383 + title: "Web search",
1384 + kind: "search",
1385 + status: "in_progress",
1386 + rawInput: { query: "streamed citations" },
1387 + rawOutput: "Sources: https://example.com/streamed_(detail)",
1388 + },
1389 + {
1390 + sessionUpdate: "tool_call_content_chunk",
1391 + toolCallId: "antigravity-web-search-streamed",
1392 + content: { type: "content", content: { type: "text", text: " (updated)" } },
1393 + },
1394 + {
1395 + sessionUpdate: "tool_call_update",
1396 + toolCallId: "antigravity-web-search-streamed",
1397 + status: "completed",
1398 + },
1399 {
1400 sessionUpdate: "compaction_update",
1401 compactionId: "compact-1",
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+41
@@ -4647,6 +4647,28 @@ describe("AcpAdapterV2", () => {
4647 search?.type === "file_search" ? { title: search.title, pattern: search.pattern } : null,
4648 { title: "Searched TODO in web", pattern: "apps/web" },
4649 );
4650 + const fileSearch = (nativeId: string) => {
4651 + const item = items.find(
4652 + (candidate) =>
4653 + candidate.type === "file_search" &&
4654 + candidate.nativeItemRef?.nativeId?.endsWith(nativeId) === true,
4655 + );
4656 + return item?.type === "file_search"
4657 + ? { pattern: item.pattern, results: item.results }
4658 + : null;
4659 + };
4660 + assert.deepEqual(fileSearch("structured-search-explicit-location"), {
4661 + pattern: "README.md",
4662 + results: [{ fileName: "README.md", preview: "# Title" }],
4663 + });
4664 + assert.deepEqual(fileSearch("structured-search-query-only"), {
4665 + pattern: "TODO",
4666 + results: [{ fileName: "TODO", preview: "src/a.ts: TODO" }],
4667 + });
4668 + assert.deepEqual(fileSearch("structured-search-query-no-output"), {
4669 + pattern: "FIXME",
4670 + results: undefined,
4671 + });
4672 const webItem = (nativeId: string, status: string) => {
4673 const item = items.findLast(
4674 (candidate) =>
@@ -4673,6 +4695,25 @@ describe("AcpAdapterV2", () => {
4695 patterns: ["t3 code"],
4696 results: [{ url: "https://t3.codes" }, { url: "https://github.com/pingdotgg/t3code" }],
4697 });
4698 + assert.deepEqual(webItem("antigravity-web-search", "completed"), {
4699 + title: "Web search: top story on Hacker News today",
4700 + patterns: ["top story on Hacker News today"],
4701 + results: [
4702 + {
4703 + url: "https://vertexaisearch.cloud.google.com/grounding-api-redirect/AUZIYQGYNzfz",
4704 + },
4705 + ],
4706 + });
4707 + assert.deepEqual(webItem("antigravity-run-search-web", "completed"), {
4708 + title: "Web search: top story on Hacker News today",
4709 + patterns: ["top story on Hacker News today"],
4710 + results: undefined,
4711 + });
4712 + assert.deepEqual(webItem("antigravity-web-search-streamed", "completed"), {
4713 + title: "Web search: streamed citations",
4714 + patterns: ["streamed citations"],
4715 + results: [{ url: "https://example.com/streamed_(detail)" }],
4716 + });
4717 assert.deepEqual(webItem("grok-web-fetch", "completed")?.results, [
4718 { url: "https://t3.codes", snippet: "T3 Code page" },
4719 ]);
packages/provider-acp/src/server/adapter.ts
+79 -16
@@ -1330,41 +1330,66 @@ export function acpToolCallDiffPatch(content: unknown): string | undefined {
1330 .join("\n");
1331 }
1332
1333 -function pathFromToolCall(toolCall: AcpToolCallState): string | undefined {
1333 +function resolvedPathInfo(
1334 + toolCall: AcpToolCallState,
1335 +): { readonly path: string; readonly fromQuery: boolean } | undefined {
1336 const locations = toolCall.data.locations;
1337 if (Array.isArray(locations)) {
1338 for (const location of locations) {
1339 const path = unknownRecord(location)?.path;
1340 if (typeof path === "string" && path.trim().length > 0) {
1339 - return path.trim();
1341 + return { path: path.trim(), fromQuery: false };
1342 }
1343 }
1344 }
1345 const rawInput = unknownRecord(toolCall.data.rawInput);
1344 - for (const key of ["path", "filePath", "file_path", "url", "query", "pattern"]) {
1346 + for (const key of ["path", "filePath", "file_path", "url"]) {
1347 + const candidate = rawInput?.[key];
1348 + if (typeof candidate === "string" && candidate.trim().length > 0) {
1349 + return { path: candidate.trim(), fromQuery: false };
1350 + }
1351 + }
1352 + for (const key of ["query", "pattern"]) {
1353 const candidate = rawInput?.[key];
1354 if (typeof candidate === "string" && candidate.trim().length > 0) {
1347 - return candidate.trim();
1355 + return { path: candidate.trim(), fromQuery: true };
1356 }
1357 }
1358 return undefined;
1359 }
1360
1361 +function pathFromToolCall(toolCall: AcpToolCallState): string | undefined {
1362 + return resolvedPathInfo(toolCall)?.path;
1363 +}
1364 +
1365 function acpBackendWebSearch(
1366 rawInput: Record<string, unknown> | undefined,
1355 - rawOutput: Record<string, unknown> | undefined,
1367 + rawOutput: unknown,
1368 + title?: string | null,
1369 ):
1370 | { readonly query: string | undefined; readonly results: OrchestrationV2WebSearchResult[] }
1371 | undefined {
1372 const variant = typeof rawInput?.variant === "string" ? rawInput.variant.toLowerCase() : "";
1360 - const action = unknownRecord(rawOutput?.action);
1361 - if (variant !== "xsearch" && variant !== "websearch" && action?.type !== "search") {
1373 + const rawOutputRecord = unknownRecord(rawOutput);
1374 + const action = unknownRecord(rawOutputRecord?.action);
1375 + const isWebSearchTitle =
1376 + /^\s*(?:web search|search the web|(?:run(?:ning)?\s+)?(?:web_search|search_web)\s*$)/iu.test(
1377 + title ?? "",
1378 + );
1379 + const isWebSearchVariant = [
1380 + "xsearch",
1381 + "websearch",
1382 + "web_search",
1383 + "search_web",
1384 + "web-search",
1385 + ].includes(variant);
1386 + if (!isWebSearchVariant && action?.type !== "search" && !isWebSearchTitle) {
1387 return undefined;
1388 }
1389 let args: Record<string, unknown> | undefined;
1365 - if (typeof rawOutput?.input === "string") {
1390 + if (typeof rawOutputRecord?.input === "string") {
1391 try {
1367 - args = unknownRecord(JSON.parse(rawOutput.input));
1392 + args = unknownRecord(JSON.parse(rawOutputRecord.input));
1393 } catch {
1394 args = undefined;
1395 }
@@ -1373,7 +1398,14 @@ function acpBackendWebSearch(
1398 .filter(([, value]) => typeof value === "string" || typeof value === "number")
1399 .map(([key, value]) => `${key}: ${value}`)
1400 .join(", ");
1376 - const query = [action?.query, args?.query, argsText]
1401 + const query = [
1402 + action?.query,
1403 + args?.query,
1404 + rawInput?.query,
1405 + rawInput?.search_query,
1406 + rawInput?.q,
1407 + argsText,
1408 + ]
1409 .find((value): value is string => typeof value === "string" && value.trim().length > 0)
1410 ?.trim();
1411 const urls = new Set<string>();
@@ -1381,9 +1413,31 @@ function acpBackendWebSearch(
1413 const url = unknownRecord(source)?.url;
1414 if (typeof url === "string" && url.trim().length > 0) urls.add(url.trim());
1415 }
1416 + if (urls.size === 0) {
1417 + for (const match of textFromUnknown(rawOutput)?.matchAll(/https?:\/\/[^\s<>"]+/gu) ?? []) {
1418 + urls.add(trimCitationUrl(match[0]));
1419 + }
1420 + }
1421 return { query, results: [...urls].map((url) => ({ url })) };
1422 }
1423
1424 +// Prose citations end in punctuation or a closing bracket that is not part of the URL.
1425 +function trimCitationUrl(raw: string): string {
1426 + let url = raw;
1427 + for (;;) {
1428 + const trimmed = url.replace(/[.,;:]+$/u, "");
1429 + const close = trimmed.at(-1);
1430 + const open = close === ")" ? "(" : close === "]" ? "[" : undefined;
1431 + if (open && close && trimmed.split(open).length < trimmed.split(close).length) {
1432 + url = trimmed.slice(0, -1);
1433 + } else if (trimmed === url) {
1434 + return url;
1435 + } else {
1436 + url = trimmed;
1437 + }
1438 + }
1439 +}
1440 +
1441 function providerRequestKind(kind: string | "unknown"): ProviderRequestKind {
1442 switch (kind) {
1443 case "execute":
@@ -4579,12 +4633,19 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4633 };
4634 break;
4635 case "search": {
4582 - const backendSearch = acpBackendWebSearch(rawInputRecord, rawOutputRecord);
4636 + const backendSearch = acpBackendWebSearch(
4637 + rawInputRecord,
4638 + rawOutput,
4639 + typeof toolCall.data.title === "string" ? toolCall.data.title : title,
4640 + );
4641 if (backendSearch !== undefined) {
4584 - const label = nonEmptyText(toolCall.data.title, title ?? "Web search").replace(
4585 - /:\s*$/u,
4586 - "",
4587 - );
4642 + const label = nonEmptyText(toolCall.data.title, title ?? "Web search")
4643 + .replace(/:\s*$/u, "")
4644 + // Antigravity titles the call "Running search_web".
4645 + .replace(
4646 + /^\s*(?:run(?:ning)?\s+)?(?:web_search|search_web)\s*$/iu,
4647 + "Web search",
4648 + );
4649 turnItem = {
4650 ...base,
4651 title:
@@ -4601,6 +4662,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4662 };
4663 break;
4664 }
4665 + const pathIsQuery = resolvedPathInfo(toolCall)?.fromQuery === true;
4666 turnItem = {
4667 ...base,
4668 title:
@@ -4611,7 +4673,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4673 }) ?? title,
4674 type: "file_search",
4675 ...(path === undefined ? {} : { pattern: path }),
4614 - ...(path === undefined
4676 + ...(path === undefined ||
4677 + (pathIsQuery && textFromUnknown(rawOutput) === undefined)
4678 ? {}
4679 : {
4680 results: [