diff options
| author | sigoden <sigoden@gmail.com> | 2024-07-12 19:28:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-12 19:28:10 +0800 |
| commit | 1051beca6a41c5112645f7e390e4e63dd6288e64 (patch) | |
| tree | acc413fc362f634b5e2d0fa1f3c72442d26a4de0 /agents/coder/tools.sh | |
| parent | 5600b68e044b4cd9bc55664ce3f41e9a339fc805 (diff) | |
| download | llm-functions-docker-1051beca6a41c5112645f7e390e4e63dd6288e64.tar.gz | |
feat: add coder agent (#70)
Diffstat (limited to 'agents/coder/tools.sh')
| -rwxr-xr-x | agents/coder/tools.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/agents/coder/tools.sh b/agents/coder/tools.sh new file mode 100755 index 0000000..dd9e7a8 --- /dev/null +++ b/agents/coder/tools.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -e + +# @env FS_BASE_DIR=. The base dir + +# @cmd Create a new file at the specified path with content. +# @option --path! The path where the file should be created +# @option --content! The content of the file +fs_create() { + path="$FS_BASE_DIR/$argc_path" + printf "%s" "$argc_content" > "$path" + echo "File created: $path" >> "$LLM_OUTPUT" +} + +# @cmd Apply changes to a file. Use this when you need to edit an existing file. +# YOU ALWAYS PROVIDE THE FULL FILE CONTENT WHEN EDITING. NO PARTIAL CONTENT OR COMMENTS. +# YOU MUST PROVIDE THE FULL FILE CONTENT. + +# @option --path! The path of the file to edit +# @option --content! The new content to apply to the file +# @meta require-tools git +fs_edit() { + path="$FS_BASE_DIR/$argc_path" + if [[ -f "$path" ]]; then + changed=0 + printf "%s" "$argc_content" | git diff --no-index "$path" - || { + changed=1 + } + if [[ "$changed" -eq 0 ]]; then + echo "No changes detected." >> "$LLM_OUTPUT" + else + if [ -t 1 ]; then + echo + read -r -p "Apply changes? [Y/n] " ans + if [[ "$ans" == "N" || "$ans" == "n" ]]; then + echo "Aborted!" + exit 1 + fi + fi + printf "%s" "$argc_content" > "$path" + echo "Applied changes" >> "$LLM_OUTPUT" + fi + else + echo "Not found file: $path" >> "$LLM_OUTPUT" + fi +} + +# See more details at https://github.com/sigoden/argc +eval "$(argc --argc-eval "$0" "$@")" |
