From a805c92131d8599351b13358c7eebb203fc5787a Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 26 Nov 2023 20:42:31 +0000 Subject: [PATCH] Update file_insert_lines Renamed `start_line` parameter to `position` --- pkg/cli/functions.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/cli/functions.go b/pkg/cli/functions.go index ef688fd..dcbe241 100644 --- a/pkg/cli/functions.go +++ b/pkg/cli/functions.go @@ -179,16 +179,16 @@ var AvailableTools = map[string]AvailableTool{ Type: "string", Description: "Path of the file to be modified, relative to the current working directory.", }, - "start_line": { + "position": { Type: "integer", - Description: `Which line to begin inserting lines at (existing line will be moved to after content).`, + Description: `Which line to insert content *before*.`, }, "content": { Type: "string", Description: `The content to insert.`, }, }, - Required: []string{"path", "start", "content"}, + Required: []string{"path", "position", "content"}, }, }}, Impl: func(args map[string]interface{}) (string, error) { @@ -200,14 +200,14 @@ var AvailableTools = map[string]AvailableTool{ if !ok { return "", fmt.Errorf("Invalid path in function arguments: %v", tmp) } - var start_line int - tmp, ok = args["start_line"] + var position int + tmp, ok = args["position"] if ok { tmp, ok := tmp.(float64) if !ok { - return "", fmt.Errorf("Invalid start_line in function arguments: %v", tmp) + return "", fmt.Errorf("Invalid position in function arguments: %v", tmp) } - start_line = int(tmp) + position = int(tmp) } var content string tmp, ok = args["content"] @@ -217,7 +217,7 @@ var AvailableTools = map[string]AvailableTool{ return "", fmt.Errorf("Invalid content in function arguments: %v", tmp) } } - return FileInsertLines(path, start_line, content), nil + return FileInsertLines(path, position, content), nil }, }, "file_replace_lines": { @@ -484,7 +484,7 @@ func WriteFile(path string, content string) string { return resultToJson(FunctionResult{}) } -func FileInsertLines(path string, startLine int, content string) string { +func FileInsertLines(path string, position int, content string) string { ok, res := isPathWithinCWD(path) if !ok { return resultToJson(*res) @@ -503,15 +503,15 @@ func FileInsertLines(path string, startLine int, content string) string { data = []byte{} } - if startLine < 1 { + if position < 1 { return resultToJson(FunctionResult{Message: "start_line cannot be less than 1"}) } lines := strings.Split(string(data), "\n") contentLines := strings.Split(strings.Trim(content, "\n"), "\n") - before := lines[:startLine-1] - after := lines[startLine-1:] + before := lines[:position-1] + after := lines[position-1:] lines = append(before, append(contentLines, after...)...) newContent := strings.Join(lines, "\n")