| 8335 | } |
| 8336 | |
| 8337 | static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const char *home, |
| 8338 | const char *binary_path, bool force, bool dry_run) { |
| 8339 | if (agents->codex) { |
| 8340 | char config_dir[CLI_BUF_1K]; |
| 8341 | char cp[CLI_BUF_1K]; |
| 8342 | char ip[CLI_BUF_1K]; |
| 8343 | char skills_dir[CLI_BUF_1K]; |
| 8344 | char ap[CLI_BUF_1K]; |
| 8345 | cbm_codex_config_dir(home, config_dir, sizeof(config_dir)); |
| 8346 | snprintf(cp, sizeof(cp), "%s/config.toml", config_dir); |
| 8347 | snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir); |
| 8348 | snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir); |
| 8349 | snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir); |
| 8350 | install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run, |
| 8351 | cbm_upsert_codex_mcp); |
| 8352 | install_agent_skill("Codex CLI", skills_dir, force, dry_run); |
| 8353 | install_tiered_agent_profiles( |
| 8354 | (cbm_tiered_profile_set_t){ |
| 8355 | .label = "Codex CLI", |
| 8356 | .verify_path = ap, |
| 8357 | .binary_path = binary_path, |
| 8358 | .legacy_verify_content = legacy_codex_verify_agent_content, |
| 8359 | .dialect = CBM_GRAPH_DIALECT_CODEX, |
| 8360 | }, |
| 8361 | dry_run); |
| 8362 | /* Choose the hook target: if ~/.codex/hooks.json already exists, the |
| 8363 | * user manages Codex hooks via the JSON representation — write the |
| 8364 | * SessionStart reminder there instead of config.toml. Writing both |
| 8365 | * makes Codex warn about loading hooks from two representations (#570). |
| 8366 | * config.toml remains the mcp_config target above either way. */ |
| 8367 | char hooks_json[CLI_BUF_1K]; |
| 8368 | snprintf(hooks_json, sizeof(hooks_json), "%s/hooks.json", config_dir); |
| 8369 | bool use_hooks_json = cbm_file_exists(hooks_json); |
| 8370 | const char *hook_target = use_hooks_json ? hooks_json : cp; |
| 8371 | if (g_install_plan) { |
| 8372 | plan_record("Codex CLI", "hook", hook_target); |
| 8373 | } else { |
| 8374 | bool hook_ok = true; |
| 8375 | if (!dry_run) { |
| 8376 | char command[CLI_BUF_8K]; |
| 8377 | char command_windows[CLI_BUF_8K]; |
| 8378 | if (cbm_build_augment_command(binary_path, command, sizeof(command)) == CLI_OK && |
| 8379 | cbm_build_augment_command_windows(binary_path, command_windows, |
| 8380 | sizeof(command_windows)) == CLI_OK) { |
| 8381 | if (use_hooks_json) { |
| 8382 | if (cbm_upsert_paired_lifecycle_hooks_json( |
| 8383 | hooks_json, command, command_windows, NULL, CMM_HOOK_TIMEOUT_SEC) == |
| 8384 | CLI_OK) { |
| 8385 | if (cbm_remove_codex_hooks(cp) != CLI_OK) { |
| 8386 | hook_ok = false; |
| 8387 | record_agent_config_error(false, "Codex CLI", "legacy_hook_cleanup", |
| 8388 | cp); |
| 8389 | } |
| 8390 | } else { |
| 8391 | hook_ok = false; |
| 8392 | record_agent_config_error(false, "Codex CLI", "hook_install", |
| 8393 | hooks_json); |
| 8394 | } |
no test coverage detected