Skip to content

Commit 5abe446

Browse files
committed
feat(grep): add distinguishing title to grep and glob tool blocks
grep: pattern (glob) in path (e.g. "foo (*.ts) in /src") glob: pattern in dir (e.g. "**/*.ts in /src") Previously both hardcoded title:"", making multiple concurrent calls in the same turn visually identical in opencode's tool blocks. Passes args through the already-supported result(value, args) signature; no interface changes needed.
1 parent 262d842 commit 5abe446

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/provider/stream-map.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,17 @@ const NATIVE_ADAPTERS: Record<string, NativeToolAdapter> = {
361361
const dir = strField(args, "targetDirectory");
362362
return dir ? { pattern, path: dir } : { pattern };
363363
},
364-
result: (value) => {
364+
result: (value, args) => {
365365
if (!isRecord(value) || !Array.isArray(value["files"])) return null;
366366
const files = (value["files"] as unknown[]).filter(
367367
(f): f is string => typeof f === "string",
368368
);
369369
const truncated =
370370
value["clientTruncated"] === true || value["ripgrepTruncated"] === true;
371+
const pattern = strField(args, "globPattern") ?? "";
372+
const dir = strField(args, "targetDirectory");
371373
return {
372-
title: "",
374+
title: dir ? `${pattern} in ${dir}` : pattern,
373375
metadata: { count: files.length, truncated },
374376
output: files.length > 0 ? files.join("\n") : "No files found",
375377
};
@@ -388,7 +390,7 @@ const NATIVE_ADAPTERS: Record<string, NativeToolAdapter> = {
388390
if (g) out["include"] = g;
389391
return out;
390392
},
391-
result: (value) => {
393+
result: (value, args) => {
392394
if (!isRecord(value)) return null;
393395
const unions: unknown[] = [];
394396
const ws = value["workspaceResults"];
@@ -434,8 +436,14 @@ const NATIVE_ADAPTERS: Record<string, NativeToolAdapter> = {
434436
}
435437
}
436438
}
439+
const pattern = strField(args, "pattern") ?? "";
440+
const glob = strField(args, "glob");
441+
const path = strField(args, "path");
442+
let title = pattern;
443+
if (glob) title += ` (${glob})`;
444+
if (path) title += ` in ${path}`;
437445
return {
438-
title: "",
446+
title,
439447
metadata: { matches: total, truncated: false },
440448
output:
441449
total > 0

test/stream-map.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ describe("native tool mapping (blocks)", () => {
939939
input: JSON.stringify({ pattern: "**/*.ts", path: "/src" }),
940940
});
941941
expect(foldedResult(result)).toMatchObject({
942+
title: "**/*.ts in /src",
942943
metadata: { count: 2, truncated: false },
943944
output: "/src/a.ts\n/src/b.ts",
944945
});
@@ -969,7 +970,10 @@ describe("native tool mapping (blocks)", () => {
969970
toolName: "grep",
970971
input: JSON.stringify({ pattern: "foo", path: "/src", include: "*.ts" }),
971972
});
972-
expect(foldedResult(result)).toMatchObject({ metadata: { matches: 1 } });
973+
expect(foldedResult(result)).toMatchObject({
974+
title: "foo (*.ts) in /src",
975+
metadata: { matches: 1 },
976+
});
973977
expect(foldedResult(result).output).toContain("/src/a.ts:");
974978
expect(foldedResult(result).output).toContain("Line 3: const foo = 1");
975979
});

0 commit comments

Comments
 (0)