File tree Expand file tree Collapse file tree
packages/opencode/src/tool Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import { CodeSearchTool } from "./codesearch"
2323import { Flag } from "@/flag/flag"
2424import { Log } from "@/util/log"
2525import { LspTool } from "./lsp"
26+ import { Truncate } from "../session/truncation"
2627
2728export namespace ToolRegistry {
2829 const log = Log . create ( { service : "tool.registry" } )
@@ -64,10 +65,11 @@ export namespace ToolRegistry {
6465 description : def . description ,
6566 execute : async ( args , ctx ) => {
6667 const result = await def . execute ( args as any , ctx )
68+ const out = Truncate . output ( result )
6769 return {
6870 title : "" ,
69- output : result ,
70- metadata : { } ,
71+ output : out . truncated ? out . content : result ,
72+ metadata : { truncated : out . truncated } ,
7173 }
7274 } ,
7375 } ) ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import z from "zod"
22import type { MessageV2 } from "../session/message-v2"
33import type { Agent } from "../agent/agent"
44import type { PermissionNext } from "../permission/next"
5+ import { Truncate } from "../session/truncation"
56
67export namespace Tool {
78 interface Metadata {
@@ -52,7 +53,7 @@ export namespace Tool {
5253 init : async ( ctx ) => {
5354 const toolInfo = init instanceof Function ? await init ( ctx ) : init
5455 const execute = toolInfo . execute
55- toolInfo . execute = ( args , ctx ) => {
56+ toolInfo . execute = async ( args , ctx ) => {
5657 try {
5758 toolInfo . parameters . parse ( args )
5859 } catch ( error ) {
@@ -64,7 +65,16 @@ export namespace Tool {
6465 { cause : error } ,
6566 )
6667 }
67- return execute ( args , ctx )
68+ const result = await execute ( args , ctx )
69+ const truncated = Truncate . output ( result . output )
70+ return {
71+ ...result ,
72+ output : truncated . content ,
73+ metadata : {
74+ ...result . metadata ,
75+ truncated : truncated . truncated ,
76+ } ,
77+ }
6878 }
6979 return toolInfo
7080 } ,
You can’t perform that action at this time.
0 commit comments