socratic-debug 0.0.5__tar.gz → 0.0.7__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.
Files changed (58) hide show
  1. {socratic_debug-0.0.5/socratic_debug.egg-info → socratic_debug-0.0.7}/PKG-INFO +5 -4
  2. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/README.md +3 -3
  3. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/pyproject.toml +2 -1
  4. {socratic_debug-0.0.5 → socratic_debug-0.0.7/socratic_debug.egg-info}/PKG-INFO +5 -4
  5. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic_debug.egg-info/SOURCES.txt +5 -0
  6. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic_debug.egg-info/requires.txt +1 -0
  7. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/nodes/human_input_node.py +6 -0
  8. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/nodes/questioner_node.py +6 -0
  9. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/nodes/solution_node.py +6 -0
  10. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/runner.py +11 -0
  11. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/state/state.py +3 -0
  12. socratic_debug-0.0.7/src/db/connection.py +64 -0
  13. socratic_debug-0.0.7/src/db/detector.py +49 -0
  14. socratic_debug-0.0.7/src/db/migrator.py +56 -0
  15. socratic_debug-0.0.7/src/db/models.py +27 -0
  16. socratic_debug-0.0.7/src/db/service.py +76 -0
  17. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/events.py +9 -0
  18. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/utils/config_template.py +4 -0
  19. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/watcher.py +12 -0
  20. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/app.py +65 -1
  21. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/settings_drawer.py +29 -0
  22. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/styles.py +2 -2
  23. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/translations.py +8 -0
  24. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/LICENSE +0 -0
  25. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/setup.cfg +0 -0
  26. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic.py +0 -0
  27. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic_debug.egg-info/dependency_links.txt +0 -0
  28. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic_debug.egg-info/entry_points.txt +0 -0
  29. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/socratic_debug.egg-info/top_level.txt +0 -0
  30. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/__init__.py +0 -0
  31. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/graph/graph.py +0 -0
  32. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/llm/factory.py +0 -0
  33. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/llm/invoker.py +0 -0
  34. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/llm/providers/__init__.py +0 -0
  35. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/llm/providers/ollama.py +0 -0
  36. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/llm/providers/openrouter.py +0 -0
  37. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/nodes/diagnose_node.py +0 -0
  38. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/nodes/evaluate_node.py +0 -0
  39. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/prompts/diagnose_prompt.py +0 -0
  40. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/prompts/evaluation_prompt.py +0 -0
  41. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/prompts/mentor_prompt.py +0 -0
  42. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/prompts/questioner_prompt.py +0 -0
  43. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/agent/prompts/solution_prompt.py +0 -0
  44. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/cli.py +0 -0
  45. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/extractor.py +0 -0
  46. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/hook.py +0 -0
  47. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/utils/config_creator.py +0 -0
  48. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/utils/config_manager.py +0 -0
  49. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/utils/config_watcher.py +0 -0
  50. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/src/utils/read_yaml.py +0 -0
  51. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/test/test_hook.py +0 -0
  52. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/__init__.py +0 -0
  53. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/adapter.py +0 -0
  54. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/bidi.py +0 -0
  55. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/console.py +0 -0
  56. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/templates.py +0 -0
  57. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/views.py +0 -0
  58. {socratic_debug-0.0.5 → socratic_debug-0.0.7}/ui/window.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: socratic-debug
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: Autonomous pedagogical debugging mentor powered by LangGraph, Rich, and LangSmith
5
5
  Author: Mohamed Elawakey
6
6
  Requires-Python: >=3.10
@@ -13,6 +13,7 @@ Requires-Dist: langgraph>=1.2.0
13
13
  Requires-Dist: langchain>=1.4.0
14
14
  Requires-Dist: langchain-ollama>=1.1.0
15
15
  Requires-Dist: langchain-openrouter>=0.2.0
16
+ Requires-Dist: sqlalchemy>=2.0.0
16
17
  Dynamic: license-file
17
18
 
18
19
  # 🧠 Socratic Debug (`socratic`)
@@ -34,11 +35,11 @@ Dynamic: license-file
34
35
  ---
35
36
 
36
37
  <p align="center">
37
- <a href="test/test_hook.py">
38
- <img src="assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
38
+ <a href="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png">
39
+ <img src="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
39
40
  </a>
40
41
  <br />
41
- <sub>⚡ <em>Interactive debugging session generated live from <a href="test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
42
+ <sub>⚡ <em>Interactive debugging session generated live from <a href="https://github.com/mohamedelawakey/socratic/blob/main/test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
42
43
  </p>
