rust_tui_coder 1.0.0

AI-powered terminal coding assistant with interactive TUI, supporting multiple LLMs and comprehensive development tools
Documentation
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# Contributing to Rust TUI Coder

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

## Table of Contents

1. [Code of Conduct]#code-of-conduct
2. [Getting Started]#getting-started
3. [Development Setup]#development-setup
4. [Project Structure]#project-structure
5. [Making Changes]#making-changes
6. [Testing]#testing
7. [Code Style]#code-style
8. [Submitting Changes]#submitting-changes
9. [Adding Features]#adding-features
10. [Reporting Bugs]#reporting-bugs

---

## Code of Conduct

### Our Pledge

We are committed to providing a welcoming and inspiring community for all. Please:

- Be respectful and inclusive
- Be patient with newcomers
- Focus on what is best for the community
- Show empathy towards others

### Unacceptable Behavior

- Harassment, discrimination, or offensive comments
- Trolling or insulting remarks
- Publishing others' private information
- Other conduct inappropriate for a professional setting

---

## Getting Started

### Prerequisites

- **Rust** 1.70 or higher
- **Git** for version control
- Basic understanding of:
  - Rust programming
  - Terminal/TUI applications
  - Async programming (Tokio)
  - REST APIs

### Find an Issue

1. Check the [Issues]../../issues page
2. Look for issues labeled:
   - `good first issue` - Great for newcomers
   - `help wanted` - Community help needed
   - `bug` - Bug fixes
   - `enhancement` - New features

3. Comment on the issue to express interest
4. Wait for maintainer confirmation before starting work

---

## Development Setup

### 1. Fork and Clone

```bash
# Fork the repository on GitHub, then:
git clone https://github.com/YOUR_USERNAME/rust_tui_coder.git
cd rust_tui_coder
```

### 2. Build the Project

```bash
# Build in debug mode
cargo build

# Build in release mode
cargo build --release
```

### 3. Run Tests

```bash
# Run all tests
cargo test

# Run specific test suite
cargo test --test agent_tests

# Run with output
cargo test -- --nocapture
```

### 4. Run the Application

```bash
# Create a config file
cp config_example.toml config.toml
# Edit config.toml with your API key

# Run the application
cargo run
```

### 5. Check Code Quality

```bash
# Run clippy for lints
cargo clippy --all-targets --all-features

# Format code
cargo fmt

# Check formatting
cargo fmt -- --check
```

---

## Project Structure

```
rust_tui_coder/
├── src/
│   ├── main.rs          # Entry point, event loop
│   ├── app.rs           # Application state
│   ├── ui.rs            # TUI rendering
│   ├── llm.rs           # LLM API interface
│   ├── agent.rs         # Tool execution
│   ├── config.rs        # Configuration loading
│   └── lib.rs           # Library exports
├── tests/
│   ├── agent_tests.rs   # Tool tests
│   ├── app_tests.rs     # App state tests
│   ├── config_tests.rs  # Config tests
│   ├── llm_tests.rs     # LLM tests
│   ├── ui_tests.rs      # UI tests
│   └── ...              # More test files
├── docs/
│   ├── README.md        # User documentation
│   ├── ARCHITECTURE.md  # System design
│   ├── API.md           # API reference
│   └── ...              # More documentation
├── Cargo.toml           # Project metadata
├── config_example.toml  # Example configuration
└── README.md            # Project overview (symlink to docs/README.md)
```

---

## Making Changes

### 1. Create a Branch

```bash
# Create a feature branch
git checkout -b feature/your-feature-name

# Or for bug fixes
git checkout -b fix/issue-description
```

### 2. Make Your Changes

- Write clear, readable code
- Follow Rust conventions
- Add comments for complex logic
- Update documentation as needed

### 3. Test Your Changes

```bash
# Run tests
cargo test

# Test your specific changes
cargo test test_name

# Run the app and test manually
cargo run
```

### 4. Commit Your Changes

```bash
# Stage changes
git add .

# Commit with descriptive message
git commit -m "feat: add new tool for database operations"
```

