From 9de7c86b87abd79890bf8ab581562794966e0748 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 10:40:58 +0200 Subject: [PATCH 01/10] trim logs from old tasks --- core/state/state_manager.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/state/state_manager.py b/core/state/state_manager.py index f1d246c9df..a9696aaa14 100644 --- a/core/state/state_manager.py +++ b/core/state/state_manager.py @@ -345,6 +345,27 @@ class StateManager: await state.delete_after() await session.commit() + # Process tasks before setting current state - trim logs from task descriptions before current task + if state.tasks and state.current_task: + try: + from core.cli.helpers import trim_logs + + # Find the current task index + current_task_index = state.tasks.index(state.current_task) + + # Trim logs from all tasks before the current task + for i in range(current_task_index): + task = state.tasks[i] + if task.get("description"): + task["description"] = trim_logs(task["description"]) + + # Flag tasks as modified so SQLAlchemy knows to save the changes + state.flag_tasks_as_modified() + except ValueError: + # Current task not found in tasks list - this shouldn't happen but handle gracefully + log.warning("Current task not found in tasks list, skipping log trimming") + pass + self.current_session = session self.current_state = state self.branch = state.branch From d1feec636c5126d215945b25e853126351beac7e Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 10:41:47 +0200 Subject: [PATCH 02/10] remove bloating log --- core/db/models/project_state.py | 1 - 1 file changed, 1 deletion(-) diff --git a/core/db/models/project_state.py b/core/db/models/project_state.py index f41af173f2..d1e341ae26 100644 --- a/core/db/models/project_state.py +++ b/core/db/models/project_state.py @@ -951,7 +951,6 @@ class ProjectState(Base): if task.get("status") == TaskStatus.SKIPPED else "Done", ] - log.debug(task_histories) last_task = {} From fef3dfbf987adb5c46c67b01910cc303c4b16642 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 10:42:44 +0200 Subject: [PATCH 03/10] ignore data folder in git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3129a8662b..3ece8cc1ed 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ dist/ workspace/ pilot-env/ venv/ +data/ .coverage *.code-workspace From 1b56f78d64007a904e35e664e300c201f0791917 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 11:34:55 +0200 Subject: [PATCH 04/10] when creating new quick implementation trim logs of old tasks --- core/agents/tech_lead.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index f5d4f1cca1..799a154a9e 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -7,6 +7,7 @@ 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, @@ -226,6 +227,14 @@ class TechLead(RelevantFilesMixin, BaseAgent): self.next_state.epics = wanted_project_state.epics + # Trim logs from existing tasks before adding the new task + if wanted_project_state.tasks: + # Trim logs from all existing tasks + for task in wanted_project_state.tasks: + if task.get("description"): + task["description"] = trim_logs(task["description"]) + + # Create tasks list with new task (after trimming logs from existing tasks) self.next_state.tasks = wanted_project_state.tasks + [ { "id": uuid4().hex, @@ -238,6 +247,9 @@ class TechLead(RelevantFilesMixin, BaseAgent): } ] + # Flag tasks as modified so SQLAlchemy knows to save the changes + self.next_state.flag_tasks_as_modified() + await self.ui.send_epics_and_tasks( self.next_state.current_epic.get("sub_epics", []), self.next_state.tasks, From ab2c68645f1cec48151e303e1e16e8cd20779a4c Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 11:41:39 +0200 Subject: [PATCH 05/10] add comment --- core/state/state_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/state/state_manager.py b/core/state/state_manager.py index a9696aaa14..1b5b5dcd43 100644 --- a/core/state/state_manager.py +++ b/core/state/state_manager.py @@ -348,6 +348,7 @@ 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 From 303bd83f929e30c26e9d6998b976d69d1e6bc0bd Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 17:33:42 +0200 Subject: [PATCH 06/10] resolve circular import --- core/agents/tech_lead.py | 2 +- core/cli/helpers.py | 31 +------------------------------ core/llm/base.py | 2 +- core/state/state_manager.py | 4 +--- core/utils/__init__.py | 1 + core/utils/text.py | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 core/utils/__init__.py create mode 100644 core/utils/text.py diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index 799a154a9e..a6dba0d85f 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -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__) diff --git a/core/cli/helpers.py b/core/cli/helpers.py index 7fa9e8677b..81b02a7969 100644 --- a/core/cli/helpers.py +++ b/core/cli/helpers.py @@ -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") diff --git a/core/llm/base.py b/core/llm/base.py index 791c70cffe..ddf92803f9 100644 --- a/core/llm/base.py +++ b/core/llm/base.py @@ -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") diff --git a/core/state/state_manager.py b/core/state/state_manager.py index 1b5b5dcd43..6c16b7cb5f 100644 --- a/core/state/state_manager.py +++ b/core/state/state_manager.py @@ -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) diff --git a/core/utils/__init__.py b/core/utils/__init__.py new file mode 100644 index 0000000000..be37f21c45 --- /dev/null +++ b/core/utils/__init__.py @@ -0,0 +1 @@ +# Utils module for common utility functions diff --git a/core/utils/text.py b/core/utils/text.py new file mode 100644 index 0000000000..e4c5ccb897 --- /dev/null +++ b/core/utils/text.py @@ -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 From 950e58ac9f8873ad93f3a438b48fe583d6a7c78c Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 17:42:42 +0200 Subject: [PATCH 07/10] add TODO --- core/state/state_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/state/state_manager.py b/core/state/state_manager.py index 6c16b7cb5f..ad713876bd 100644 --- a/core/state/state_manager.py +++ b/core/state/state_manager.py @@ -346,6 +346,8 @@ class StateManager: await state.delete_after() await session.commit() + # TODO: this is a temporary fix to unblock users! + # TODO: REMOVE THIS AFTER 1 WEEK FROM THIS COMMIT # Process tasks before setting current state - trim logs from task descriptions before current task if state.tasks and state.current_task: try: From 471b1b4e8542998a4239e686bf584645e96fa1d2 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 17:50:22 +0200 Subject: [PATCH 08/10] add extra safety try catch --- core/agents/tech_lead.py | 2 +- core/state/state_manager.py | 6 +++--- core/utils/text.py | 37 +++++++++++++++++++++++-------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index a6dba0d85f..fe4d497512 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -251,7 +251,7 @@ class TechLead(RelevantFilesMixin, BaseAgent): self.next_state.flag_tasks_as_modified() await self.ui.send_epics_and_tasks( - self.next_state.current_epic.get("sub_epics", []), + self.next_state.epics[-1].get("sub_epics", []), self.next_state.tasks, ) diff --git a/core/state/state_manager.py b/core/state/state_manager.py index ad713876bd..e19427cf6e 100644 --- a/core/state/state_manager.py +++ b/core/state/state_manager.py @@ -362,9 +362,9 @@ class StateManager: # Flag tasks as modified so SQLAlchemy knows to save the changes state.flag_tasks_as_modified() - except ValueError: - # Current task not found in tasks list - this shouldn't happen but handle gracefully - log.warning("Current task not found in tasks list, skipping log trimming") + except Exception as e: + # Handle any error during log trimming gracefully + log.warning(f"Error during log trimming: {e}, skipping log trimming") pass self.current_session = session diff --git a/core/utils/text.py b/core/utils/text.py index e4c5ccb897..e70a0d1867 100644 --- a/core/utils/text.py +++ b/core/utils/text.py @@ -13,21 +13,30 @@ def trim_logs(logs: str) -> str: :param logs: Log text to trim :return: Trimmed log text with the marker phrase removed """ - if not logs: - return "" + try: + if not logs: + return "" - # Define marker phrases - markers = ["Here are the backend logs", "Here are the frontend logs"] + # Ensure we have a string + if not isinstance(logs, str): + logs = str(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 + # Define marker phrases + markers = ["Here are the backend logs", "Here are the frontend logs"] - # If a marker was found, trim the string - if index != float("inf"): - return logs[:index] + # 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 - return logs + # If a marker was found, trim the string + if index != float("inf"): + return logs[:index] + + return logs + + except Exception: + # If anything goes wrong, return the original input as string or empty string + return str(logs) if logs is not None else "" From 35508f2f5dd895808225b4a0f8cf5f65978f306d Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 17:56:31 +0200 Subject: [PATCH 09/10] fix last epic completed state --- core/agents/tech_lead.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index fe4d497512..74b338558b 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -225,6 +225,7 @@ class TechLead(RelevantFilesMixin, BaseAgent): # load the previous state, because in this state we have deleted tasks due to epic being completed! wanted_project_state = await self.state_manager.get_project_state_by_id(self.current_state.prev_state_id) + wanted_project_state.epics[-1]["completed"] = False self.next_state.epics = wanted_project_state.epics # Trim logs from existing tasks before adding the new task From c6d1b80befff7b1b2e0a4189f531a92f9c2985cd Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Thu, 3 Jul 2025 18:14:29 +0200 Subject: [PATCH 10/10] flag epic as modified --- core/agents/tech_lead.py | 1 + 1 file changed, 1 insertion(+) diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index 74b338558b..7b84964db4 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -249,6 +249,7 @@ class TechLead(RelevantFilesMixin, BaseAgent): ] # Flag tasks as modified so SQLAlchemy knows to save the changes + self.next_state.flag_epics_as_modified() self.next_state.flag_tasks_as_modified() await self.ui.send_epics_and_tasks(