Skip to content

Commit f610510

Browse files
added a new event for "modifiedFiles" which sends the list of modified files on project load
1 parent 5e87a47 commit f610510

File tree

6 files changed

+72
-2
lines changed

6 files changed

+72
-2
lines changed

core/agents/base.py

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ async def send_message(self, message: str):
6161
"""
6262
await self.ui.send_message(message + "\n", source=self.ui_source)
6363

64+
async def send_modified_files(self, files: dict[str, str, str]):
65+
"""
66+
Send modified files to the user.
67+
68+
Convenience method, uses `UIBase.send_modified_files()` to send the files,
69+
setting the correct files.
70+
:param files: Files to send.
71+
"""
72+
await self.ui.send_modified_files(files)
73+
6474
async def ask_question(
6575
self,
6676
question: str,

core/agents/orchestrator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def offline_changes_check(self):
8686
"""
8787

8888
log.info("Checking for offline changes.")
89-
modified_files = await self.state_manager.get_modified_files()
89+
modified_files = await self.state_manager.get_modified_files_with_content()
9090

9191
if self.state_manager.workspace_is_empty():
9292
# NOTE: this will currently get triggered on a new project, but will do
@@ -95,7 +95,7 @@ async def offline_changes_check(self):
9595
await self.state_manager.restore_files()
9696
elif modified_files:
9797
await self.send_message(f"We found {len(modified_files)} new and/or modified files.")
98-
98+
await self.send_modified_files(modified_files)
9999
hint = "".join(
100100
[
101101
"If you would like Pythagora to import those changes, click 'Yes'.\n",

core/state/state_manager.py

+40
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,47 @@ async def get_modified_files(self) -> list[str]:
495495
modified_files.append(db_file.path)
496496

497497
return modified_files
498+
499+
async def get_modified_files_with_content(self) -> list[dict]:
500+
"""
501+
Return a list of new or modified files from the file system,
502+
including their paths, old content, and new content.
503+
504+
:return: List of dictionaries containing paths, old content,
505+
and new content for new or modified files.
506+
"""
507+
508+
modified_files = []
509+
files_in_workspace = self.file_system.list()
510+
511+
for path in files_in_workspace:
512+
content = self.file_system.read(path)
513+
saved_file = self.current_state.get_file_by_path(path)
498514

515+
# If there's a saved file, serialize its content; otherwise, set it to None
516+
saved_file_content = saved_file.content.content if saved_file else None
517+
518+
if saved_file_content == content:
519+
continue
520+
521+
modified_files.append({
522+
"path": path,
523+
"file_old": saved_file_content, # Serialized content
524+
"file_new": content
525+
})
526+
527+
# Handle files removed from disk
528+
await self.current_state.awaitable_attrs.files
529+
for db_file in self.current_state.files:
530+
if db_file.path not in files_in_workspace:
531+
modified_files.append({
532+
"path": db_file.path,
533+
"file_old": db_file.content.content, # Serialized content
534+
"file_new": "" # Empty string as the file is removed
535+
})
536+
537+
return modified_files
538+
499539
def workspace_is_empty(self) -> bool:
500540
"""
501541
Returns whether the workspace has any files in them or is empty.

core/ui/base.py

+9
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,16 @@ async def send_step_progress(
230230
:param task_source: Source of the task, one of: 'app', 'feature', 'debugger', 'troubleshooting', 'review'.
231231
"""
232232
raise NotImplementedError()
233+
async def send_modified_files(
234+
self,
235+
modified_files: dict[str, str,str],
236+
):
237+
"""
238+
Send a list of modified files to the UI.
233239
240+
:param modified_files: List of modified files.
241+
"""
242+
raise NotImplementedError()
234243
async def send_run_command(self, run_command: str):
235244
"""
236245
Send a run command to the UI.

core/ui/ipc_client.py

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class MessageType(str, Enum):
4444
FEATURE_FINISHED = "featureFinished"
4545
GENERATE_DIFF = "generateDiff"
4646
CLOSE_DIFF = "closeDiff"
47+
MODIFIED_FILES = "modifiedFiles"
4748

4849

4950
class Message(BaseModel):
@@ -311,6 +312,16 @@ async def send_task_progress(
311312
"all_tasks": tasks,
312313
},
313314
)
315+
async def send_modified_files(
316+
self,
317+
modified_files: dict[str, str, str],
318+
):
319+
await self._send(
320+
MessageType.MODIFIED_FILES,
321+
content={
322+
"files": modified_files
323+
},
324+
)
314325

315326
async def send_step_progress(
316327
self,

pythagora.db-journal

44.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)