mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-21 12:53:37 +08:00
fix: harden subprocess output decoding across lessons
This commit is contained in:
@@ -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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -57,8 +57,8 @@ 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,
|
||||
encoding="utf-8", errors="replace", timeout=120)
|
||||
capture_output=True, text=True, errors="replace",
|
||||
timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -108,7 +108,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -62,7 +62,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -133,7 +133,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -150,7 +150,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -140,7 +140,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -74,7 +74,7 @@ class BackgroundManager:
|
||||
try:
|
||||
r = subprocess.run(
|
||||
command, shell=True, cwd=WORKDIR,
|
||||
capture_output=True, text=True, timeout=300
|
||||
capture_output=True, text=True, errors="replace", timeout=300
|
||||
)
|
||||
output = (r.stdout + r.stderr).strip()[:50000]
|
||||
status = "completed"
|
||||
@@ -130,7 +130,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
@@ -273,7 +273,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, errors="replace", timeout=120,
|
||||
)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
|
||||
@@ -314,7 +314,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, errors="replace", timeout=120,
|
||||
)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
|
||||
@@ -400,7 +400,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, errors="replace", timeout=120,
|
||||
)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
|
||||
@@ -63,7 +63,7 @@ def detect_repo_root(cwd: Path) -> Path | None:
|
||||
["git", "rev-parse", "--show-toplevel"],
|
||||
cwd=cwd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=10,
|
||||
)
|
||||
if r.returncode != 0:
|
||||
@@ -246,7 +246,7 @@ class WorktreeManager:
|
||||
["git", "rev-parse", "--is-inside-work-tree"],
|
||||
cwd=self.repo_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=10,
|
||||
)
|
||||
return r.returncode == 0
|
||||
@@ -260,7 +260,7 @@ class WorktreeManager:
|
||||
["git", *args],
|
||||
cwd=self.repo_root,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=120,
|
||||
)
|
||||
if r.returncode != 0:
|
||||
@@ -365,7 +365,7 @@ class WorktreeManager:
|
||||
["git", "status", "--short", "--branch"],
|
||||
cwd=path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=60,
|
||||
)
|
||||
text = (r.stdout + r.stderr).strip()
|
||||
@@ -389,7 +389,7 @@ class WorktreeManager:
|
||||
shell=True,
|
||||
cwd=path,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=300,
|
||||
)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
@@ -498,7 +498,7 @@ def run_bash(command: str) -> str:
|
||||
shell=True,
|
||||
cwd=WORKDIR,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
text=True, errors="replace",
|
||||
timeout=120,
|
||||
)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
|
||||
@@ -89,7 +89,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, errors="replace", timeout=120)
|
||||
out = (r.stdout + r.stderr).strip()
|
||||
return out[:50000] if out else "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
@@ -345,7 +345,7 @@ class BackgroundManager:
|
||||
def _exec(self, tid: str, command: str, timeout: int):
|
||||
try:
|
||||
r = subprocess.run(command, shell=True, cwd=WORKDIR,
|
||||
capture_output=True, text=True, timeout=timeout)
|
||||
capture_output=True, text=True, errors="replace", timeout=timeout)
|
||||
output = (r.stdout + r.stderr).strip()[:50000]
|
||||
self.tasks[tid].update({"status": "completed", "result": output or "(no output)"})
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user