feat(src): Resolve imports and create sloppy.py entry point

This commit is contained in:
2026-03-04 10:01:55 -05:00
parent a0276e0894
commit c102392320
44 changed files with 90 additions and 21 deletions

View File

@@ -12,16 +12,8 @@
- [ ] Task: Conductor - User Manual Verification 'Phase 2: Directory Restructuring & Migration' (Protocol in workflow.md)
## Phase 3: Entry Point & Import Resolution
- [ ] Task: Create `sloppy.py` Entry Point
- [ ] WHERE: Project root (`sloppy.py`)
- [ ] WHAT: Create the script to act as the primary launch point. It should import `App` from `src.gui_2` and pass CLI args.
- [ ] HOW: Write a standard Python script wrapper.
- [ ] SAFETY: Ensure it correctly propagates `sys.argv`.
- [ ] Task: Resolve Absolute and Relative Imports
- [ ] WHERE: `src/*.py`, `tests/*.py`, `simulation/*.py`
- [ ] WHAT: Update import statements. E.g., `import gui_2` becomes `from src import gui_2` or adjust `sys.path.append` in tests.
- [ ] HOW: Surgical string replacements. Ensure `pytest` can still find fixtures and test modules.
- [ ] SAFETY: Run `uv run pytest` to aggressively check for `ModuleNotFoundError`s.
- [x] Task: Create `sloppy.py` Entry Point
- [x] Task: Resolve Absolute and Relative Imports
- [ ] Task: Conductor - User Manual Verification 'Phase 3: Entry Point & Import Resolution' (Protocol in workflow.md)
## Phase 4: Final Validation & Documentation

View File

@@ -13,8 +13,10 @@ import asyncio
import os
import sys
# Add project root to sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
# Add project root and src/ to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, project_root)
sys.path.insert(0, os.path.join(project_root, "src"))
import mcp_client
import shell_runner

View File

@@ -7,8 +7,10 @@ import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
# Add project root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
# Add project root and src/ to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(project_root)
sys.path.append(os.path.join(project_root, "src"))
try:
import mcp_client

View File

@@ -2,8 +2,10 @@ import json
import sys
import os
# Add project root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
# Add project root and src/ to sys.path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(project_root)
sys.path.append(os.path.join(project_root, "src"))
try:
import mcp_client

20
scripts/update_paths.py Normal file
View File

@@ -0,0 +1,20 @@
import os
import glob
pattern = 'sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))'
replacement = pattern + '\nsys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))'
# Files to update
files = glob.glob("tests/*.py") + glob.glob("simulation/*.py") + glob.glob("scripts/*.py")
for file_path in files:
if not os.path.isfile(file_path):
continue
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
if pattern in content and replacement not in content:
print(f"Updating {file_path}")
new_content = content.replace(pattern, replacement)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)

View File

@@ -4,6 +4,7 @@ import time
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient
from simulation.user_agent import UserSimAgent

View File

@@ -5,8 +5,10 @@ from typing import Any, Optional
from api_hook_client import ApiHookClient
from simulation.workflow_sim import WorkflowSimulator
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
# Ensure project root and src/ are in path
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(project_root)
sys.path.append(os.path.join(project_root, "src"))
class BaseSimulation:
def __init__(self, client: ApiHookClient = None) -> None:

12
sloppy.py Normal file
View File

@@ -0,0 +1,12 @@
import sys
import os
# Add src to sys.path so we can import from it easily
project_root = os.path.dirname(os.path.abspath(__file__))
src_path = os.path.join(project_root, "src")
sys.path.insert(0, src_path)
from gui_2 import main
if __name__ == "__main__":
main()

View File

@@ -12,8 +12,9 @@ from pathlib import Path
from typing import Generator, Any
from unittest.mock import patch
# Ensure project root is in path for imports
# Ensure project root and src/ are in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import the App class after patching if necessary, but here we just need the type hint
from gui_2 import App
@@ -161,10 +162,10 @@ def app_instance() -> Generator[App, None, None]:
@pytest.fixture(scope="session")
def live_gui() -> Generator[tuple[subprocess.Popen, str], None, None]:
"""
Session-scoped fixture that starts gui_2.py with --enable-test-hooks.
Session-scoped fixture that starts sloppy.py with --enable-test-hooks.
Includes high-signal environment telemetry and workspace isolation.
"""
gui_script = os.path.abspath("gui_2.py")
gui_script = os.path.abspath("sloppy.py")
diag = VerificationLogger("live_gui_startup", "live_gui_diag")
diag.log_state("GUI Script", "N/A", "gui_2.py")

View File

@@ -4,6 +4,7 @@ from unittest.mock import patch, MagicMock
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
import ai_client

View File

@@ -4,6 +4,7 @@ import ai_client
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from ai_client import set_agent_tools, _build_anthropic_tools

View File

@@ -5,6 +5,7 @@ import os
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -5,6 +5,7 @@ from unittest.mock import patch
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -7,6 +7,7 @@ import os
# Add project root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import after path fix
from scripts.cli_tool_bridge import main

View File

@@ -7,6 +7,7 @@ import os
# Add project root to sys.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import after path fix
from scripts.cli_tool_bridge import main

View File

@@ -5,6 +5,7 @@ from typing import Any
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -5,6 +5,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
import ai_client
import project_manager

View File

@@ -6,6 +6,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient
from simulation.sim_context import ContextSimulation

View File

@@ -8,6 +8,7 @@ import os
# Ensure the project root is in sys.path to resolve imports correctly
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from gemini_cli_adapter import GeminiCliAdapter

View File

@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import the necessary functions from ai_client, including the reset helper
from ai_client import get_gemini_cache_stats, reset_session

View File

@@ -8,6 +8,7 @@ import sys
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient
# Define a temporary file path for callback testing

View File

@@ -5,6 +5,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -4,6 +4,7 @@ from typing import Any
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
def test_diagnostics_panel_initialization(app_instance: Any) -> None:

View File

@@ -5,6 +5,7 @@ from gui_2 import App
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
def test_gui_updates_on_event(app_instance: App) -> None:
app_instance.last_md = "mock_md"

View File

@@ -4,6 +4,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -4,6 +4,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -5,6 +5,7 @@ from typing import Any
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from gui_2 import App

View File

@@ -6,6 +6,7 @@ from pathlib import Path
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
# Import necessary modules from the project
import aggregate

View File

@@ -4,6 +4,7 @@ from unittest.mock import patch
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -5,6 +5,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from gui_2 import App

View File

@@ -5,6 +5,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -4,6 +4,7 @@ from unittest.mock import patch
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
import mcp_client

View File

@@ -4,6 +4,7 @@ import time
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from performance_monitor import PerformanceMonitor

View File

@@ -4,6 +4,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.sim_ai_settings import AISettingsSimulation

View File

@@ -4,6 +4,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.sim_base import BaseSimulation

View File

@@ -4,6 +4,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.sim_context import ContextSimulation

View File

@@ -4,6 +4,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.sim_execution import ExecutionSimulation

View File

@@ -4,6 +4,7 @@ import sys
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.sim_tools import ToolsSimulation

View File

@@ -6,6 +6,7 @@ from types import SimpleNamespace
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
import ai_client

View File

@@ -3,6 +3,7 @@ import os
# Ensure project root is in path for imports
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.user_agent import UserSimAgent

View File

@@ -5,6 +5,7 @@ import os
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -5,6 +5,7 @@ import os
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -4,6 +4,7 @@ import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from api_hook_client import ApiHookClient

View File

@@ -4,6 +4,7 @@ from unittest.mock import MagicMock
# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
from simulation.workflow_sim import WorkflowSimulator