MCPcopy Create free account
hub / github.com/OpenRaiser/NanoResearch / _run_shell

Method _run_shell

nanoresearch/agents/setup_github.py:405–443  ·  view source on GitHub ↗

Run a shell command asynchronously with proxy environment.

(self, cmd: str, timeout: int = 60, env: dict | None = None)

Source from the content-addressed store, hash-verified

403 }
404
405 async def _run_shell(self, cmd: str, timeout: int = 60, env: dict | None = None) -> dict:
406 """Run a shell command asynchronously with proxy environment."""
407 _env = {**__import__('os').environ}
408 proxy_url = _env.get("https_proxy") or _env.get("HTTPS_PROXY", "")
409 if not proxy_url:
410 import re as _re
411 bashrc = Path.home() / ".bashrc"
412 if bashrc.exists():
413 content = bashrc.read_text(errors="replace")
414 m = _re.search(r"https_proxy=(http://[^\s;'\"]+)", content)
415 if m:
416 proxy_url = m.group(1)
417 if proxy_url:
418 _env.update({
419 "http_proxy": proxy_url,
420 "https_proxy": proxy_url,
421 "HTTP_PROXY": proxy_url,
422 "HTTPS_PROXY": proxy_url,
423 })
424 if env:
425 _env.update(env)
426
427 proc = await asyncio.create_subprocess_shell(
428 cmd,
429 stdout=asyncio.subprocess.PIPE,
430 stderr=asyncio.subprocess.PIPE,
431 cwd=str(self.workspace.path),
432 env=_env,
433 )
434 try:
435 stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)
436 except asyncio.TimeoutError:
437 proc.kill()
438 return {"returncode": -1, "stdout": "", "stderr": "Command timed out"}
439 return {
440 "returncode": proc.returncode or 0,
441 "stdout": stdout.decode(errors="replace"),
442 "stderr": stderr.decode(errors="replace"),
443 }
444
445 async def close(self) -> None:
446 pass

Callers 7

_clone_dataset_repoMethod · 0.95
_search_and_cloneMethod · 0.45
_github_searchMethod · 0.45
_analyze_cloned_codeMethod · 0.45
_download_resourcesMethod · 0.45

Calls 2

getMethod · 0.80
read_textMethod · 0.80

Tested by

no test coverage detected