| 940 | } |
| 941 | |
| 942 | const char *cbm_find_cli(const char *name, const char *home_dir) { |
| 943 | static char buf[CLI_BUF_512]; |
| 944 | if (!name || !name[0]) { |
| 945 | return ""; |
| 946 | } |
| 947 | if (find_in_path(name, buf, sizeof(buf))) { |
| 948 | return buf; |
| 949 | } |
| 950 | if (!home_dir || !home_dir[0]) { |
| 951 | return ""; |
| 952 | } |
| 953 | enum { NUM_PATHS = 5 }; |
| 954 | char paths[NUM_PATHS][CLI_BUF_512]; |
| 955 | snprintf(paths[0], sizeof(paths[0]), "/usr/local/bin/%s", name); |
| 956 | snprintf(paths[1], sizeof(paths[1]), "%s/.npm/bin/%s", home_dir, name); |
| 957 | snprintf(paths[2], sizeof(paths[2]), "%s/.local/bin/%s", home_dir, name); |
| 958 | snprintf(paths[3], sizeof(paths[3]), "%s/.cargo/bin/%s", home_dir, name); |
| 959 | #ifdef __APPLE__ |
| 960 | snprintf(paths[4], sizeof(paths[4]), "/opt/homebrew/bin/%s", name); |
| 961 | #else |
| 962 | paths[4][0] = '\0'; |
| 963 | #endif |
| 964 | for (int i = 0; i < NUM_RETRIES; i++) { |
| 965 | if (paths[i][0] && is_executable(paths[i])) { |
| 966 | snprintf(buf, sizeof(buf), "%s", paths[i]); |
| 967 | return buf; |
| 968 | } |
| 969 | } |
| 970 | return ""; |
| 971 | } |
| 972 | |
| 973 | /* Agent scans are also used for dry-run plans against an explicit/synthetic |
| 974 | * home. In that mode, machine-global /usr/local and Homebrew fallbacks would |