Skip to content
Open
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
2 changes: 1 addition & 1 deletion agents/s01_agent_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=os.getcwd(),
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
Expand Down
6 changes: 3 additions & 3 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,7 +83,7 @@ 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))
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 @@ -102,15 +102,15 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
return "Error: Timeout (120s)"

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,15 +121,15 @@ 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))
Expand Down
8 changes: 4 additions & 4 deletions agents/s04_subagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
Expand All @@ -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,15 +77,15 @@ 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))
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 @@ -127,15 +127,15 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
return "Error: Timeout (120s)"

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,15 +146,15 @@ 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))
Expand Down
8 changes: 4 additions & 4 deletions agents/s06_context_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
return "Error: Timeout (120s)"

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,15 +163,15 @@ 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))
Expand Down
14 changes: 7 additions & 7 deletions agents/s07_task_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ 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"
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 All @@ -134,15 +134,15 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
return "Error: Timeout (120s)"

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,15 +153,15 @@ 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))
Expand Down
10 changes: 5 additions & 5 deletions agents/s08_background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _execute(self, task_id: str, command: str):
try:
r = subprocess.run(
command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=300
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=300
)
output = (r.stdout + r.stderr).strip()[:50000]
status = "completed"
Expand Down Expand Up @@ -124,15 +124,15 @@ def run_bash(command: str) -> str:
return "Error: Dangerous command blocked"
try:
r = subprocess.run(command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120)
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
except subprocess.TimeoutExpired:
return "Error: Timeout (120s)"

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,15 +143,15 @@ 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))
Expand Down
12 changes: 6 additions & 6 deletions agents/s09_agent_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def read_inbox(self, name: str) -> 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))
inbox_path.write_text("")
Expand Down Expand Up @@ -131,7 +131,7 @@ 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):
Expand Down Expand Up @@ -266,7 +266,7 @@ def _run_bash(command: str) -> str:
try:
r = subprocess.run(
command, shell=True, cwd=WORKDIR,
capture_output=True, text=True, timeout=120,
capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=120,
)
out = (r.stdout + r.stderr).strip()
return out[:50000] if out else "(no output)"
Expand All @@ -276,7 +276,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 @@ -288,7 +288,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 @@ -297,7 +297,7 @@ 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))
Expand Down
Loading