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. */
| 1193 | * leak the host's agents into the result. Keep those fallbacks for a real-home |
| 1194 | * scan while still honoring the supplied PATH and home-local bin dirs. */ |
| 1195 | static bool cbm_agent_cli_exists(const char *name, const char *home_dir) { |
| 1196 | const char *actual_home = cbm_get_home_dir(); |
| 1197 | if (actual_home && home_dir && strcmp(actual_home, home_dir) == 0) { |
| 1198 | return cbm_find_cli(name, home_dir)[0] != '\0'; |
| 1199 | } |
| 1200 | |
| 1201 | char found[CLI_BUF_512]; |
| 1202 | if (find_in_path(name, found, sizeof(found))) { |
| 1203 | return true; |
| 1204 | } |
| 1205 | if (!name || !name[0] || !home_dir || !home_dir[0]) { |
| 1206 | return false; |
| 1207 | } |
| 1208 | const char *const suffixes[] = {".npm/bin", ".local/bin", ".cargo/bin"}; |
| 1209 | char candidate[CLI_BUF_512]; |
| 1210 | for (size_t i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); i++) { |
| 1211 | int written = |
| 1212 | snprintf(candidate, sizeof(candidate), "%s/%s/%s", home_dir, suffixes[i], name); |
| 1213 | if (written > 0 && (size_t)written < sizeof(candidate) && is_executable(candidate)) { |
| 1214 | return true; |
| 1215 | } |
| 1216 | } |
| 1217 | return false; |
| 1218 | } |
| 1219 | |
| 1220 | /* ── File utilities ───────────────────────────────────────────── */ |
| 1221 |
no test coverage detected