Skip to content

Add Claude CLI agent support#12

Merged
plebioda merged 1 commit intomasterfrom
claude-cli
Apr 2, 2026
Merged

Add Claude CLI agent support#12
plebioda merged 1 commit intomasterfrom
claude-cli

Conversation

@plebioda
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread src/mergai/agents/gemini_cli.py Fixed
Comment thread src/mergai/agents/gemini_cli.py Fixed
Comment thread src/mergai/agents/gemini_cli.py Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Claude CLI-backed agent and begins shifting agent I/O toward writing structured JSON to a response file (instead of stdout), with shared JSON parsing utilities and related prompt/executor updates.

Changes:

  • Introduces ClaudeCLIAgent and registers it in the agent factory.
  • Adds shared JSON response parsing utilities and refactors Gemini CLI parsing to use them.
  • Updates system prompts and execution flow in preparation for response-file based outputs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/mergai/prompts/system_prompt_resolve.md Changes output instructions to response-file/Write-tool based JSON output.
src/mergai/prompts/system_prompt_describe.md Changes output instructions to response-file/Write-tool based JSON output.
src/mergai/app.py Forces YOLO for describe() to support Claude CLI writing a response file.
src/mergai/agents/response_utils.py Adds shared helpers to extract/parse JSON from agent outputs.
src/mergai/agents/gemini_cli.py Refactors response parsing toward shared utilities and response-file support (currently broken).
src/mergai/agents/factory.py Registers the new claude-cli agent type.
src/mergai/agents/claude_cli.py Adds the Claude CLI agent implementation (stream-json parsing, session reading, optional response-file read).
src/mergai/agent_executor.py Moves prompt files into state dir and starts adding response-file path handling/validation flow (currently broken).
Comments suppressed due to low confidence (2)

src/mergai/agents/gemini_cli.py:189

  • This block still calls fix_response_json(...), but that helper was removed from this file and is no longer imported. It will crash at runtime; it looks like the intent is to use parse_response_json(result) (or skip parsing if the response was read from a file).
        try:
            result = fix_response_json(response)
            version = self.get_version()
        except AgentError as e:

src/mergai/agent_executor.py:191

  • A response_path is created, but it’s never passed to the agent and the prompt never mentions it, so the updated system prompts (“file path will be provided”) can’t be satisfied. If response-file mode is required, include the path in current_prompt and pass it to agents that support it (or update the base Agent.run interface to accept response_file).
        # Create response file path in state_dir (same location as prompt)
        # state_dir is typically .cache/mergai which is gitignored
        response_filename = self._generate_response_filename()
        response_path = self.state_dir / response_filename

        current_prompt = (
            f"See @{prompt_path} make sure the output is in specified format"
        )
        error = None

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/agents/gemini_cli.py Outdated
Comment thread src/mergai/agents/gemini_cli.py
Comment thread src/mergai/agent_executor.py
Comment thread src/mergai/agent_executor.py Outdated
Comment thread src/mergai/prompts/system_prompt_describe.md Outdated
Comment thread src/mergai/prompts/system_prompt_resolve.md Outdated
Comment thread src/mergai/agents/response_utils.py
Comment thread src/mergai/agents/claude_cli.py
Comment thread src/mergai/app.py Outdated
Comment thread src/mergai/agents/claude_cli.py
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/agent_executor.py Outdated
Comment thread src/mergai/agent_executor.py Outdated
Comment thread src/mergai/agent_executor.py
Comment thread src/mergai/agents/gemini_cli.py Outdated
Comment thread src/mergai/agents/claude_cli.py
Comment thread src/mergai/agents/claude_cli.py
Comment thread src/mergai/prompts/system_prompt_resolve.md Outdated
Comment thread src/mergai/agents/factory.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/agent_executor.py Outdated
Comment thread src/mergai/agents/claude_cli.py Outdated
Comment thread src/mergai/agents/response_utils.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/agents/response_utils.py
Comment thread src/mergai/agent_executor.py Outdated
plebioda added a commit that referenced this pull request Apr 1, 2026
- gemini_cli.py: Add fallback to stdout parsing when response file is
  missing or contains invalid JSON, instead of failing immediately

- agent_executor.py: Fix retry loop to execute all attempts (was breaking
  before final attempt). Preserve file instructions across retries by
  appending error context to base prompt instead of replacing it.

- response_utils.py: Add explicit type check for response before calling
  extract_json_block() to avoid TypeError from re.search on non-strings.
  Also simplified exception handling to only catch JSONDecodeError.
Comment thread src/mergai/agent_executor.py Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/agent_executor.py
Comment thread src/mergai/agents/claude_cli.py
Comment thread src/mergai/agents/gemini_cli.py Outdated
- Add ClaudeCLIAgent for integration with Claude Code CLI
  - Support JSON streaming output and session management
  - Support both yolo mode and limited write permissions (acceptEdits)
  - Parse token usage statistics and cost information

- Implement file-based response pattern across all agents
  - Agents write JSON responses to designated files in state_dir
  - Add response_file and allowed_write_paths parameters to Agent.run()
  - Provides more reliable JSON parsing than stdout extraction

- Extract shared response parsing utilities to response_utils.py
  - Move JSON block extraction and parsing from gemini_cli.py
  - Support both direct JSON and markdown-wrapped formats

- Update system prompts to instruct agents to write to response files

- Improve validation error messages to list modified files
@plebioda plebioda merged commit a3825e9 into master Apr 2, 2026
7 checks passed
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.

3 participants