MCPcopy
hub / github.com/shareAI-lab/learn-claude-code / run

Method run

agents/s12_worktree_task_isolation.py:368–392  ·  view source on GitHub ↗
(self, name: str, command: str)

Source from the content-addressed store, hash-verified

366 return text or "Clean worktree"
367
368 def run(self, name: str, command: str) -> str:
369 dangerous = ["rm -rf /", "sudo", "shutdown", "reboot", "> /dev/"]
370 if any(d in command for d in dangerous):
371 return "Error: Dangerous command blocked"
372
373 wt = self._find(name)
374 if not wt:
375 return f"Error: Unknown worktree '{name}'"
376 path = Path(wt["path"])
377 if not path.exists():
378 return f"Error: Worktree path missing: {path}"
379
380 try:
381 r = subprocess.run(
382 command,
383 shell=True,
384 cwd=path,
385 capture_output=True,
386 text=True,
387 timeout=300,
388 )
389 out = (r.stdout + r.stderr).strip()
390 return out[:50000] if out else "(no output)"
391 except subprocess.TimeoutExpired:
392 return "Error: Timeout (300s)"
393
394 def remove(self, name: str, force: bool = False, complete_task: bool = False) -> str:
395 wt = self._find(name)

Callers 6

detect_repo_rootFunction · 0.45
_is_git_repoMethod · 0.45
_run_gitMethod · 0.45
statusMethod · 0.45
run_bashFunction · 0.45

Calls 2

_findMethod · 0.95
existsMethod · 0.80

Tested by

no test coverage detected