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

Function _unwrap_shell_wrapper

nanoresearch/agents/project_runner_core.py:81–101  ·  view source on GitHub ↗
(tokens: list[str])

Source from the content-addressed store, hash-verified

79
80
81def _unwrap_shell_wrapper(tokens: list[str]) -> tuple[dict[str, str], list[str]]:
82 current = _truncate_shell_chain(tokens)
83 env_vars, current = _extract_env_assignments(current)
84 if not current:
85 return env_vars, current
86
87 first = Path(str(current[0]).strip("\"'")).name.lower()
88 if first == "cmd" and len(current) >= 3 and current[1].lower() == "/c":
89 nested_env, nested_tokens = _unwrap_shell_wrapper(current[2:])
90 return {**env_vars, **nested_env}, nested_tokens
91
92 if first in {"bash", "sh"} and len(current) >= 3 and current[1] in {"-c", "-lc"}:
93 nested_env, nested_tokens = _unwrap_shell_wrapper(_split_command(current[2]))
94 return {**env_vars, **nested_env}, nested_tokens
95
96 if first in {"powershell", "powershell.exe", "pwsh", "pwsh.exe"} and len(current) >= 3:
97 if current[1].lower() in {"-command", "-c"}:
98 nested_env, nested_tokens = _unwrap_shell_wrapper(_split_command(current[2]))
99 return {**env_vars, **nested_env}, nested_tokens
100
101 return env_vars, current
102
103
104def normalize_target_spec(train_command: str, code_dir: Path) -> tuple[list[str], dict[str, str]]:

Callers 1

normalize_target_specFunction · 0.85

Calls 3

_truncate_shell_chainFunction · 0.85
_extract_env_assignmentsFunction · 0.85
_split_commandFunction · 0.85

Tested by

no test coverage detected