Skip to content

Commit

Permalink
Handle missing relevant_files.
Browse files Browse the repository at this point in the history
  • Loading branch information
gperetin authored and senko committed Jun 4, 2024
1 parent cbc03f5 commit c124502
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/agents/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ async def run(self) -> AgentResponse:
log.debug(f"Some files are missing descriptions: {', '.join(missing_descriptions)}, reqesting analysis")
return AgentResponse.describe_files(self)

log.debug(f"Current state files: {len(self.current_state.files)}, relevant {self.current_state.relevant_files}")
log.debug(
f"Current state files: {len(self.current_state.files)}, relevant {self.current_state.relevant_files or []}"
)
# Check which files are relevant to the current task
if self.current_state.files and not self.current_state.relevant_files:
if self.current_state.files and self.current_state.relevant_files is None:
await self.get_relevant_files()
return AgentResponse.done(self)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Make relevant_files nullable
Revision ID: f352dbe45751
Revises: 0a1bb637fa26
Create Date: 2024-06-04 15:07:40.175466
"""

from typing import Sequence, Union

from alembic import op
from sqlalchemy.dialects import sqlite

# revision identifiers, used by Alembic.
revision: str = "f352dbe45751"
down_revision: Union[str, None] = "0a1bb637fa26"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("project_states", schema=None) as batch_op:
batch_op.alter_column("relevant_files", existing_type=sqlite.JSON(), nullable=True)

# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table("project_states", schema=None) as batch_op:
batch_op.alter_column("relevant_files", existing_type=sqlite.JSON(), nullable=False)

# ### end Alembic commands ###
7 changes: 5 additions & 2 deletions core/db/models/project_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ProjectState(Base):
tasks: Mapped[list[dict]] = mapped_column(default=list)
steps: Mapped[list[dict]] = mapped_column(default=list)
iterations: Mapped[list[dict]] = mapped_column(default=list)
relevant_files: Mapped[list[str]] = mapped_column(default=list)
relevant_files: Mapped[Optional[list[str]]] = mapped_column(default=None)
modified_files: Mapped[dict] = mapped_column(default=dict)
run_command: Mapped[Optional[str]] = mapped_column()
action: Mapped[Optional[str]] = mapped_column()
Expand Down Expand Up @@ -167,7 +167,8 @@ def relevant_file_objects(self):
:return: List of tuples with file path and content.
"""
return [file for file in self.files if file.path in self.relevant_files]
relevant = self.relevant_files or []
return [file for file in self.files if file.path in relevant]

@staticmethod
def create_initial_state(branch: "Branch") -> "ProjectState":
Expand Down Expand Up @@ -361,6 +362,8 @@ def save_file(self, path: str, content: "FileContent", external: bool = False) -

if path not in self.modified_files and not external:
self.modified_files[path] = original_content

self.relevant_files = self.relevant_files or []
if path not in self.relevant_files:
self.relevant_files.append(path)

Expand Down
4 changes: 2 additions & 2 deletions tests/db/test_project_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ async def test_create_next_deep_copies_fields(testdb):
next_state.tasks[0]["completed"] = True
next_state.iterations[0]["completed"] = True
next_state.steps[0]["completed"] = True
next_state.relevant_files.append("test.txt")
next_state.relevant_files = ["test.txt"]
next_state.modified_files["test.txt"] = "Hello World"

assert state.epics[0]["completed"] is False
assert state.tasks[0]["completed"] is False
assert state.iterations[0]["completed"] is False
assert state.steps[0]["completed"] is False
assert state.relevant_files == []
assert state.relevant_files is None
assert state.modified_files == {}


Expand Down

0 comments on commit c124502

Please sign in to comment.