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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# Usage Examples

This document provides practical examples of using Rust TUI Coder for various development tasks.

## Table of Contents

1. [Basic File Operations]#basic-file-operations
2. [Code Generation]#code-generation
3. [Refactoring Code]#refactoring-code
4. [Debugging Assistance]#debugging-assistance
5. [Project Setup]#project-setup
6. [Testing]#testing
7. [Documentation]#documentation
8. [Git Workflows]#git-workflows
9. [Data Processing]#data-processing
10. [Advanced Workflows]#advanced-workflows

---

## Basic File Operations

### Example 1: Create a Simple File

**User:**
```
Create a README.md file with a title "My Project" and a brief description
```

**What happens:**
- AI writes content
- Saves to README.md
- Confirms creation

**Result:**
```markdown
# My Project

A brief description of what this project does.
```

---

### Example 2: Read and Analyze a File

**User:**
```
Read the file src/main.rs and tell me what it does
```

**What happens:**
- AI reads the file using `read_file` tool
- Analyzes the code
- Explains functionality

---

### Example 3: Modify Existing Content

**User:**
```
In config.toml, change the model_name from gpt-3.5-turbo to gpt-4
```

**What happens:**
- AI reads config.toml
- Uses `search_and_replace` tool
- Updates the model name
- Confirms the change

---

## Code Generation

### Example 4: Generate a Python Script

**User:**
```
Create a Python script that reads a CSV file and calculates the average of the 'price' column
```

**What happens:**
```python
# average_price.py
import csv

def calculate_average_price(filename):
    total = 0
    count = 0
    
    with open(filename, 'r') as file:
        reader = csv.DictReader(file)
        for row in reader:
            total += float(row['price'])
            count += 1
    
    return total / count if count > 0 else 0

if __name__ == "__main__":
    avg = calculate_average_price('data.csv')
    print(f"Average price: ${avg:.2f}")
```

- AI generates the code
- Saves to `average_price.py`
- Explains usage

---

### Example 5: Generate a Web API Endpoint

**User:**
```
Create a Node.js Express endpoint that handles POST requests to /users and saves the data to a JSON file
```

**What happens:**
```javascript
// server.js
const express = require('express');
const fs = require('fs');
const app = express();

app.use(express.json());

app.post('/users', (req, res) => {
    const userData = req.body;
    const users = JSON.parse(fs.readFileSync('users.json', 'utf8') || '[]');
    users.push(userData);
    fs.writeFileSync('users.json', JSON.stringify(users, null, 2));
    res.status(201).json({ message: 'User created', user: userData });
});

app.listen(3000, () => console.log('Server running on port 3000'));
```

---

### Example 6: Generate Test Cases

**User:**
```
Create unit tests for the calculate_average_price function using pytest
```

**What happens:**
- AI creates `test_average_price.py`
- Includes multiple test cases
- Tests edge cases (empty file, invalid data, etc.)

---

## Refactoring Code

### Example 7: Extract Function

**User:**
```
Read server.js and extract the user validation logic into a separate function
```

**What happens:**
- AI reads the file
- Identifies validation code
- Creates new function
- Updates calls to use new function
- Shows the refactored code

---

### Example 8: Add Error Handling

**User:**
```
Add try-catch error handling to all file operations in backup.py
```

**What happens:**
- AI reads the file
- Identifies file operations
- Adds appropriate error handling
- Updates the file

---

### Example 9: Convert Callback to Async/Await

**User:**
```
Convert the callback-based code in api.js to use async/await
```

**What happens:**
- AI reads the file
- Converts callbacks to promises
- Uses async/await syntax
- Updates the file

---

## Debugging Assistance

### Example 10: Find Bug

**User:**
```
This function is giving wrong results. Can you help?

def calculate_discount(price, percent):
    discount = price * percent
    return price - discount
```

**AI Response:**
```
The bug is that you're using the percentage as a decimal multiplier without dividing by 100.

Fixed version:
def calculate_discount(price, percent):
    discount = price * (percent / 100)
    return price - discount

Example: calculate_discount(100, 20) now correctly returns 80
```

