| 1158 | } |
| 1159 | |
| 1160 | const char *cbm_find_cli(const char *name, const char *home_dir) { |
| 1161 | static CBM_TLS char buf[CLI_BUF_512]; |
| 1162 | if (!name || !name[0]) { |
| 1163 | return ""; |
| 1164 | } |
| 1165 | if (find_in_path(name, buf, sizeof(buf))) { |
| 1166 | return buf; |
| 1167 | } |
| 1168 | if (!home_dir || !home_dir[0]) { |
| 1169 | return ""; |
| 1170 | } |
| 1171 | enum { NUM_PATHS = 5 }; |
| 1172 | char paths[NUM_PATHS][CLI_BUF_512]; |
| 1173 | snprintf(paths[0], sizeof(paths[0]), "/usr/local/bin/%s", name); |
| 1174 | snprintf(paths[1], sizeof(paths[1]), "%s/.npm/bin/%s", home_dir, name); |
| 1175 | snprintf(paths[2], sizeof(paths[2]), "%s/.local/bin/%s", home_dir, name); |
| 1176 | snprintf(paths[3], sizeof(paths[3]), "%s/.cargo/bin/%s", home_dir, name); |
| 1177 | #ifdef __APPLE__ |
| 1178 | snprintf(paths[4], sizeof(paths[4]), "/opt/homebrew/bin/%s", name); |
| 1179 | #else |
| 1180 | paths[4][0] = '\0'; |
| 1181 | #endif |
| 1182 | for (int i = 0; i < NUM_RETRIES; i++) { |
| 1183 | if (paths[i][0] && is_executable(paths[i])) { |
| 1184 | snprintf(buf, sizeof(buf), "%s", paths[i]); |
| 1185 | return buf; |
| 1186 | } |
| 1187 | } |
| 1188 | return ""; |
| 1189 | } |
| 1190 | |
| 1191 | /* Agent scans are also used for dry-run plans against an explicit/synthetic |
| 1192 | * home. In that mode, machine-global /usr/local and Homebrew fallbacks would |