43
44
 
44
45
  ---
@@ -17,11 +17,11 @@
17
17
  ---
18
18
 
19
19
  <p align="center">
20
- <a href="test/test_hook.py">
21
- <img src="assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
20
+ <a href="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png">
21
+ <img src="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
22
22
  </a>
23
23
  <br />
24
- <sub>⚡ <em>Interactive debugging session generated live from <a href="test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
24
+ <sub>⚡ <em>Interactive debugging session generated live from <a href="https://github.com/mohamedelawakey/socratic/blob/main/test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
25
25
  </p>
26
26
 
27
27
  ---
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "socratic-debug"
7
- version = "0.0.5"
7
+ version = "0.0.7"
8
8
  description = "Autonomous pedagogical debugging mentor powered by LangGraph, Rich, and LangSmith"
9
9
  authors = [{ name = "Mohamed Elawakey" }]
10
10
  readme = "README.md"
@@ -17,6 +17,7 @@ dependencies = [
17
17
  "langchain>=1.4.0",
18
18
  "langchain-ollama>=1.1.0",
19
19
  "langchain-openrouter>=0.2.0",
20
+ "sqlalchemy>=2.0.0",
20
21
  ]
21
22
 
22
23
  [project.scripts]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: socratic-debug
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: Autonomous pedagogical debugging mentor powered by LangGraph, Rich, and LangSmith
5
5
  Author: Mohamed Elawakey
6
6
  Requires-Python: >=3.10
@@ -13,6 +13,7 @@ Requires-Dist: langgraph>=1.2.0
13
13
  Requires-Dist: langchain>=1.4.0
14
14
  Requires-Dist: langchain-ollama>=1.1.0
15
15
  Requires-Dist: langchain-openrouter>=0.2.0
16
+ Requires-Dist: sqlalchemy>=2.0.0
16
17
  Dynamic: license-file
17
18
 
18
19
  # 🧠 Socratic Debug (`socratic`)
@@ -34,11 +35,11 @@ Dynamic: license-file
34
35
  ---
35
36
 
36
37
  <p align="center">
37
- <a href="test/test_hook.py">
38
- <img src="assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
38
+ <a href="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png">
39
+ <img src="https://raw.githubusercontent.com/mohamedelawakey/socratic/main/assets/socratic_ui_demo.png" alt="Socratic Debug Interactive Desktop UI" width="900" style="border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);" />
39
40
  </a>
40
41
  <br />
41
- <sub>⚡ <em>Interactive debugging session generated live from <a href="test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
42
+ <sub>⚡ <em>Interactive debugging session generated live from <a href="https://github.com/mohamedelawakey/socratic/blob/main/test/test_hook.py"><code>test/test_hook.py</code></a></em></sub>
42
43
  </p>
43
44
 
44
45
  ---
@@ -32,6 +32,11 @@ src/agent/prompts/mentor_prompt.py
32
32
  src/agent/prompts/questioner_prompt.py
33
33
  src/agent/prompts/solution_prompt.py
34
34
  src/agent/state/state.py
35
+ src/db/connection.py
36
+ src/db/detector.py
37
+ src/db/migrator.py
38
+ src/db/models.py
39
+ src/db/service.py
35
40
  src/utils/config_creator.py
36
41
  src/utils/config_manager.py
37
42
  src/utils/config_template.py
@@ -5,3 +5,4 @@ langgraph>=1.2.0
5
5
  langchain>=1.4.0
6
6
  langchain-ollama>=1.1.0
7
7
  langchain-openrouter>=0.2.0
8
+ sqlalchemy>=2.0.0
@@ -7,6 +7,12 @@ class HumanInputNode:
7
7
  def human_input_node(state: SocraticAgentState) -> dict:
8
8
  user_input = EventBus.request_user_input()
9
9
 
10
+ # Increment dialogue turns count in database
11
+ event_id = state.get("event_id")
12
+ if event_id:
13
+ from src.db.service import MetricsService
14
+ MetricsService.increment_dialogue_turns(event_id)
15
+
10
16
  history = list(state.get("dialogue_history", []))
11
17
  history.append({"role": "student", "content": user_input})
12
18
 
@@ -36,6 +36,12 @@ class QuestionerNode:
36
36
 
37
37
  response = LLMInvoker.invoke_with_retry(prompt)
38
38
 
