qfix-cli 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qfix_cli-0.1.0/.gitignore +8 -0
- qfix_cli-0.1.0/LICENSE +21 -0
- qfix_cli-0.1.0/MANIFEST.in +4 -0
- qfix_cli-0.1.0/PKG-INFO +151 -0
- qfix_cli-0.1.0/README.md +109 -0
- qfix_cli-0.1.0/bin/qfix +2 -0
- qfix_cli-0.1.0/list_models.py +20 -0
- qfix_cli-0.1.0/package.json +13 -0
- qfix_cli-0.1.0/pyproject.toml +5 -0
- qfix_cli-0.1.0/qfix/__init__.py +1 -0
- qfix_cli-0.1.0/qfix/main.py +71 -0
- qfix_cli-0.1.0/qfix/processor.py +79 -0
- qfix_cli-0.1.0/qfix/utils.py +51 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/PKG-INFO +151 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/SOURCES.txt +21 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/dependency_links.txt +1 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/entry_points.txt +2 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/requires.txt +3 -0
- qfix_cli-0.1.0/qfix_cli.egg-info/top_level.txt +1 -0
- qfix_cli-0.1.0/requirements.txt +3 -0
- qfix_cli-0.1.0/setup.cfg +4 -0
- qfix_cli-0.1.0/setup.py +48 -0
- qfix_cli-0.1.0/test_code.py +9 -0
qfix_cli-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kunshika
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
qfix_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qfix-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-powered CLI tool to format and explain code blocks using Groq API
|
|
5
|
+
Home-page: https://github.com/kunshika/QuickFix.git
|
|
6
|
+
Author: Kunshika
|
|
7
|
+
Author-email:
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/kunshika/QuickFix.git/issues
|
|
10
|
+
Project-URL: Source, https://github.com/kunshika/QuickFix.git
|
|
11
|
+
Keywords: code formatter,AI,CLI,code quality,groq,llama
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
15
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Operating System :: OS Independent
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: rich
|
|
28
|
+
Requires-Dist: python-dotenv
|
|
29
|
+
Requires-Dist: langchain-groq
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: classifier
|
|
32
|
+
Dynamic: description
|
|
33
|
+
Dynamic: description-content-type
|
|
34
|
+
Dynamic: home-page
|
|
35
|
+
Dynamic: keywords
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: project-url
|
|
39
|
+
Dynamic: requires-dist
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
Dynamic: summary
|
|
42
|
+
|
|
43
|
+
# QuickFix (qfix)
|
|
44
|
+
|
|
45
|
+
A powerful command-line tool that uses AI (Groq's Llama models) to format and explain specific blocks of code within your files. It allows you to target specific lines, receive intelligent improvements without logic changes, and optionally write the changes back to your file in proper format.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **Targeted Formatting**: Select specific line ranges to process, leaving the rest of the file untouched.
|
|
50
|
+
- **AI-Powered**: Uses Groq's fast Llama models for intelligent code formatting.
|
|
51
|
+
- **Strict Formatting**: Enforces best practices (indentation, spacing) without altering the underlying logic.
|
|
52
|
+
- **Detailed Explanations**: Provides a Markdown-formatted explanation of *why* changes were made.
|
|
53
|
+
- **Write-Back Support**: Apply the improved code directly to your file with the `--apply` flag or interactive prompt.
|
|
54
|
+
- **Mock Mode**: Works offline or without an API key (returns a mock response for testing).
|
|
55
|
+
|
|
56
|
+
## Prerequisites
|
|
57
|
+
|
|
58
|
+
- Python 3.8+
|
|
59
|
+
- A Groq API Key (Get one free from [Groq Console](https://console.groq.com/))
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
### Option 1: Install from PyPI (Recommended)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install qfix-cli
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Option 2: Install from GitHub
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install git+https://github.com/Kunshika/QuickFix.git
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Option 3: Install from Source
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git clone https://github.com/Kunshika/QuickFix.git
|
|
79
|
+
cd QuickFix
|
|
80
|
+
pip install .
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
1. Create a `.env` file in your project directory or home directory:
|
|
86
|
+
```bash
|
|
87
|
+
touch .env
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
2. Add your Groq API Key to `.env`:
|
|
91
|
+
```env
|
|
92
|
+
GROQ_API_KEY=your_api_key_here
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
*Alternatively, you can pass the key via the CLI argument `--api-key`.*
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
Run the tool using `qfix` with the target file and line range.
|
|
101
|
+
|
|
102
|
+
### Basic Usage (View Only)
|
|
103
|
+
This will print the original code, the improved version, and the explanation to the console without modifying the file.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
qfix path/to/file.py --start 10 --end 20
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Apply Changes
|
|
110
|
+
To write the formatted code back to the file, use the `--apply` flag or answer "Yes" to the interactive prompt.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
qfix path/to/file.py --start 10 --end 20 --apply
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Command Line Arguments
|
|
117
|
+
|
|
118
|
+
| Argument | Description | Required |
|
|
119
|
+
| :--- | :--- | :--- |
|
|
120
|
+
| `file` | Path to the source file to process. | Yes |
|
|
121
|
+
| `--start` | Start line number (1-based). | Yes |
|
|
122
|
+
| `--end` | End line number (1-based). | Yes |
|
|
123
|
+
| `--apply` | Automatically apply changes to the file. | No |
|
|
124
|
+
| `--api-key`| Provide API key directly (overrides `.env`).| No |
|
|
125
|
+
|
|
126
|
+
## Example
|
|
127
|
+
|
|
128
|
+
**Input File (`example.py`):**
|
|
129
|
+
```python
|
|
130
|
+
7 def complex_logic(a, b):
|
|
131
|
+
8 # This is a bad implementation
|
|
132
|
+
9 if a > b: return a - b
|
|
133
|
+
10 else: return
|
|
134
|
+
11 b - a
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Command:**
|
|
138
|
+
```bash
|
|
139
|
+
qfix example.py --start 7 --end 11
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Output:**
|
|
143
|
+
The tool will display:
|
|
144
|
+
1. **Original Code**: Syntax-highlighted view of lines 7-11.
|
|
145
|
+
2. **Improved Implementation**: Properly formatted code (e.g., fixing the `else: return` line break).
|
|
146
|
+
3. **Detailed Explanation**: "Fixed indentation and line breaks for readability..."
|
|
147
|
+
|
|
148
|
+
## Troubleshooting
|
|
149
|
+
|
|
150
|
+
- **429 Quota Exceeded**: The free tier of Gemini API has rate limits. If you see this error, wait a minute and try again.
|
|
151
|
+
- **Mock Explanation**: If you see this, it means the tool couldn't access the API (missing key or network issue). Check your `.env` file.
|
qfix_cli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# QuickFix (qfix)
|
|
2
|
+
|
|
3
|
+
A powerful command-line tool that uses AI (Groq's Llama models) to format and explain specific blocks of code within your files. It allows you to target specific lines, receive intelligent improvements without logic changes, and optionally write the changes back to your file in proper format.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Targeted Formatting**: Select specific line ranges to process, leaving the rest of the file untouched.
|
|
8
|
+
- **AI-Powered**: Uses Groq's fast Llama models for intelligent code formatting.
|
|
9
|
+
- **Strict Formatting**: Enforces best practices (indentation, spacing) without altering the underlying logic.
|
|
10
|
+
- **Detailed Explanations**: Provides a Markdown-formatted explanation of *why* changes were made.
|
|
11
|
+
- **Write-Back Support**: Apply the improved code directly to your file with the `--apply` flag or interactive prompt.
|
|
12
|
+
- **Mock Mode**: Works offline or without an API key (returns a mock response for testing).
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- Python 3.8+
|
|
17
|
+
- A Groq API Key (Get one free from [Groq Console](https://console.groq.com/))
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### Option 1: Install from PyPI (Recommended)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install qfix-cli
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Option 2: Install from GitHub
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install git+https://github.com/Kunshika/QuickFix.git
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Option 3: Install from Source
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/Kunshika/QuickFix.git
|
|
37
|
+
cd QuickFix
|
|
38
|
+
pip install .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
1. Create a `.env` file in your project directory or home directory:
|
|
44
|
+
```bash
|
|
45
|
+
touch .env
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Add your Groq API Key to `.env`:
|
|
49
|
+
```env
|
|
50
|
+
GROQ_API_KEY=your_api_key_here
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
*Alternatively, you can pass the key via the CLI argument `--api-key`.*
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
Run the tool using `qfix` with the target file and line range.
|
|
59
|
+
|
|
60
|
+
### Basic Usage (View Only)
|
|
61
|
+
This will print the original code, the improved version, and the explanation to the console without modifying the file.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
qfix path/to/file.py --start 10 --end 20
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Apply Changes
|
|
68
|
+
To write the formatted code back to the file, use the `--apply` flag or answer "Yes" to the interactive prompt.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
qfix path/to/file.py --start 10 --end 20 --apply
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Command Line Arguments
|
|
75
|
+
|
|
76
|
+
| Argument | Description | Required |
|
|
77
|
+
| :--- | :--- | :--- |
|
|
78
|
+
| `file` | Path to the source file to process. | Yes |
|
|
79
|
+
| `--start` | Start line number (1-based). | Yes |
|
|
80
|
+
| `--end` | End line number (1-based). | Yes |
|
|
81
|
+
| `--apply` | Automatically apply changes to the file. | No |
|
|
82
|
+
| `--api-key`| Provide API key directly (overrides `.env`).| No |
|
|
83
|
+
|
|
84
|
+
## Example
|
|
85
|
+
|
|
86
|
+
**Input File (`example.py`):**
|
|
87
|
+
```python
|
|
88
|
+
7 def complex_logic(a, b):
|
|
89
|
+
8 # This is a bad implementation
|
|
90
|
+
9 if a > b: return a - b
|
|
91
|
+
10 else: return
|
|
92
|
+
11 b - a
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Command:**
|
|
96
|
+
```bash
|
|
97
|
+
qfix example.py --start 7 --end 11
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Output:**
|
|
101
|
+
The tool will display:
|
|
102
|
+
1. **Original Code**: Syntax-highlighted view of lines 7-11.
|
|
103
|
+
2. **Improved Implementation**: Properly formatted code (e.g., fixing the `else: return` line break).
|
|
104
|
+
3. **Detailed Explanation**: "Fixed indentation and line breaks for readability..."
|
|
105
|
+
|
|
106
|
+
## Troubleshooting
|
|
107
|
+
|
|
108
|
+
- **429 Quota Exceeded**: The free tier of Gemini API has rate limits. If you see this error, wait a minute and try again.
|
|
109
|
+
- **Mock Explanation**: If you see this, it means the tool couldn't access the API (missing key or network issue). Check your `.env` file.
|
qfix_cli-0.1.0/bin/qfix
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import google.generativeai as genai
|
|
3
|
+
from dotenv import load_dotenv
|
|
4
|
+
|
|
5
|
+
load_dotenv()
|
|
6
|
+
|
|
7
|
+
api_key = os.getenv("GEMINI_API_KEY")
|
|
8
|
+
if not api_key:
|
|
9
|
+
print("No API key found")
|
|
10
|
+
exit(1)
|
|
11
|
+
|
|
12
|
+
genai.configure(api_key=api_key)
|
|
13
|
+
|
|
14
|
+
print("Listing models...")
|
|
15
|
+
try:
|
|
16
|
+
for m in genai.list_models():
|
|
17
|
+
if 'generateContent' in m.supported_generation_methods:
|
|
18
|
+
print(m.name)
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"Error: {e}")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .main import main
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
from rich.syntax import Syntax
|
|
8
|
+
from rich.markdown import Markdown
|
|
9
|
+
from rich.prompt import Confirm
|
|
10
|
+
from .utils import read_file_segment, get_file_extension, write_file_segment
|
|
11
|
+
from .processor import CodeProcessor
|
|
12
|
+
|
|
13
|
+
load_dotenv()
|
|
14
|
+
|
|
15
|
+
console = Console()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def main():
|
|
20
|
+
parser = argparse.ArgumentParser(description="Code Formatter & Explainer CLI")
|
|
21
|
+
parser.add_argument("file", help="Path to the source file")
|
|
22
|
+
parser.add_argument("--start", type=int, required=True, help="Start line number (1-based)")
|
|
23
|
+
parser.add_argument("--end", type=int, required=True, help="End line number (1-based)")
|
|
24
|
+
parser.add_argument("--api-key", help="Groq API Key (optional, can use env var GROQ_API_KEY)")
|
|
25
|
+
parser.add_argument("--apply", action="store_true", help="Apply changes to the file")
|
|
26
|
+
|
|
27
|
+
args = parser.parse_args()
|
|
28
|
+
|
|
29
|
+
# Validate file
|
|
30
|
+
if not os.path.exists(args.file):
|
|
31
|
+
console.print(f"[red]Error: File '{args.file}' not found.[/red]")
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
|
|
34
|
+
# Read Code
|
|
35
|
+
try:
|
|
36
|
+
code_segment = read_file_segment(args.file, args.start, args.end)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
console.print(f"[red]Error reading file: {e}[/red]")
|
|
39
|
+
sys.exit(1)
|
|
40
|
+
|
|
41
|
+
if not code_segment.strip():
|
|
42
|
+
console.print("[yellow]Warning: Selected range is empty.[/yellow]")
|
|
43
|
+
sys.exit(0)
|
|
44
|
+
|
|
45
|
+
ext = get_file_extension(args.file)
|
|
46
|
+
|
|
47
|
+
# Display Original
|
|
48
|
+
console.print(Panel(Syntax(code_segment, ext, theme="monokai", line_numbers=True, start_line=args.start), title="[bold blue]Original Code[/bold blue]", expand=False))
|
|
49
|
+
|
|
50
|
+
# Process
|
|
51
|
+
with console.status("[bold green]Processing with AI...[/bold green]"):
|
|
52
|
+
processor = CodeProcessor(api_key=args.api_key)
|
|
53
|
+
result = processor.process_code(code_segment, language=ext or "text")
|
|
54
|
+
|
|
55
|
+
# Display Result
|
|
56
|
+
console.print("\n")
|
|
57
|
+
console.print(Panel(Syntax(result["code"], ext, theme="monokai", line_numbers=True), title="[bold green]Improved Implementation[/bold green]", expand=False))
|
|
58
|
+
|
|
59
|
+
console.print("\n")
|
|
60
|
+
console.print(Panel(Markdown(result["explanation"]), title="[bold magenta]Detailed Explanation[/bold magenta]", expand=False))
|
|
61
|
+
|
|
62
|
+
# Apply Changes
|
|
63
|
+
if args.apply or Confirm.ask("\n[bold yellow]Do you want to apply these changes to the file?[/bold yellow]"):
|
|
64
|
+
try:
|
|
65
|
+
write_file_segment(args.file, args.start, args.end, result["code"])
|
|
66
|
+
console.print(f"[bold green]Successfully updated {args.file}[/bold green]")
|
|
67
|
+
except Exception as e:
|
|
68
|
+
console.print(f"[red]Error writing to file: {e}[/red]")
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
main()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.markdown import Markdown
|
|
4
|
+
from rich.syntax import Syntax
|
|
5
|
+
from langchain_groq import ChatGroq
|
|
6
|
+
|
|
7
|
+
console = Console()
|
|
8
|
+
|
|
9
|
+
class CodeProcessor:
|
|
10
|
+
def __init__(self, api_key: str = None):
|
|
11
|
+
self.api_key = api_key or os.getenv("GROQ_API_KEY")
|
|
12
|
+
if self.api_key:
|
|
13
|
+
# Initialize ChatGroq with a specific model
|
|
14
|
+
self.model = ChatGroq(
|
|
15
|
+
api_key=self.api_key,
|
|
16
|
+
model="groq/compound" # Fast and capable model
|
|
17
|
+
)
|
|
18
|
+
else:
|
|
19
|
+
self.model = None
|
|
20
|
+
console.print("[yellow]Warning: No GROQ_API_KEY found. Running in mock mode.[/yellow]")
|
|
21
|
+
|
|
22
|
+
def process_code(self, code_snippet: str, language: str = "python"):
|
|
23
|
+
if not self.model:
|
|
24
|
+
return self._mock_process(code_snippet, language)
|
|
25
|
+
|
|
26
|
+
prompt = f"""
|
|
27
|
+
You are an expert code formatting and explanation assistant.
|
|
28
|
+
I will provide you with a snippet of {language} code.
|
|
29
|
+
|
|
30
|
+
Your task is to:
|
|
31
|
+
1. Format the code according to best practices (indentation, spacing, etc.).
|
|
32
|
+
2. STRICTLY DO NOT CHANGE THE LOGIC. Only improve readability and formatting.
|
|
33
|
+
3. Explain the formatting changes you made.
|
|
34
|
+
|
|
35
|
+
Output format should be strictly separated sections:
|
|
36
|
+
|
|
37
|
+
---IMPROVED_CODE---
|
|
38
|
+
(The code block only)
|
|
39
|
+
---EXPLANATION---
|
|
40
|
+
(The explanation in Markdown)
|
|
41
|
+
|
|
42
|
+
Here is the code:
|
|
43
|
+
```
|
|
44
|
+
{code_snippet}
|
|
45
|
+
```
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
response = self.model.invoke(prompt)
|
|
50
|
+
return self._parse_response(response.content)
|
|
51
|
+
except Exception as e:
|
|
52
|
+
console.print(f"[red]Error calling Groq API: {e}[/red]")
|
|
53
|
+
return self._mock_process(code_snippet, language)
|
|
54
|
+
|
|
55
|
+
def _parse_response(self, text: str):
|
|
56
|
+
parts = text.split("---IMPROVED_CODE---")
|
|
57
|
+
if len(parts) < 2:
|
|
58
|
+
return {"code": "", "explanation": text} # Fallback
|
|
59
|
+
|
|
60
|
+
content = parts[1].split("---EXPLANATION---")
|
|
61
|
+
code = content[0].strip()
|
|
62
|
+
# Remove markdown code fences if present
|
|
63
|
+
if code.startswith("```"):
|
|
64
|
+
code = "\n".join(code.split("\n")[1:])
|
|
65
|
+
if code.endswith("```"):
|
|
66
|
+
code = "\n".join(code.split("\n")[:-1])
|
|
67
|
+
|
|
68
|
+
explanation = content[1].strip() if len(content) > 1 else ""
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
"code": code.strip(),
|
|
72
|
+
"explanation": explanation
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
def _mock_process(self, code_snippet: str, language: str):
|
|
76
|
+
return {
|
|
77
|
+
"code": code_snippet, # Just return original in mock
|
|
78
|
+
"explanation": "## Mock Explanation\n\nNo API key provided. This is a mock response.\n\n- The code was not actually processed by AI.\n- Please set `GROQ_API_KEY` in your .env file to get real results."
|
|
79
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
def read_file_segment(file_path: str, start_line: int, end_line: int) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Reads a specific range of lines from a file.
|
|
6
|
+
Lines are 1-indexed.
|
|
7
|
+
"""
|
|
8
|
+
if not os.path.exists(file_path):
|
|
9
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
10
|
+
|
|
11
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
12
|
+
lines = f.readlines()
|
|
13
|
+
|
|
14
|
+
# Adjust for 0-based indexing
|
|
15
|
+
start_index = max(0, start_line - 1)
|
|
16
|
+
end_index = min(len(lines), end_line)
|
|
17
|
+
|
|
18
|
+
if start_index >= len(lines):
|
|
19
|
+
return ""
|
|
20
|
+
|
|
21
|
+
return "".join(lines[start_index:end_index])
|
|
22
|
+
|
|
23
|
+
def get_file_extension(file_path: str) -> str:
|
|
24
|
+
"""Returns the file extension without the dot."""
|
|
25
|
+
return os.path.splitext(file_path)[1].lstrip('.')
|
|
26
|
+
|
|
27
|
+
def write_file_segment(file_path: str, start_line: int, end_line: int, new_content: str):
|
|
28
|
+
"""
|
|
29
|
+
Replaces a specific range of lines in a file with new content.
|
|
30
|
+
Lines are 1-indexed.
|
|
31
|
+
"""
|
|
32
|
+
if not os.path.exists(file_path):
|
|
33
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
34
|
+
|
|
35
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
36
|
+
lines = f.readlines()
|
|
37
|
+
|
|
38
|
+
# Adjust for 0-based indexing
|
|
39
|
+
start_index = max(0, start_line - 1)
|
|
40
|
+
end_index = min(len(lines), end_line)
|
|
41
|
+
|
|
42
|
+
# Prepare new content lines
|
|
43
|
+
new_lines = new_content.splitlines(keepends=True)
|
|
44
|
+
if not new_content.endswith('\n'):
|
|
45
|
+
new_lines[-1] += '\n'
|
|
46
|
+
|
|
47
|
+
# Replace lines
|
|
48
|
+
lines[start_index:end_index] = new_lines
|
|
49
|
+
|
|
50
|
+
with open(file_path, 'w', encoding='utf-8') as f:
|
|
51
|
+
f.writelines(lines)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qfix-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI-powered CLI tool to format and explain code blocks using Groq API
|
|
5
|
+
Home-page: https://github.com/kunshika/QuickFix.git
|
|
6
|
+
Author: Kunshika
|
|
7
|
+
Author-email:
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/kunshika/QuickFix.git/issues
|
|
10
|
+
Project-URL: Source, https://github.com/kunshika/QuickFix.git
|
|
11
|
+
Keywords: code formatter,AI,CLI,code quality,groq,llama
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
15
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Operating System :: OS Independent
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: rich
|
|
28
|
+
Requires-Dist: python-dotenv
|
|
29
|
+
Requires-Dist: langchain-groq
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: classifier
|
|
32
|
+
Dynamic: description
|
|
33
|
+
Dynamic: description-content-type
|
|
34
|
+
Dynamic: home-page
|
|
35
|
+
Dynamic: keywords
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: project-url
|
|
39
|
+
Dynamic: requires-dist
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
Dynamic: summary
|
|
42
|
+
|
|
43
|
+
# QuickFix (qfix)
|
|
44
|
+
|
|
45
|
+
A powerful command-line tool that uses AI (Groq's Llama models) to format and explain specific blocks of code within your files. It allows you to target specific lines, receive intelligent improvements without logic changes, and optionally write the changes back to your file in proper format.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **Targeted Formatting**: Select specific line ranges to process, leaving the rest of the file untouched.
|
|
50
|
+
- **AI-Powered**: Uses Groq's fast Llama models for intelligent code formatting.
|
|
51
|
+
- **Strict Formatting**: Enforces best practices (indentation, spacing) without altering the underlying logic.
|
|
52
|
+
- **Detailed Explanations**: Provides a Markdown-formatted explanation of *why* changes were made.
|
|
53
|
+
- **Write-Back Support**: Apply the improved code directly to your file with the `--apply` flag or interactive prompt.
|
|
54
|
+
- **Mock Mode**: Works offline or without an API key (returns a mock response for testing).
|
|
55
|
+
|
|
56
|
+
## Prerequisites
|
|
57
|
+
|
|
58
|
+
- Python 3.8+
|
|
59
|
+
- A Groq API Key (Get one free from [Groq Console](https://console.groq.com/))
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
### Option 1: Install from PyPI (Recommended)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install qfix-cli
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Option 2: Install from GitHub
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install git+https://github.com/Kunshika/QuickFix.git
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Option 3: Install from Source
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git clone https://github.com/Kunshika/QuickFix.git
|
|
79
|
+
cd QuickFix
|
|
80
|
+
pip install .
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
1. Create a `.env` file in your project directory or home directory:
|
|
86
|
+
```bash
|
|
87
|
+
touch .env
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
2. Add your Groq API Key to `.env`:
|
|
91
|
+
```env
|
|
92
|
+
GROQ_API_KEY=your_api_key_here
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
*Alternatively, you can pass the key via the CLI argument `--api-key`.*
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
Run the tool using `qfix` with the target file and line range.
|
|
101
|
+
|
|
102
|
+
### Basic Usage (View Only)
|
|
103
|
+
This will print the original code, the improved version, and the explanation to the console without modifying the file.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
qfix path/to/file.py --start 10 --end 20
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Apply Changes
|
|
110
|
+
To write the formatted code back to the file, use the `--apply` flag or answer "Yes" to the interactive prompt.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
qfix path/to/file.py --start 10 --end 20 --apply
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Command Line Arguments
|
|
117
|
+
|
|
118
|
+
| Argument | Description | Required |
|
|
119
|
+
| :--- | :--- | :--- |
|
|
120
|
+
| `file` | Path to the source file to process. | Yes |
|
|
121
|
+
| `--start` | Start line number (1-based). | Yes |
|
|
122
|
+
| `--end` | End line number (1-based). | Yes |
|
|
123
|
+
| `--apply` | Automatically apply changes to the file. | No |
|
|
124
|
+
| `--api-key`| Provide API key directly (overrides `.env`).| No |
|
|
125
|
+
|
|
126
|
+
## Example
|
|
127
|
+
|
|
128
|
+
**Input File (`example.py`):**
|
|
129
|
+
```python
|
|
130
|
+
7 def complex_logic(a, b):
|
|
131
|
+
8 # This is a bad implementation
|
|
132
|
+
9 if a > b: return a - b
|
|
133
|
+
10 else: return
|
|
134
|
+
11 b - a
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Command:**
|
|
138
|
+
```bash
|
|
139
|
+
qfix example.py --start 7 --end 11
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Output:**
|
|
143
|
+
The tool will display:
|
|
144
|
+
1. **Original Code**: Syntax-highlighted view of lines 7-11.
|
|
145
|
+
2. **Improved Implementation**: Properly formatted code (e.g., fixing the `else: return` line break).
|
|
146
|
+
3. **Detailed Explanation**: "Fixed indentation and line breaks for readability..."
|
|
147
|
+
|
|
148
|
+
## Troubleshooting
|
|
149
|
+
|
|
150
|
+
- **429 Quota Exceeded**: The free tier of Gemini API has rate limits. If you see this error, wait a minute and try again.
|
|
151
|
+
- **Mock Explanation**: If you see this, it means the tool couldn't access the API (missing key or network issue). Check your `.env` file.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
list_models.py
|
|
6
|
+
package.json
|
|
7
|
+
pyproject.toml
|
|
8
|
+
requirements.txt
|
|
9
|
+
setup.py
|
|
10
|
+
test_code.py
|
|
11
|
+
bin/qfix
|
|
12
|
+
qfix/__init__.py
|
|
13
|
+
qfix/main.py
|
|
14
|
+
qfix/processor.py
|
|
15
|
+
qfix/utils.py
|
|
16
|
+
qfix_cli.egg-info/PKG-INFO
|
|
17
|
+
qfix_cli.egg-info/SOURCES.txt
|
|
18
|
+
qfix_cli.egg-info/dependency_links.txt
|
|
19
|
+
qfix_cli.egg-info/entry_points.txt
|
|
20
|
+
qfix_cli.egg-info/requires.txt
|
|
21
|
+
qfix_cli.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
qfix
|
qfix_cli-0.1.0/setup.cfg
ADDED
qfix_cli-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
# Read README for long description
|
|
4
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
5
|
+
long_description = fh.read()
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name="qfix-cli",
|
|
9
|
+
version="0.1.0",
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
install_requires=[
|
|
12
|
+
"rich",
|
|
13
|
+
"python-dotenv",
|
|
14
|
+
"langchain-groq",
|
|
15
|
+
],
|
|
16
|
+
entry_points={
|
|
17
|
+
"console_scripts": [
|
|
18
|
+
"qfix=qfix.main:main",
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
author="Kunshika",
|
|
22
|
+
author_email="", # Add your email if you want
|
|
23
|
+
description="AI-powered CLI tool to format and explain code blocks using Groq API",
|
|
24
|
+
long_description=long_description,
|
|
25
|
+
long_description_content_type="text/markdown",
|
|
26
|
+
url="https://github.com/kunshika/QuickFix.git",
|
|
27
|
+
project_urls={
|
|
28
|
+
"Bug Reports": "https://github.com/kunshika/QuickFix.git/issues",
|
|
29
|
+
"Source": "https://github.com/kunshika/QuickFix.git",
|
|
30
|
+
},
|
|
31
|
+
classifiers=[
|
|
32
|
+
"Development Status :: 3 - Alpha",
|
|
33
|
+
"Intended Audience :: Developers",
|
|
34
|
+
"Topic :: Software Development :: Code Generators",
|
|
35
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
36
|
+
"License :: OSI Approved :: MIT License",
|
|
37
|
+
"Programming Language :: Python :: 3",
|
|
38
|
+
"Programming Language :: Python :: 3.8",
|
|
39
|
+
"Programming Language :: Python :: 3.9",
|
|
40
|
+
"Programming Language :: Python :: 3.10",
|
|
41
|
+
"Programming Language :: Python :: 3.11",
|
|
42
|
+
"Programming Language :: Python :: 3.12",
|
|
43
|
+
"Operating System :: OS Independent",
|
|
44
|
+
],
|
|
45
|
+
keywords="code formatter, AI, CLI, code quality, groq, llama",
|
|
46
|
+
python_requires=">=3.8",
|
|
47
|
+
license="MIT",
|
|
48
|
+
)
|