change output
This commit is contained in:
+18
-10
@@ -18,6 +18,7 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
@@ -335,21 +336,28 @@ def run_claude(claude_bin, project_root, prompt, extra_dir=None):
|
|||||||
text=True,
|
text=True,
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
)
|
)
|
||||||
stdout_lines = []
|
|
||||||
for line in proc.stdout:
|
|
||||||
line = line.rstrip("\n")
|
|
||||||
stdout_lines.append(line)
|
|
||||||
if line:
|
|
||||||
print(f"[claude] {line}", file=sys.stderr)
|
|
||||||
|
|
||||||
|
def _stream(pipe, label, dest_lines):
|
||||||
|
for line in pipe:
|
||||||
|
line = line.rstrip("\n")
|
||||||
|
if line:
|
||||||
|
print(f"[{label}] {line}", file=sys.stderr)
|
||||||
|
dest_lines.append(line)
|
||||||
|
|
||||||
|
stderr_lines = []
|
||||||
|
t = threading.Thread(target=_stream, args=(proc.stderr, "claude:stderr", stderr_lines))
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
stdout_lines = []
|
||||||
|
_stream(proc.stdout, "claude", stdout_lines)
|
||||||
|
|
||||||
|
t.join(timeout=10)
|
||||||
proc.wait(timeout=600)
|
proc.wait(timeout=600)
|
||||||
# Drain remaining stderr
|
|
||||||
stderr_output = proc.stderr.read()
|
|
||||||
if stderr_output:
|
|
||||||
print(stderr_output, file=sys.stderr)
|
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
print(f"Claude exited with code {proc.returncode}", file=sys.stderr)
|
print(f"Claude exited with code {proc.returncode}", file=sys.stderr)
|
||||||
|
if stderr_lines:
|
||||||
|
print("\n".join(stderr_lines[-50:]), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return "\n".join(stdout_lines)
|
return "\n".join(stdout_lines)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user