summaryrefslogtreecommitdiffhomepage
path: root/internal/llm/tools/bash.go
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-12 14:49:01 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:38:42 +0200
commit0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345 (patch)
tree9b45cabbb2c8f0195d8428445db4d8a710db7951 /internal/llm/tools/bash.go
parent8d874b839db169906e18e4277cd198504018e022 (diff)
downloadopencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.tar.gz
opencode-0697dcc1d9c7330d8c9d8a2be0bb94b3d46c9345.zip
implement nested tool calls and initial setup for result metadata
Diffstat (limited to 'internal/llm/tools/bash.go')
-rw-r--r--internal/llm/tools/bash.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/internal/llm/tools/bash.go b/internal/llm/tools/bash.go
index 4e80ae60a..d20afb7f2 100644
--- a/internal/llm/tools/bash.go
+++ b/internal/llm/tools/bash.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
+ "time"
"github.com/kujtimiihoxha/termai/internal/config"
"github.com/kujtimiihoxha/termai/internal/llm/tools/shell"
@@ -21,6 +22,9 @@ type BashPermissionsParams struct {
Timeout int `json:"timeout"`
}
+type BashToolResponseMetadata struct {
+ Took int64 `json:"took"`
+}
type bashTool struct {
permissions permission.Service
}
@@ -272,11 +276,13 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
return NewTextErrorResponse("permission denied"), nil
}
}
+ startTime := time.Now()
shell := shell.GetPersistentShell(config.WorkingDirectory())
stdout, stderr, exitCode, interrupted, err := shell.Exec(ctx, params.Command, params.Timeout)
if err != nil {
return NewTextErrorResponse(fmt.Sprintf("error executing command: %s", err)), nil
}
+ took := time.Since(startTime).Milliseconds()
stdout = truncateOutput(stdout)
stderr = truncateOutput(stderr)
@@ -304,10 +310,13 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
stdout += "\n" + errorMessage
}
+ metadata := BashToolResponseMetadata{
+ Took: took,
+ }
if stdout == "" {
- return NewTextResponse("no output"), nil
+ return WithResponseMetadata(NewTextResponse("no output"), metadata), nil
}
- return NewTextResponse(stdout), nil
+ return WithResponseMetadata(NewTextResponse(stdout), metadata), nil
}
func truncateOutput(content string) string {