Skip to content
Open
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: 5 additions & 3 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mac code — claude code for your Mac
"""

import json, sys, os, time, subprocess, re, threading, queue
import json, sys, os, time, subprocess, re, threading, queue, codecs
import urllib.request, random
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -543,11 +543,13 @@ def stream_llm(messages):

with urllib.request.urlopen(req, timeout=300) as resp:
buf = ""
decoder = codecs.getincrementaldecoder("utf-8")(errors="replace")
while True:
ch = resp.read(1)
ch = resp.read(4096)
if not ch:
buf += decoder.decode(b"", final=True)
break
buf += ch.decode("utf-8", errors="replace")
buf += decoder.decode(ch)
while "\n" in buf:
line, buf = buf.split("\n", 1)
line = line.strip()
Expand Down