Fix opencode discovery for Spark and Windows

This commit is contained in:
Daniel Maddern 2026-08-16 15:11:28 +07:00
parent 2bbcc9e272
commit 5f58354772

View file

@ -2,6 +2,7 @@ from __future__ import annotations
import os
import shutil
from pathlib import Path
from django.core.management.base import BaseCommand
@ -15,7 +16,12 @@ class Command(BaseCommand):
env_name = f"ARTIFEX_{model_key.upper()}_OPENCODE_COMMAND"
if os.environ.get(env_name):
return os.environ[env_name]
executable = shutil.which("opencode") or "opencode"
if os.environ.get("ARTIFEX_OPENCODE_COMMAND"):
return os.environ["ARTIFEX_OPENCODE_COMMAND"]
executable = shutil.which("opencode")
if executable is None:
default_user_install = Path.home() / ".opencode" / "bin" / "opencode"
executable = str(default_user_install) if default_user_install.exists() else "opencode"
return f"{executable} run"
def opencode_config(self, model_key: str) -> dict[str, object]: