@@ -43,10 +43,17 @@ object OpenCodeChecker {
4343 add(" /usr/local/bin/opencode" ) // Homebrew (Intel Mac)
4444 add(" /opt/homebrew/bin/opencode" ) // Homebrew (Apple Silicon)
4545 home?.let {
46+ addAll(nvmInstallLocations(" $it /.nvm" ))
4647 add(" $it /.local/bin/opencode" )
4748 add(" $it /.bun/bin/opencode" )
4849 add(" $it /.npm-global/bin/opencode" )
4950 }
51+ System .getenv(" NVM_BIN" )?.takeIf { it.isNotBlank() }?.let {
52+ add(File (it, " opencode" ).path)
53+ }
54+ System .getenv(" NVM_DIR" )?.takeIf { it.isNotBlank() }?.let {
55+ addAll(nvmInstallLocations(it))
56+ }
5057 }
5158 }
5259
@@ -55,11 +62,18 @@ object OpenCodeChecker {
5562 buildList {
5663 add(" /usr/bin/opencode" )
5764 home?.let {
65+ addAll(nvmInstallLocations(" $it /.nvm" ))
5866 add(" $it /.opencode/bin/opencode" )
5967 add(" $it /.local/bin/opencode" )
6068 add(" $it /.bun/bin/opencode" )
6169 add(" $it /.npm-global/bin/opencode" )
6270 }
71+ System .getenv(" NVM_BIN" )?.takeIf { it.isNotBlank() }?.let {
72+ add(File (it, " opencode" ).path)
73+ }
74+ System .getenv(" NVM_DIR" )?.takeIf { it.isNotBlank() }?.let {
75+ addAll(nvmInstallLocations(it))
76+ }
6377 }
6478 }
6579
@@ -97,6 +111,22 @@ object OpenCodeChecker {
97111 }
98112 }
99113
114+ // NVM keeps packages under each installed Node version, so scan versions/node/*/bin/opencode.
115+ private fun nvmInstallLocations (rootPath : String ): List <String > {
116+ val root = File (rootPath)
117+ val versionsRoot = File (root, " versions/node" )
118+ if (! versionsRoot.isDirectory) return emptyList()
119+
120+ return versionsRoot.listFiles()
121+ .orEmpty()
122+ .asSequence()
123+ .filter { it.isDirectory }
124+ .sortedByDescending { it.name }
125+ .map { versionDir -> File (versionDir, " bin/opencode" ).path }
126+ .distinct()
127+ .toList()
128+ }
129+
100130 private fun autoResolve (): OpenCodeInfo ? {
101131 val executableNames =
102132 if (SystemInfo .isWindows) {
@@ -212,6 +242,7 @@ object OpenCodeChecker {
212242 return try {
213243 val process = ProcessBuilder (path, arg)
214244 .redirectErrorStream(true )
245+ .apply { OpenCodeProcessEnvironment .configure(this , path) }
215246 .start()
216247
217248 var output = " "
0 commit comments