From 0485d3f3b1ffde47fde87b69573b909eb1401af7 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Sun, 31 May 2026 12:54:58 +0200 Subject: [PATCH] fix(cli): probe Windows PATHEXT variants in find_in_path (#221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/cli/cli.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cli/cli.c b/src/cli/cli.c index 79ba5a446..d37ac4281 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -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;