Files
enkly-ai/services/agent/internal/infrastructure/toolexec/writetodos.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

59 lines
1.9 KiB
Go

package toolexec
import (
"fmt"
"strings"
"enkly/pkg/vllmkit"
)
// writeTodos replaces Toolbox.writeTodos verbatim. It was always pure,
// in-memory formatting with no filesystem or database dependency, so
// unlike every other tool it doesn't move to the workspace service —
// there's nothing to execute remotely.
func writeTodos(call vllmkit.ToolCallRequest) vllmkit.ToolResult {
raw, ok := call.Arguments["todos"]
if !ok {
return vllmkit.ToolResult{Name: call.Name, Content: `write_todos: missing "todos" array`, IsError: true}
}
list, ok := raw.([]any)
if !ok {
return vllmkit.ToolResult{Name: call.Name, Content: `write_todos: "todos" must be an array`, IsError: true}
}
if len(list) == 0 {
return vllmkit.ToolResult{Name: call.Name, Content: "write_todos: the todo list is empty", IsError: true}
}
var sb strings.Builder
inProgress := 0
for _, item := range list {
m, ok := item.(map[string]any)
if !ok {
return vllmkit.ToolResult{Name: call.Name, Content: `write_todos: each todo must be an object with "content" and "status"`, IsError: true}
}
content, _ := m["content"].(string)
status, _ := m["status"].(string)
if strings.TrimSpace(content) == "" {
return vllmkit.ToolResult{Name: call.Name, Content: `write_todos: a todo is missing "content"`, IsError: true}
}
var box string
switch status {
case "completed":
box = "[x]"
case "in_progress":
box = "[~]"
inProgress++
case "pending", "":
box = "[ ]"
default:
return vllmkit.ToolResult{Name: call.Name, Content: fmt.Sprintf("write_todos: unknown status %q (want pending, in_progress, or completed)", status), IsError: true}
}
fmt.Fprintf(&sb, "%s %s\n", box, content)
}
if inProgress > 1 {
return vllmkit.ToolResult{Name: call.Name, Content: "write_todos: more than one todo is in_progress — focus on one step at a time", IsError: true}
}
return vllmkit.ToolResult{Name: call.Name, Content: sb.String()}
}