feat: optimize analyze_code for Claude Code with improved formatting
BREAKING CHANGES: - Remove verbose_output from tool schema (Claude Code can't accidentally use it) - Always show minimal terminal output with file previews - Improved file content formatting for Gemini with clear delimiters Key improvements: - Files formatted as "--- BEGIN FILE: path --- content --- END FILE: path ---" - Direct code formatted as "--- BEGIN DIRECT CODE --- code --- END DIRECT CODE ---" - Terminal shows file paths, sizes, and small previews (not full content) - Clear prompt structure for Gemini: USER REQUEST | CODE TO ANALYZE sections - Prevents terminal hangs/glitches with large files in Claude Code - All tests updated and passing This ensures Claude Code stays responsive while Gemini gets properly formatted content. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -61,7 +61,6 @@ class TestModels:
|
||||
assert request.max_tokens == 8192
|
||||
assert request.temperature == 0.2
|
||||
assert request.model == DEFAULT_MODEL
|
||||
assert request.verbose_output == False
|
||||
|
||||
|
||||
class TestFileOperations:
|
||||
@@ -73,7 +72,8 @@ class TestFileOperations:
|
||||
test_file.write_text("def hello():\n return 'world'", encoding='utf-8')
|
||||
|
||||
content = read_file_content(str(test_file))
|
||||
assert "=== File:" in content
|
||||
assert "--- BEGIN FILE:" in content
|
||||
assert "--- END FILE:" in content
|
||||
assert "def hello():" in content
|
||||
assert "return 'world'" in content
|
||||
|
||||
@@ -84,12 +84,14 @@ class TestFileOperations:
|
||||
os.path.sep, "nonexistent_dir_12345", "nonexistent_file.py"
|
||||
)
|
||||
content = read_file_content(nonexistent_path)
|
||||
assert "Error: File not found" in content
|
||||
assert "--- FILE NOT FOUND:" in content
|
||||
assert "Error: File does not exist" in content
|
||||
|
||||
def test_read_file_content_directory(self, tmp_path):
|
||||
"""Test reading a directory instead of file"""
|
||||
content = read_file_content(str(tmp_path))
|
||||
assert "Error: Not a file" in content
|
||||
assert "--- NOT A FILE:" in content
|
||||
assert "Error: Path is not a file" in content
|
||||
|
||||
def test_prepare_code_context_with_files(self, tmp_path):
|
||||
"""Test preparing context from files"""
|
||||
@@ -99,20 +101,23 @@ class TestFileOperations:
|
||||
file2.write_text("print('file2')", encoding='utf-8')
|
||||
|
||||
context, summary = prepare_code_context([str(file1), str(file2)], None)
|
||||
assert "--- BEGIN FILE:" in context
|
||||
assert "file1.py" in context
|
||||
assert "file2.py" in context
|
||||
assert "print('file1')" in context
|
||||
assert "print('file2')" in context
|
||||
assert "Analyzing 2 file(s)" in summary
|
||||
assert "--- END FILE:" in context
|
||||
assert "📁 Analyzing 2 file(s)" in summary
|
||||
assert "bytes)" in summary
|
||||
|
||||
def test_prepare_code_context_with_code(self):
|
||||
"""Test preparing context from direct code"""
|
||||
code = "def test():\n pass"
|
||||
context, summary = prepare_code_context(None, code)
|
||||
assert "=== Direct Code ===" in context
|
||||
assert "--- BEGIN DIRECT CODE ---" in context
|
||||
assert "--- END DIRECT CODE ---" in context
|
||||
assert code in context
|
||||
assert "Direct code provided" in summary
|
||||
assert "💻 Direct code provided" in summary
|
||||
|
||||
def test_prepare_code_context_mixed(self, tmp_path):
|
||||
"""Test preparing context from both files and code"""
|
||||
@@ -123,8 +128,8 @@ class TestFileOperations:
|
||||
context, summary = prepare_code_context([str(test_file)], code)
|
||||
assert "# From file" in context
|
||||
assert "# Direct code" in context
|
||||
assert "Analyzing 1 file(s)" in summary
|
||||
assert "Direct code provided" in summary
|
||||
assert "📁 Analyzing 1 file(s)" in summary
|
||||
assert "💻 Direct code provided" in summary
|
||||
|
||||
|
||||
class TestToolHandlers:
|
||||
@@ -227,8 +232,8 @@ class TestToolHandlers:
|
||||
assert len(result) == 1
|
||||
# Check that the response contains both summary and Gemini's response
|
||||
response_text = result[0].text
|
||||
assert "Analyzing 1 file(s)" in response_text
|
||||
assert "Gemini's response:" in response_text
|
||||
assert "📁 Analyzing 1 file(s)" in response_text
|
||||
assert "🤖 Gemini's Analysis:" in response_text
|
||||
assert "Analysis result" in response_text
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user