**Commit Message Format:**

```
<type>: <description>

[optional body]

[optional footer]
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation changes
- `style`: Code style changes (formatting)
- `refactor`: Code refactoring
- `test`: Adding or updating tests
- `chore`: Maintenance tasks

**Examples:**
```
feat: add execute_rust tool for running Rust code
fix: handle empty conversation scroll correctly
docs: update API documentation for new tools
test: add edge case tests for file operations
```

---

## Testing

### Writing Tests

All tests should follow these guidelines:

#### 1. Test File Naming

- Place tests in `tests/` directory
- Name files `{module}_tests.rs`
- Example: `agent_tests.rs`, `app_tests.rs`

#### 2. Test Naming Convention

```rust
#[tokio::test]
async fn test_tool_name_success_case() {
    // Test implementation
}

#[tokio::test]
async fn test_tool_name_error_case() {
    // Test implementation
}
```

#### 3. Use Temporary Files

Always use the `tmp_rovodev_` prefix for test files:

```rust
#[tokio::test]
async fn test_write_file() {
    let path = "tmp_rovodev_test.txt";
    
    // Test code here
    
    // Cleanup
    std::fs::remove_file(path).ok();
}
```

#### 4. Test Categories

Write tests for:
- **Happy path**: Normal, expected usage
- **Edge cases**: Boundary conditions, empty inputs
- **Error handling**: Invalid inputs, failures
- **Integration**: Component interactions

#### 5. Example Test

```rust
#[tokio::test]
async fn test_read_file_success() {
    // Setup
    let path = "tmp_rovodev_read_test.txt";
    let content = "test content";
    std::fs::write(path, content).unwrap();
    
    // Execute
    let args = json!({ "path": path });
    let result = agent::execute_tool("read_file", &args).await;
    
    // Assert
    assert!(result.is_ok());
    assert_eq!(result.unwrap(), content);
    
    // Cleanup
    std::fs::remove_file(path).ok();
}
```

### Running Tests

```bash
# All tests
cargo test

# Specific suite
cargo test --test agent_tests

# Specific test
cargo test test_read_file_success

# With output
cargo test -- --nocapture

# With verbose output
cargo test -- --nocapture --test-threads=1
```

---

## Code Style

### Rust Style Guidelines

1. **Follow Rustfmt**
   ```bash
   cargo fmt
   ```

2. **Follow Clippy Suggestions**
   ```bash
   cargo clippy --all-targets --all-features
   ```

3. **Naming Conventions**
   - Functions: `snake_case`
   - Types: `PascalCase`
   - Constants: `SCREAMING_SNAKE_CASE`
   - Modules: `snake_case`

4. **Error Handling**
   - Use `Result` types
   - Provide descriptive error messages
   - Don't panic in library code
   ```rust
   // Good
   fn read_config() -> Result<Config, io::Error> {
       // ...
   }
   
   // Avoid
   fn read_config() -> Config {
       // ... panics on error
   }
   ```

5. **Documentation**
   - Add doc comments for public items
   ```rust
   /// Executes a tool by name with the given arguments.
   ///
   /// # Arguments
   ///
   /// * `tool_name` - Name of the tool to execute
   /// * `arguments` - JSON object with tool arguments
   ///
   /// # Returns
   ///
   /// * `Ok(String)` - Tool execution result
   /// * `Err(String)` - Error message
   pub async fn execute_tool(
       tool_name: &str,
       arguments: &serde_json::Value,
   ) -> Result<String, String>
   ```

6. **Imports**
   - Group imports logically
   - Use `use` statements, not full paths
   ```rust
   use std::fs;
   use std::io;
   
   use serde::{Deserialize, Serialize};
   use tokio::process::Command;
   
   use crate::config::Config;
   ```

---

## Submitting Changes

### 1. Push Your Branch

```bash
git push origin feature/your-feature-name
```

### 2. Create a Pull Request

1. Go to the repository on GitHub
2. Click "Pull Request"
3. Select your branch
4. Fill in the PR template:

```markdown
## Description
Brief description of changes

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Testing
- [ ] Tests pass locally
- [ ] Added new tests
- [ ] Manual testing performed

