resolve circular import

This commit is contained in:
LeonOstrez
2025-07-03 17:33:42 +02:00
parent ab2c68645f
commit 303bd83f92
6 changed files with 38 additions and 35 deletions

View File

@@ -7,7 +7,6 @@ from core.agents.base import BaseAgent
from core.agents.convo import AgentConvo
from core.agents.mixins import RelevantFilesMixin
from core.agents.response import AgentResponse
from core.cli.helpers import trim_logs
from core.config import TECH_LEAD_EPIC_BREAKDOWN, TECH_LEAD_PLANNING
from core.config.actions import (
TL_CREATE_INITIAL_EPIC,
@@ -22,6 +21,7 @@ from core.log import get_logger
from core.telemetry import telemetry
from core.templates.registry import PROJECT_TEMPLATES
from core.ui.base import ProjectStage, pythagora_source, success_source
from core.utils.text import trim_logs
log = get_logger(__name__)

View File

@@ -45,6 +45,7 @@ from core.ui.base import AgentSource, UIBase, UISource
from core.ui.console import PlainConsoleUI
from core.ui.ipc_client import IPCClientUI
from core.ui.virtual import VirtualUI
from core.utils.text import trim_logs
log = get_logger(__name__)
@@ -433,36 +434,6 @@ def get_epic_task_number(state, current_task) -> (int, int):
return epic_num, task_num
def trim_logs(logs: str) -> str:
"""
Trim logs by removing everything after specific marker phrases.
This function cuts off the string at the first occurrence of
"Here are the backend logs" or "Here are the frontend logs".
:param logs: Log text to trim
:return: Trimmed log text with the marker phrase removed
"""
if not logs:
return ""
# Define marker phrases
markers = ["Here are the backend logs", "Here are the frontend logs"]
# Find the first occurrence of any marker
index = float("inf")
for marker in markers:
pos = logs.find(marker)
if pos != -1 and pos < index:
index = pos
# If a marker was found, trim the string
if index != float("inf"):
return logs[:index]
return logs
def get_source_for_history(msg_type: Optional[str] = "", question: Optional[str] = ""):
if question in [TL_EDIT_DEV_PLAN]:
return AgentSource("Tech Lead", "tech-lead")

View File

@@ -10,13 +10,13 @@ import httpx
import tiktoken
from httpx import AsyncClient
from core.cli.helpers import trim_logs
from core.config import LLMConfig, LLMProvider
from core.llm.convo import Convo
from core.llm.request_log import LLMRequestLog, LLMRequestStatus
from core.log import get_logger
from core.state.state_manager import StateManager
from core.ui.base import UIBase, pythagora_source
from core.utils.text import trim_logs
log = get_logger(__name__)
tokenizer = tiktoken.get_encoding("cl100k_base")

View File

@@ -36,6 +36,7 @@ from core.proc.exec_log import ExecLog as ExecLogData
from core.telemetry import telemetry
from core.ui.base import UIBase
from core.ui.base import UserInput as UserInputData
from core.utils.text import trim_logs
if TYPE_CHECKING:
from core.agents.base import BaseAgent
@@ -348,9 +349,6 @@ class StateManager:
# Process tasks before setting current state - trim logs from task descriptions before current task
if state.tasks and state.current_task:
try:
# import here to avoid circular import
from core.cli.helpers import trim_logs
# Find the current task index
current_task_index = state.tasks.index(state.current_task)

1
core/utils/__init__.py Normal file
View File

@@ -0,0 +1 @@
# Utils module for common utility functions

33
core/utils/text.py Normal file
View File

@@ -0,0 +1,33 @@
"""
Text processing utility functions.
"""
def trim_logs(logs: str) -> str:
"""
Trim logs by removing everything after specific marker phrases.
This function cuts off the string at the first occurrence of
"Here are the backend logs" or "Here are the frontend logs".
:param logs: Log text to trim
:return: Trimmed log text with the marker phrase removed
"""
if not logs:
return ""
# Define marker phrases
markers = ["Here are the backend logs", "Here are the frontend logs"]
# Find the first occurrence of any marker
index = float("inf")
for marker in markers:
pos = logs.find(marker)
if pos != -1 and pos < index:
index = pos
# If a marker was found, trim the string
if index != float("inf"):
return logs[:index]
return logs