Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
Fix: Ensure UTF-8 encoding and ensure_ascii=False for remaining file/JSON operations
chtangwina2379a08ac54
diff --git a/nanobot/agent/tools/web.py b/nanobot/agent/tools/web.pyindex 9de1d3ce4..90cdda80b 100644--- a/nanobot/agent/tools/web.py+++ b/nanobot/agent/tools/web.py@@ -116,7 +116,7 @@ class WebFetchTool(Tool):# Validate URL before fetchingis_valid, error_msg = _validate_url(url)if not is_valid:- return json.dumps({"error": f"URL validation failed: {error_msg}", "url": url})+ return json.dumps({"error": f"URL validation failed: {error_msg}", "url": url}, ensure_ascii=False)try:async with httpx.AsyncClient(@@ -131,7 +131,7 @@ class WebFetchTool(Tool):# JSONif "application/json" in ctype:- text, extractor = json.dumps(r.json(), indent=2), "json"+ text, extractor = json.dumps(r.json(), indent=2, ensure_ascii=False), "json"# HTMLelif "text/html" in ctype or r.text[:256].lower().startswith(("<!doctype", "<html")):doc = Document(r.text)@@ -146,9 +146,9 @@ class WebFetchTool(Tool):text = text[:max_chars]return json.dumps({"url": url, "finalUrl": str(r.url), "status": r.status_code,- "extractor": extractor, "truncated": truncated, "length": len(text), "text": text})+ "extractor": extractor, "truncated": truncated, "length": len(text), "text": text}, ensure_ascii=False)except Exception as e:- return json.dumps({"error": str(e), "url": url})+ return json.dumps({"error": str(e), "url": url}, ensure_ascii=False)def _to_markdown(self, html: str) -> str:"""Convert HTML to markdown."""diff --git a/nanobot/channels/dingtalk.py b/nanobot/channels/dingtalk.pyindex 4a8cdd98a..6b27af44b 100644--- a/nanobot/channels/dingtalk.py+++ b/nanobot/channels/dingtalk.py@@ -208,7 +208,7 @@ class DingTalkChannel(BaseChannel):"msgParam": json.dumps({"text": msg.content,"title": "Nanobot Reply",- }),+ }, ensure_ascii=False),}if not self._http:diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.pyindex 2f4ba7b5c..d879d5806 100644--- a/nanobot/cli/commands.py+++ b/nanobot/cli/commands.py@@ -243,7 +243,7 @@ Information about the user goes here.for filename, content in templates.items():file_path = workspace / filenameif not file_path.exists():- file_path.write_text(content)+ file_path.write_text(content, encoding="utf-8")console.print(f" [dim]Created {filename}[/dim]")# Create memory directory and MEMORY.md@@ -266,12 +266,12 @@ This file stores important information that should persist across sessions.## Important Notes(Things to remember)-""")+""", encoding="utf-8")console.print(" [dim]Created memory/MEMORY.md[/dim]")history_file = memory_dir / "HISTORY.md"if not history_file.exists():- history_file.write_text("")+ history_file.write_text("", encoding="utf-8")console.print(" [dim]Created memory/HISTORY.md[/dim]")# Create skills directory for custom user skillsdiff --git a/nanobot/config/loader.py b/nanobot/config/loader.pyindex 134e95fe5..c789efdaf 100644--- a/nanobot/config/loader.py+++ b/nanobot/config/loader.py@@ -55,8 +55,8 @@ def save_config(config: Config, config_path: Path | None = None) -> None:data = config.model_dump(by_alias=True)- with open(path, "w") as f:- json.dump(data, f, indent=2)+ with open(path, "w", encoding="utf-8") as f:+ json.dump(data, f, indent=2, ensure_ascii=False)def _migrate_config(data: dict) -> dict:diff --git a/nanobot/heartbeat/service.py b/nanobot/heartbeat/service.pyindex 221ed27d9..a51e5a0f2 100644--- a/nanobot/heartbeat/service.py+++ b/nanobot/heartbeat/service.py@@ -65,7 +65,7 @@ class HeartbeatService:"""Read HEARTBEAT.md content."""if self.heartbeat_file.exists():try:- return self.heartbeat_file.read_text()+ return self.heartbeat_file.read_text(encoding="utf-8")except Exception:return Nonereturn None