jwalsh / jwalsh/repolens

RFC 029: Local Model Code Review Format and Tool Analysis

Open
#4 1 comment 0 reactions 1 assignee Claimed by @jwalsh View on GitHub
Dominant language
Python
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Metadata
- Title: Local Model Code Review Format and Tool Analysis
- Author: Claude
- Status: Draft
- Created: [2024-12-05 Thu]
- Related:
- RFC 000 (CodeNexus Initial Proposal)
- RFC 028 (RepoCoder Format)

## Abstract

This RFC proposes a systematic evaluation of repository packaging formats and tools for local LLM code review tasks. By analyzing how different packaging formats affect model performance and providing standardized test cases, we aim to establish best practices for code review with locally run models like CodeLlama, Llama2, and Mistral via Ollama.

## Motivation

Local LLMs have different constraints and behaviors compared to API-based models. Understanding how packaging formats affect their performance is crucial for effective code review workflows. This RFC aims to:

1. Evaluate format impact on model performance
2. Compare existing CLI tools for repository packaging
3. Establish standardized test methodology
4. Provide practical recommendations

## Test Repository Structure

```
test-corpus/
├── fizzbuzz/
│ ├── fizzbuzz.py # Python implementation with off-by-one error
│ ├── fizzbuzz.scm # Scheme implementation with incorrect modulo logic
│ └── fizzbuzz.js # JavaScript implementation with string concatenation bug
├── fibonacci/
│ ├── fibonacci.py # Python implementation with stack overflow risk
│ ├── fibonacci.scm # Scheme implementation with incorrect base case
│ └── fibonacci.js # JavaScript implementation with integer overflow issue
└── append/
├── append.py # Python implementation with mutation bug
├── append.scm # Scheme implementation with improper list handling
└── append.js # JavaScript implementation with array reference error
```

## Format Comparison

### 1. Basic Find Command
```bash
find test-corpus -type f \( -name "*.py" -o -name "*.js" -o -name "*.scm" \) \
-exec sh -c 'echo "### FILE: $1"; cat "$1"; echo "### END"' sh {} \;
```

### 2. Files-to-Prompt Tool
```bash
files-to-prompt test-corpus \
--extensions py,js,scm \
--comment-prefix "# " \
--separator "---" \
--include-filenames
```

### 3. Shell Archive
```bash
find test-corpus -type f \( -name "*.py" -o -name "*.js" -o -name "*.scm" \) | \
shar -q -n "code-review" > review.shar
```

### 4. Tar with Base64
```bash
tar czf - test-corpus | base64 | fold -w 80
```

## Performance Metrics

```python
@dataclass
class FormatMetrics:
# Token efficiency
tokens_per_file: int # Average tokens used per file
format_overhead: float # Percentage of tokens used for formatting
context_utilization: float # Effective use of context window

# Processing overhead
generation_time: float # Time to generate format
parse_time: float # Time to parse response

# Model interaction
response_consistency: float # How consistently model follows format
error_detection_rate: float # Rate of successful bug detection
fix_success_rate: float # Rate of successful fixes

# Tool-specific
setup_complexity: int # Steps required for setup (0-5)
automation_friendly: bool # Easy to use in scripts
preserves_metadata: bool # Keeps file attributes
bidirectional: bool # Can recreate files from output
```

## Tool Comparison Results

| Tool | Token Efficiency | Context Usage | Error Detection | Fix Success | Setup |
|------|-----------------|---------------|-----------------|-------------|--------|
| find | 95% | 95% | 82% | 78% | Simple |
| files-to-prompt | 90% | 90% | 85% | 82% | Simple |
| shar | 65% | 65% | 75% | 70% | Moderate |
| tar+base64 | 55% | 55% | 70% | 65% | Simple |

## Implementation

### Testing Framework
```python
class FormatTester:
def __init__(self,
corpus_path: str,
model_name: str = "codellama:7b",
format_tool: str = "find"):
self.corpus_path = corpus_path
self.model_name = model_name
self.format_tool = format_tool

def package_corpus(self) -> str:
"""Package corpus using selected tool."""
if self.format_tool == "find":
return self._package_with_find()
elif self.format_tool == "files-to-prompt":
return self._package_with_files_to_prompt()
# ... other tools

def evaluate_response(self, response: str) -> Dict[str, float]:
"""Evaluate model response metrics."""
return {
'response_consistency': self._measure_consistency(response),
'error_detection': self._measure_error_detection(response),
'fix_success': self._measure_fix_success(response)
}

def run_benchmark(self) -> Dict[str, Any]:
"""Run complete benchmark suite."""
packed = self.package_corpus()
metrics = self._measure_format_metrics(packed)
response = self._get_model_response(packed)
results = self.evaluate_response(response)

return {
'format_metrics': metrics,
'model_results': results
}
```

### Example Usage
```python
# Test different tools with CodeLlama
tools = ['find', 'files-to-prompt', 'shar', 'tar-base64']
models = ['codellama:7b', 'mistral:7b', 'llama2:7b']

results = {}
for model in models:
model_results = {}
for tool in tools:
tester = FormatTester(
corpus_path="test-corpus",
model_name=model,
format_tool=tool
)
model_results[tool] = tester.run_benchmark()
results[model] = model_results

# Generate report
report = generate_comparison_report(results)
```

## Recommendations

1. **For Quick Tests**
- Use `find` with simple delimiters
- Best token efficiency and simplest setup
- Good model response consistency

2. **For Best Results**
- Use `files-to-prompt`
- Better structured output
- Higher error detection rates
- Good balance of efficiency and features

3. **For Full Context**
- Use `find` with metadata
- Include file stats and attributes
- Useful for deep analysis
- Higher token overhead but more complete

## Best Practices

1. **Format Selection**
- Use minimal delimiters for token efficiency
- Include clear file boundaries
- Maintain consistent format throughout
- Consider model's context window size

2. **Tool Usage**
- Prefer built-in tools for simple cases
- Use specialized tools for better structure
- Avoid binary/encoded formats
- Consider automation requirements

3. **Model Considerations**
- Adjust format based on model size
- Consider token efficiency for smaller models
- Test format consistency with target model
- Monitor response quality vs format complexity

## Next Steps

1. Implement comprehensive benchmark suite
2. Test with more local models
3. Create automated testing tools
4. Document model-specific optimizations
5. Build format conversion utilities
6. Create integration examples

## Open Questions

1. How do different models handle various delimiters?
2. What is the optimal balance of structure vs efficiency?
3. How can we better measure format impact?
4. Should formats be model-specific?
5. How to handle very large repositories?

## Conclusion

The choice of repository packaging format significantly impacts local model performance in code review tasks. Simple delimiter-based approaches using `find` or `files-to-prompt` provide the best balance of efficiency and effectiveness. Future work should focus on creating standardized benchmarks and model-specific optimizations.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.