| 962 | } |
| 963 | |
| 964 | const char *cbm_find_cli(const char *name, const char *home_dir) { |
| 965 | static char buf[CLI_BUF_512]; |
| 966 | if (!name || !name[0]) { |
| 967 | return ""; |
| 968 | } |
| 969 | if (find_in_path(name, buf, sizeof(buf))) { |
| 970 | return buf; |
| 971 | } |
| 972 | if (!home_dir || !home_dir[0]) { |
| 973 | return ""; |
| 974 | } |
| 975 | enum { NUM_PATHS = 5 }; |
| 976 | char paths[NUM_PATHS][CLI_BUF_512]; |
| 977 | snprintf(paths[0], sizeof(paths[0]), "/usr/local/bin/%s", name); |
| 978 | snprintf(paths[1], sizeof(paths[1]), "%s/.npm/bin/%s", home_dir, name); |
| 979 | snprintf(paths[2], sizeof(paths[2]), "%s/.local/bin/%s", home_dir, name); |
| 980 | snprintf(paths[3], sizeof(paths[3]), "%s/.cargo/bin/%s", home_dir, name); |
| 981 | #ifdef __APPLE__ |
| 982 | snprintf(paths[4], sizeof(paths[4]), "/opt/homebrew/bin/%s", name); |
| 983 | #else |
| 984 | paths[4][0] = '\0'; |
| 985 | #endif |
| 986 | for (int i = 0; i < NUM_RETRIES; i++) { |
| 987 | if (paths[i][0] && is_executable(paths[i])) { |
| 988 | snprintf(buf, sizeof(buf), "%s", paths[i]); |
| 989 | return buf; |
| 990 | } |
| 991 | } |
| 992 | return ""; |
| 993 | } |
| 994 | |
| 995 | /* Agent scans are also used for dry-run plans against an explicit/synthetic |
| 996 | * home. In that mode, machine-global /usr/local and Homebrew fallbacks would |