| 8637 | } |
| 8638 | |
| 8639 | static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const char *home, |
| 8640 | const char *binary_path, bool force, bool dry_run) { |
| 8641 | if (agents->codex) { |
| 8642 | char config_dir[CLI_BUF_1K]; |
| 8643 | char cp[CLI_BUF_1K]; |
| 8644 | char ip[CLI_BUF_1K]; |
| 8645 | char skills_dir[CLI_BUF_1K]; |
| 8646 | char ap[CLI_BUF_1K]; |
| 8647 | cbm_codex_config_dir(home, config_dir, sizeof(config_dir)); |
| 8648 | snprintf(cp, sizeof(cp), "%s/config.toml", config_dir); |
| 8649 | snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir); |
| 8650 | snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir); |
| 8651 | snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir); |
| 8652 | char command[CLI_BUF_8K]; |
| 8653 | char command_windows[CLI_BUF_8K]; |
| 8654 | char hooks_json[CLI_BUF_1K]; |
| 8655 | snprintf(hooks_json, sizeof(hooks_json), "%s/hooks.json", config_dir); |
| 8656 | bool use_hooks_json = cbm_file_exists(hooks_json); |
| 8657 | bool commands_ok = |
| 8658 | cbm_build_augment_command(binary_path, command, sizeof(command)) == CLI_OK && |
| 8659 | cbm_build_augment_command_windows(binary_path, command_windows, |
| 8660 | sizeof(command_windows)) == CLI_OK; |
| 8661 | cbm_toml_codex_hook_action_t preflight_action = |
| 8662 | use_hooks_json ? CBM_TOML_CODEX_HOOK_REMOVE : CBM_TOML_CODEX_HOOK_UPSERT; |
| 8663 | cbm_toml_codex_hook_failure_t preflight_failure = CBM_TOML_CODEX_HOOK_FAILURE_NONE; |
| 8664 | int preflight_result = commands_ok ? cbm_reconcile_codex_hooks_command_detailed( |
| 8665 | cp, command, command_windows, preflight_action, |
| 8666 | true, &preflight_failure) |
| 8667 | : CLI_ERR; |
| 8668 | if (preflight_result != CLI_OK) { |
| 8669 | if (!g_install_plan) { |
| 8670 | printf("Codex CLI:\n"); |
| 8671 | fflush(stdout); |
| 8672 | } |
| 8673 | const char *reason = preflight_failure == CBM_TOML_CODEX_HOOK_FAILURE_NONE |
| 8674 | ? NULL |
| 8675 | : cbm_toml_codex_hook_failure_name(preflight_failure); |
| 8676 | record_agent_config_error_with_reason( |
| 8677 | false, "Codex CLI", commands_ok ? "hook_preflight" : "hook_command_build", cp, |
| 8678 | reason); |
| 8679 | goto codex_install_done; |
| 8680 | } |
| 8681 | install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run, |
| 8682 | cbm_upsert_codex_mcp); |
| 8683 | install_agent_skill("Codex CLI", skills_dir, force, dry_run); |
| 8684 | install_tiered_agent_profiles( |
| 8685 | (cbm_tiered_profile_set_t){ |
| 8686 | .label = "Codex CLI", |
| 8687 | .verify_path = ap, |
| 8688 | .binary_path = binary_path, |
| 8689 | .legacy_verify_content = legacy_codex_verify_agent_content, |
| 8690 | .dialect = CBM_GRAPH_DIALECT_CODEX, |
| 8691 | }, |
| 8692 | dry_run); |
| 8693 | /* Choose the hook target: if ~/.codex/hooks.json already exists, the |
| 8694 | * user manages Codex hooks via the JSON representation — write the |
| 8695 | * SessionStart reminder there instead of config.toml. Writing both |
| 8696 | * makes Codex warn about loading hooks from two representations (#570). |
no test coverage detected