aidbg-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.
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: aidbg-cli
3
+ Version: 0.1.0
4
+ Summary: Multi-language AI code debugger using local LLM
5
+ Author-email: Piyush Maheshwari <maheshwaripiyush846@gmail.com>
6
+ License: MIT
7
+ Keywords: AI,debugger,code,LLM,developer-tools
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # aidbg — AI Code Debugger
14
+
15
+ Multi-language AI debugger powered by local LLM (DeepSeek via Ollama).
16
+
17
+ ## Features
18
+
19
+ - Fix Python, C, C++, Java, JavaScript
20
+ - Compiler-level validation
21
+ - Safe fix with automatic backup
22
+ - VS Code integration
23
+ - Works offline
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install aidbg
@@ -0,0 +1,16 @@
1
+ # aidbg — AI Code Debugger
2
+
3
+ Multi-language AI debugger powered by local LLM (DeepSeek via Ollama).
4
+
5
+ ## Features
6
+
7
+ - Fix Python, C, C++, Java, JavaScript
8
+ - Compiler-level validation
9
+ - Safe fix with automatic backup
10
+ - VS Code integration
11
+ - Works offline
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install aidbg
File without changes
@@ -0,0 +1,44 @@
1
+ import os
2
+ import subprocess
3
+ def call_ai(prompt: str) -> str:
4
+ """
5
+ Call Ollama model safely using absolute path.
6
+ """
7
+
8
+ # HARD-SET absolute path (this is correct on your system)
9
+ ollama_path = r"C:\Users\91968\AppData\Local\Programs\Ollama\ollama.exe"
10
+
11
+ # Step 1: Verify executable exists
12
+ if not os.path.isfile(ollama_path):
13
+ print("CRITICAL ERROR: Ollama executable not found at:")
14
+ print(ollama_path)
15
+ return ""
16
+
17
+ try:
18
+
19
+ # Step 2: Run Ollama model
20
+ result = subprocess.run(
21
+ [ollama_path, "run", "deepseek-coder:6.7b"],
22
+ input=prompt,
23
+ text=True,
24
+ capture_output=True,
25
+ encoding="utf-8",
26
+ timeout=120
27
+ )
28
+
29
+ # Step 3: Debug info
30
+ print("DEBUG return code:", result.returncode)
31
+ print("DEBUG stderr:", result.stderr)
32
+
33
+ # Step 4: Check failure
34
+ if result.returncode != 0:
35
+ print("ERROR: Ollama execution failed")
36
+ return ""
37
+
38
+ # Step 5: Return clean output
39
+ return result.stdout.strip()
40
+
41
+ except Exception as e:
42
+ print("CRITICAL ERROR:", str(e))
43
+ return ""
44
+
@@ -0,0 +1,114 @@
1
+ import subprocess
2
+ import tempfile #this creates temporary file for compiler validation because compiler only accepts file
3
+ from pathlib import Path
4
+ import os
5
+
6
+ def validate_python(code:str)->bool:
7
+ try:
8
+ compile(code,"<string>","exec")
9
+ return True
10
+ except SyntaxError:
11
+ return False
12
+
13
+
14
+ def validate_javascript(code:str)->bool:
15
+ try:
16
+ result =subprocess.run(
17
+ ["node","--check"],
18
+ input=code,
19
+ text=True,
20
+ capture_output=True
21
+ )
22
+ return result.returncode == 0
23
+
24
+ except FileNotFoundError:
25
+ print("Validator error : Node.js not installed")
26
+ return False
27
+
28
+ def validate_c(code: str)->bool:
29
+ try:
30
+ with tempfile.NamedTemporaryFile(suffix=".c",delete=False,mode="w",encoding="utf-8") as f:
31
+ f.write(code)
32
+ temp_path =f.name
33
+
34
+ result = subprocess.run(
35
+ ["gcc", "-fsyntax-only",temp_path],
36
+ capture_output=True,
37
+ text=True,
38
+ )
39
+ os.remove(temp_path)
40
+
41
+ return result.returncode == 0
42
+
43
+ except FileNotFoundError:
44
+ print("validator Error: GCC not installed")
45
+ return False
46
+
47
+ def validate_cpp(code:str)->bool:
48
+ try:
49
+ with tempfile.NamedTemporaryFile(suffix=".cpp",delete=False, mode="w" ,encoding ="utf-8") as f:
50
+ f.write(code)
51
+ temp_path =f.name
52
+
53
+ result = subprocess.run(
54
+ ["g++", "-fsyntax-only",temp_path],
55
+ capture_output=True,
56
+ text=True
57
+ )
58
+ print("DEBUG g++ return code:", result.returncode)
59
+ print("DEBUG g++ stderr:", result.stderr)
60
+ os.remove(temp_path)
61
+
62
+ return result.returncode == 0
63
+
64
+ except FileNotFoundError:
65
+ print("validor error:G++ not installed")
66
+ return False
67
+
68
+
69
+ def validate_java(code:str)->bool:
70
+ try:
71
+ with tempfile.NamedTemporaryFile(suffix=".java", delete=False, mode="w", encoding="utf-8") as f:
72
+ f.write(code)
73
+ temp_path = f.name
74
+
75
+
76
+ result = subprocess.run(
77
+ ["javac",temp_path],
78
+ capture_output=True,
79
+ text = True
80
+
81
+ )
82
+ os.remove(temp_path)
83
+ return result.returncode ==0
84
+
85
+ except FileNotFoundError:
86
+ print("Validator error:Java JDK not installed")
87
+ return False
88
+
89
+
90
+ def validate_code(code:str, language:str)->bool:
91
+
92
+ language=language.lower()
93
+
94
+ if language == "python":
95
+ return validate_python(code)
96
+
97
+ elif language=="javascript":
98
+ return validate_javascript(code)
99
+
100
+ elif language=="c":
101
+ return validate_c(code)
102
+
103
+ elif language =="c++":
104
+ return validate_cpp(code)
105
+
106
+ elif language == "java":
107
+ return validate_java(code)
108
+
109
+ else:
110
+ print(f"No Validator available for{language}")
111
+ return True
112
+
113
+
114
+
@@ -0,0 +1,14 @@
1
+ def classify_error(code:str)->str:
2
+ code_lower = code.lower()
3
+
4
+ if "def" in code_lower and ":" not in code_lower:
5
+ return "Possible Python syntax error(missing colon)"
6
+
7
+ if "while(true)" in code_lower:
8
+ return "Possible infinite Loop"
9
+
10
+ if "int" in code_lower and ";" not in code_lower:
11
+ return "Possible missing semicolon"
12
+
13
+ return "Unknown or Logical error"
14
+
@@ -0,0 +1,52 @@
1
+ def extract_fixed_code(ai_output: str) -> str | None:
2
+ """
3
+ Extract the fixed code section from AI output.
4
+ Supports markdown and plain text.
5
+ Removes markdown language labels like python, cpp, c++, java, js.
6
+ """
7
+
8
+ if "FIXED CODE:" not in ai_output:
9
+ return None
10
+
11
+ # Step 1: get everything after FIXED CODE:
12
+ fixed_section = ai_output.split("FIXED CODE:", 1)[1].strip()
13
+
14
+
15
+ # Step 2: handle markdown code blocks
16
+ if "```" in fixed_section:
17
+
18
+ parts = fixed_section.split("```")
19
+
20
+ if len(parts) >= 2:
21
+
22
+ code_block = parts[1].strip()
23
+
24
+ lines = code_block.splitlines()
25
+
26
+ # Step 3: remove language label line
27
+ if lines:
28
+
29
+ first_line = lines[0].strip().lower()
30
+
31
+ language_labels = [
32
+ "python",
33
+ "cpp",
34
+ "c++",
35
+ "c",
36
+ "java",
37
+ "javascript",
38
+ "js"
39
+ ]
40
+
41
+ if first_line in language_labels:
42
+ lines = lines[1:]
43
+
44
+ code_block = "\n".join(lines)
45
+
46
+ return code_block.strip()
47
+
48
+
49
+ # Step 4: fallback plain text
50
+ fixed_section = fixed_section.strip()
51
+
52
+ return fixed_section if fixed_section else None
@@ -0,0 +1,21 @@
1
+ from pathlib import Path
2
+ def apply_fix(file_path: str, fixed_code: str):
3
+ '''
4
+ Docstring for apply_fix\
5
+ Safely apply fix:
6
+ create backup
7
+ overwrite original file
8
+
9
+ '''
10
+ original = Path(file_path) #Path object is safer than plain string.
11
+
12
+ backup = original.with_suffix(original.suffix + ".bak") #test.py → test.py.bak Now backup file path is ready
13
+
14
+ backup.write_text(original.read_text(encoding="utf-8"),encoding="utf-8") #This is very important | this creates backup file.
15
+
16
+ original.write_text(fixed_code, encoding="utf-8") #This overwrited original file with fixed code
17
+
18
+ print(f"Fix applied successfully")
19
+
20
+ print(f"Backup created at :{backup}") # this shows backup file location
21
+
@@ -0,0 +1,34 @@
1
+ from pathlib import Path #help us to work with file name safely
2
+
3
+ def detect_language(code:str, filename: str |None = None) ->str:
4
+ if filename:
5
+ suffix=Path(filename).suffix.lower()
6
+ if suffix ==".py":
7
+ return "Python"
8
+ if suffix == ".js":
9
+ return "Javascript"
10
+ if suffix in[".cpp",".cc",".ccx"]:
11
+ return "C++"
12
+ if suffix ==".c":
13
+ return "C"
14
+ if suffix == ".java":
15
+ return "Java"
16
+
17
+ code_lower=code.lower()
18
+ if "def" in code_lower:
19
+ return "Python"
20
+ if "#include" in code_lower:
21
+ return "C/C++"
22
+ if "public static void main" in code_lower:
23
+ return "Java"
24
+ if "console.log" in code_lower:
25
+ return "Javascript"
26
+
27
+ return "Unknown"
28
+
29
+ '''
30
+ Do we have filename?
31
+ Yes → Check extension → Return language
32
+ No → Check code text → Return language
33
+ If nothing matches → Return Unknown
34
+ '''
@@ -0,0 +1,65 @@
1
+ from agent.compiler_validator import validate_code
2
+ from agent.extractor import extract_fixed_code
3
+
4
+ def retry_fix(call_ai, build_prompt, code, language,error_type,filename ,max_attempts=4):
5
+ attempt =1
6
+ while attempt<= max_attempts:
7
+ print(f"attempt {attempt} of {max_attempts}")
8
+
9
+ prompt=build_prompt(code,language, error_type)
10
+
11
+ output = call_ai(prompt)
12
+ print("\nDebug : RAW AI OUTPUT \n")
13
+ print( output)
14
+ print("\nDebug end\n")
15
+
16
+ fixed_code= extract_fixed_code(output)
17
+
18
+ if not fixed_code:
19
+ print("Could not extract fix from AI response")
20
+ attempt += 1
21
+ continue #skip ramaining steps go to next attempt
22
+ valid = validate_code(fixed_code,language)
23
+
24
+ if valid:
25
+ print("valid fix found")
26
+ return fixed_code
27
+ print("Invalid fix: compiler validtion failed")
28
+
29
+ code =fixed_code # It upadates input code for next attempt Instead of retrying original broken code, agent retries improved version.
30
+
31
+ attempt += 1
32
+ return None
33
+
34
+
35
+ '''
36
+ roken code:
37
+
38
+ def add(a,b)
39
+ return a+b
40
+
41
+
42
+ Agent flow:
43
+
44
+ Attempt 1
45
+ LLM fix invalid
46
+ retry
47
+
48
+ Attempt 2
49
+ LLM fix valid
50
+ return fixed_code
51
+
52
+ Why retry loop makes this a real agent
53
+
54
+ Without retry:
55
+
56
+ LLM fails → agent fails
57
+
58
+
59
+ With retry:
60
+
61
+ LLM fails → agent retries → succeeds
62
+
63
+
64
+ Agent becomes persistent.
65
+ '''
@@ -0,0 +1,8 @@
1
+ def validate_python_syntax(code: str, filename: str ="<string>")-> tuple[bool,str | None]:
2
+ try:
3
+ compile(code, filename, "exec") #this tell python check if this code is valid syntax
4
+ return True, None
5
+ except SyntaxError as e:
6
+ return False, f"{e.msg} at line {e.lineno}" # returns expected ':' at line 1"
7
+ except Exception as e: # it catches any unexpected error
8
+ return False ,str(e)
@@ -0,0 +1,224 @@
1
+ import argparse #handle CLI argument
2
+ import subprocess #talk to OLLama
3
+ import sys #read stdin
4
+ import os
5
+ import shutil
6
+ from pathlib import Path #Safe file handling
7
+ from agent.validator import validate_python_syntax
8
+ from agent.language_detector import detect_language # for early language detection
9
+ from agent.error_classifier import classify_error #for the early error classficattiono
10
+ from agent.extractor import extract_fixed_code
11
+ from agent.retry import retry_fix
12
+ from agent.ai_client import call_ai
13
+ from agent.fixer import apply_fix
14
+ from agent.compiler_validator import validate_code
15
+
16
+ def get_arguments():
17
+ parser =argparse.ArgumentParser(
18
+ description="AI Code Debugger(Free,Local)"
19
+ )
20
+
21
+
22
+ parser.add_argument(
23
+ "file",
24
+ nargs="?",
25
+ help="Path to Code file"
26
+
27
+ )
28
+ parser.add_argument(
29
+ "--stdin",
30
+ action="store_true",
31
+ help="Read code from standard input"
32
+ )
33
+ parser.add_argument(
34
+ "--fix",
35
+ action="store_true",
36
+ help="Automatically apply the suggested fix(safe mode with backup)"
37
+ )
38
+
39
+ return parser.parse_args() #Reads terminal input Validates arguments Converts them into object Returns structured result
40
+
41
+
42
+ def read_code(args):
43
+ if args.stdin:
44
+ return sys.stdin.read()
45
+ if args.file:
46
+ path = Path(args.file)
47
+
48
+ if not path.exists():
49
+
50
+ print("File not Found")
51
+ sys.exit(1) # 1 menas failur or error code
52
+ return path.read_text(encoding ="utf-8")
53
+ print ("provide a file or use --stdin")
54
+ sys.exit(1)
55
+
56
+
57
+
58
+ def build_prompt(code: str, language: str, error_type: str)-> str :
59
+ template = Path("prompts/debugger.txt").read_text(encoding="utf-8")
60
+ structured_context = f"""
61
+ Detected Language: {language}
62
+ Pre-analysis Result: {error_type}
63
+
64
+ CODE:
65
+ {code}
66
+ """
67
+ return template.replace("{code}", structured_context)
68
+
69
+
70
+ def main():
71
+ args=get_arguments()
72
+ code = read_code(args)
73
+ print(f"File being processed : {args.file}")
74
+ language = detect_language(code, args.file)
75
+ error_type = classify_error(code)
76
+
77
+ print(f" Detected Language: {language}")
78
+ print(f"Pre-analysis:{error_type}")
79
+ print("Debuggin......\n")
80
+
81
+ prompt= build_prompt(code,language,error_type)
82
+ output= call_ai(prompt)
83
+
84
+ print("Result:\n")
85
+ print(output)
86
+
87
+ if args.fix and args.file:
88
+ print("\n Applying fix in safe mode...")
89
+
90
+ fixed_code= retry_fix(call_ai,
91
+ build_prompt,
92
+ code,
93
+ language,
94
+ error_type,
95
+ args.file,
96
+ max_attempts=4
97
+ )
98
+ if fixed_code is None:
99
+ print(" NO error found or Failed to generate valid after multiple attempts")
100
+ return
101
+
102
+ is_valid = validate_code(fixed_code,language)
103
+
104
+ if not is_valid:
105
+ print("fix failed compiler validatioin")
106
+ print("Original file preserved")
107
+ return
108
+ apply_fix(args.file, fixed_code)
109
+
110
+ print("Syntax validation passed. Fix applied successfully")
111
+ if __name__=="__main__":
112
+ main()
113
+ '''strip() removes extra: Spaces New lines It ccleans the output before returning '''
114
+
115
+
116
+ '''Your code builds a:p
117
+
118
+ Command-Line AI Debugger Tool
119
+ that reads code → sends it to a local AI model → prints debugging output.
120
+
121
+ It is:
122
+
123
+ CLI-based
124
+
125
+ IDE-independent
126
+
127
+ Local (offline AI)
128
+
129
+ Modular
130
+
131
+ User (Terminal)
132
+
133
+ get_arguments()
134
+
135
+ read_code()
136
+
137
+ build_prompt()
138
+
139
+ call_ai()
140
+
141
+ print result
142
+
143
+ read_code function works for :
144
+ If stdin → read from stdin
145
+ Else if file → check file exists → read file
146
+ Else → show error and exit
147
+ Decides where the code comes from, reads it safely, and returns it.
148
+
149
+ build prompt:
150
+ this function build a very structured analysis
151
+ Detected Language: Python
152
+ Pre-analysis Result: Possible Python syntax error
153
+
154
+ CODE:
155
+ def add(a,b)
156
+ return a+b
157
+
158
+ Simple Summary of call_ai()
159
+
160
+ This function:
161
+
162
+ Takes prompt
163
+
164
+ Runs Ollama
165
+
166
+ Sends prompt to model
167
+
168
+ Receives AI answer
169
+
170
+ Returns cleaned result
171
+
172
+ extract_fixed_code():
173
+ This is very important function
174
+
175
+
176
+ # Why This Function Is Critical
177
+
178
+ Without this function:
179
+
180
+ Your program cannot safely extract fixed code.
181
+
182
+ AI output contains:
183
+
184
+ - explanation
185
+ - markdown
186
+ - extra text
187
+
188
+ This function extracts only usable code.
189
+
190
+ ---
191
+
192
+ # Visual Flow
193
+
194
+ AI Output
195
+
196
+ Find "FIXED CODE:"
197
+
198
+ Extract section
199
+
200
+ Remove markdown
201
+
202
+ Return clean code
203
+
204
+ apply fix:
205
+ this is the function which enable agentic behaviour
206
+
207
+ Original file → read content
208
+
209
+ Create backup file
210
+
211
+ Write fixed code to original file
212
+
213
+ Show success message
214
+ Why Backup Is Critical
215
+ Without backup:
216
+
217
+ If AI makes mistake → original file lost.
218
+
219
+ With backup:
220
+
221
+ You can restore original anytime.
222
+
223
+ Professional tools ALWAYS create backups.
224
+ '''
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: aidbg-cli
3
+ Version: 0.1.0
4
+ Summary: Multi-language AI code debugger using local LLM
5
+ Author-email: Piyush Maheshwari <maheshwaripiyush846@gmail.com>
6
+ License: MIT
7
+ Keywords: AI,debugger,code,LLM,developer-tools
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # aidbg — AI Code Debugger
14
+
15
+ Multi-language AI debugger powered by local LLM (DeepSeek via Ollama).
16
+
17
+ ## Features
18
+
19
+ - Fix Python, C, C++, Java, JavaScript
20
+ - Compiler-level validation
21
+ - Safe fix with automatic backup
22
+ - VS Code integration
23
+ - Works offline
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install aidbg
@@ -0,0 +1,17 @@
1
+ README.md
2
+ aidbg.py
3
+ pyproject.toml
4
+ agent/__init__.py
5
+ agent/ai_client.py
6
+ agent/compiler_validator.py
7
+ agent/error_classifier.py
8
+ agent/extractor.py
9
+ agent/fixer.py
10
+ agent/language_detector.py
11
+ agent/retry.py
12
+ agent/validator.py
13
+ aidbg_cli.egg-info/PKG-INFO
14
+ aidbg_cli.egg-info/SOURCES.txt
15
+ aidbg_cli.egg-info/dependency_links.txt
16
+ aidbg_cli.egg-info/entry_points.txt
17
+ aidbg_cli.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ aidbg = aidbg:main
@@ -0,0 +1,2 @@
1
+ agent
2
+ aidbg
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "aidbg-cli"
7
+ version = "0.1.0"
8
+ description = "Multi-language AI code debugger using local LLM"
9
+ authors = [
10
+ { name = "Piyush Maheshwari", email = "maheshwaripiyush846@gmail.com" }
11
+ ]
12
+ readme = "README.md"
13
+ requires-python = ">=3.10"
14
+ license = { text = "MIT" }
15
+
16
+ keywords = ["AI", "debugger", "code", "LLM", "developer-tools"]
17
+
18
+ classifiers = [
19
+ "Programming Language :: Python :: 3",
20
+ "Operating System :: OS Independent",
21
+ ]
22
+
23
+ [tool.setuptools]
24
+ packages = ["agent"]
25
+ py-modules = ["aidbg"]
26
+
27
+ [tool.setuptools.package-data]
28
+ "*" = ["*.txt"]
29
+
30
+ [project.scripts]
31
+ aidbg = "aidbg:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+