From c3ebceb76dec70b27fbf8a3d94e37c44f0a1dfd4 Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Mon, 11 May 2026 15:03:15 -0600 Subject: [PATCH] fix: Improve the coder agent's usage of tools --- assets/agents/coder/config.yaml | 19 +---- assets/agents/coder/tools.sh | 118 -------------------------------- 2 files changed, 3 insertions(+), 134 deletions(-) diff --git a/assets/agents/coder/config.yaml b/assets/agents/coder/config.yaml index 730ce8c..3f06dee 100644 --- a/assets/agents/coder/config.yaml +++ b/assets/agents/coder/config.yaml @@ -62,22 +62,9 @@ instructions: | 3. Implement each, calling `todo__done` immediately after ## Writing Code - - **CRITICAL**: Write code using `write_file` tool, NEVER paste code in chat. - - Correct: - ``` - write_file --path "src/user.rs" --content "pub struct User { ... }" - ``` - - Wrong: - ``` - Here's the implementation: - \`\`\`rust - pub struct User { ... } - \`\`\` - ``` - + 1. **Use fs_patch for surgical edits** - `fs_patch --path "src/main.rs" --contents ""` applies targeted changes without rewriting the whole file + 2. **use fs_write for full file writes** - `fs_write --path "src/main.rs" --contents "/dev/null && pwd) || echo "${dir}" } -# Normalize a path to be relative to project root. -# Strips the project_dir prefix if the LLM passes an absolute path. -# Usage: local rel_path; rel_path=$(_normalize_path "/abs/or/rel/path") -_normalize_path() { - local input_path="$1" - local project_dir - project_dir=$(_project_dir) - - if [[ "${input_path}" == /* ]]; then - input_path="${input_path#"${project_dir}"/}" - fi - - input_path="${input_path#./}" - echo "${input_path}" -} - -# @cmd Read a file's contents before modifying -# @option --path! Path to the file (relative to project root) -read_file() { - local file_path - # shellcheck disable=SC2154 - file_path=$(_normalize_path "${argc_path}") - local project_dir - project_dir=$(_project_dir) - local full_path="${project_dir}/${file_path}" - - if [[ ! -f "${full_path}" ]]; then - warn "File not found: ${file_path}" >> "$LLM_OUTPUT" - return 0 - fi - - { - info "Reading: ${file_path}" - echo "" - cat "${full_path}" - } >> "$LLM_OUTPUT" -} - -# @cmd Write complete file contents -# @option --path! Path for the file (relative to project root) -# @option --content! Complete file contents to write -write_file() { - local file_path - file_path=$(_normalize_path "${argc_path}") - # shellcheck disable=SC2154 - local content="${argc_content}" - local project_dir - project_dir=$(_project_dir) - local full_path="${project_dir}/${file_path}" - - mkdir -p "$(dirname "${full_path}")" - printf '%s' "${content}" > "${full_path}" - - green "Wrote: ${file_path}" >> "$LLM_OUTPUT" -} - -# @cmd Find files similar to a given path (for pattern matching) -# @option --path! Path to find similar files for -find_similar_files() { - local file_path - file_path=$(_normalize_path "${argc_path}") - local project_dir - project_dir=$(_project_dir) - - local ext="${file_path##*.}" - local dir - dir=$(dirname "${file_path}") - - info "Similar files to: ${file_path}" >> "$LLM_OUTPUT" - echo "" >> "$LLM_OUTPUT" - - local results - results=$(find "${project_dir}/${dir}" -maxdepth 1 -type f -name "*.${ext}" \ - ! -name "$(basename "${file_path}")" \ - ! -name "*test*" \ - ! -name "*spec*" \ - 2>/dev/null | sed "s|^${project_dir}/||" | head -3) - - if [[ -z "${results}" ]]; then - results=$(find "${project_dir}/src" -type f -name "*.${ext}" \ - ! -name "*test*" \ - ! -name "*spec*" \ - -not -path '*/target/*' \ - 2>/dev/null | sed "s|^${project_dir}/||" | head -3) - fi - - if [[ -n "${results}" ]]; then - echo "${results}" >> "$LLM_OUTPUT" - else - warn "No similar files found" >> "$LLM_OUTPUT" - fi -} - # @cmd Verify the project builds successfully verify_build() { local project_dir @@ -189,28 +96,3 @@ get_project_structure() { } >> "$LLM_OUTPUT" } -# @cmd Search for content in the codebase -# @option --pattern! Pattern to search for -search_code() { - # shellcheck disable=SC2154 - local pattern="${argc_pattern}" - local project_dir - project_dir=$(_project_dir) - - info "Searching: ${pattern}" >> "$LLM_OUTPUT" - echo "" >> "$LLM_OUTPUT" - - local results - results=$(grep -rn "${pattern}" "${project_dir}" 2>/dev/null | \ - grep -v '/target/' | \ - grep -v '/node_modules/' | \ - grep -v '/.git/' | \ - sed "s|^${project_dir}/||" | \ - head -20) || true - - if [[ -n "${results}" ]]; then - echo "${results}" >> "$LLM_OUTPUT" - else - warn "No matches" >> "$LLM_OUTPUT" - fi -} \ No newline at end of file