Skip to content
Open
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
6 changes: 3 additions & 3 deletions cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def wrapper(*args, **kwargs):
func(*args, **kwargs)
timestamp, message_type, content = obj.messages[-1]
content = content.replace("\n", " ") # Replace newlines with spaces
with open(log_file, "a") as f:
with open(log_file, "a", encoding="utf-8") as f:
f.write(f"{timestamp} [{message_type}] {content}\n")
Comment on lines +767 to 768

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding the encoding is correct, I noticed that the logic for opening and writing to the log file is duplicated here and in save_tool_call_decorator (lines 778-779). Since you're modifying this code, it would be a good opportunity to refactor this into a single helper function to avoid code duplication and improve maintainability. For example:

def _append_to_log(log_line: str):
    with open(log_file, "a", encoding="utf-8") as f:
        f.write(log_line)

This helper could then be called from both save_message_decorator and save_tool_call_decorator.

return wrapper

Expand All @@ -775,7 +775,7 @@ def wrapper(*args, **kwargs):
func(*args, **kwargs)
timestamp, tool_name, args = obj.tool_calls[-1]
args_str = ", ".join(f"{k}={v}" for k, v in args.items())
with open(log_file, "a") as f:
with open(log_file, "a", encoding="utf-8") as f:
f.write(f"{timestamp} [Tool Call] {tool_name}({args_str})\n")
return wrapper

Expand All @@ -788,7 +788,7 @@ def wrapper(section_name, content):
content = obj.report_sections[section_name]
if content:
file_name = f"{section_name}.md"
with open(report_dir / file_name, "w") as f:
with open(report_dir / file_name, "w", encoding="utf-8") as f:
f.write(content)
return wrapper

Expand Down