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:
@@ -142,7 +142,7 @@ def execute(name: str, args: dict) -> str:
|
||||
|
||||
if name == "read_file":
|
||||
try:
|
||||
return safe_path(args["path"]).read_text()[:50000]
|
||||
return safe_path(args["path"]).read_text(encoding="utf-8")[:50000]
|
||||
except Exception as e:
|
||||
return f"Error: {{e}}"
|
||||
|
||||
@@ -150,7 +150,7 @@ def execute(name: str, args: dict) -> str:
|
||||
try:
|
||||
p = safe_path(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}}"
|
||||
@@ -158,10 +158,13 @@ def execute(name: str, args: dict) -> str:
|
||||
if name == "edit_file":
|
||||
try:
|
||||
p = safe_path(args["path"])
|
||||
content = p.read_text()
|
||||
content = p.read_text(encoding="utf-8")
|
||||
if args["old_text"] not in content:
|
||||
return f"Error: Text not found in {{args['path']}}"
|
||||
p.write_text(content.replace(args["old_text"], args["new_text"], 1))
|
||||
p.write_text(
|
||||
content.replace(args["old_text"], args["new_text"], 1),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return f"Edited {{args['path']}}"
|
||||
except Exception as e:
|
||||
return f"Error: {{e}}"
|
||||
@@ -230,17 +233,17 @@ def create_agent(name: str, level: int, output_dir: Path):
|
||||
# Write agent file
|
||||
agent_file = agent_dir / f"{name}.py"
|
||||
template = TEMPLATES.get(level, TEMPLATES[1])
|
||||
agent_file.write_text(template.format(name=name))
|
||||
agent_file.write_text(template.format(name=name), encoding="utf-8")
|
||||
print(f"Created: {agent_file}")
|
||||
|
||||
# Write .env.example
|
||||
env_file = agent_dir / ".env.example"
|
||||
env_file.write_text(ENV_TEMPLATE)
|
||||
env_file.write_text(ENV_TEMPLATE, encoding="utf-8")
|
||||
print(f"Created: {env_file}")
|
||||
|
||||
# Write .gitignore
|
||||
gitignore = agent_dir / ".gitignore"
|
||||
gitignore.write_text(".env\n__pycache__/\n*.pyc\n")
|
||||
gitignore.write_text(".env\n__pycache__/\n*.pyc\n", encoding="utf-8")
|
||||
print(f"Created: {gitignore}")
|
||||
|
||||
print(f"\nAgent '{name}' created at {agent_dir}")
|
||||
|
||||
Reference in New Issue
Block a user