Agent scans are also used for dry-run plans against an explicit/synthetic * home. In that mode, machine-global /usr/local and Homebrew fallbacks would * leak the host's agents into the result. Keep those fallbacks for a real-home * scan while still honoring the supplied PATH and home-local bin dirs. */
| 975 | * leak the host's agents into the result. Keep those fallbacks for a real-home |
| 976 | * scan while still honoring the supplied PATH and home-local bin dirs. */ |
| 977 | static bool cbm_agent_cli_exists(const char *name, const char *home_dir) { |
| 978 | const char *actual_home = cbm_get_home_dir(); |
| 979 | if (actual_home && home_dir && strcmp(actual_home, home_dir) == 0) { |
| 980 | return cbm_find_cli(name, home_dir)[0] != '\0'; |
| 981 | } |
| 982 | |
| 983 | char found[CLI_BUF_512]; |
| 984 | if (find_in_path(name, found, sizeof(found))) { |
| 985 | return true; |
| 986 | } |
| 987 | if (!name || !name[0] || !home_dir || !home_dir[0]) { |
| 988 | return false; |
| 989 | } |
| 990 | const char *const suffixes[] = {".npm/bin", ".local/bin", ".cargo/bin"}; |
| 991 | char candidate[CLI_BUF_512]; |
| 992 | for (size_t i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); i++) { |
| 993 | int written = |
| 994 | snprintf(candidate, sizeof(candidate), "%s/%s/%s", home_dir, suffixes[i], name); |
| 995 | if (written > 0 && (size_t)written < sizeof(candidate) && is_executable(candidate)) { |
| 996 | return true; |
| 997 | } |
| 998 | } |
| 999 | return false; |
| 1000 | } |
| 1001 | |
| 1002 | /* ── File utilities ───────────────────────────────────────────── */ |
| 1003 |
no test coverage detected