fix(cli): probe Windows PATHEXT variants in find_in_path (#221)

Agent CLIs on Windows are installed as .cmd/.ps1/.exe shims (e.g. opencode
via mise/npm), but find_in_path only probed the bare name, so they weren't
detected. Try .exe/.cmd/.bat/.ps1 per PATH entry on Windows.

Relates to #221 (opencode not detected). The install-time taskkill 'eq'
error from the same report is addressed separately — cbm_kill_other_instances
now uses _spawnvp with an argv array rather than a shell string.
This commit is contained in:
Martin Vogel
2026-05-31 12:54:58 +02:00
parent d198403e21
commit 0485d3f3b1
+13
View File
@@ -262,6 +262,19 @@ static bool find_in_path(const char *name, char *out, size_t out_sz) {
if (is_executable(out)) {
return true;
}
#ifdef _WIN32
/* On Windows executables carry an extension (PATHEXT). A CLI like
* opencode is often installed as a .cmd / .ps1 / .exe shim (e.g. via
* mise or npm), so the bare-name probe above misses it (#221). Try the
* common executable extensions before moving to the next PATH entry. */
static const char *const win_exts[] = {".exe", ".cmd", ".bat", ".ps1", NULL};
for (int i = 0; win_exts[i]; i++) {
snprintf(out, out_sz, "%s/%s%s", dir, name, win_exts[i]);
if (is_executable(out)) {
return true;
}
}
#endif
dir = strtok_r(NULL, PATH_DELIM, &saveptr);
}
return false;