Skip to content
Merged
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
8 changes: 4 additions & 4 deletions agents/s02_tool_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
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):
lines = lines[:limit] + [f"... ({len(lines) - limit} more lines)"]
Expand All @@ -74,7 +74,7 @@ def run_write(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:
return f"Error: {e}"
Expand All @@ -83,10 +83,10 @@ def run_write(path: str, content: str) -> str:
def run_edit(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}"
fp.write_text(content.replace(old_text, new_text, 1))
fp.write_text(content.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
8 changes: 4 additions & 4 deletions agents/s03_todo_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -121,18 +121,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(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}"
fp.write_text(content.replace(old_text, new_text, 1))
fp.write_text(content.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
8 changes: 4 additions & 4 deletions agents/s04_subagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -77,18 +77,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(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}"
fp.write_text(content.replace(old_text, new_text, 1))
fp.write_text(content.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
10 changes: 5 additions & 5 deletions agents/s05_skill_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _load_all(self):
if not self.skills_dir.exists():
return
for f in sorted(self.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, "path": str(f)}
Expand Down Expand Up @@ -135,7 +135,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -146,18 +146,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(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}"
fp.write_text(content.replace(old_text, new_text, 1))
fp.write_text(content.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
10 changes: 5 additions & 5 deletions agents/s06_context_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def auto_compact(messages: list, focus: str = "") -> list:
# Save full transcript to disk
TRANSCRIPT_DIR.mkdir(exist_ok=True)
transcript_path = TRANSCRIPT_DIR / f"transcript_{int(time.time())}.jsonl"
with open(transcript_path, "w") as f:
with open(transcript_path, "w", encoding="utf-8") as f:
for msg in messages:
f.write(json.dumps(msg, default=str) + "\n")
print(f"[transcript saved: {transcript_path}]")
Expand Down Expand Up @@ -152,7 +152,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -163,18 +163,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(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}"
fp.write_text(content.replace(old_text, new_text, 1))
fp.write_text(content.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
16 changes: 8 additions & 8 deletions agents/s07_task_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def _load(self, task_id: int) -> dict:
path = self.dir / f"task_{task_id}.json"
if not path.exists():
raise ValueError(f"Task {task_id} not found")
return json.loads(path.read_text())
return json.loads(path.read_text(encoding="utf-8"))

def _save(self, task: dict):
path = self.dir / f"task_{task['id']}.json"
path.write_text(json.dumps(task, indent=2, ensure_ascii=False))
path.write_text(json.dumps(task, indent=2, ensure_ascii=False), encoding="utf-8")

def create(self, subject: str, description: str = "") -> str:
task = {
Expand Down Expand Up @@ -95,7 +95,7 @@ def update(self, task_id: int, status: str = None,
def _clear_dependency(self, completed_id: int):
"""Remove completed_id from all other tasks' blockedBy lists."""
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)
Expand All @@ -107,7 +107,7 @@ def list_all(self) -> str:
key=lambda f: int(f.stem.split("_")[1])
)
for f in files:
tasks.append(json.loads(f.read_text()))
tasks.append(json.loads(f.read_text(encoding="utf-8")))
if not tasks:
return "No tasks."
lines = []
Expand Down Expand Up @@ -142,7 +142,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -153,18 +153,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(path: str, old_text: str, new_text: str) -> str:
try:
fp = safe_path(path)
c = fp.read_text()
c = fp.read_text(encoding="utf-8")
if old_text not in c:
return f"Error: Text not found in {path}"
fp.write_text(c.replace(old_text, new_text, 1))
fp.write_text(c.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
8 changes: 4 additions & 4 deletions agents/s08_background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def run_bash(command: str) -> str:

def run_read(path: str, limit: int = None) -> str:
try:
lines = safe_path(path).read_text().splitlines()
lines = safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -143,18 +143,18 @@ def run_write(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"
except Exception as e:
return f"Error: {e}"

def run_edit(path: str, old_text: str, new_text: str) -> str:
try:
fp = safe_path(path)
c = fp.read_text()
c = fp.read_text(encoding="utf-8")
if old_text not in c:
return f"Error: Text not found in {path}"
fp.write_text(c.replace(old_text, new_text, 1))
fp.write_text(c.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
18 changes: 9 additions & 9 deletions agents/s09_agent_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def send(self, sender: str, to: str, content: str,
if extra:
msg.update(extra)
inbox_path = self.dir / f"{to}.jsonl"
with open(inbox_path, "a") as f:
with open(inbox_path, "a", encoding="utf-8") as f:
f.write(json.dumps(msg) + "\n")
return f"Sent {msg_type} to {to}"

Expand All @@ -102,11 +102,11 @@ def read_inbox(self, name: str, clear: bool = True) -> list:
if not inbox_path.exists():
return []
messages = []
for line in inbox_path.read_text().strip().splitlines():
for line in inbox_path.read_text(encoding="utf-8").strip().splitlines():
if line:
messages.append(json.loads(line))
if clear:
inbox_path.write_text("")
inbox_path.write_text("", encoding="utf-8")
return messages

def broadcast(self, sender: str, content: str, teammates: list) -> str:
Expand All @@ -132,11 +132,11 @@ def __init__(self, team_dir: Path):

def _load_config(self) -> dict:
if self.config_path.exists():
return json.loads(self.config_path.read_text())
return json.loads(self.config_path.read_text(encoding="utf-8"))
return {"team_name": "default", "members": []}

def _save_config(self):
self.config_path.write_text(json.dumps(self.config, indent=2))
self.config_path.write_text(json.dumps(self.config, indent=2), encoding="utf-8")

def _find_member(self, name: str) -> dict:
for m in self.config["members"]:
Expand Down Expand Up @@ -277,7 +277,7 @@ def _run_bash(command: str) -> str:

def _run_read(path: str, limit: int = None) -> str:
try:
lines = _safe_path(path).read_text().splitlines()
lines = _safe_path(path).read_text(encoding="utf-8").splitlines()
if limit and limit < len(lines):
lines = lines[:limit] + [f"... ({len(lines) - limit} more)"]
return "\n".join(lines)[:50000]
Expand All @@ -289,7 +289,7 @@ def _run_write(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"
except Exception as e:
return f"Error: {e}"
Expand All @@ -298,10 +298,10 @@ def _run_write(path: str, content: str) -> str:
def _run_edit(path: str, old_text: str, new_text: str) -> str:
try:
fp = _safe_path(path)
c = fp.read_text()
c = fp.read_text(encoding="utf-8")
if old_text not in c:
return f"Error: Text not found in {path}"
fp.write_text(c.replace(old_text, new_text, 1))
fp.write_text(c.replace(old_text, new_text, 1), encoding="utf-8")
return f"Edited {path}"
except Exception as e:
return f"Error: {e}"
Expand Down
Loading