Install OpenCode globally via npm. Returns True on success.
()
| 46 | |
| 47 | |
| 48 | def _install_opencode() -> bool: |
| 49 | """Install OpenCode globally via npm. Returns True on success.""" |
| 50 | print(" Installing opencode-ai (this may take a minute)...") |
| 51 | try: |
| 52 | r = subprocess.run( |
| 53 | ["npm", "i", "-g", "opencode-ai@latest"], |
| 54 | capture_output=True, text=True, timeout=120, |
| 55 | ) |
| 56 | if r.returncode == 0: |
| 57 | print(" OpenCode installed successfully!") |
| 58 | return True |
| 59 | else: |
| 60 | print(f" Installation failed (exit {r.returncode}):") |
| 61 | if r.stderr: |
| 62 | for line in r.stderr.strip().splitlines()[:5]: |
| 63 | print(f" {line}") |
| 64 | return False |
| 65 | except subprocess.TimeoutExpired: |
| 66 | print(" Installation timed out.") |
| 67 | return False |
| 68 | except Exception as exc: # noqa: BLE001 |
| 69 | print(f" Installation failed: {exc}") |
| 70 | return False |
| 71 | |
| 72 | |
| 73 | def _prompt_opencode_install() -> bool: |
no test coverage detected