ralphloop 0.1.0

A CLI tool for creating and running Ralphloops with LLM integration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# Contributing to Ralphloop

Thank you for your interest in contributing to Ralphloop! This document provides guidelines and instructions for contributing.

## Table of Contents
- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [Development Setup]#development-setup
- [Making Changes]#making-changes
- [Testing]#testing
- [Submitting Changes]#submitting-changes
- [Style Guide]#style-guide
- [Community]#community

## Code of Conduct

### Our Pledge
We are committed to providing a welcoming and inclusive environment for all contributors.

### Expected Behavior
- Be respectful and considerate
- Welcome newcomers and help them get started
- Accept constructive criticism gracefully
- Focus on what's best for the community
- Show empathy towards others

### Unacceptable Behavior
- Harassment or discrimination
- Trolling or insulting comments
- Publishing others' private information
- Other unprofessional conduct

## Getting Started

### Prerequisites
- Rust 1.70 or later
- Git
- Basic understanding of async Rust
- Familiarity with LLM APIs (optional)

### Fork and Clone
```bash
# Fork the repository on GitHub
# Then clone your fork
git clone https://github.com/YOUR_USERNAME/ralphiloop.git
cd ralphiloop

# Add upstream remote
git remote add upstream https://github.com/ORIGINAL_OWNER/ralphiloop.git
```

## Development Setup

### Install Dependencies
```bash
# Build the project
cargo build

# Run tests
cargo test

# Run with logging
RUST_LOG=debug cargo run -- --help
```

### IDE Setup

**VS Code:**
```json
{
  "rust-analyzer.checkOnSave.command": "clippy",
  "editor.formatOnSave": true
}
```

**Recommended Extensions:**
- rust-analyzer
- CodeLLDB (for debugging)
- Better TOML

## Making Changes

### Branch Naming
Use descriptive branch names:
- `feature/add-new-provider` - New features
- `fix/rate-limit-handling` - Bug fixes
- `docs/api-documentation` - Documentation
- `refactor/config-module` - Code refactoring
- `test/integration-tests` - Test additions

### Commit Messages
Follow conventional commits:
```
type(scope): subject

body (optional)

footer (optional)
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation
- `style`: Formatting
- `refactor`: Code restructuring
- `test`: Adding tests
- `chore`: Maintenance

**Examples:**
```
feat(llm): add support for Cohere provider

Implements the Cohere API integration with streaming support.

Closes #123
```

```
fix(config): handle missing profile gracefully

Previously crashed when profile didn't exist.
Now returns helpful error message.
```

### Code Organization

**Module Structure:**
```
src/
├── main.rs           # CLI entry point
├── llm.rs            # LLM provider implementations
├── config.rs         # Configuration management
├── ralph_loop.rs     # Loop execution engine
├── error.rs          # Error types
├── templates.rs      # Loop templates
├── repl.rs           # REPL mode
├── analytics.rs      # Analytics & monitoring
├── audit.rs          # Audit trail
└── tests/            # Test modules
```

### Adding a New LLM Provider

1. **Implement the trait:**
```rust
pub struct MyProvider {
    api_key: String,
    model: String,
    client: Client,
}

#[async_trait]
impl LLMProvider for MyProvider {
    async fn complete(&self, prompt: &str) -> Result<LLMResponse> {
        // Implementation
    }
    
    fn provider_name(&self) -> &'static str {
        "myprovider"
    }
}
```

2. **Add to config.rs:**
```rust
"myprovider" => {
    let api_key = profile.api_key.clone()
        .ok_or_else(|| RalphError::MissingConfig("API key not configured".to_string()))?;
    Ok(Box::new(MyProvider::new(api_key, profile.model.clone())))
}
```

3. **Add tests:**
```rust
#[tokio::test]
async fn test_myprovider() {
    let provider = MyProvider::new("test-key".to_string(), "model".to_string());
    // Test implementation
}
```

4. **Update documentation:**
- Add to README.md
- Add to API.md
- Add example configuration

## Testing

### Running Tests
```bash
# All tests
cargo test

