fix(reporting): remove a previous run's sections when a report is saved to the same folder (#1566)

- write_report_tree deletes the section files and HTML page this run did not write; other files in the folder are kept
This commit is contained in:
Yijia-Xiao
2026-10-27 07:59:26 +00:00
parent 2717033ad8
commit 21bc5d8fe7
2 changed files with 56 additions and 0 deletions
+16
View File
@@ -96,6 +96,8 @@ def write_report_tree(final_state: dict, ticker: str, save_path, settings: dict
``settings`` (``TradingAgentsGraph.run_settings()``) adds what produced the run
to the report's header. ``html`` also writes ``complete_report.html``, one
self-contained page of the same report (#1419).
Reusing a directory replaces the generated report files, removing sections
absent from this run and disabled HTML. Other files and directories are kept.
"""
save_path = Path(save_path)
save_path.mkdir(parents=True, exist_ok=True)
@@ -117,4 +119,18 @@ def write_report_tree(final_state: dict, ticker: str, save_path, settings: dict
(save_path / "complete_report.html").write_text(
render_report(ticker, final_state, settings, parts), encoding="utf-8"
)
else:
(save_path / "complete_report.html").unlink(missing_ok=True)
# Reconcile only the filenames owned by this writer; never clear the tree,
# since callers may keep notes or other artifacts alongside the reports.
current_files = {
(folder, filename)
for _heading, folder, written in parts
for _agent, filename, _text in written
}
for _heading, folder, agents in _SECTIONS:
for _agent, filename, _path in agents:
if (folder, filename) not in current_files:
(save_path / folder / filename).unlink(missing_ok=True)
return save_path / "complete_report.md"