Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a new event for "modifiedFiles" which sends the list of modifie… #1085

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions core/agents/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ async def send_message(self, message: str):
"""
await self.ui.send_message(message + "\n", source=self.ui_source)

async def send_modified_files(self, files: dict[str, str, str]):
"""
Send modified files to the user.

Convenience method, uses `UIBase.send_modified_files()` to send the files,
setting the correct files.
:param files: Files to send.
"""
await self.ui.send_modified_files(files)

async def ask_question(
self,
question: str,
Expand Down
4 changes: 2 additions & 2 deletions core/agents/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def offline_changes_check(self):
"""

log.info("Checking for offline changes.")
modified_files = await self.state_manager.get_modified_files()
modified_files = await self.state_manager.get_modified_files_with_content()

if self.state_manager.workspace_is_empty():
# NOTE: this will currently get triggered on a new project, but will do
Expand All @@ -95,7 +95,7 @@ async def offline_changes_check(self):
await self.state_manager.restore_files()
elif modified_files:
await self.send_message(f"We found {len(modified_files)} new and/or modified files.")

await self.send_modified_files(modified_files)
hint = "".join(
[
"If you would like Pythagora to import those changes, click 'Yes'.\n",
Expand Down
43 changes: 43 additions & 0 deletions core/state/state_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,49 @@ async def get_modified_files(self) -> list[str]:

return modified_files

async def get_modified_files_with_content(self) -> list[dict]:
"""
Return a list of new or modified files from the file system,
including their paths, old content, and new content.

:return: List of dictionaries containing paths, old content,
and new content for new or modified files.
"""

modified_files = []
files_in_workspace = self.file_system.list()

for path in files_in_workspace:
content = self.file_system.read(path)
saved_file = self.current_state.get_file_by_path(path)

# If there's a saved file, serialize its content; otherwise, set it to None
saved_file_content = saved_file.content.content if saved_file else None
if saved_file_content == content:
continue

modified_files.append(
{
"path": path,
"file_old": saved_file_content, # Serialized content
"file_new": content,
}
)

# Handle files removed from disk
await self.current_state.awaitable_attrs.files
for db_file in self.current_state.files:
if db_file.path not in files_in_workspace:
modified_files.append(
{
"path": db_file.path,
"file_old": db_file.content.content, # Serialized content
"file_new": "", # Empty string as the file is removed
}
)

return modified_files

def workspace_is_empty(self) -> bool:
"""
Returns whether the workspace has any files in them or is empty.
Expand Down
11 changes: 11 additions & 0 deletions core/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ async def send_step_progress(
"""
raise NotImplementedError()

async def send_modified_files(
self,
modified_files: dict[str, str, str],
):
"""
Send a list of modified files to the UI.

:param modified_files: List of modified files.
"""
raise NotImplementedError()

async def send_run_command(self, run_command: str):
"""
Send a run command to the UI.
Expand Down
10 changes: 10 additions & 0 deletions core/ui/ipc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MessageType(str, Enum):
FEATURE_FINISHED = "featureFinished"
GENERATE_DIFF = "generateDiff"
CLOSE_DIFF = "closeDiff"
MODIFIED_FILES = "modifiedFiles"


class Message(BaseModel):
Expand Down Expand Up @@ -312,6 +313,15 @@ async def send_task_progress(
},
)

async def send_modified_files(
self,
modified_files: dict[str, str, str],
):
await self._send(
MessageType.MODIFIED_FILES,
content={"files": modified_files},
)

async def send_step_progress(
self,
index: int,
Expand Down
Binary file added pythagora.db-journal
Binary file not shown.
Loading