Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions internal/agent/response_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,20 @@ func (g *ResponsePrinterGenerator) renderToolCall(content string) string {
var toolCall gai.ToolCallInput
if err := json.Unmarshal([]byte(content), &toolCall); err == nil {
if toolCall.Name == codemode.ExecuteGoCodeToolName {
if code, ok := toolCall.Parameters["code"].(string); ok && code != "" {
result := fmt.Sprintf("#### [tool call]\n```go\n%s\n```", code)
rendered, err := g.contentRenderer.Render(result)
if err == nil {
return rendered
// Unmarshal parameters into the typed struct
paramsJSON, err := json.Marshal(toolCall.Parameters)
if err == nil {
var input codemode.ExecuteGoCodeInput
if err := json.Unmarshal(paramsJSON, &input); err == nil && input.Code != "" {
header := "#### [tool call]"
if input.ExecutionTimeout > 0 {
header = fmt.Sprintf("#### [tool call] (timeout: %ds)", input.ExecutionTimeout)
}
result := fmt.Sprintf("%s\n```go\n%s\n```", header, input.Code)
rendered, err := g.contentRenderer.Render(result)
if err == nil {
return rendered
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/agent/response_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func TestRenderToolCall(t *testing.T) {
{
name: "execute_go_code renders as Go block",
content: `{"name":"execute_go_code","parameters":{"code":"package main\n\nfunc Run() error { return nil }","executionTimeout":30}}`,
want: "#### [tool call] (timeout: 30s)\n```go\npackage main\n\nfunc Run() error { return nil }\n```",
},
{
name: "execute_go_code without timeout renders without timeout",
content: `{"name":"execute_go_code","parameters":{"code":"package main\n\nfunc Run() error { return nil }"}}`,
want: "#### [tool call]\n```go\npackage main\n\nfunc Run() error { return nil }\n```",
},
{
Expand Down
4 changes: 2 additions & 2 deletions internal/codemode/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// executeGoCodeInput represents the input parameters for the execute_go_code tool
type executeGoCodeInput struct {
type ExecuteGoCodeInput struct {
Code string `json:"code"`
ExecutionTimeout int `json:"executionTimeout"`
}
Expand All @@ -28,7 +28,7 @@ type ExecuteGoCodeCallback struct {
// - Infrastructure errors: error that stops agent execution
func (c *ExecuteGoCodeCallback) Call(ctx context.Context, parametersJSON json.RawMessage, toolCallID string) (gai.Message, error) {
// Parse input parameters
var input executeGoCodeInput
var input ExecuteGoCodeInput
if err := json.Unmarshal(parametersJSON, &input); err != nil {
return gai.ToolResultMessage(toolCallID, gai.Text, "text/plain", gai.Str("Error parsing parameters: "+err.Error())), nil
}
Expand Down
20 changes: 10 additions & 10 deletions internal/codemode/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
func TestExecuteGoCodeCallback_Call(t *testing.T) {
tests := []struct {
name string
input executeGoCodeInput
input ExecuteGoCodeInput
wantErr bool
wantFatalErr bool
wantOutputSub string // substring expected in output
wantErrContain string // substring expected in error message
}{
{
name: "successful execution",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

import (
Expand All @@ -40,7 +40,7 @@ func Run(ctx context.Context) error {
},
{
name: "compilation error - syntax",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

func Run(ctx context.Context) error {
Expand All @@ -54,7 +54,7 @@ func Run(ctx context.Context) error {
},
{
name: "compilation error - missing import",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

func Run(ctx context.Context) error {
Expand All @@ -68,7 +68,7 @@ func Run(ctx context.Context) error {
},
{
name: "Run returns error - exit code 1",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

import (
Expand All @@ -86,7 +86,7 @@ func Run(ctx context.Context) error {
},
{
name: "panic - exit code 2",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

import "context"
Expand All @@ -101,7 +101,7 @@ func Run(ctx context.Context) error {
},
{
name: "fatal exit - exit code 3",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

import (
Expand All @@ -124,7 +124,7 @@ func Run(ctx context.Context) error {
},
{
name: "timeout exceeded",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: `package main

import (
Expand All @@ -144,7 +144,7 @@ func Run(ctx context.Context) error {
},
{
name: "invalid JSON parameters",
input: executeGoCodeInput{
input: ExecuteGoCodeInput{
Code: "", // Will test with raw invalid JSON
ExecutionTimeout: 0,
},
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestExecuteGoCodeCallback_ContextCancellation(t *testing.T) {

callback := &ExecuteGoCodeCallback{Servers: nil}

input := executeGoCodeInput{
input := ExecuteGoCodeInput{
Code: `package main

import (
Expand Down