mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-21 21:03:38 +08:00
fix: use UTF-8 for text file operations
This commit is contained in:
@@ -78,7 +78,7 @@ def execute_tool(name: str, args: dict) -> str:
|
||||
|
||||
if name == "read_file":
|
||||
try:
|
||||
return (WORKDIR / args["path"]).read_text()[:50000]
|
||||
return (WORKDIR / args["path"]).read_text(encoding="utf-8")[:50000]
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
@@ -86,7 +86,7 @@ def execute_tool(name: str, args: dict) -> str:
|
||||
try:
|
||||
p = WORKDIR / args["path"]
|
||||
p.parent.mkdir(parents=True, exist_ok=True)
|
||||
p.write_text(args["content"])
|
||||
p.write_text(args["content"], encoding="utf-8")
|
||||
return f"Wrote {len(args['content'])} bytes to {args['path']}"
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
@@ -190,7 +190,7 @@ def run_read_file(path: str, limit: int = None) -> str:
|
||||
- Output truncated to 50KB
|
||||
"""
|
||||
try:
|
||||
text = safe_path(path).read_text()
|
||||
text = safe_path(path).read_text(encoding="utf-8")
|
||||
lines = text.splitlines()
|
||||
|
||||
if limit and limit < len(lines):
|
||||
@@ -215,7 +215,7 @@ def run_write_file(path: str, content: str) -> str:
|
||||
try:
|
||||
fp = safe_path(path)
|
||||
fp.parent.mkdir(parents=True, exist_ok=True)
|
||||
fp.write_text(content)
|
||||
fp.write_text(content, encoding="utf-8")
|
||||
return f"Wrote {len(content)} bytes to {path}"
|
||||
|
||||
except Exception as e:
|
||||
@@ -233,13 +233,13 @@ def run_edit_file(path: str, old_text: str, new_text: str) -> str:
|
||||
"""
|
||||
try:
|
||||
fp = safe_path(path)
|
||||
content = fp.read_text()
|
||||
content = fp.read_text(encoding="utf-8")
|
||||
|
||||
if old_text not in content:
|
||||
return f"Error: Text not found in {path}"
|
||||
|
||||
new_content = content.replace(old_text, new_text, 1)
|
||||
fp.write_text(new_content)
|
||||
fp.write_text(new_content, encoding="utf-8")
|
||||
return f"Edited {path}"
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user