# Specific test
cargo test test_name

# With output
cargo test -- --nocapture

# Integration tests
cargo test --test '*'

# Benchmarks
cargo bench
```

### Writing Tests

**Unit Tests:**
```rust
#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_feature() {
        // Arrange
        let input = "test";
        
        // Act
        let result = function(input);
        
        // Assert
        assert_eq!(result, expected);
    }
}
```

**Integration Tests:**
```rust
#[tokio::test]
async fn test_integration() {
    let provider = MockLLMProvider::new(vec!["response".to_string()]);
    let result = provider.complete("prompt").await;
    assert!(result.is_ok());
}
```

### Test Coverage
```bash
# Install cargo-llvm-cov
cargo install cargo-llvm-cov

# Generate coverage
cargo llvm-cov --html

# Open report
open target/llvm-cov/html/index.html
```

## Submitting Changes

### Before Submitting
- [ ] Code compiles without errors
- [ ] All tests pass
- [ ] Code follows style guide
- [ ] Documentation updated
- [ ] Commit messages follow convention
- [ ] Branch is up to date with main

### Pull Request Process

1. **Update your branch:**
```bash
git fetch upstream
git rebase upstream/main
```

2. **Push to your fork:**
```bash
git push origin feature/my-feature
```

3. **Create Pull Request:**
- Use descriptive title
- Reference related issues
- Describe changes made
- Include testing done
- Add screenshots if UI changes

4. **PR Template:**
```markdown
## Description
Brief description of changes

## Related Issues
Closes #123

## Changes Made
- Added feature X
- Fixed bug Y
- Updated documentation

## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests pass
- [ ] Manual testing completed

## Screenshots (if applicable)
```

### Review Process
- Maintainers will review within 48 hours
- Address feedback promptly
- Keep discussions professional
- Be patient and respectful

## Style Guide

### Rust Style
Follow official Rust style guide:
```bash
# Format code
cargo fmt

# Check lints
cargo clippy
```

### Code Conventions

**Naming:**
- `snake_case` for functions and variables
- `PascalCase` for types and traits
- `SCREAMING_SNAKE_CASE` for constants

**Error Handling:**
```rust
// Use Result types
pub fn function() -> Result<T> {
    // Implementation
}

// Provide context
.map_err(|e| RalphError::Custom(format!("Failed to X: {}", e)))?
```

**Documentation:**
```rust
/// Brief description
///
/// # Arguments
/// * `param` - Description
///
/// # Returns
/// Description of return value
///
/// # Errors
/// When this function errors
///
/// # Example
/// ```
/// let result = function(param);
/// ```
pub fn function(param: Type) -> Result<ReturnType> {
    // Implementation
}
```

### Documentation Style
- Use clear, concise language
- Include code examples
- Document error cases
- Keep examples up to date

## Community

### Getting Help
- **GitHub Issues:** Bug reports and feature requests
- **Discussions:** Questions and general discussion
- **Discord:** Real-time chat (if available)

### Reporting Bugs

**Bug Report Template:**
```markdown
## Bug Description
Clear description of the bug

## Steps to Reproduce
1. Step 1
2. Step 2
3. See error

## Expected Behavior
What should happen

## Actual Behavior
What actually happens

## Environment
- OS: macOS 13.0
- Rust: 1.70
- Ralph CLI: 0.1.0

## Additional Context
Any other relevant information
```

### Feature Requests

**Feature Request Template:**
```markdown
## Feature Description
Clear description of the feature

## Use Case
Why is this feature needed?

## Proposed Solution
How should it work?

## Alternatives Considered
Other approaches considered

## Additional Context
Any other relevant information
```

## Recognition

Contributors will be:
- Listed in CONTRIBUTORS.md
- Mentioned in release notes
- Credited in documentation

## License

By contributing, you agree that your contributions will be licensed under the same license as the project.

## Questions?

Don't hesitate to ask! Open an issue or discussion if you need help.

---

Thank you for contributing to Ralph CLI! 🎉