39
+ # Update hint level metric in database
40
+ event_id = state.get("event_id")
41
+ if event_id:
42
+ from src.db.service import MetricsService
43
+ MetricsService.update_hint_level(event_id, current_hint)
44
+
39
45
  EventBus.emit_mentor_message(
40
46
  content=response.content,
41
47
  hint_level=current_hint,
@@ -27,6 +27,12 @@ class SolutionNode:
27
27
 
28
28
  response = LLMInvoker.invoke_with_retry(prompt)
29
29
 
30
+ # Mark error event as resolved in database
31
+ event_id = state.get("event_id")
32
+ if event_id:
33
+ from src.db.service import MetricsService
34
+ MetricsService.record_error_resolved(event_id)
35
+
30
36
  EventBus.emit_solution(response.content)
31
37
 
32
38
  history = list(state.get("dialogue_history", []))
@@ -1,9 +1,19 @@
1
1
  from src.extractor import extract_crash_context
2
2
  from src.agent.graph.graph import SocraticGraph
3
+ from src.db.service import MetricsService
3
4
 
4
5
  def run_socratic_agent(exception_type, exception_value, exception_traceback):
5
6
  context = extract_crash_context(exception_traceback, exception_value)
6
7
 
8
+ # 1. Record error crash event in local database (metrics tracking)
9
+ event_id = MetricsService.record_error_start(
10
+ error_type=exception_type.__name__,
11
+ error_message=str(exception_value),
12
+ file_path=context["file_path"],
13
+ )
14
+ from src.events import EventBus
15
+ EventBus.set_active_event_id(event_id)
16
+
7
17
  initial_state = {
8
18
  "file_path": context["file_path"],
9
19
  "function_name": context["function_name"],
@@ -12,6 +22,7 @@ def run_socratic_agent(exception_type, exception_value, exception_traceback):
12
22
  "code_snippet": context["code_snippet"],
13
23
  "error_type": exception_type.__name__,
14
24
  "error_name": str(exception_value),
25
+ "event_id": event_id,
15
26
  "root_cause": "",
16
27
  "dialogue_history": [],
17
28
  "is_solved": False,
@@ -11,6 +11,9 @@ class SocraticAgentState(TypedDict):
11
11
  error_type: str
12
12
  error_name: str
13
13
 
14
+ # Metrics Event Tracking ID (UUID in database)
15
+ event_id: Optional[str]
16
+
14
17
  # root cause of the problem
15
18
  root_cause: str
16
19
 
@@ -0,0 +1,64 @@
1
+ from pathlib import Path
2
+ from sqlalchemy import create_engine
3
+ from sqlalchemy.orm import sessionmaker
4
+ from src.db.models import Base
5
+ from src.utils.read_yaml import ReadYaml
6
+
7
+
8
+ def get_default_db_path() -> str:
9
+ # Try user home ~/.socratic, fallback to local workspace .socratic/ if home is read-only
10
+ try:
11
+ socratic_dir = Path.home() / ".socratic"
12
+ socratic_dir.mkdir(parents=True, exist_ok=True)
13
+ return str(socratic_dir / "socratic.db")
14
+ except (OSError, PermissionError):
15
+ local_dir = Path(".socratic")
16
+ local_dir.mkdir(parents=True, exist_ok=True)
17
+ return str(local_dir / "socratic.db")
18
+
19
+
20
+ def get_database_url() -> str:
21
+ try:
22
+ config = ReadYaml.read_yaml()
23
+ db_type = str(config.get("database_type", "sqlite")).lower().strip()
24
+ db_url = config.get("database_url")
25
+
26
+ # If explicit full URL provided, use it directly
27
+ if db_url and str(db_url).strip():
28
+ return str(db_url).strip()
29
+
30
+ # If user picked a type other than sqlite but didn't write full url, provide smart default localhost URL
31
+ if db_type == "postgresql":
32
+ return "postgresql://postgres:postgres@localhost:5432/socratic"
33
+ elif db_type in ["mysql", "mariadb"]:
34
+ return "mysql+pymysql://root:root@localhost:3306/socratic"
35
+ elif db_type in ["mssql", "sqlserver"]:
36
+ return "mssql+pyodbc://sa:YourPassword123@localhost:1433/socratic?driver=ODBC+Driver+17+for+SQL+Server"
37
+ elif db_type == "oracle":
38
+ return "oracle+oracledb://system:oracle@localhost:1521/socratic"
39
+ except Exception:
40
+ pass
41
+
42
+ db_path = get_default_db_path()
43
+ return f"sqlite:///{db_path}"
44
+
45
+
46
+ DATABASE_URL = get_database_url()
47
+ engine = create_engine(DATABASE_URL, echo=False)
48
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
49
+
50
+
51
+ def init_db():
52
+ Base.metadata.create_all(bind=engine)
53
+
54
+ # Check if target is not default sqlite, perform auto-migration if needed
55
+ try:
56
+ from src.utils.read_yaml import ReadYaml
57
+ config = ReadYaml.read_yaml()
58
+ target_url = config.get("database_url")
59
+ default_sqlite = f"sqlite:///{get_default_db_path()}"
60
+ if target_url and target_url.strip() != default_sqlite.strip():
61
+ from src.db.migrator import DatabaseMigrator
62
+ DatabaseMigrator.migrate_sqlite_to_target(target_url)
63
+ except Exception:
64
+ pass
@@ -0,0 +1,49 @@
1
+ import socket
2
+ from typing import List, Dict
3
+
4
+
5
+ class DatabaseDetector:
6
+ KNOWN_SERVICES = [
7
+ {"name": "PostgreSQL", "port": 5432, "default_scheme": "postgresql", "driver": "psycopg2"},
8
+ {"name": "MySQL", "port": 3306, "default_scheme": "mysql+pymysql", "driver": "pymysql"},
9
+ {"name": "MariaDB", "port": 3307, "default_scheme": "mariadb+pymysql", "driver": "pymysql"},
10
+ {"name": "SQL Server", "port": 1433, "default_scheme": "mssql+pyodbc", "driver": "pyodbc"},
11
+ {"name": "Oracle Database", "port": 1521, "default_scheme": "oracle+oracledb", "driver": "oracledb"},
12
+ {"name": "DuckDB", "port": 0, "default_scheme": "duckdb", "driver": "duckdb"},
13
+ {"name": "CockroachDB", "port": 26257, "default_scheme": "cockroachdb+psycopg2", "driver": "psycopg2"},
14
+ ]
15
+
16
+ @staticmethod
17
+ def is_port_open(host: str, port: int, timeout: float = 0.4) -> bool:
18
+ try:
19
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
20
+ sock.settimeout(timeout)
21
+ return sock.connect_ex((host, port)) == 0
22
+ except (OSError, socket.error):
23
+ return False
24
+
25
+ @classmethod
26
+ def detect_available_databases(cls) -> List[Dict[str, str]]:
27
+ detected = []
28
+
29
+ # Always include default SQLite
30
+ detected.append({
31
+ "engine": "sqlite",
32
+ "name": "SQLite (Default Local)",
33
+ "port": 0,
34
+ "is_running": True,
35
+ "url_template": "sqlite:///$HOME/.socratic/socratic.db"
36
+ })
37
+
38
+ for s in cls.KNOWN_SERVICES:
39
+ if cls.is_port_open("127.0.0.1", s["port"]):
40
+ detected.append({
41
+ "engine": s["default_scheme"].split("+")[0],
42
+ "name": s["name"],
43
+ "port": s["port"],
44
+ "is_running": True,
45
+ "url_template": f"{s['default_scheme']}://user:password@localhost:{s['port']}/socratic"
46
+ })
47
+
48
+ return detected
49
+
@@ -0,0 +1,56 @@
1
+ from sqlalchemy import create_engine
2
+ from sqlalchemy.orm import sessionmaker
3
+ from src.db.models import Base, ErrorEvent
4
+ from src.db.connection import get_default_db_path
5
+
6
+
7
+ class DatabaseMigrator:
8
+ @staticmethod
9
+ def migrate_sqlite_to_target(target_db_url: str) -> int:
10
+ sqlite_path = get_default_db_path()
11
+ sqlite_url = f"sqlite:///{sqlite_path}"
12
+
13
+ if target_db_url.strip() == sqlite_url.strip():
14
+ return 0
15
+
16
+ # Source SQLite session
17
+ src_engine = create_engine(sqlite_url, echo=False)
18
+ SrcSession = sessionmaker(bind=src_engine)
19
+ src_session = SrcSession()
20
+
21
+ # Target DB session & table initialization
22
+ target_engine = create_engine(target_db_url, echo=False)
23
+ Base.metadata.create_all(bind=target_engine)
24
+ TargetSession = sessionmaker(bind=target_engine)
25
+ target_session = TargetSession()
26
+
27
+ migrated_count = 0
28
+ try:
29
+ records = src_session.query(ErrorEvent).all()
30
+ for r in records:
31
+ # Check if already present in target DB
32
+ existing = target_session.query(ErrorEvent).filter(ErrorEvent.id == r.id).first()
33
+ if not existing:
34
+ new_item = ErrorEvent(
35
+ id=r.id,
36
+ error_type=r.error_type,
37
+ error_message=r.error_message,
38
+ file_name=r.file_name,
39
+ project_name=r.project_name,
40
+ started_at=r.started_at,
41
+ resolved_at=r.resolved_at,
42
+ duration_seconds=r.duration_seconds,
43
+ hints_used=r.hints_used,
44
+ dialogue_turns=r.dialogue_turns,
45
+ status=r.status,
46
+ )
47
+ target_session.add(new_item)
48
+ migrated_count += 1
49
+
50
+ if migrated_count > 0:
51
+ target_session.commit()
52
+ return migrated_count
53
+ finally:
54
+ src_session.close()
55
+ target_session.close()
56
+
@@ -0,0 +1,27 @@
1
+ import uuid
2
+ from datetime import datetime
3
+ from sqlalchemy import Column, Integer, String, DateTime
4
+ from sqlalchemy.orm import declarative_base
5
+
6
+ Base = declarative_base()
7
+
8
+
9
+ class ErrorEvent(Base):
10
+ __tablename__ = "error_events"
11
+
12
+ id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
13
+ error_type = Column(String(100), nullable=False)
14
+ error_message = Column(String(500), nullable=True)
15
+ file_name = Column(String(255), nullable=True)
16
+ project_name = Column(String(255), nullable=True)
17
+
18
+ started_at = Column(DateTime, default=datetime.utcnow, nullable=False)
19
+ resolved_at = Column(DateTime, nullable=True)
20
+ duration_seconds = Column(Integer, nullable=True)
21
+
22
+ hints_used = Column(Integer, default=1, nullable=False)
23
+ dialogue_turns = Column(Integer, default=0, nullable=False)
24
+ status = Column(String(50), default="unsolved", nullable=False)
25
+
26
+ def __repr__(self):
27
+ return f"<ErrorEvent(id='{self.id}', type='{self.error_type}', status='{self.status}')>"
@@ -0,0 +1,76 @@
1
+ import os
2
+ from datetime import datetime
3
+ from src.db.connection import SessionLocal, init_db
4
+ from src.db.models import ErrorEvent
5
+
6
+ # Ensure tables exist
7
+ init_db()
8
+
9
+
10
+ class MetricsService:
11
+ @staticmethod
12
+ def record_error_start(error_type: str, error_message: str, file_path: str) -> str:
13
+ session = SessionLocal()
14
+ try:
15
+ file_name = os.path.basename(file_path) if file_path else "unknown"
16
+ project_name = os.path.basename(os.path.dirname(os.path.abspath(file_path))) if file_path else "unknown"
17
+
18
+ event = ErrorEvent(
19
+ error_type=error_type,
20
+ error_message=str(error_message)[:500] if error_message else "",
21
+ file_name=file_name,
22
+ project_name=project_name,
23
+ started_at=datetime.utcnow(),
24
+ status="unsolved",
25
+ )
26
+ session.add(event)
27
+ session.commit()
28
+ session.refresh(event)
29
+ return event.id
30
+ finally:
31
+ session.close()
32
+
33
+ @staticmethod
34
+ def record_error_resolved(event_id: str):
35
+ if not event_id:
36
+ return
37
+
38
+ session = SessionLocal()
39
+ try:
40
+ event = session.query(ErrorEvent).filter(ErrorEvent.id == event_id).first()
41
+ if event:
42
+ now = datetime.utcnow()
43
+ event.resolved_at = now
44
+ event.duration_seconds = int((now - event.started_at).total_seconds())
45
+ event.status = "solved"
46
+ session.commit()
47
+ finally:
48
+ session.close()
49
+
50
+ @staticmethod
51
+ def update_hint_level(event_id: str, hint_level: int):
52
+ if not event_id:
53
+ return
54
+
55
+ session = SessionLocal()
56
+ try:
57
+ event = session.query(ErrorEvent).filter(ErrorEvent.id == event_id).first()
58
+ if event and hint_level > event.hints_used:
59
+ event.hints_used = hint_level
60
+ session.commit()
61
+ finally:
62
+ session.close()
63
+
64
+ @staticmethod
65
+ def increment_dialogue_turns(event_id: str):
66
+ if not event_id:
67
+ return
68
+
69
+ session = SessionLocal()
70
+ try:
71
+ event = session.query(ErrorEvent).filter(ErrorEvent.id == event_id).first()
72
+ if event:
73
+ event.dialogue_turns += 1
74
+ session.commit()
75
+ finally:
76
+ session.close()
@@ -9,8 +9,17 @@ class EventBus:
9
9
  _on_solution: Optional[Callable[[str], None]] = None
10
10
  _on_crash: Optional[Callable[[Dict[str, Any], Any, Any, Any], None]] = None
11
11
  _on_llm_error: Optional[Callable[[str], None]] = None
12
+ _active_event_id: Optional[str] = None
12
13
  _is_session_cancelled: bool = False
13
14
 
15
+ @classmethod
16
+ def set_active_event_id(cls, event_id: str):
17
+ cls._active_event_id = event_id
18
+
19
+ @classmethod
20
+ def get_active_event_id(cls) -> Optional[str]:
21
+ return cls._active_event_id
22
+
14
23
  @classmethod
15
24
  def emit_session_cancelled(cls):
16
25
  cls._is_session_cancelled = True
@@ -14,6 +14,10 @@ api_key: "your_api_key"
14
14
  socratic_language: "English"
15
15
  socratic_style: "friendly"
16
16
 
17
+ # Metrics & Database (defaults to "sqlite", or "postgresql", "mysql", "mssql", "oracle")
18
+ database_type: "sqlite"
19
+ database_url: ""
20
+
17
21
  # Observability
18
22
  LANGSMITH_TRACING: "true"
19
23
  LANGSMITH_API_KEY: "your_langsmith_api_key"
@@ -61,6 +61,12 @@ class FileMonitor(threading.Thread):
61
61
 
62
62
  # Scenario A: Clean execution with zero errors
63
63
  if res.returncode == 0:
64
+ from src.events import EventBus
65
+ from src.db.service import MetricsService
66
+ active_id = EventBus.get_active_event_id()
67
+ if active_id:
68
+ MetricsService.record_error_resolved(active_id)
69
+
64
70
  self.on_solved_callback()
65
71
  self.running = False
66
72
  break
@@ -72,6 +78,12 @@ class FileMonitor(threading.Thread):
72
78
  # Scenario B: Target error is resolved and code progresses past it
73
79
  if self.target_error and self.target_error not in res.stderr:
74
80
  # Ensure it's not a generic failure before the target error
81
+ from src.events import EventBus
82
+ from src.db.service import MetricsService
83
+ active_id = EventBus.get_active_event_id()
84
+ if active_id:
85
+ MetricsService.record_error_resolved(active_id)
86
+
75
87
  self.on_solved_callback()
76
88
  self.running = False
77
89
  break
@@ -7,7 +7,7 @@ try:
7
7
  QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
8
8
  QTextEdit, QLineEdit, QPushButton, QLabel, QFrame
9
9
  )
10
- from PyQt6.QtCore import Qt, pyqtSignal, QObject
10
+ from PyQt6.QtCore import Qt, pyqtSignal, QObject, QTimer, QPropertyAnimation, QPoint
11
11
  from PyQt6.QtGui import QTextCursor
12
12
 
13
13
  HAS_PYQT = True
@@ -123,6 +123,12 @@ class SocraticWindow(QMainWindow):
123
123
  header_label = QLabel(self.translations["header_title"], self)
124
124
  header_label.setObjectName("headerTitle")
125
125
 
126
+ self.dashboard_btn = QPushButton(self.translations.get("dashboard_btn", "📊 Dashboard"), self)
127
+ self.dashboard_btn.setObjectName("dashboardButton")
128
+ if Qt is not None:
129
+ self.dashboard_btn.setCursor(Qt.CursorShape.PointingHandCursor)
130
+ self.dashboard_btn.clicked.connect(self._on_dashboard_clicked)
131
+
126
132
  self.settings_btn = QPushButton(self.translations.get("settings_btn", "⚙️ Settings"), self)
127
133
  self.settings_btn.setObjectName("settingsButton")
128
134
  if Qt is not None:
@@ -135,6 +141,7 @@ class SocraticWindow(QMainWindow):
135
141
 
136
142
  top_bar.addWidget(header_label)
137
143
  top_bar.addStretch()
144
+ top_bar.addWidget(self.dashboard_btn)
138
145
  top_bar.addWidget(self.settings_btn)
139
146
  top_bar.addWidget(self.status_badge)
140
147
  main_layout.addLayout(top_bar)
@@ -206,6 +213,63 @@ class SocraticWindow(QMainWindow):
206
213
  else:
207
214
  self._open_settings_drawer()
208
215
 
216
+ def _on_dashboard_clicked(self):
217
+ # Toast Notification popup in the corner that automatically fades out
218
+ self._show_toast(self.translations.get("dashboard_coming_soon", "🚀 Learning Curve Dashboard is coming soon in the next release!"))
219
+
220
+ def _show_toast(self, message: str, duration_ms: int = 4000):
221
+ # Safely hide/remove previous toast if it still exists in C++ Qt memory
222
+ old_toast = getattr(self, "_toast_frame", None)
223
+ if old_toast is not None:
224
+ try:
225
+ old_toast.hide()
226
+ old_toast.deleteLater()
227
+ except RuntimeError:
228
+ pass
229
+ self._toast_frame = None
230
+
231
+ self._toast_frame = QFrame(self)
232
+ self._toast_frame.setStyleSheet("""
233
+ QFrame {
234
+ background-color: #1f242c;
235
+ border: 1px solid #388bfd;
236
+ border-radius: 8px;
237
+ }
238
+ QLabel {
239
+ color: #58a6ff;
240
+ font-size: 13px;
241
+ font-weight: 600;
242
+ background-color: transparent;
243
+ }
244
+ """)
245
+ toast_layout = QHBoxLayout(self._toast_frame)
246
+ toast_layout.setContentsMargins(16, 10, 16, 10)
247
+
248
+ lbl = QLabel(message, self._toast_frame)
249
+ toast_layout.addWidget(lbl)
250
+
251
+ self._toast_frame.adjustSize()
252
+ # Position in top-right corner of the window
253
+ margin_x = 24
254
+ margin_y = 60
255
+ pos_x = max(10, self.width() - self._toast_frame.width() - margin_x)
256
+ self._toast_frame.move(pos_x, margin_y)
257
+ self._toast_frame.show()
258
+ self._toast_frame.raise_()
259
+
260
+ # Auto-hide timer that safely removes reference
261
+ def _cleanup():
262
+ toast = getattr(self, "_toast_frame", None)
263
+ if toast is not None:
264
+ try:
265
+ toast.hide()
266
+ toast.deleteLater()
267
+ except RuntimeError:
268
+ pass
269
+ self._toast_frame = None
270
+
271
+ QTimer.singleShot(duration_ms, _cleanup)
272
+
209
273
  def _open_settings_drawer(self):
210
274
  self.settings_drawer.load_settings()
211
275
  self.settings_drawer.show()
@@ -169,6 +169,26 @@ class SettingsDrawer(QFrame):
169
169
  self.style_combo.addItems(["friendly", "academic", "concise"])
170
170
  form_layout.addWidget(self.style_combo)
171
171
 
172
+ # Separator line
173
+ sep0 = QFrame()
174
+ sep0.setFrameShape(QFrame.Shape.HLine)
175
+ sep0.setStyleSheet("color: #30363d; margin: 8px 0;")
176
+ form_layout.addWidget(sep0)
177
+
178
+ # Database Engine Selection
179
+ form_layout.addWidget(self._make_label(self.translations.get("database_type_label", "Database Engine:")))
180
+ self.database_type_combo = QComboBox(form_widget)
181
+ self.database_type_combo.setProperty("class", "settingsCombo")
182
+ self.database_type_combo.addItems(["sqlite", "postgresql", "mysql", "mariadb", "mssql", "oracle", "duckdb", "cockroachdb"])
183
+ form_layout.addWidget(self.database_type_combo)
184
+
185
+ # Database Custom URL
186
+ form_layout.addWidget(self._make_label(self.translations.get("database_url_label", "Database URL (Optional):")))
187
+ self.database_url_edit = QLineEdit(form_widget)
188
+ self.database_url_edit.setProperty("class", "settingsInput")
189
+ self.database_url_edit.setPlaceholderText("sqlite:///$HOME/.socratic/socratic.db")
190
+ form_layout.addWidget(self.database_url_edit)
191
+
172
192
  # Separator line
173
193
  sep = QFrame()
174
194
  sep.setFrameShape(QFrame.Shape.HLine)
@@ -244,6 +264,13 @@ class SettingsDrawer(QFrame):
244
264
  if idx >= 0:
245
265
  self.style_combo.setCurrentIndex(idx)
246
266
 
267
+ # Database Engine & URL
268
+ db_type = str(cfg.get("database_type", "sqlite")).lower()
269
+ idx = self.database_type_combo.findText(db_type, Qt.MatchFlag.MatchFixedString)
270
+ if idx >= 0:
271
+ self.database_type_combo.setCurrentIndex(idx)
272
+ self.database_url_edit.setText(str(cfg.get("database_url", "")))
273
+
247
274
  tracing = str(cfg.get("LANGSMITH_TRACING", "true")).lower()
248
275
  idx = self.tracing_combo.findText(tracing, Qt.MatchFlag.MatchFixedString)
249
276
  if idx >= 0:
@@ -260,6 +287,8 @@ class SettingsDrawer(QFrame):
260
287
  "api_key": self.api_key_field.get_value(),
261
288
  "socratic_language": self.language_combo.currentText().strip(),
262
289
  "socratic_style": self.style_combo.currentText().strip(),
290
+ "database_type": self.database_type_combo.currentText().strip(),
291
+ "database_url": self.database_url_edit.text().strip(),
263
292
  "LANGSMITH_TRACING": self.tracing_combo.currentText().strip(),
264
293
  "LANGSMITH_API_KEY": self.langsmith_key_field.get_value(),
265
294
  "LANGSMITH_PROJECT": self.langsmith_project_edit.text().strip(),
@@ -60,7 +60,7 @@ SOCRATIC_DARK_THEME = """
60
60
  padding: 4px 10px;
61
61
  border-radius: 4px;
62
62
  }
63
- QPushButton#settingsButton {
63
+ QPushButton#settingsButton, QPushButton#dashboardButton {
64
64
  background-color: transparent;
65
65
  color: #8b949e;
66
66
  border: 1px solid #30363d;
@@ -69,7 +69,7 @@ SOCRATIC_DARK_THEME = """
69
69
  font-size: 13px;
70
70
  font-weight: 500;
71
71
  }
