(no commit message)

This commit is contained in:
2026-01-18 22:37:06 -08:00
parent 2945d17b91
commit 192a744884
12 changed files with 599 additions and 0 deletions

34
utils/shell_ops.py Normal file
View File

@@ -0,0 +1,34 @@
"""Shell operation utilities for nanocode."""
import subprocess
from .display import DIM, RESET
def run_bash(cmd: str) -> str:
"""Run a shell command and return output.
Args:
cmd: Shell command to execute
Returns:
Command output (stdout and stderr combined)
"""
proc = subprocess.Popen(
cmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
text=True
)
output_lines = []
try:
while True:
line = proc.stdout.readline()
if not line and proc.poll() is not None:
break
if line:
print(f" {DIM}{line.rstrip()}{RESET}", flush=True)
output_lines.append(line)
proc.wait(timeout=30)
except subprocess.TimeoutExpired:
proc.kill()
output_lines.append("\n(timed out after 30s)")
return "".join(output_lines).strip() or "(empty output)"