Skip to content

Conversation

@bhauman
Copy link
Owner

@bhauman bhauman commented Jan 2, 2026

Summary

  • Restore the clojure-edit-agent that was previously removed (commit 315f31c)
  • Specializes in applying code changes to a single Clojure file using structural editing tools
  • Includes file discovery tools (glob, grep) in case provided paths are incorrect

Tools enabled

  • read_file - read target file
  • clojure_edit - structural defn/def replacements
  • clojure_edit_replace_sexp - structural expression changes
  • glob_files - find files by pattern
  • grep - search for code patterns
  • file_edit - fallback text-based editing

Test plan

  • All tests pass (275 tests, 1993 assertions)
  • Linter passes
  • Manual test 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"

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced a new Clojure code-editing agent available by default. This agent enables users to perform structured edits on Clojure files with support for file operations, edit application, and automatic diff generation for review.

✏️ Tip: You can customize this high-level summary in your review settings.

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"
@coderabbitai
Copy link

coderabbitai bot commented Jan 2, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
New Agent Configuration
resources/clojure-mcp/agents/clojure_edit_agent.edn
New EDN configuration file defining the clojure-edit-agent with metadata (id, name, description), usage instructions, formatting rules, system message specifying read-locate-edit workflow, enabled tools (read_file, clojure_edit, clojure_edit_replace_sexp, glob_files, grep, file_edit), and track-file-changes setting.
Agent Registry Integration
src/clojure_mcp/tools/agent_tool_builder/default_agents.clj
Adds new function clojure-edit-agent-config that loads EDN config via clojure.edn; integrates into parent-agent-config, make-default-agents, and default-agent-ids to include the new agent in the default set; updates namespace to require clojure.edn.
Tool ID Mapping
src/clojure_mcp/tools/agent_tool_builder/tool.clj
Adds mapping in tool-id->agent-id to resolve :clojure_edit_agent (underscore) to :clojure-edit-agent (dashes) in two locations: within create-single-agent-tool and create-agent-tools contexts.
Test Updates
test/clojure_mcp/tools/agent_tool_builder/tool_test.clj
Updates test expectations to reflect the new default agent: default agent count increases from 3 to 4; total agent/tool counts adjusted across multiple tests; new assertions verify presence of clojure_edit_agent in default and merged agent sets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A new agent hops into the warren, ready to edit Clojure code with care,
With dashes in names and underscores bound, it finds its place in the registry fair.
Four agents now instead of three, dancing through the tooling sea! ✨

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a clojure_edit_agent for structural code editing, which is clearly the primary focus of this pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bhauman bhauman merged commit 0c30320 into main Jan 2, 2026
1 of 2 checks passed
Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between f53436e and d51b15c.

📒 Files selected for processing (4)
  • resources/clojure-mcp/agents/clojure_edit_agent.edn
  • src/clojure_mcp/tools/agent_tool_builder/default_agents.clj
  • src/clojure_mcp/tools/agent_tool_builder/tool.clj
  • test/clojure_mcp/tools/agent_tool_builder/tool_test.clj
🧰 Additional context used
📓 Path-based instructions (2)
**/*.clj

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.clj: Use :require with 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?)
Use try/catch with 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-tools for clojure_mcp/repl_tools.clj)
Include clear tool :description for 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.clj
  • src/clojure_mcp/tools/agent_tool_builder/tool.clj
  • src/clojure_mcp/tools/agent_tool_builder/default_agents.clj
**/*_test.clj

📄 CodeRabbit inference engine (CLAUDE.md)

Use deftest with descriptive test names; use testing for subsections; use is for 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.clj
  • src/clojure_mcp/tools/agent_tool_builder/tool.clj
  • resources/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.clj
  • src/clojure_mcp/tools/agent_tool_builder/tool.clj
  • src/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.edn require 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-agent ID 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_agent in 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 :id uses kebab-case (:clojure-edit-agent) while :name uses underscores (clojure_edit_agent), which aligns with the mapping in tool.clj and 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 :description for 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-tools list 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

Comment on lines +40 to +45
(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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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 -20

Repository: 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.clj

Repository: 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.clj

Repository: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants