Просмотр исходного кода

tweak: bash tool improve output metadata for agent consumption, fix small timeout issue (#5131)

Shantur Rathore 2 месяцев назад
Родитель
Сommit
ba417d80b1
1 измененных файлов с 13 добавлено и 11 удалено
  1. 13 11
      packages/opencode/src/tool/bash.ts

+ 13 - 11
packages/opencode/src/tool/bash.ts

@@ -234,13 +234,15 @@ export const BashTool = Tool.define("bash", async () => {
       })
 
       const append = (chunk: Buffer) => {
-        output += chunk.toString()
-        ctx.metadata({
-          metadata: {
-            output,
-            description: params.description,
-          },
-        })
+        if (output.length <= MAX_OUTPUT_LENGTH) {
+          output += chunk.toString()
+          ctx.metadata({
+            metadata: {
+              output,
+              description: params.description,
+            },
+          })
+        }
       }
 
       proc.stdout?.on("data", append)
@@ -295,7 +297,7 @@ export const BashTool = Tool.define("bash", async () => {
       const timeoutTimer = setTimeout(() => {
         timedOut = true
         void killTree()
-      }, timeout)
+      }, timeout + 100)
 
       await new Promise<void>((resolve, reject) => {
         const cleanup = () => {
@@ -320,15 +322,15 @@ export const BashTool = Tool.define("bash", async () => {
 
       if (output.length > MAX_OUTPUT_LENGTH) {
         output = output.slice(0, MAX_OUTPUT_LENGTH)
-        resultMetadata.push(`Output exceeded length limit of ${MAX_OUTPUT_LENGTH} chars`)
+        resultMetadata.push(`bash tool truncated output as it exceeded ${MAX_OUTPUT_LENGTH} char limit`)
       }
 
       if (timedOut) {
-        resultMetadata.push(`Command terminated after exceeding timeout ${timeout} ms`)
+        resultMetadata.push(`bash tool terminated commmand after exceeding timeout ${timeout} ms`)
       }
 
       if (aborted) {
-        resultMetadata.push("Command aborted by user")
+        resultMetadata.push("User aborted the command")
       }
 
       if (resultMetadata.length > 1) {