---

### Example 11: Debug with Logs

**User:**
```
Add debug logging to process_data.py to help track down where it's failing
```

**What happens:**
- AI adds logging statements
- Includes relevant variable values
- Updates the file

---

### Example 12: Analyze Error Messages

**User:**
```
I'm getting this error: "TypeError: Cannot read property 'name' of undefined"
Here's my code: [paste code]
```

**AI Response:**
- Identifies the issue
- Explains why it happens
- Suggests fixes
- Can update the code if requested

---

## Project Setup

### Example 13: Initialize a Python Project

**User:**
```
Set up a new Python project structure with virtual environment, requirements.txt, and basic folders
```

**What happens:**
- Creates directory structure
- Generates requirements.txt
- Creates __init__.py files
- Provides setup instructions

---

### Example 14: Create a React App Structure

**User:**
```
Create a basic React app structure with components, hooks, and utils folders
```

**What happens:**
```
my-app/
├── src/
│   ├── components/
│   │   └── App.jsx
│   ├── hooks/
│   │   └── useCustomHook.js
│   ├── utils/
│   │   └── helpers.js
│   └── index.js
├── public/
│   └── index.html
└── package.json
```

---

### Example 15: Set Up Configuration Files

**User:**
```
Create a .eslintrc.json and .prettierrc for my JavaScript project
```

**What happens:**
- Creates ESLint configuration
- Creates Prettier configuration
- Both with sensible defaults
- Explains how to customize

---

## Testing

### Example 16: Generate Test Data

**User:**
```
Create a JSON file with 10 sample user records including name, email, and age
```

**What happens:**
```json
[
  {
    "id": 1,
    "name": "Alice Johnson",
    "email": "alice@example.com",
    "age": 28
  },
  // ... 9 more records
]
```

---

### Example 17: Create Integration Test

**User:**
```
Write an integration test that tests the entire user registration flow
```

**What happens:**
- AI creates test file
- Includes setup and teardown
- Tests complete workflow
- Adds assertions

---

### Example 18: Run Tests and Analyze

**User:**
```
Run the tests in test_api.py and show me the results
```

**What happens:**
- AI executes `pytest test_api.py`
- Shows output
- Explains failures if any
- Suggests fixes

---

## Documentation

### Example 19: Generate Function Documentation

**User:**
```
Add docstrings to all functions in utils.py following Google style
```

**What happens:**
- AI reads the file
- Adds comprehensive docstrings
- Includes parameters, returns, examples
- Updates the file

---

### Example 20: Create API Documentation

**User:**
```
Document all the API endpoints in server.js in Markdown format
```

**What happens:**
- AI analyzes endpoints
- Creates API.md
- Includes request/response examples
- Lists all routes

---

### Example 21: Generate README

**User:**
```
Create a comprehensive README for this project based on the files in the current directory
```

**What happens:**
- AI scans project structure
- Generates README with:
  - Project description
  - Installation instructions
  - Usage examples
  - API documentation
  - Contributing guidelines

---

## Git Workflows

### Example 22: Check Status Before Commit

**User:**
```
Show me the current git status
```

**What happens:**
- AI runs `git_status` tool
- Shows modified, staged, untracked files
- Can suggest what to commit

---

### Example 23: Generate Commit Message

**User:**
```
Based on the changes I've made, suggest a good commit message
```

**What happens:**
- AI reviews git status
- Suggests descriptive commit message
- Follows conventional commit format

---

## Data Processing

### Example 24: Process CSV File

**User:**
```
Read sales.csv, filter rows where amount > 1000, and save to high_value_sales.csv
```

**What happens:**
- AI writes Python script
- Processes the data
- Saves filtered results
- Shows summary statistics

---

### Example 25: Convert JSON to CSV

**User:**
```
Convert users.json to users.csv with columns: id, name, email
```

**What happens:**
- AI reads JSON
- Converts to CSV format
- Saves to file
- Confirms conversion

