From 5abe446bcda76a23fd79994de3706ea918ebbab1 Mon Sep 17 00:00:00 2001 From: Justin Carper Date: Tue, 16 Jun 2026 13:21:02 -0400 Subject: [PATCH] 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. --- src/provider/stream-map.ts | 16 ++++++++++++---- test/stream-map.test.ts | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/provider/stream-map.ts b/src/provider/stream-map.ts index 1c7a9e5..768b485 100644 --- a/src/provider/stream-map.ts +++ b/src/provider/stream-map.ts @@ -361,15 +361,17 @@ const NATIVE_ADAPTERS: Record = { const dir = strField(args, "targetDirectory"); return dir ? { pattern, path: dir } : { pattern }; }, - result: (value) => { + result: (value, args) => { if (!isRecord(value) || !Array.isArray(value["files"])) return null; const files = (value["files"] as unknown[]).filter( (f): f is string => typeof f === "string", ); const truncated = value["clientTruncated"] === true || value["ripgrepTruncated"] === true; + const pattern = strField(args, "globPattern") ?? ""; + const dir = strField(args, "targetDirectory"); return { - title: "", + title: dir ? `${pattern} in ${dir}` : pattern, metadata: { count: files.length, truncated }, output: files.length > 0 ? files.join("\n") : "No files found", }; @@ -388,7 +390,7 @@ const NATIVE_ADAPTERS: Record = { if (g) out["include"] = g; return out; }, - result: (value) => { + result: (value, args) => { if (!isRecord(value)) return null; const unions: unknown[] = []; const ws = value["workspaceResults"]; @@ -434,8 +436,14 @@ const NATIVE_ADAPTERS: Record = { } } } + const pattern = strField(args, "pattern") ?? ""; + const glob = strField(args, "glob"); + const path = strField(args, "path"); + let title = pattern; + if (glob) title += ` (${glob})`; + if (path) title += ` in ${path}`; return { - title: "", + title, metadata: { matches: total, truncated: false }, output: total > 0 diff --git a/test/stream-map.test.ts b/test/stream-map.test.ts index 0f85043..f1cf927 100644 --- a/test/stream-map.test.ts +++ b/test/stream-map.test.ts @@ -939,6 +939,7 @@ describe("native tool mapping (blocks)", () => { input: JSON.stringify({ pattern: "**/*.ts", path: "/src" }), }); expect(foldedResult(result)).toMatchObject({ + title: "**/*.ts in /src", metadata: { count: 2, truncated: false }, output: "/src/a.ts\n/src/b.ts", }); @@ -969,7 +970,10 @@ describe("native tool mapping (blocks)", () => { toolName: "grep", input: JSON.stringify({ pattern: "foo", path: "/src", include: "*.ts" }), }); - expect(foldedResult(result)).toMatchObject({ metadata: { matches: 1 } }); + expect(foldedResult(result)).toMatchObject({ + title: "foo (*.ts) in /src", + metadata: { matches: 1 }, + }); expect(foldedResult(result).output).toContain("/src/a.ts:"); expect(foldedResult(result).output).toContain("Line 3: const foo = 1"); });