## Checklist
- [ ] Code follows style guidelines
- [ ] Comments added for complex code
- [ ] Documentation updated
- [ ] No new warnings from clippy
```

### 3. Code Review Process

- Maintainers will review your PR
- Address feedback and comments
- Make requested changes
- Push updates to the same branch

### 4. Merging

- Once approved, a maintainer will merge
- Your contribution will be in the next release!

---

## Adding Features

### Adding a New Tool

1. **Define the tool in `agent.rs`**

```rust
// Add to the match statement in execute_tool()
"my_new_tool" => {
    let arg1 = arguments["arg1"]
        .as_str()
        .ok_or("Missing arg1")?;
    
    // Tool implementation
    Ok("Success".to_string())
}
```

2. **Add tool description to system prompt**

Update the system prompt in `main.rs` to include:

```
### my_new_tool
Description: What the tool does
Arguments:
- arg1 (string): Description of argument
Returns: Description of return value
```

3. **Write tests**

Create tests in `tests/agent_tests.rs`:

```rust
#[tokio::test]
async fn test_my_new_tool() {
    let args = json!({ "arg1": "test" });
    let result = agent::execute_tool("my_new_tool", &args).await;
    assert!(result.is_ok());
}
```

4. **Update documentation**

Add to `docs/API.md`:

```markdown
##### `my_new_tool`

Description of the tool.

**Arguments:**
```json
{
    "arg1": "value"
}
```

**Returns:** Success message
```

### Adding a New Feature

1. **Discuss in an issue first**
2. **Create a design plan**
3. **Implement the feature**
4. **Add tests**
5. **Update documentation**
6. **Submit PR**

---

## Reporting Bugs

### Before Reporting

1. **Search existing issues** - Your bug may already be reported
2. **Try latest version** - Bug may be fixed
3. **Minimal reproduction** - Create simplest case that shows bug

### Bug Report Template

```markdown
**Describe the bug**
Clear description of the bug

**To Reproduce**
Steps to reproduce:
1. Launch application
2. Type command '...'
3. See error

**Expected behavior**
What you expected to happen

**Actual behavior**
What actually happened

**Environment:**
- OS: [e.g., Ubuntu 22.04]
- Rust version: [e.g., 1.70]
- Application version: [e.g., 1.0.0]

**Configuration:**
```toml
[llm]
provider = "openai"
model_name = "gpt-4"
```

**Screenshots/Logs**
If applicable, add screenshots or error logs
```

---

## Development Tips

### Debugging

1. **Add logging**
   ```rust
   eprintln!("Debug: variable = {:?}", variable);
   ```

2. **Use rust-gdb or rust-lldb**
   ```bash
   rust-gdb target/debug/rct
   ```

3. **Check tool logs in app**
   - Tool execution details appear in tool logs area

### Testing Locally

1. **Use test config**
   ```bash
   cp config_example.toml test_config.toml
   # Add test API key
   ```

2. **Test with different models**
   - Try GPT-3.5 for faster iteration
   - Test with GPT-4 before submitting

3. **Test edge cases**
   - Empty inputs
   - Very long inputs
   - Special characters
   - Network failures

### Performance

- Profile with `cargo flamegraph`
- Check token usage efficiency
- Monitor memory with large conversations

---

## Release Process

(For maintainers)

1. Update version in `Cargo.toml`
2. Update CHANGELOG
3. Run full test suite
4. Create git tag
5. Publish to crates.io
6. Create GitHub release

---

## Getting Help

- **Questions**: Open a discussion on GitHub
- **Chat**: Join our community chat (if available)
- **Documentation**: Check the docs/ folder
- **Examples**: See EXAMPLES.md

---

## Recognition

Contributors will be:
- Listed in CONTRIBUTORS.md
- Mentioned in release notes
- Acknowledged in project README

Thank you for contributing to Rust TUI Coder!