-
-
Notifications
You must be signed in to change notification settings - Fork 67
Add clojure_edit_agent for structural code editing #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Restore the clojure-edit-agent that was previously removed (commit 315f31c). This agent specializes in applying code changes to a single Clojure file using structural editing tools. Features: - Focused single-file editing with structural tools - Uses clojure_edit for defn/def replacements - Uses clojure_edit_replace_sexp for expression changes - Includes glob_files and grep for file discovery if path is incorrect - Falls back to file_edit for non-structural edits - Tracks file changes and shows diffs automatically Tools enabled: read_file, clojure_edit, clojure_edit_replace_sexp, glob_files, grep, file_edit Can be tested with prompt-cli: clojure -M:prompt-cli -c resources/clojure-mcp/agents/clojure_edit_agent.edn -p "Add docstring to function foo in /path/to/file.clj"
📝 WalkthroughWalkthroughThis pull request introduces a new Clojure code-edit agent by adding an EDN configuration file that defines the agent's metadata, tools, and system message. The agent is then registered in the default agents registry and mapped in the tool builder with corresponding test updates reflecting the addition of a fourth default agent. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
resources/clojure-mcp/agents/clojure_edit_agent.ednsrc/clojure_mcp/tools/agent_tool_builder/default_agents.cljsrc/clojure_mcp/tools/agent_tool_builder/tool.cljtest/clojure_mcp/tools/agent_tool_builder/tool_test.clj
🧰 Additional context used
📓 Path-based instructions (2)
**/*.clj
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.clj: Use:requirewith ns aliases in import statements (e.g.,[clojure.string :as string])
Use kebab-case for variable and function names
End predicate functions with?(e.g.,is-top-level-form?)
Usetry/catchwith specific exception handling; use atom for tracking errors
Use 2-space indentation and maintain whitespace in edited forms
Align namespace names with directory structure (e.g.,clojure-mcp.repl-toolsforclojure_mcp/repl_tools.clj)
Include clear tool:descriptionfor LLM guidance in MCP tool definitions
Validate inputs and provide helpful error messages in MCP tools
Return structured data with both result and error status from MCP tools
Maintain atom-based state for consistent service access in MCP tools
Files:
test/clojure_mcp/tools/agent_tool_builder/tool_test.cljsrc/clojure_mcp/tools/agent_tool_builder/tool.cljsrc/clojure_mcp/tools/agent_tool_builder/default_agents.clj
**/*_test.clj
📄 CodeRabbit inference engine (CLAUDE.md)
Use
deftestwith descriptive test names; usetestingfor subsections; useisfor assertions
Files:
test/clojure_mcp/tools/agent_tool_builder/tool_test.clj
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-07T23:16:26.445Z
Learning: Applies to **/*.clj : Include clear tool `:description` for LLM guidance in MCP tool definitions
📚 Learning: 2025-12-07T23:16:26.445Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-07T23:16:26.445Z
Learning: Applies to **/*.clj : Include clear tool `:description` for LLM guidance in MCP tool definitions
Applied to files:
test/clojure_mcp/tools/agent_tool_builder/tool_test.cljsrc/clojure_mcp/tools/agent_tool_builder/tool.cljresources/clojure-mcp/agents/clojure_edit_agent.edn
📚 Learning: 2025-12-27T06:54:07.157Z
Learnt from: nandoolle
Repo: bhauman/clojure-mcp PR: 138
File: src/clojure_mcp/agent/langchain/model.clj:91-97
Timestamp: 2025-12-27T06:54:07.157Z
Learning: When reviewing Clojure code (e.g., in src/clojure_mcp/... ), verify calls to presets/get-preset follow the two arities: [preset-key] and [preset-key overrides]. The 2-arg version should merge the provided overrides map with the preset defaults and return the resulting configuration. Check for correct map merging, preservation of immutability, and validation of overrides keys to ensure predictable configuration outcomes.
Applied to files:
test/clojure_mcp/tools/agent_tool_builder/tool_test.cljsrc/clojure_mcp/tools/agent_tool_builder/tool.cljsrc/clojure_mcp/tools/agent_tool_builder/default_agents.clj
📚 Learning: 2025-12-07T23:16:26.445Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-07T23:16:26.445Z
Learning: Applies to **/*.clj : Align namespace names with directory structure (e.g., `clojure-mcp.repl-tools` for `clojure_mcp/repl_tools.clj`)
Applied to files:
src/clojure_mcp/tools/agent_tool_builder/tool.clj
📚 Learning: 2025-12-07T23:16:26.445Z
Learnt from: CR
Repo: bhauman/clojure-mcp PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-07T23:16:26.445Z
Learning: Applies to **/*.clj : Maintain atom-based state for consistent service access in MCP tools
Applied to files:
src/clojure_mcp/tools/agent_tool_builder/default_agents.clj
🔇 Additional comments (12)
src/clojure_mcp/tools/agent_tool_builder/default_agents.clj (3)
4-5: LGTM!Clean addition of the
clojure.ednrequire for parsing the new EDN-based agent configuration.
65-66: LGTM!The new agent is correctly added to the default agents vector.
71-71: LGTM!The
:clojure-edit-agentID is consistently added to the default agent IDs set.src/clojure_mcp/tools/agent_tool_builder/tool.clj (1)
91-92: LGTM!The mapping follows the established pattern for translating underscore-based tool IDs to kebab-case agent IDs, maintaining consistency with the existing mappings.
test/clojure_mcp/tools/agent_tool_builder/tool_test.clj (4)
44-45: LGTM!Test correctly updated to expect 4 default agents with descriptive comment.
58-64: LGTM!The test properly verifies all 5 agents (4 defaults + 1 user) are created and includes the new
clojure_edit_agentin the presence checks.
181-188: LGTM!Test assertions correctly updated for 4 default agents with proper presence verification.
205-206: LGTM!Override test correctly expects 4 total agents when one default is replaced by a user-defined agent.
resources/clojure-mcp/agents/clojure_edit_agent.edn (4)
1-2: LGTM!The
:iduses kebab-case (:clojure-edit-agent) while:nameuses underscores (clojure_edit_agent), which aligns with the mapping intool.cljand follows the convention used by other agents.
3-52: Clear and comprehensive description for LLM guidance.The description provides excellent documentation including usage instructions, format rules, and a concrete example. This aligns well with the learning to include clear tool
:descriptionfor LLM guidance in MCP tool definitions.
53-61: LGTM!The system message provides clear, actionable guidance for the agent's behavior. It correctly emphasizes preferring structural editing tools over text-based editing.
62-64: All enabled tool keywords are correctly registered.Verification confirms all six tool keywords in the
:enable-toolslist match registered tool types in the codebase:
:read_file→ unified-read-file tool:clojure_edit→ clojure-edit-form tool:clojure_edit_replace_sexp→ clojure-update-sexp tool:glob_files→ glob-files tool:grep→ grep tool:file_edit→ file-edit tool
| (defn clojure-edit-agent-config | ||
| "Configuration for the clojure edit agent - loaded from EDN resource" | ||
| [] | ||
| (-> (io/resource "clojure-mcp/agents/clojure_edit_agent.edn") | ||
| slurp | ||
| edn/read-string)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if the EDN resource file exists
echo "=== Searching for clojure_edit_agent.edn ==="
find . -name "clojure_edit_agent.edn" -o -name "*clojure*edit*agent*"
echo ""
echo "=== Checking resources directory structure ==="
ls -la resources/ 2>/dev/null | head -20
echo ""
echo "=== Finding all .edn files in resources ==="
find resources -name "*.edn" 2>/dev/null | head -20Repository: bhauman/clojure-mcp
Length of output: 911
🏁 Script executed:
#!/bin/bash
# Display the full file to review code quality
echo "=== File content for code review ==="
cat -n src/clojure_mcp/tools/agent_tool_builder/default_agents.cljRepository: bhauman/clojure-mcp
Length of output: 4362
🏁 Script executed:
#!/bin/bash
# Check the namespace structure and imports
echo "=== Checking for require statements and namespace definition ==="
head -30 src/clojure_mcp/tools/agent_tool_builder/default_agents.cljRepository: bhauman/clojure-mcp
Length of output: 1486
Resource file exists; add error handling for robustness.
The EDN resource file exists at resources/clojure-mcp/agents/clojure_edit_agent.edn, so io/resource will find it correctly. The path naming difference (hyphens vs. underscores) is intentional: tool resources live in clojure_mcp/tools/ while agents and prompts use clojure-mcp/.
However, the code lacks error handling. If io/resource returns nil or the EDN is malformed, slurp will throw an NPE. Per the coding guidelines, wrap this in try/catch with specific exception handling and return structured data with both result and error status.
🤖 Prompt for AI Agents
In src/clojure_mcp/tools/agent_tool_builder/default_agents.clj around lines 40
to 45, the function clojure-edit-agent-config assumes io/resource and slurp
always succeed; update it to check for a nil resource and wrap the
slurp/edn/read-string steps in a try/catch, returning a structured map like {:ok
true :config <data>} on success or {:ok false :error <exception-or-message>} on
failure; specifically handle a nil resource by returning a clear error map,
catch IOExceptions from slurp and runtime/EDN parse exceptions from
edn/read-string, and include the caught exception message/instance in the
returned error field for debugging.
Summary
Tools enabled
read_file- read target fileclojure_edit- structural defn/def replacementsclojure_edit_replace_sexp- structural expression changesglob_files- find files by patterngrep- search for code patternsfile_edit- fallback text-based editingTest plan
clojure -M:prompt-cli -c resources/clojure-mcp/agents/clojure_edit_agent.edn -p "Add docstring to function foo in /path/to/file.clj"🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.