Dax Raad hai 8 meses
pai
achega
636133e6cb

+ 1 - 0
packages/opencode/src/tool/glob.ts

@@ -60,6 +60,7 @@ export const GlobTool = Tool.define({
       metadata: {
         count: files.length,
         truncated,
+        title: path.relative(app.path.root, search),
       },
       output: output.join("\n"),
     }

+ 1 - 0
packages/opencode/src/tool/grep.ts

@@ -124,6 +124,7 @@ export const GrepTool = Tool.define({
       metadata: {
         matches: finalMatches.length,
         truncated,
+        title: params.pattern,
       },
       output: outputLines.join("\n"),
     }

+ 5 - 1
packages/opencode/src/tool/ls.ts

@@ -98,7 +98,11 @@ export const ListTool = Tool.define({
     const output = `${searchPath}/\n` + renderDir(".", 0)
 
     return {
-      metadata: { count: files.length, truncated: files.length >= 1000 },
+      metadata: {
+        count: files.length,
+        truncated: files.length >= 1000,
+        title: path.relative(app.path.root, searchPath),
+      },
       output,
     }
   },

+ 1 - 0
packages/opencode/src/tool/lsp-diagnostics.ts

@@ -22,6 +22,7 @@ export const LspDiagnosticTool = Tool.define({
     return {
       metadata: {
         diagnostics,
+        title: path.relative(app.path.root, normalized),
       },
       output: file?.length
         ? file.map(LSP.Diagnostic.pretty).join("\n")

+ 6 - 0
packages/opencode/src/tool/lsp-hover.ts

@@ -27,6 +27,12 @@ export const LspHoverTool = Tool.define({
     return {
       metadata: {
         result,
+        title:
+          path.relative(app.path.root, file) +
+          ":" +
+          args.line +
+          ":" +
+          args.character,
       },
       output: JSON.stringify(result, null, 2),
     }

+ 4 - 1
packages/opencode/src/tool/multiedit.ts

@@ -2,6 +2,8 @@ import { z } from "zod"
 import { Tool } from "./tool"
 import { EditTool } from "./edit"
 import DESCRIPTION from "./multiedit.txt"
+import path from "path"
+import { App } from "../app/app"
 
 export const MultiEditTool = Tool.define({
   id: "opencode.multiedit",
@@ -26,10 +28,11 @@ export const MultiEditTool = Tool.define({
       )
       results.push(result)
     }
-
+    const app = App.info()
     return {
       metadata: {
         results: results.map((r) => r.metadata),
+        title: path.relative(app.path.root, params.filePath),
       },
       output: results.at(-1)!.output,
     }

+ 3 - 11
packages/opencode/src/tool/patch.ts

@@ -4,6 +4,7 @@ import * as fs from "fs/promises"
 import { Tool } from "./tool"
 import { FileTimes } from "./util/file-times"
 import DESCRIPTION from "./patch.txt"
+import { App } from "../app/app"
 
 const PatchParams = z.object({
   patchText: z
@@ -11,12 +12,6 @@ const PatchParams = z.object({
     .describe("The full patch text that describes all changes to be made"),
 })
 
-interface PatchResponseMetadata {
-  changed: string[]
-  additions: number
-  removals: number
-}
-
 interface Change {
   type: "add" | "update" | "delete"
   old_content?: string
@@ -242,10 +237,6 @@ export const PatchTool = Tool.define({
   description: DESCRIPTION,
   parameters: PatchParams,
   execute: async (params, ctx) => {
-    if (!params.patchText) {
-      throw new Error("patchText is required")
-    }
-
     // Identify all files needed for the patch and verify they've been read
     const filesToRead = identifyFilesNeeded(params.patchText)
     for (const filePath of filesToRead) {
@@ -372,7 +363,8 @@ export const PatchTool = Tool.define({
         changed: changedFiles,
         additions: totalAdditions,
         removals: totalRemovals,
-      } satisfies PatchResponseMetadata,
+        title: `${filesToRead.length} files`,
+      },
       output,
     }
   },

+ 2 - 0
packages/opencode/src/tool/read.ts

@@ -5,6 +5,7 @@ import { Tool } from "./tool"
 import { LSP } from "../lsp"
 import { FileTimes } from "./util/file-times"
 import DESCRIPTION from "./read.txt"
+import { App } from "../app/app"
 
 const MAX_READ_SIZE = 250 * 1024
 const DEFAULT_READ_LIMIT = 2000
@@ -95,6 +96,7 @@ export const ReadTool = Tool.define({
       output,
       metadata: {
         preview,
+        title: path.relative(App.info().path.root, filePath),
       },
     }
   },

+ 2 - 0
packages/opencode/src/tool/todo.ts

@@ -34,6 +34,7 @@ export const TodoWriteTool = Tool.define({
     return {
       output: JSON.stringify(params.todos, null, 2),
       metadata: {
+        title: `${params.todos.length} todos`,
         todos: params.todos,
       },
     }
@@ -49,6 +50,7 @@ export const TodoReadTool = Tool.define({
     return {
       metadata: {
         todos,
+        title: ``,
       },
       output: JSON.stringify(todos, null, 2),
     }

+ 4 - 1
packages/opencode/src/tool/write.ts

@@ -5,6 +5,7 @@ import { FileTimes } from "./util/file-times"
 import { LSP } from "../lsp"
 import { Permission } from "../permission"
 import DESCRIPTION from "./write.txt"
+import { App } from "../app/app"
 
 export const WriteTool = Tool.define({
   id: "opencode.write",
@@ -18,9 +19,10 @@ export const WriteTool = Tool.define({
     content: z.string().describe("The content to write to the file"),
   }),
   async execute(params, ctx) {
+    const app = App.info()
     const filepath = path.isAbsolute(params.filePath)
       ? params.filePath
-      : path.join(process.cwd(), params.filePath)
+      : path.join(app.path.cwd, params.filePath)
 
     const file = Bun.file(filepath)
     const exists = await file.exists()
@@ -59,6 +61,7 @@ export const WriteTool = Tool.define({
         diagnostics,
         filepath,
         exists: exists,
+        title: path.relative(app.path.root, filepath),
       },
       output,
     }