---

### Example 26: Data Analysis

**User:**
```
Analyze data.csv and show me:
- Total number of records
- Average of the 'value' column
- Top 5 highest values
```

**What happens:**
- AI processes the data
- Calculates statistics
- Presents results clearly

---

## Advanced Workflows

### Example 27: Multi-Step Project Creation

**User:**
```
Create a complete REST API with user authentication
```

**AI Creates Plan:**
```markdown
## Phase 1: Setup
- [ ] Create project structure
- [ ] Initialize package.json
- [ ] Install dependencies

## Phase 2: Database
- [ ] Create user schema
- [ ] Set up database connection
- [ ] Create migration files

## Phase 3: Authentication
- [ ] Implement JWT auth
- [ ] Create login endpoint
- [ ] Create register endpoint

## Phase 4: User Routes
- [ ] Get user profile
- [ ] Update user
- [ ] Delete user

## Phase 5: Testing
- [ ] Write unit tests
- [ ] Write integration tests
- [ ] Test authentication flow
```

**Then:**
```
Implement Phase 1 of the plan
```

---

### Example 28: Code Review

**User:**
```
Review the code in app.py and suggest improvements for:
- Performance
- Readability
- Best practices
```

**What happens:**
- AI analyzes code
- Points out issues
- Suggests improvements
- Can apply changes if requested

---

### Example 29: Migration Between Languages

**User:**
```
Convert the function in utils.js to Python
```

**What happens:**
- AI reads JavaScript code
- Converts to Python equivalent
- Maintains functionality
- Explains differences

---

### Example 30: Batch File Operations

**User:**
```
Read all .txt files in the docs/ folder and create a combined.txt with all their contents
```

**What happens:**
- AI lists directory
- Reads each file
- Combines content
- Saves to combined.txt

---

## Real-World Scenario Examples

### Scenario A: Bug Fix Workflow

1. **User:** "I have a bug in payment.py where discounts aren't being applied correctly"
2. **AI:** Reads the file, finds the issue
3. **User:** "Can you fix it?"
4. **AI:** Fixes the bug
5. **User:** "Add a test to prevent this in the future"
6. **AI:** Creates test case

---

### Scenario B: Feature Addition

1. **User:** "Add a rate limiting feature to the API"
2. **AI:** Creates plan with steps
3. **User:** "Implement step 1"
4. **AI:** Creates middleware file
5. **User:** "Continue with step 2"
6. **AI:** Integrates middleware
7. **User:** "Add tests"
8. **AI:** Creates test cases

---

### Scenario C: Code Exploration

1. **User:** "Show me the structure of this project"
2. **AI:** Lists directory recursively
3. **User:** "What does main.rs do?"
4. **AI:** Reads and explains
5. **User:** "How does it connect to the database?"
6. **AI:** Finds and explains database code

---

## Tips for Best Results

### Be Specific
 "Make it better"
 "Add input validation and error messages to the login form"

### Provide Context
 "Fix the bug"
 "The calculate_total function returns NaN when the cart is empty. Fix this."

### Work Iteratively
Instead of asking for everything at once, work step-by-step and refine as you go.

### Use the Plan Feature
For complex tasks, ask for a plan first, then implement step by step.

### Review Tool Logs
Check the tool logs to see exactly what operations were performed.

---

## Command Reference Quick Guide

| Task | Example Command |
|------|-----------------|
| Create file | "Create a file named test.py" |
| Read file | "Show me the contents of config.json" |
| Modify file | "Update the API key in settings.py" |
| Delete file | "Remove the old_backup.sql file" |
| List files | "Show me all files in the src/ directory" |
| Run code | "Execute the script.py file" |
| Create plan | "Create a plan to build a blog system" |
| Check git | "Show git status" |
| Get stats | "/stats" |
| Quit | "/quit" or Ctrl+C |

---

For more examples and inspiration, experiment with your own use cases! The AI is designed to help with a wide variety of development tasks.