| 917 | } |
| 918 | |
| 919 | const char *cbm_find_cli(const char *name, const char *home_dir) { |
| 920 | static char buf[CLI_BUF_512]; |
| 921 | if (!name || !name[0]) { |
| 922 | return ""; |
| 923 | } |
| 924 | if (find_in_path(name, buf, sizeof(buf))) { |
| 925 | return buf; |
| 926 | } |
| 927 | if (!home_dir || !home_dir[0]) { |
| 928 | return ""; |
| 929 | } |
| 930 | enum { NUM_PATHS = 5 }; |
| 931 | char paths[NUM_PATHS][CLI_BUF_512]; |
| 932 | snprintf(paths[0], sizeof(paths[0]), "/usr/local/bin/%s", name); |
| 933 | snprintf(paths[1], sizeof(paths[1]), "%s/.npm/bin/%s", home_dir, name); |
| 934 | snprintf(paths[2], sizeof(paths[2]), "%s/.local/bin/%s", home_dir, name); |
| 935 | snprintf(paths[3], sizeof(paths[3]), "%s/.cargo/bin/%s", home_dir, name); |
| 936 | #ifdef __APPLE__ |
| 937 | snprintf(paths[4], sizeof(paths[4]), "/opt/homebrew/bin/%s", name); |
| 938 | #else |
| 939 | paths[4][0] = '\0'; |
| 940 | #endif |
| 941 | for (int i = 0; i < NUM_RETRIES; i++) { |
| 942 | if (paths[i][0] && is_executable(paths[i])) { |
| 943 | snprintf(buf, sizeof(buf), "%s", paths[i]); |
| 944 | return buf; |
| 945 | } |
| 946 | } |
| 947 | return ""; |
| 948 | } |
| 949 | |
| 950 | /* Agent scans are also used for dry-run plans against an explicit/synthetic |
| 951 | * home. In that mode, machine-global /usr/local and Homebrew fallbacks would |