Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 53 additions & 15 deletions codeframe/agents/backend_worker_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ def fetch_next_task(self) -> Optional[Dict[str, Any]]:
"""
cursor = self.db.conn.cursor()
# Get project_id from current_task context
project_id = getattr(self.current_task, 'project_id', None) if hasattr(self, 'current_task') and self.current_task else None
project_id = (
getattr(self.current_task, "project_id", None)
if hasattr(self, "current_task") and self.current_task
else None
)
if not project_id:
logger.warning("No current task context available, unable to fetch tasks")
return None
Expand Down Expand Up @@ -321,13 +325,15 @@ async def generate_code(self, context: Dict[str, Any]) -> Dict[str, Any]:
user_prompt_parts.append("Return JSON with the structure specified in the system prompt.")
user_prompt = "\n".join(user_prompt_parts)

logger.debug(f"Generating code for task {task.get('id', 'unknown')} (use_sdk={self.use_sdk})")
logger.debug(
f"Generating code for task {task.get('id', 'unknown')} (use_sdk={self.use_sdk})"
)

if self.use_sdk and self.sdk_client:
# SDK path - let SDK handle file operations via tools
response = await self.sdk_client.send_message([
{"role": "user", "content": user_prompt}
])
response = await self.sdk_client.send_message(
[{"role": "user", "content": user_prompt}]
)

# Parse JSON response from SDK
response_text = response.get("content", "{}")
Expand All @@ -337,7 +343,7 @@ async def generate_code(self, context: Dict[str, Any]) -> Dict[str, Any]:
# Fallback if SDK doesn't return JSON
result = {
"files": [],
"explanation": "SDK execution completed but no structured output returned"
"explanation": "SDK execution completed but no structured output returned",
}
else:
# Fallback to direct Anthropic API
Expand Down Expand Up @@ -526,7 +532,9 @@ async def _run_and_check_linting(self, task: Dict[str, Any], files_modified: Lis
total_errors = sum(r.error_count for r in lint_results)

# Format question with title and description combined
question = f"Linting failed: {total_errors} critical errors\n\n{blocker_description}"
question = (
f"Linting failed: {total_errors} critical errors\n\n{blocker_description}"
)

self.db.create_blocker(
agent_id=self.agent_id,
Expand All @@ -543,7 +551,11 @@ async def _run_and_check_linting(self, task: Dict[str, Any], files_modified: Lis
try:
from codeframe.ui.websocket_broadcasts import broadcast_to_project

project_id = task.get('project_id') or (self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None)
project_id = task.get("project_id") or (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_to_project(
self.ws_manager,
Expand All @@ -570,7 +582,11 @@ async def _run_and_check_linting(self, task: Dict[str, Any], files_modified: Lis
try:
from codeframe.ui.websocket_broadcasts import broadcast_to_project

project_id = task.get('project_id') or (self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None)
project_id = task.get("project_id") or (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_to_project(
self.ws_manager,
Expand Down Expand Up @@ -654,7 +670,11 @@ async def _run_and_record_tests(self, task_id: int) -> None:
)

# Broadcast test result
project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_test_result(
self.ws_manager,
Expand Down Expand Up @@ -817,7 +837,11 @@ async def _self_correction_loop(
try:
from codeframe.ui.websocket_broadcasts import broadcast_correction_attempt

project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_correction_attempt(
self.ws_manager,
Expand Down Expand Up @@ -945,7 +969,9 @@ async def _self_correction_loop(
question=question,
)
else:
logger.warning(f"Cannot create blocker for task {task_id}: project_id not found in task")
logger.warning(
f"Cannot create blocker for task {task_id}: project_id not found in task"
)

return False

Expand Down Expand Up @@ -1035,7 +1061,11 @@ async def execute_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
try:
from codeframe.ui.websocket_broadcasts import broadcast_activity_update

project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_activity_update(
self.ws_manager,
Expand Down Expand Up @@ -1122,7 +1152,11 @@ async def create_blocker(
blocker_task_id = task_id if task_id is not None else getattr(self, "current_task_id", None)

# Get project_id from current_task
project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if not project_id:
raise ValueError("Cannot create blocker without project context")

Expand Down Expand Up @@ -1250,7 +1284,11 @@ async def wait_for_blocker_resolution(
try:
from codeframe.ui.websocket_broadcasts import broadcast_agent_resumed

project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if project_id:
await broadcast_agent_resumed(
manager=self.ws_manager,
Expand Down
12 changes: 10 additions & 2 deletions codeframe/agents/frontend_worker_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ async def create_blocker(
)

# Get project_id from current_task
project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if not project_id:
raise RuntimeError(
"Project context required for blocker workflow. Agent must have current_task set."
Expand Down Expand Up @@ -727,7 +731,11 @@ async def wait_for_blocker_resolution(
)

# Get project_id from current_task
project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)
if not project_id:
raise RuntimeError(
"Project context required for blocker workflow. Agent must have current_task set."
Expand Down
8 changes: 6 additions & 2 deletions codeframe/agents/hybrid_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def _record_token_usage(self, task: Task, response: Dict[str, Any]) -> Non
return # No tokens to record

# Get project_id from task
project_id = task.project_id if hasattr(task, 'project_id') else None
project_id = task.project_id if hasattr(task, "project_id") else None
if not project_id:
logger.warning("Cannot record token usage without project context")
return
Expand Down Expand Up @@ -409,7 +409,11 @@ def get_session_info(self) -> Dict[str, Any]:
dict with agent and session details
"""
# Get project_id from current_task if available
project_id = self.current_task.project_id if hasattr(self, 'current_task') and self.current_task else None
project_id = (
self.current_task.project_id
if hasattr(self, "current_task") and self.current_task
else None
)

return {
"agent_id": self.agent_id,
Expand Down
Loading
Loading