fix: use UTF-8 for text file operations

This commit is contained in:
Haoran
2026-08-24 20:28:37 +08:00
parent a32a73f700
commit 199402f9d4
59 changed files with 435 additions and 289 deletions

View File

@@ -41,7 +41,7 @@ def safe_path(p: str) -> Path:
return path
def run_read(path: str, limit: int = None) -> str:
text = safe_path(path).read_text()
text = safe_path(path).read_text(encoding="utf-8")
lines = text.splitlines()
if limit and limit < len(lines):
lines = lines[:limit]

View File

@@ -52,7 +52,7 @@ class SkillLoader:
def __init__(self, skills_dir: Path):
self.skills = {}
for f in sorted(skills_dir.rglob("SKILL.md")):
text = f.read_text()
text = f.read_text(encoding="utf-8")
meta, body = self._parse_frontmatter(text)
name = meta.get("name", f.parent.name)
self.skills[name] = {"meta": meta, "body": body}

View File

@@ -71,7 +71,7 @@ class TaskManager:
```python
def _clear_dependency(self, completed_id):
for f in self.dir.glob("task_*.json"):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if completed_id in task.get("blockedBy", []):
task["blockedBy"].remove(completed_id)
self._save(task)

View File

@@ -78,8 +78,8 @@ class MessageBus:
def read_inbox(self, name):
path = self.dir / f"{name}.jsonl"
if not path.exists(): return "[]"
msgs = [json.loads(l) for l in path.read_text().strip().splitlines() if l]
path.write_text("") # drain
msgs = [json.loads(l) for l in path.read_text(encoding="utf-8").strip().splitlines() if l]
path.write_text("", encoding="utf-8") # drain
return json.dumps(msgs, indent=2)
```

View File

@@ -98,7 +98,7 @@ def _idle_poll(self, name, messages):
def scan_unclaimed_tasks() -> list:
unclaimed = []
for f in sorted(TASKS_DIR.glob("task_*.json")):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if (task.get("status") == "pending"
and not task.get("owner")
and not task.get("blockedBy")):

View File

@@ -41,7 +41,7 @@ def safe_path(p: str) -> Path:
return path
def run_read(path: str, limit: int = None) -> str:
text = safe_path(path).read_text()
text = safe_path(path).read_text(encoding="utf-8")
lines = text.splitlines()
if limit and limit < len(lines):
lines = lines[:limit]

View File

@@ -52,7 +52,7 @@ class SkillLoader:
def __init__(self, skills_dir: Path):
self.skills = {}
for f in sorted(skills_dir.rglob("SKILL.md")):
text = f.read_text()
text = f.read_text(encoding="utf-8")
meta, body = self._parse_frontmatter(text)
name = meta.get("name", f.parent.name)
self.skills[name] = {"meta": meta, "body": body}

View File

@@ -71,7 +71,7 @@ class TaskManager:
```python
def _clear_dependency(self, completed_id):
for f in self.dir.glob("task_*.json"):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if completed_id in task.get("blockedBy", []):
task["blockedBy"].remove(completed_id)
self._save(task)

View File

@@ -78,8 +78,8 @@ class MessageBus:
def read_inbox(self, name):
path = self.dir / f"{name}.jsonl"
if not path.exists(): return "[]"
msgs = [json.loads(l) for l in path.read_text().strip().splitlines() if l]
path.write_text("") # drain
msgs = [json.loads(l) for l in path.read_text(encoding="utf-8").strip().splitlines() if l]
path.write_text("", encoding="utf-8") # drain
return json.dumps(msgs, indent=2)
```

View File

@@ -98,7 +98,7 @@ def _idle_poll(self, name, messages):
def scan_unclaimed_tasks() -> list:
unclaimed = []
for f in sorted(TASKS_DIR.glob("task_*.json")):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if (task.get("status") == "pending"
and not task.get("owner")
and not task.get("blockedBy")):

View File

@@ -41,7 +41,7 @@ def safe_path(p: str) -> Path:
return path
def run_read(path: str, limit: int = None) -> str:
text = safe_path(path).read_text()
text = safe_path(path).read_text(encoding="utf-8")
lines = text.splitlines()
if limit and limit < len(lines):
lines = lines[:limit]

View File

@@ -52,7 +52,7 @@ class SkillLoader:
def __init__(self, skills_dir: Path):
self.skills = {}
for f in sorted(skills_dir.rglob("SKILL.md")):
text = f.read_text()
text = f.read_text(encoding="utf-8")
meta, body = self._parse_frontmatter(text)
name = meta.get("name", f.parent.name)
self.skills[name] = {"meta": meta, "body": body}

View File

@@ -71,7 +71,7 @@ class TaskManager:
```python
def _clear_dependency(self, completed_id):
for f in self.dir.glob("task_*.json"):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if completed_id in task.get("blockedBy", []):
task["blockedBy"].remove(completed_id)
self._save(task)

View File

@@ -78,8 +78,8 @@ class MessageBus:
def read_inbox(self, name):
path = self.dir / f"{name}.jsonl"
if not path.exists(): return "[]"
msgs = [json.loads(l) for l in path.read_text().strip().splitlines() if l]
path.write_text("") # drain
msgs = [json.loads(l) for l in path.read_text(encoding="utf-8").strip().splitlines() if l]
path.write_text("", encoding="utf-8") # drain
return json.dumps(msgs, indent=2)
```

View File

@@ -98,7 +98,7 @@ def _idle_poll(self, name, messages):
def scan_unclaimed_tasks() -> list:
unclaimed = []
for f in sorted(TASKS_DIR.glob("task_*.json")):
task = json.loads(f.read_text())
task = json.loads(f.read_text(encoding="utf-8"))
if (task.get("status") == "pending"
and not task.get("owner")
and not task.get("blockedBy")):