refactor: remove GiteaTools facade, use focused tool classes directly

- Removed gitea/tools/gitea_tools.py (useless facade layer)
- Removed tests/test_gitea_tools.py (tests for removed facade)
- Updated core/dispatcher.py to use IssueTools, PRTools, FileTools, GitTools directly
- Updated core/orchestrator.py to use individual tool instances
- Updated main.py to create individual tool instances

This eliminates the triple layer of indirection (Issue 2.2 from bad_code.md)
where GiteaTools just delegated to IssueTools/PRTools/etc with zero added value.
This commit is contained in:
meeks
2026-07-16 13:15:18 +02:00
parent 26d69707c6
commit 9b63fbbcfc
5 changed files with 522 additions and 496 deletions
+30 -11
View File
@@ -7,7 +7,10 @@ from pathlib import Path
from dotenv import load_dotenv
from gitea.client import GiteaClient
from gitea.tools.gitea_tools import GiteaTools
from gitea.tools.issue_tools import IssueTools
from gitea.tools.pr_tools import PRTools
from gitea.tools.file_tools import FileTools
from gitea.tools.git_tools import GitTools
from gitea.config import AGENT_MODEL_ID, AGENT_MAX_RETRIES
from core.orchestrator import AgentOrchestrator
@@ -38,12 +41,11 @@ file_handler = RotatingFileHandler(LOG_FILE, maxBytes=5 * 1024 * 1024, backupCou
file_handler.setFormatter(JSONFormatter())
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))
logging.basicConfig(
level=logging.INFO,
handlers=[file_handler, stream_handler]
stream_handler.setFormatter(
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
)
logging.basicConfig(level=logging.INFO, handlers=[file_handler, stream_handler])
logger: logging.Logger = logging.getLogger("coding-agent")
@@ -64,14 +66,27 @@ async def main() -> None:
raise RuntimeError("No authenticated user found.")
logger.info(f"Authenticated as user: {user.login}")
except Exception as e:
logger.critical(f"Critical initialization error: No authenticated user found. {e}")
logger.critical(
f"Critical initialization error: No authenticated user found. {e}"
)
raise SystemExit(1)
tools: GiteaTools = GiteaTools(client)
issue_tools: IssueTools = IssueTools(client)
pr_tools: PRTools = PRTools(client)
file_tools: FileTools = FileTools(client)
git_tools: GitTools = GitTools(client)
model_name: str = AGENT_MODEL_ID
# Initialize orchestrator
orchestrator: AgentOrchestrator = AgentOrchestrator(client, tools, model_name, AGENT_MAX_RETRIES)
orchestrator: AgentOrchestrator = AgentOrchestrator(
client,
issue_tools,
pr_tools,
file_tools,
git_tools,
model_name,
AGENT_MAX_RETRIES,
)
logger.info("--- Autonomous Coding Agent Active ---")
logger.info(f"Model: {model_name}")
@@ -100,11 +115,15 @@ async def main() -> None:
break
except Exception as e:
consecutive_errors += 1
logger.error(f"Error in main loop (attempt {consecutive_errors}/{max_consecutive_errors}): {e}")
logger.error(
f"Error in main loop (attempt {consecutive_errors}/{max_consecutive_errors}): {e}"
)
# If too many consecutive errors, wait longer
if consecutive_errors >= max_consecutive_errors:
logger.error(f"Too many consecutive errors ({max_consecutive_errors}). Waiting 5 minutes before retry.")
logger.error(
f"Too many consecutive errors ({max_consecutive_errors}). Waiting 5 minutes before retry."
)
await asyncio.sleep(300)
consecutive_errors = 0
else: