Files
enkly-ai/services/workspace/internal/infrastructure/sandboxfs/facade.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

79 lines
2.8 KiB
Go

package sandboxfs
import "context"
// The methods below are thin, exported wrappers around the Toolbox's
// unexported per-tool methods (readFile, writeFile, ...), built so the
// gRPC layer (internal/interfaces/grpc) can call them without needing
// package-private access. Each one keeps the original tool's exact
// map[string]any argument contract internally — this is deliberate:
// agent-service tool-calling, the gRPC layer here, and the underlying
// tool implementation all agree on the same argument names
// ("old_string", "replace_all", "path_glob", ...), so nothing about the
// monolith's tool behavior (including its exact success/error message
// text, which the model has been prompted around) has to change.
func (t *Toolbox) ReadFile(path string, offset, limit int) ToolResult {
args := map[string]any{"path": path}
if offset != 0 {
args["offset"] = float64(offset)
}
if limit != 0 {
args["limit"] = float64(limit)
}
return t.readFile(ToolCallRequest{Name: "read_file", Arguments: args})
}
func (t *Toolbox) WriteFile(path, content string) ToolResult {
return t.writeFile(ToolCallRequest{Name: "write_file", Arguments: map[string]any{
"path": path, "content": content,
}})
}
func (t *Toolbox) EditFile(path, oldString, newString string, replaceAll bool) ToolResult {
return t.editFile(ToolCallRequest{Name: "edit_file", Arguments: map[string]any{
"path": path, "old_string": oldString, "new_string": newString, "replace_all": replaceAll,
}})
}
// WorkspaceEdit mirrors one element of multi_edit_file's "edits" array.
type WorkspaceEdit struct {
OldString string
NewString string
ReplaceAll bool
}
func (t *Toolbox) MultiEditFile(path string, edits []WorkspaceEdit) ToolResult {
rawEdits := make([]any, len(edits))
for i, e := range edits {
rawEdits[i] = map[string]any{
"old_string": e.OldString, "new_string": e.NewString, "replace_all": e.ReplaceAll,
}
}
return t.multiEditFile(ToolCallRequest{Name: "multi_edit_file", Arguments: map[string]any{
"path": path, "edits": rawEdits,
}})
}
func (t *Toolbox) ListDirectory(path string) ToolResult {
return t.listDirectory(ToolCallRequest{Name: "list_directory", Arguments: map[string]any{"path": path}})
}
func (t *Toolbox) GlobSearch(pattern, path string) ToolResult {
return t.globSearch(ToolCallRequest{Name: "glob_search", Arguments: map[string]any{
"pattern": pattern, "path": path,
}})
}
func (t *Toolbox) Grep(pattern, path, pathGlob string, caseInsensitive bool) ToolResult {
return t.grep(ToolCallRequest{Name: "grep", Arguments: map[string]any{
"pattern": pattern, "path": path, "path_glob": pathGlob, "case_insensitive": caseInsensitive,
}})
}
func (t *Toolbox) RunBashCommand(ctx context.Context, command string) ToolResult {
return t.runBashCommand(ctx, ToolCallRequest{Name: "run_bash_command", Arguments: map[string]any{
"command": command,
}})
}