Aiden Cline 1 месяц назад
Родитель
Сommit
6590c1641f
2 измененных файлов с 16 добавлено и 4 удалено
  1. 4 2
      packages/opencode/src/tool/registry.ts
  2. 12 2
      packages/opencode/src/tool/tool.ts

+ 4 - 2
packages/opencode/src/tool/registry.ts

@@ -23,6 +23,7 @@ import { CodeSearchTool } from "./codesearch"
 import { Flag } from "@/flag/flag"
 import { Log } from "@/util/log"
 import { LspTool } from "./lsp"
+import { Truncate } from "../session/truncation"
 
 export namespace ToolRegistry {
   const log = Log.create({ service: "tool.registry" })
@@ -64,10 +65,11 @@ export namespace ToolRegistry {
         description: def.description,
         execute: async (args, ctx) => {
           const result = await def.execute(args as any, ctx)
+          const out = Truncate.output(result)
           return {
             title: "",
-            output: result,
-            metadata: {},
+            output: out.truncated ? out.content : result,
+            metadata: { truncated: out.truncated },
           }
         },
       }),

+ 12 - 2
packages/opencode/src/tool/tool.ts

@@ -2,6 +2,7 @@ import z from "zod"
 import type { MessageV2 } from "../session/message-v2"
 import type { Agent } from "../agent/agent"
 import type { PermissionNext } from "../permission/next"
+import { Truncate } from "../session/truncation"
 
 export namespace Tool {
   interface Metadata {
@@ -52,7 +53,7 @@ export namespace Tool {
       init: async (ctx) => {
         const toolInfo = init instanceof Function ? await init(ctx) : init
         const execute = toolInfo.execute
-        toolInfo.execute = (args, ctx) => {
+        toolInfo.execute = async (args, ctx) => {
           try {
             toolInfo.parameters.parse(args)
           } catch (error) {
@@ -64,7 +65,16 @@ export namespace Tool {
               { cause: error },
             )
           }
-          return execute(args, ctx)
+          const result = await execute(args, ctx)
+          const truncated = Truncate.output(result.output)
+          return {
+            ...result,
+            output: truncated.content,
+            metadata: {
+              ...result.metadata,
+              truncated: truncated.truncated,
+            },
+          }
         }
         return toolInfo
       },