Skip to content
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
4 changes: 2 additions & 2 deletions gateway/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _deliver_local(
lines.append("")
lines.append(content)

output_path.write_text("\n".join(lines))
output_path.write_text("\n".join(lines), encoding='utf-8')

return {
"path": str(output_path),
Expand All @@ -291,7 +291,7 @@ def _save_full_output(self, content: str, job_id: str) -> Path:
out_dir = get_hermes_home() / "cron" / "output"
out_dir.mkdir(parents=True, exist_ok=True)
path = out_dir / f"{job_id}_{timestamp}.txt"
path.write_text(content)
path.write_text(content, encoding='utf-8')
return path

def _filter_silence_narration_enabled(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion gateway/platforms/qqbot/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ def _write_update_response(answer: str, operator: str = "") -> None:
home = get_hermes_home()
response_path = home / ".update_response"
tmp = response_path.with_suffix(".tmp")
tmp.write_text(answer)
tmp.write_text(answer, encoding='utf-8')
tmp.replace(response_path)
logger.info(
"QQ update prompt answered %r by %s",
Expand Down
38 changes: 19 additions & 19 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,7 @@ def _voice_key(self, platform: Platform, chat_id: str) -> str:

def _load_voice_modes(self) -> Dict[str, str]:
try:
data = json.loads(self._VOICE_MODE_PATH.read_text())
data = json.loads(self._VOICE_MODE_PATH.read_text(encoding='utf-8'))
except (FileNotFoundError, json.JSONDecodeError, OSError):
return {}

Expand Down Expand Up @@ -2889,7 +2889,7 @@ def _save_voice_modes(self) -> None:
try:
self._VOICE_MODE_PATH.parent.mkdir(parents=True, exist_ok=True)
self._VOICE_MODE_PATH.write_text(
json.dumps(self._voice_mode, indent=2)
json.dumps(self._voice_mode, indent=2), encoding='utf-8'
)
except OSError as e:
logger.warning("Failed to save voice modes: %s", e)
Expand Down Expand Up @@ -4813,7 +4813,7 @@ def _increment_restart_failure_counts(self, active_session_keys: set) -> None:

path = _hermes_home / self._STUCK_LOOP_FILE
try:
counts = json.loads(path.read_text()) if path.exists() else {}
counts = json.loads(path.read_text(encoding='utf-8')) if path.exists() else {}
except Exception:
counts = {}

Expand Down Expand Up @@ -4843,7 +4843,7 @@ def _suspend_stuck_loop_sessions(self) -> int:
return 0

try:
counts = json.loads(path.read_text())
counts = json.loads(path.read_text(encoding='utf-8'))
except Exception:
return 0

Expand Down Expand Up @@ -4889,7 +4889,7 @@ def _clear_restart_failure_count(self, session_key: str) -> None:
if not path.exists():
return
try:
counts = json.loads(path.read_text())
counts = json.loads(path.read_text(encoding='utf-8'))
if session_key in counts:
del counts[session_key]
if counts:
Expand Down Expand Up @@ -7417,7 +7417,7 @@ async def _handle_message(self, event: MessageEvent) -> Optional[str]:
prompt_path = _hermes_home / ".update_prompt.json"
try:
tmp = response_path.with_suffix(".tmp")
tmp.write_text(response_text)
tmp.write_text(response_text, encoding='utf-8')
tmp.replace(response_path)
prompt_path.unlink(missing_ok=True)
except OSError as e:
Expand All @@ -7437,7 +7437,7 @@ async def _handle_message(self, event: MessageEvent) -> Optional[str]:
prompt_path = _hermes_home / ".update_prompt.json"
try:
tmp = response_path.with_suffix(".tmp")
tmp.write_text("")
tmp.write_text("", encoding='utf-8')
tmp.replace(response_path)
prompt_path.unlink(missing_ok=True)
logger.info(
Expand Down Expand Up @@ -10408,7 +10408,7 @@ def _is_stale_restart_redelivery(self, event: MessageEvent) -> bool:
marker_path = _hermes_home / ".restart_last_processed.json"
if not marker_path.exists():
return False
data = json.loads(marker_path.read_text())
data = json.loads(marker_path.read_text(encoding='utf-8'))
except Exception:
return False

Expand Down Expand Up @@ -12239,7 +12239,7 @@ async def _watch_update_progress(
for path in (claimed_path, pending_path):
if path.exists():
try:
pending = json.loads(path.read_text())
pending = json.loads(path.read_text(encoding='utf-8'))
platform_str = pending.get("platform")
chat_id = pending.get("chat_id")
chat_type = pending.get("chat_type")
Expand Down Expand Up @@ -12278,7 +12278,7 @@ async def _watch_update_progress(
return
await asyncio.sleep(poll_interval)
if (pending_path.exists() or claimed_path.exists()) and not exit_code_path.exists():
exit_code_path.write_text("124")
exit_code_path.write_text("124", encoding='utf-8')
await self._send_update_notification()
return

Expand Down Expand Up @@ -12320,7 +12320,7 @@ async def _flush_buffer() -> None:
# Read any remaining output
if output_path.exists():
try:
content = output_path.read_text()
content = output_path.read_text(encoding='utf-8')
if len(content) > bytes_sent:
buffer += content[bytes_sent:]
bytes_sent = len(content)
Expand All @@ -12330,7 +12330,7 @@ async def _flush_buffer() -> None:

# Send final status
try:
exit_code_raw = exit_code_path.read_text().strip() or "1"
exit_code_raw = exit_code_path.read_text(encoding='utf-8').strip() or "1"
exit_code = int(exit_code_raw)
if exit_code == 0:
await adapter.send(
Expand Down Expand Up @@ -12359,7 +12359,7 @@ async def _flush_buffer() -> None:
# Check for new output
if output_path.exists():
try:
content = output_path.read_text()
content = output_path.read_text(encoding='utf-8')
if len(content) > bytes_sent:
buffer += content[bytes_sent:]
bytes_sent = len(content)
Expand All @@ -12377,7 +12377,7 @@ async def _flush_buffer() -> None:
if (prompt_path.exists() and session_key
and not self._update_prompt_pending.get(session_key)):
try:
prompt_data = json.loads(prompt_path.read_text())
prompt_data = json.loads(prompt_path.read_text(encoding='utf-8'))
prompt_text = prompt_data.get("prompt", "")
default = prompt_data.get("default", "")
if prompt_text:
Expand Down Expand Up @@ -12425,7 +12425,7 @@ async def _flush_buffer() -> None:
# Timeout
if not exit_code_path.exists():
logger.warning("Update watcher timed out after %.0fs", timeout)
exit_code_path.write_text("124")
exit_code_path.write_text("124", encoding='utf-8')
await _flush_buffer()
try:
await adapter.send(
Expand Down Expand Up @@ -12471,7 +12471,7 @@ async def _send_update_notification(self) -> bool:
elif not claimed_path.exists():
return True

pending = json.loads(claimed_path.read_text())
pending = json.loads(claimed_path.read_text(encoding='utf-8'))
platform_str = pending.get("platform")
chat_id = pending.get("chat_id")
chat_type = pending.get("chat_type")
Expand All @@ -12485,13 +12485,13 @@ async def _send_update_notification(self) -> bool:
claimed_path.replace(pending_path)
return False

exit_code_raw = exit_code_path.read_text().strip() or "1"
exit_code_raw = exit_code_path.read_text(encoding='utf-8').strip() or "1"
exit_code = int(exit_code_raw)

# Read the captured update output
output = ""
if output_path.exists():
output = output_path.read_text()
output = output_path.read_text(encoding='utf-8')

# Resolve adapter
platform = Platform(platform_str)
Expand Down Expand Up @@ -12566,7 +12566,7 @@ async def _send_restart_notification(self) -> Optional[tuple[str, str, Optional[
return None

try:
data = json.loads(notify_path.read_text())
data = json.loads(notify_path.read_text(encoding='utf-8'))
platform_str = data.get("platform")
chat_id = data.get("chat_id")
chat_type = data.get("chat_type")
Expand Down
2 changes: 1 addition & 1 deletion gateway/slash_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3945,7 +3945,7 @@ async def _handle_update_command(self, event: MessageEvent) -> str:
if event.message_id:
pending["message_id"] = event.message_id
_tmp_pending = pending_path.with_suffix(".tmp")
_tmp_pending.write_text(json.dumps(pending))
_tmp_pending.write_text(json.dumps(pending), encoding='utf-8')
_tmp_pending.replace(pending_path)
exit_code_path.unlink(missing_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion gateway/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _read_pid_record(pid_path: Optional[Path] = None) -> Optional[dict]:
return None

try:
raw = pid_path.read_text().strip()
raw = pid_path.read_text(encoding='utf-8').strip()
except (OSError, UnicodeDecodeError):
# File was deleted between exists() and read_text(), permission
# flipped, or it holds non-UTF-8 / binary garbage.
Expand Down