72
- QPushButton#settingsButton:hover {
72
+ QPushButton#settingsButton:hover, QPushButton#dashboardButton:hover {
73
73
  background-color: #21262d;
74
74
  color: #58a6ff;
75
75
  border-color: #58a6ff;
@@ -16,6 +16,8 @@ TRANSLATIONS = {
16
16
  "live_solved_msg": "🎉 عاش يا بطل! لقطت إنك عدلت الكود واشتغل بنجاح والمشكلة اتحلت خلاص!",
17
17
  "live_retry_msg": "👀 لقطت تعديلك على الكود، بس لسه فيه خطأ بيظهر. راجع التعديل وفكر في النقطة اللي اتكلمنا فيها!",
18
18
  "close_btn": "إنهاء الجلسة",
19
+ "dashboard_btn": "📊 لوحة التعلم",
20
+ "dashboard_coming_soon": "🚀 ميزة لوحة التعلم (Learning Dashboard) قادمة قريباً في التحديث القادم!",
19
21
  "settings_btn": "⚙️ الإعدادات",
20
22
  "settings_title": "⚙️ إعدادات سُقراط",
21
23
  "settings_desc": "تعديل مزود الذكاء الاصطناعي والمفاتيح السرية بسهولة",
@@ -28,6 +30,8 @@ TRANSLATIONS = {
28
30
  "langsmith_project_label": "مشروع LangSmith:",
29
31
  "language_label": "لغة المحاور:",
30
32
  "style_label": "أسلوب الشرح:",
33
+ "database_type_label": "نوع قاعدة البيانات (Database):",
34
+ "database_url_label": "رابط الاتصال (Database URL - اختياري):",
31
35
  "save_settings_btn": "💾 حفظ الإعدادات",
32
36
  "settings_saved_msg": "✔ تم حفظ الإعدادات بنجاح!",
33
37
  "settings_save_error": "❌ حدث خطأ أثناء الحفظ",
@@ -53,6 +57,8 @@ TRANSLATIONS = {
53
57
  "live_solved_msg": "🎉 Awesome! Detected your code change and the script executed successfully with no errors!",
54
58
  "live_retry_msg": "👀 Detected your code change, but an error is still occurring. Review the change and keep thinking!",
55
59
  "close_btn": "Close Session",
60
+ "dashboard_btn": "📊 Dashboard",
61
+ "dashboard_coming_soon": "🚀 Learning Curve Dashboard is coming soon in the next release!",
56
62
  "settings_btn": "⚙️ Settings",
57
63
  "settings_title": "⚙️ Socratic Settings",
58
64
  "settings_desc": "Configure LLM provider and API secrets",
@@ -65,6 +71,8 @@ TRANSLATIONS = {
65
71
  "langsmith_project_label": "LangSmith Project:",
66
72
  "language_label": "Mentor Language:",
67
73
  "style_label": "Mentor Style:",
74
+ "database_type_label": "Database Engine:",
75
+ "database_url_label": "Database URL (Optional):",
68
76
  "save_settings_btn": "💾 Save Settings",
69
77
  "settings_saved_msg": "✔ Settings saved successfully!",
70
78
  "settings_save_error": "❌ Error saving settings",
File without changes
File without changes