socratic-debug 0.0.1__py3-none-any.whl
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.
- socratic.py +8 -0
- socratic_debug-0.0.1.dist-info/METADATA +143 -0
- socratic_debug-0.0.1.dist-info/RECORD +40 -0
- socratic_debug-0.0.1.dist-info/WHEEL +5 -0
- socratic_debug-0.0.1.dist-info/entry_points.txt +2 -0
- socratic_debug-0.0.1.dist-info/licenses/LICENSE +21 -0
- socratic_debug-0.0.1.dist-info/top_level.txt +3 -0
- src/__init__.py +1 -0
- src/agent/graph/graph.py +47 -0
- src/agent/llm/factory.py +15 -0
- src/agent/llm/providers/__init__.py +8 -0
- src/agent/llm/providers/ollama.py +13 -0
- src/agent/llm/providers/openrouter.py +14 -0
- src/agent/nodes/diagnose_node.py +21 -0
- src/agent/nodes/evaluate_node.py +38 -0
- src/agent/nodes/human_input_node.py +18 -0
- src/agent/nodes/questioner_node.py +47 -0
- src/agent/nodes/solution_node.py +36 -0
- src/agent/prompts/diagnose_prompt.py +34 -0
- src/agent/prompts/evaluation_prompt.py +33 -0
- src/agent/prompts/mentor_prompt.py +30 -0
- src/agent/prompts/questioner_prompt.py +47 -0
- src/agent/prompts/solution_prompt.py +38 -0
- src/agent/runner.py +21 -0
- src/agent/state/state.py +21 -0
- src/cli.py +98 -0
- src/config_creator.py +32 -0
- src/config_template.py +21 -0
- src/extractor.py +34 -0
- src/hook.py +67 -0
- src/utils/read_yaml.py +36 -0
- ui/__init__.py +15 -0
- ui/app.py +203 -0
- ui/bidi.py +23 -0
- ui/console.py +23 -0
- ui/styles.py +63 -0
- ui/templates.py +102 -0
- ui/translations.py +31 -0
- ui/views.py +52 -0
- ui/window.py +140 -0
socratic.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: socratic-debug
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Autonomous pedagogical debugging mentor powered by LangGraph, Rich, and LangSmith
|
|
5
|
+
Author: Mohamed Elawakey
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: pyyaml>=6.0
|
|
10
|
+
Requires-Dist: rich>=13.7.0
|
|
11
|
+
Requires-Dist: PyQt6>=6.6.0
|
|
12
|
+
Requires-Dist: langgraph>=1.2.0
|
|
13
|
+
Requires-Dist: langchain>=1.4.0
|
|
14
|
+
Requires-Dist: langchain-ollama>=1.1.0
|
|
15
|
+
Requires-Dist: langchain-openrouter>=0.2.0
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# 🧠 Socratic Debug (`socratic`)
|
|
19
|
+
|
|
20
|
+
> **Stop copying stack traces. Start mastering your bugs.**
|
|
21
|
+
> An autonomous pedagogical debugger and mentor powered by LangGraph, PyQt6, and LangSmith.
|
|
22
|
+
|
|
23
|
+
[](https://github.com/mohamedelawakey/socratic/actions/workflows/ci.yml)
|
|
24
|
+
[](https://pypi.org/project/socratic-debug/)
|
|
25
|
+
[](https://www.python.org/)
|
|
26
|
+
[](LICENSE)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 💡 Why Socratic?
|
|
31
|
+
|
|
32
|
+
When a runtime crash happens, most developers find themselves trapped in one of two extremes:
|
|
33
|
+
1. **The Intimidating Traceback:** Staring at a terrifying wall of 50-line red terminal text, unsure which line actually caused the root flaw.
|
|
34
|
+
2. **The "Copier" Reflex:** Blindly copying the error into an LLM chat, pasting the patch without understanding *why* it failed, only to trigger the exact same design mistake minutes later.
|
|
35
|
+
|
|
36
|
+
**Socratic Debug changes the game.**
|
|
37
|
+
Instead of dumping stack traces or spoon-feeding copy-paste patches, `socratic` intercepts uncaught runtime crashes and launches a **dedicated desktop mentorship window**. It analyzes the bug silently and guides you through a calibrated, interactive dialogue to help you **discover, understand, and fix the root cause yourself.**
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## ✨ Features
|
|
42
|
+
|
|
43
|
+
- 🖥️ **Standalone Desktop Window:** Launches an isolated, dark-themed GUI terminal window right at the center of your screen. No terminal pollution.
|
|
44
|
+
- 🌍 **Pure Native BiDi & Arabic Support:** Flawlessly displays English and Arabic with full Right-to-Left (RTL) text shaping and formatting.
|
|
45
|
+
- 🎯 **Calibrated Socratic Mentorship:** 3-tier adaptive hints (Observation ➔ Mechanism ➔ Idiomatic Prevention).
|
|
46
|
+
- 🧠 **Smart Evaluator:** Distinguishes between partial observations (e.g., stating a variable's value) and true comprehension before unlocking the defensive code solution.
|
|
47
|
+
- 🔌 **Universal LLM Support:** Plug into local models via **Ollama** (Gemma, Llama, Qwen) or cloud providers via **OpenRouter** / **Google Gemini**.
|
|
48
|
+
- 📊 **Built-in Observability:** Native tracing with **LangSmith** to monitor latency, tokens, and node execution graphs.
|
|
49
|
+
- 🌐 **Cross-Platform:** Runs seamlessly on **Linux**, **macOS**, and **Windows**.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🚀 Quick Start
|
|
54
|
+
|
|
55
|
+
### Installation
|
|
56
|
+
|
|
57
|
+
The cleanest, recommended way to install `socratic` globally across your system without virtual environment conflicts:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Recommended (isolated global CLI)
|
|
61
|
+
pipx install socratic-debug
|
|
62
|
+
|
|
63
|
+
# Or via standard pip
|
|
64
|
+
pip install socratic-debug
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Alternatively, use the one-line install script:
|
|
68
|
+
```bash
|
|
69
|
+
# Linux & macOS
|
|
70
|
+
curl -sSL https://raw.githubusercontent.com/mohamedelawakey/socratic/main/install.sh | bash
|
|
71
|
+
|
|
72
|
+
# Windows (PowerShell)
|
|
73
|
+
irm https://raw.githubusercontent.com/mohamedelawakey/socratic/main/install.ps1 | iex
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 🛠️ Usage
|
|
79
|
+
|
|
80
|
+
You can use `socratic` in two distinct ways:
|
|
81
|
+
|
|
82
|
+
### Method 1: Zero-Code-Change CLI Runner (Recommended)
|
|
83
|
+
You don't need to add any code or imports to your script! Simply prefix your execution:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
socratic run my_script.py
|
|
87
|
+
```
|
|
88
|
+
- If your script runs successfully, it outputs normally.
|
|
89
|
+
- If an unhandled exception occurs, the **Socratic Mentor Window** springs to life immediately!
|
|
90
|
+
|
|
91
|
+
### Method 2: In-Process Runtime Hook
|
|
92
|
+
If you are building an application or library and want Socratic guidance baked directly into development runs:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import socratic
|
|
96
|
+
socratic.install()
|
|
97
|
+
|
|
98
|
+
# Your regular application code
|
|
99
|
+
number_1 = 10
|
|
100
|
+
number_2 = 0
|
|
101
|
+
print(number_1 / number_2) # <-- ZeroDivisionError triggers Socratic window!
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## ⚙️ Configuration (`.socratic.yaml`)
|
|
107
|
+
|
|
108
|
+
When you run `socratic` for the first time, it automatically creates a `.socratic.yaml` config file in your project or home directory:
|
|
109
|
+
|
|
110
|
+
```yaml
|
|
111
|
+
# LLM Provider: "ollama" or "openrouter"
|
|
112
|
+
provider: "ollama"
|
|
113
|
+
provider_name: "gemma4:31b-cloud"
|
|
114
|
+
provider_link: "http://localhost:11434"
|
|
115
|
+
|
|
116
|
+
# API Key (for cloud providers like OpenRouter)
|
|
117
|
+
api_key: "your_api_key_here"
|
|
118
|
+
|
|
119
|
+
# Mentor Personality & Language ("Arabic" or "English")
|
|
120
|
+
socratic_language: "Arabic"
|
|
121
|
+
socratic_style: "friendly"
|
|
122
|
+
|
|
123
|
+
# Observability with LangSmith (Optional)
|
|
124
|
+
LANGSMITH_TRACING: "true"
|
|
125
|
+
LANGSMITH_API_KEY: "lsv2_pt_..."
|
|
126
|
+
LANGSMITH_PROJECT: "socratic-debug"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🤝 Contributing
|
|
132
|
+
|
|
133
|
+
We welcome contributions! Please review our [CONTRIBUTING.md](CONTRIBUTING.md) guidelines:
|
|
134
|
+
- For large architectural changes or new features, **please open a GitHub Discussion first**.
|
|
135
|
+
- For minor bug fixes, direct Pull Requests are warmly welcome.
|
|
136
|
+
|
|
137
|
+
Please note that this project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 📄 License
|
|
142
|
+
|
|
143
|
+
Distributed under the **MIT License**. See [LICENSE](LICENSE) for full details.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
socratic.py,sha256=vjvn2kb04RYGlU0rpDraG2HvbKbsq1AazT2PHW2mpeM,191
|
|
2
|
+
socratic_debug-0.0.1.dist-info/licenses/LICENSE,sha256=ihM1UFgq0KNRA1mK7zKHG4Ek4gRjZ0lz-Jqf5R6k5HY,1073
|
|
3
|
+
src/__init__.py,sha256=cCoVrcqlB8PoIqGQPWXjHrYJjZ6kyI_JK-pgTtOPKzQ,19
|
|
4
|
+
src/cli.py,sha256=jcgjcf3IueLgaYmvXxHezOWKNp8lrMZ_fSxcbH451fk,3052
|
|
5
|
+
src/config_creator.py,sha256=Lro60P0YQnw5hNgdFyDhNm-pLltHbGjMufweV4hXyoY,798
|
|
6
|
+
src/config_template.py,sha256=gRQ9N17nnQpwXozpzaSEazyGscmTZf8fccRj6wO7BSg,548
|
|
7
|
+
src/extractor.py,sha256=5i3WWr2ZysDuY-UioDAiiOrYcy7t3mxxxThkKnjrNb0,1148
|
|
8
|
+
src/hook.py,sha256=HZFAXeHma52Ko5qZwrsNk4ZDCTj_z9qq2GiQ248pTgg,2329
|
|
9
|
+
src/agent/runner.py,sha256=gydqyps4cXvWZVpCF_ApRPfhOFHimo_mwjcJp-I34ko,750
|
|
10
|
+
src/agent/graph/graph.py,sha256=ZV7vYMJygbvh2pAKdVa49GQqEN7ef-4LpTUjQSxnuz0,1597
|
|
11
|
+
src/agent/llm/factory.py,sha256=FzZhh9C_Vy9aZRBZrY82KcIgtD3myroTS1jN27dLMAc,422
|
|
12
|
+
src/agent/llm/providers/__init__.py,sha256=JUftuQkiHppcu7epf4YumISPY8wK-XHLBDuBuSGgrWM,168
|
|
13
|
+
src/agent/llm/providers/ollama.py,sha256=VQDwx3C3WWcdax_ZQcnFoZz9S86sfyzvEUTLHbIQv_4,306
|
|
14
|
+
src/agent/llm/providers/openrouter.py,sha256=7ACDWjjNt75PovWTUUFFqvXqKCGEQp1VRCyHGynOKUQ,364
|
|
15
|
+
src/agent/nodes/diagnose_node.py,sha256=Gwk3P2SPpOBFvFn17XiSxtjrT75fvuMQNzE0DLyo_AY,753
|
|
16
|
+
src/agent/nodes/evaluate_node.py,sha256=wCiUsdu8nvi1vhWgJf-MhZz7o16rBhIUF57AV_4q6CQ,1317
|
|
17
|
+
src/agent/nodes/human_input_node.py,sha256=GANj4vUVBdeESGB4ufK3X9iB1QQn75gG3lpGEvEwp5E,695
|
|
18
|
+
src/agent/nodes/questioner_node.py,sha256=TdtDJ_8uBzsnK7pGtouie5-sHVx5z0rx0OqRrRCZnYY,1628
|
|
19
|
+
src/agent/nodes/solution_node.py,sha256=h8rVtOG7vQNDcHXd6FqP-864-HQVomnQXP9mS2pFlQw,1171
|
|
20
|
+
src/agent/prompts/diagnose_prompt.py,sha256=gDHtGO62MUVbLxl-maWb0iyIhBMZr74dBmWCIoUbvy0,1334
|
|
21
|
+
src/agent/prompts/evaluation_prompt.py,sha256=51sBNxB2Oog7scg_TIn94aPIoWHiVLaiNY7m4zfVezY,1334
|
|
22
|
+
src/agent/prompts/mentor_prompt.py,sha256=mgQ6iD0XlR_YOIciySAogjSyMI1-_T6E14MrrjFCHRI,1078
|
|
23
|
+
src/agent/prompts/questioner_prompt.py,sha256=Xj7RZAyl2EYv9LZL530tyFZX0LShkl_kozPG8HgJ0uk,2160
|
|
24
|
+
src/agent/prompts/solution_prompt.py,sha256=MTHldmB96ZEgzOFOSh1_grGl6WmnmP9MhoVcnl5Bqnk,1378
|
|
25
|
+
src/agent/state/state.py,sha256=pPLGBzrityoDB8BsCMCtkDGWyl35VE5Vu2WawpPnvBM,458
|
|
26
|
+
src/utils/read_yaml.py,sha256=nXhgCLt3P6PlwvLeyy471lWmDOaKIP_c8X3-LUx_WCQ,1179
|
|
27
|
+
ui/__init__.py,sha256=kgCb95xam0txNsto6-77OamiWeibjDntEYNMQizeQkU,389
|
|
28
|
+
ui/app.py,sha256=alt-5nFQeWsFP52A9z9EXIJMsTzAdIwN3zOJqOPArJc,7613
|
|
29
|
+
ui/bidi.py,sha256=6c94A9TvcMFapDZBIENK-LrX0PB9zWWYZSQ-A-t4TMw,814
|
|
30
|
+
ui/console.py,sha256=Vml-Mlg6cyignegw4AFWfaRZXDyxGlLM2o-GyhLmP8g,588
|
|
31
|
+
ui/styles.py,sha256=3Au_ATVjGfnCB1UFVkLzgbjU_VCfCBF688vYB9vW3Dw,1588
|
|
32
|
+
ui/templates.py,sha256=89cPdnQK4YsdZGiiLiEEgTzmt8Jh1mLtenyowh78L1I,4432
|
|
33
|
+
ui/translations.py,sha256=DI-SaA_u5Xy41aFe3_cNlOd5xpdLSyNLzVhLKm0lIyc,1483
|
|
34
|
+
ui/views.py,sha256=KWHyj44kiWosZFbdSMfKJoPcXt4R04RouhfigM-Xbs0,1992
|
|
35
|
+
ui/window.py,sha256=cR22-64IGo7VlJpNqz8lGqEvYJYX418P89-jmHSIIJ4,4341
|
|
36
|
+
socratic_debug-0.0.1.dist-info/METADATA,sha256=6XSpJv_Ct74s6DW32PVY339vHWmDtuHa747aUf6RGLA,5454
|
|
37
|
+
socratic_debug-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
38
|
+
socratic_debug-0.0.1.dist-info/entry_points.txt,sha256=33bxMIy6yZotp4XPq64BMjsMceJdLln5wzJ8cFzRjJ0,42
|
|
39
|
+
socratic_debug-0.0.1.dist-info/top_level.txt,sha256=nuecBGJAx4dR_afXHk8yT2mz3JAhpkYh-JcmwNzBnvI,16
|
|
40
|
+
socratic_debug-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamed Alawakey
|
|
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.
|
src/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# socratic package
|
src/agent/graph/graph.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from langgraph.graph import StateGraph, END, START
|
|
2
|
+
from src.agent.state.state import SocraticAgentState
|
|
3
|
+
from src.agent.nodes.diagnose_node import DiagnoseNode
|
|
4
|
+
from src.agent.nodes.questioner_node import QuestionerNode
|
|
5
|
+
from src.agent.nodes.human_input_node import HumanInputNode
|
|
6
|
+
from src.agent.nodes.evaluate_node import EvaluationNode
|
|
7
|
+
from src.agent.nodes.solution_node import SolutionNode
|
|
8
|
+
|
|
9
|
+
def decision_router(state: SocraticAgentState) -> str:
|
|
10
|
+
if state.get("is_solved"):
|
|
11
|
+
return "solution"
|
|
12
|
+
if state.get("hint_level", 1) > 3:
|
|
13
|
+
return "solution"
|
|
14
|
+
return "questioner"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SocraticGraph:
|
|
18
|
+
@staticmethod
|
|
19
|
+
def build_graph():
|
|
20
|
+
# We will assemble nodes and edges here
|
|
21
|
+
graph = StateGraph(SocraticAgentState)
|
|
22
|
+
|
|
23
|
+
# add nodes
|
|
24
|
+
graph.add_node("diagnose", DiagnoseNode.diagnose_node)
|
|
25
|
+
graph.add_node("questioner", QuestionerNode.questioner_node)
|
|
26
|
+
graph.add_node("human_input", HumanInputNode.human_input_node)
|
|
27
|
+
graph.add_node("evaluate", EvaluationNode.evaluation_node)
|
|
28
|
+
graph.add_node("solution", SolutionNode.solution_node)
|
|
29
|
+
|
|
30
|
+
# edges
|
|
31
|
+
graph.add_edge(START, "diagnose")
|
|
32
|
+
graph.add_edge("diagnose", "questioner")
|
|
33
|
+
graph.add_edge("questioner", "human_input")
|
|
34
|
+
graph.add_edge("human_input", "evaluate")
|
|
35
|
+
|
|
36
|
+
graph.add_conditional_edges(
|
|
37
|
+
"evaluate",
|
|
38
|
+
decision_router,
|
|
39
|
+
{
|
|
40
|
+
"solution": "solution",
|
|
41
|
+
"questioner": "questioner",
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
graph.add_edge("solution", END)
|
|
45
|
+
|
|
46
|
+
return graph.compile()
|
|
47
|
+
|
src/agent/llm/factory.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from src.agent.llm.providers import *
|
|
2
|
+
from src.utils.read_yaml import ReadYaml
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LLMFactory:
|
|
6
|
+
@staticmethod
|
|
7
|
+
def get_llm():
|
|
8
|
+
config = ReadYaml.read_yaml()
|
|
9
|
+
|
|
10
|
+
if config["provider"] == "openrouter":
|
|
11
|
+
return OpenRouterLLM.openrouter_llm()
|
|
12
|
+
elif config["provider"] == "ollama":
|
|
13
|
+
return OllamaLLM.ollama_llm()
|
|
14
|
+
else:
|
|
15
|
+
raise ValueError("Invalid provider")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from langchain_ollama import ChatOllama
|
|
2
|
+
from src.utils.read_yaml import ReadYaml
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OllamaLLM:
|
|
6
|
+
@staticmethod
|
|
7
|
+
def ollama_llm():
|
|
8
|
+
config = ReadYaml.read_yaml()
|
|
9
|
+
|
|
10
|
+
return ChatOllama (
|
|
11
|
+
model=config["provider_name"],
|
|
12
|
+
base_url=config["provider_link"],
|
|
13
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from langchain_openrouter import ChatOpenRouter
|
|
2
|
+
from src.utils.read_yaml import ReadYaml
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class OpenRouterLLM:
|
|
6
|
+
@staticmethod
|
|
7
|
+
def openrouter_llm():
|
|
8
|
+
config = ReadYaml.read_yaml()
|
|
9
|
+
|
|
10
|
+
return ChatOpenRouter(
|
|
11
|
+
model=config["provider_name"],
|
|
12
|
+
base_url=config["provider_link"],
|
|
13
|
+
api_key=config["api_key"],
|
|
14
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from src.agent.prompts.diagnose_prompt import DiagnosePrompt
|
|
2
|
+
from src.agent.state.state import SocraticAgentState
|
|
3
|
+
from src.agent.llm.factory import LLMFactory
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DiagnoseNode:
|
|
7
|
+
@staticmethod
|
|
8
|
+
def diagnose_node(state: SocraticAgentState) -> dict:
|
|
9
|
+
prompt = DiagnosePrompt.diagnose_prompt(
|
|
10
|
+
error_type=state["error_type"],
|
|
11
|
+
error_name=state["error_name"],
|
|
12
|
+
file_path=state["file_path"],
|
|
13
|
+
line_number=state["line_number"],
|
|
14
|
+
line_content=state["line_content"],
|
|
15
|
+
code_snippet=state["code_snippet"],
|
|
16
|
+
function_name=state.get("function_name") or "",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
response = LLMFactory.get_llm().invoke(prompt)
|
|
20
|
+
|
|
21
|
+
return {"root_cause": response.content}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from src.agent.prompts.evaluation_prompt import EvaluationPrompt
|
|
2
|
+
from src.agent.state.state import SocraticAgentState
|
|
3
|
+
from src.agent.llm.factory import LLMFactory
|
|
4
|
+
|
|
5
|
+
from ui.views import SocraticUI
|
|
6
|
+
|
|
7
|
+
class EvaluationNode:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def evaluation_node(state: SocraticAgentState):
|
|
10
|
+
prompt = EvaluationPrompt.evaluation_prompt(
|
|
11
|
+
error_type=state["error_type"],
|
|
12
|
+
code_snippet=state["code_snippet"],
|
|
13
|
+
root_cause=state["root_cause"],
|
|
14
|
+
user_input=state.get("user_input") or state["dialogue_history"][-1]["content"]
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
response = LLMFactory.get_llm().invoke(prompt)
|
|
18
|
+
verdict = response.content.strip().upper()
|
|
19
|
+
|
|
20
|
+
if "SOLVED" in verdict and "UNSOLVED" not in verdict and "NOT SOLVED" not in verdict:
|
|
21
|
+
verdict_key = "SOLVED"
|
|
22
|
+
status = "solved"
|
|
23
|
+
is_solved = True
|
|
24
|
+
elif "SURRENDERED" in verdict:
|
|
25
|
+
verdict_key = "SURRENDERED"
|
|
26
|
+
status = "surrendered"
|
|
27
|
+
is_solved = True
|
|
28
|
+
else:
|
|
29
|
+
verdict_key = "STRUGGLING"
|
|
30
|
+
status = "struggling"
|
|
31
|
+
is_solved = False
|
|
32
|
+
|
|
33
|
+
SocraticUI.display_evaluator_verdict(verdict_key)
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
"eval_status": status,
|
|
37
|
+
"is_solved": is_solved,
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from src.agent.state.state import SocraticAgentState
|
|
2
|
+
from ui.views import SocraticUI
|
|
3
|
+
from ui.console import console
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class HumanInputNode:
|
|
7
|
+
@staticmethod
|
|
8
|
+
def human_input_node(state: SocraticAgentState) -> dict:
|
|
9
|
+
user_input = SocraticUI.prompt_user_input()
|
|
10
|
+
|
|
11
|
+
if user_input.lower().strip() in ["exit", "quit", "q"]:
|
|
12
|
+
console.print("\n[bold yellow]👋 Exiting Socratic debugging session. Keep coding![/bold yellow]\n")
|
|
13
|
+
return {"is_solved": True}
|
|
14
|
+
|
|
15
|
+
history = list(state.get("dialogue_history", []))
|
|
16
|
+
history.append({"role": "student", "content": user_input})
|
|
17
|
+
|
|
18
|
+
return {"user_input": user_input, "dialogue_history": history}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from src.agent.prompts.questioner_prompt import QuestionerPrompt
|
|
2
|
+
from src.agent.state.state import SocraticAgentState
|
|
3
|
+
from src.agent.llm.factory import LLMFactory
|
|
4
|
+
from src.utils.read_yaml import ReadYaml
|
|
5
|
+
|
|
6
|
+
from ui.views import SocraticUI
|
|
7
|
+
|
|
8
|
+
config = ReadYaml.read_yaml()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class QuestionerNode:
|
|
12
|
+
@staticmethod
|
|
13
|
+
def questioner_node(state: SocraticAgentState) -> dict:
|
|
14
|
+
current_hint = state.get("hint_level", 1)
|
|
15
|
+
raw_history = state.get("dialogue_history", [])
|
|
16
|
+
|
|
17
|
+
formatted_history = "\n".join(
|
|
18
|
+
f"- {turn.get('role', 'unknown').capitalize()}: {turn.get('content', '')}"
|
|
19
|
+
for turn in raw_history
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
prompt = QuestionerPrompt.questioner_prompt(
|
|
23
|
+
error_type=state["error_type"],
|
|
24
|
+
line_number=state["line_number"],
|
|
25
|
+
line_content=state["line_content"],
|
|
26
|
+
code_snippet=state["code_snippet"],
|
|
27
|
+
root_cause=state["root_cause"],
|
|
28
|
+
dialogue_history=formatted_history,
|
|
29
|
+
hint_level=current_hint,
|
|
30
|
+
language=config.get("socratic_language", "English"),
|
|
31
|
+
style=config.get("socratic_style", "friendly"),
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
response = LLMFactory.get_llm().invoke(prompt)
|
|
35
|
+
|
|
36
|
+
SocraticUI.display_mentor_message(
|
|
37
|
+
content=response.content,
|
|
38
|
+
hint_level=current_hint,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
history = list(state.get("dialogue_history", []))
|
|
42
|
+
history.append({"role": "mentor", "content": response.content})
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
"dialogue_history": history,
|
|
46
|
+
"hint_level": current_hint + 1 if current_hint < 3 else current_hint,
|
|
47
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from src.agent.prompts.solution_prompt import SolutionPrompt
|
|
2
|
+
from src.agent.state.state import SocraticAgentState
|
|
3
|
+
from src.agent.llm.factory import LLMFactory
|
|
4
|
+
from src.utils.read_yaml import ReadYaml
|
|
5
|
+
|
|
6
|
+
from ui.views import SocraticUI
|
|
7
|
+
|
|
8
|
+
config = ReadYaml.read_yaml()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SolutionNode:
|
|
12
|
+
@staticmethod
|
|
13
|
+
def solution_node(state: SocraticAgentState) -> dict:
|
|
14
|
+
current_status = state.get("eval_status", "solved")
|
|
15
|
+
|
|
16
|
+
prompt = SolutionPrompt.solution_prompt(
|
|
17
|
+
error_type=state["error_type"],
|
|
18
|
+
line_number=state["line_number"],
|
|
19
|
+
code_snippet=state["code_snippet"],
|
|
20
|
+
root_cause=state["root_cause"],
|
|
21
|
+
eval_status=current_status,
|
|
22
|
+
language=config.get("socratic_language", "English"),
|
|
23
|
+
style=config.get("socratic_style", "friendly"),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
response = LLMFactory.get_llm().invoke(prompt)
|
|
27
|
+
|
|
28
|
+
SocraticUI.display_solution(response.content)
|
|
29
|
+
|
|
30
|
+
history = list(state.get("dialogue_history", []))
|
|
31
|
+
history.append({"role": "mentor", "content": response.content})
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
"dialogue_history": history,
|
|
35
|
+
"is_solved": True,
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class DiagnosePrompt:
|
|
2
|
+
@staticmethod
|
|
3
|
+
def diagnose_prompt(
|
|
4
|
+
error_type: str,
|
|
5
|
+
error_name: str,
|
|
6
|
+
file_path: str,
|
|
7
|
+
line_number: int,
|
|
8
|
+
line_content: str,
|
|
9
|
+
code_snippet: str,
|
|
10
|
+
function_name: str = "",
|
|
11
|
+
) -> str:
|
|
12
|
+
return f"""You are an Expert Code Diagnostic Engine. Your mission is to silently analyze a runtime crash and identify the exact root cause and the faulty variable/expression.
|
|
13
|
+
|
|
14
|
+
Crash Information:
|
|
15
|
+
- Error Type: {error_type}
|
|
16
|
+
- Error Message: {error_name}
|
|
17
|
+
- File: {file_path} (Function: {function_name or 'global'})
|
|
18
|
+
- Faulty Line #{line_number}: `{line_content}`
|
|
19
|
+
|
|
20
|
+
Surrounding Code Context:
|
|
21
|
+
```python
|
|
22
|
+
{code_snippet}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Instructions:
|
|
26
|
+
1. Identify the exact root cause: Why did this specific error occur at this exact line?
|
|
27
|
+
2. Identify the culprit: Which variable, index, operation, or missing key caused the crash?
|
|
28
|
+
3. Define the pedagogical angle: What conceptual programming misunderstanding led to this bug, and what core question should we guide the developer to reflect upon?
|
|
29
|
+
|
|
30
|
+
Output your diagnosis strictly in this format:
|
|
31
|
+
- Root Cause: [Concise 1-2 sentence technical explanation of why it failed]
|
|
32
|
+
- Culprit: [The specific variable, operation, or expression responsible]
|
|
33
|
+
- Pedagogical Angle: [The core programming concept the developer needs to discover]
|
|
34
|
+
"""
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class EvaluationPrompt:
|
|
2
|
+
@staticmethod
|
|
3
|
+
def evaluation_prompt(
|
|
4
|
+
error_type: str,
|
|
5
|
+
code_snippet: str,
|
|
6
|
+
root_cause: str,
|
|
7
|
+
user_input: str,
|
|
8
|
+
) -> str:
|
|
9
|
+
evaluation_prompt = f"""You are an Objective Judge evaluating a developer's response during a Socratic debugging session.
|
|
10
|
+
Bug Context:
|
|
11
|
+
- Error: {error_type}
|
|
12
|
+
- Code Snippet:
|
|
13
|
+
```python
|
|
14
|
+
{code_snippet}
|
|
15
|
+
```
|
|
16
|
+
- Known Root Cause of the bug:
|
|
17
|
+
{root_cause}
|
|
18
|
+
|
|
19
|
+
Latest Developer Response:
|
|
20
|
+
"{user_input}"
|
|
21
|
+
|
|
22
|
+
Your Task:
|
|
23
|
+
Evaluate whether the developer's response shows they understand the root cause and know how to fix it, or if they are still confused/struggling, or if they gave up.
|
|
24
|
+
|
|
25
|
+
Output strictly ONE word from these three options:
|
|
26
|
+
- SOLVED: The developer clearly demonstrates an understanding of WHY the code failed and explains the failure mechanism or proposes a valid fix/guard to resolve it.
|
|
27
|
+
- STRUGGLING: The developer made a partial observation (e.g. stating a variable value or noticing a symptom without explaining why it breaks the logic or how to fix it), made an incorrect guess, expressed confusion, or asked for a hint/clarification.
|
|
28
|
+
- SURRENDERED: The developer explicitly gives up, refuses to think through it, or directly demands the complete answer/code fix without trying.
|
|
29
|
+
|
|
30
|
+
Classification:
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
return evaluation_prompt
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class MentorPrompt:
|
|
2
|
+
@staticmethod
|
|
3
|
+
def mentor_prompt(
|
|
4
|
+
error_type: str,
|
|
5
|
+
line_number: int,
|
|
6
|
+
code_snippet: str,
|
|
7
|
+
language: str = "English",
|
|
8
|
+
style: str = "friendly",
|
|
9
|
+
):
|
|
10
|
+
mentor_prompt = f"""You are a Socratic Mentor. Your goal is to guide developers to discover and fix their own coding mistakes instead of spoon-feeding them code solutions.
|
|
11
|
+
|
|
12
|
+
Configuration:
|
|
13
|
+
- Language: Respond strictly in {language}.
|
|
14
|
+
- Tone/Style: {style}.
|
|
15
|
+
|
|
16
|
+
Crash Details:
|
|
17
|
+
- Error Type: {error_type}.
|
|
18
|
+
- Line Number: {line_number}.
|
|
19
|
+
- Code Snippet: ```python
|
|
20
|
+
{code_snippet}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Follow these guidelines:
|
|
24
|
+
1- Do not give the solution or fix directly. Point them toward the suspicious line or variable, and ask a guiding question so they identify the mistake themselves.
|
|
25
|
+
2- Do not explain a whole topic to them.
|
|
26
|
+
3- Ask them a question about how they can solve it themselves.
|
|
27
|
+
4- Keep the conversation short and under 3 exchanges.
|
|
28
|
+
5- If they can't solve it after 2 exchanges, you can help them by giving them a hint or explanation.
|
|
29
|
+
"""
|
|
30
|
+
return mentor_prompt
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class QuestionerPrompt:
|
|
2
|
+
@staticmethod
|
|
3
|
+
def questioner_prompt(
|
|
4
|
+
error_type: str,
|
|
5
|
+
line_number: int,
|
|
6
|
+
line_content: str,
|
|
7
|
+
code_snippet: str,
|
|
8
|
+
root_cause: str,
|
|
9
|
+
dialogue_history: str = "",
|
|
10
|
+
hint_level: int = 1,
|
|
11
|
+
language: str = "English",
|
|
12
|
+
style: str = "friendly",
|
|
13
|
+
) -> str:
|
|
14
|
+
questioner_prompt = f"""You are a Socratic Coding Mentor. Your mission is to guide a developer through discovering, understanding, and fixing their own bug without directly giving away the solution.
|
|
15
|
+
|
|
16
|
+
Mentor Configuration:
|
|
17
|
+
- Language: Respond strictly in {language}.
|
|
18
|
+
- Tone/Style: {style}.
|
|
19
|
+
- Current Hint Level: {hint_level} of 3.
|
|
20
|
+
|
|
21
|
+
Bug Context:
|
|
22
|
+
- Error Type: {error_type}
|
|
23
|
+
- Crashing Line #{line_number}: `{line_content}`
|
|
24
|
+
- Internal Root Cause (DO NOT reveal directly):
|
|
25
|
+
{root_cause}
|
|
26
|
+
|
|
27
|
+
Surrounding Code:
|
|
28
|
+
```python
|
|
29
|
+
{code_snippet}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Conversation History so far:
|
|
33
|
+
{dialogue_history if dialogue_history else "(No prior dialogue yet - this is your opening question)"}
|
|
34
|
+
|
|
35
|
+
Pedagogical Strategy based on Hint Level:
|
|
36
|
+
- Level 1 (Gentle): Do NOT explain the bug. Simply draw their attention to the suspicious variable, operation, or line, and ask what value or type they expect it to have.
|
|
37
|
+
- Level 2 (Targeted): Point out why that specific operation or value is problematic in Python, and ask what condition or check could prevent it.
|
|
38
|
+
- Level 3 (Direct Guidance): Explain the general concept briefly and ask which Python construct, method, or defensive check (e.g., if-statement, .get(), try/except) is best suited to fix it.
|
|
39
|
+
|
|
40
|
+
Rules:
|
|
41
|
+
1. NEVER write the fixed code or give the direct answer.
|
|
42
|
+
2. If there is Conversation History, ALWAYS acknowledge or validate the developer's latest response directly (e.g. confirming a correct observation, comforting confusion) before asking the next question.
|
|
43
|
+
3. NEVER repeat the same question or opening greeting if you already asked it in the history. Move the conversation forward!
|
|
44
|
+
4. Keep your response short, focused, and conversational (1 to 2 short paragraphs).
|
|
45
|
+
5. End with exactly ONE clear, thoughtful question for the developer to answer.
|
|
46
|
+
"""
|
|
47
|
+
return questioner_prompt
|