| 8279 | } |
| 8280 | |
| 8281 | static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const char *home, |
| 8282 | const char *binary_path, bool force, bool dry_run) { |
| 8283 | if (agents->codex) { |
| 8284 | char config_dir[CLI_BUF_1K]; |
| 8285 | char cp[CLI_BUF_1K]; |
| 8286 | char ip[CLI_BUF_1K]; |
| 8287 | char skills_dir[CLI_BUF_1K]; |
| 8288 | char ap[CLI_BUF_1K]; |
| 8289 | cbm_codex_config_dir(home, config_dir, sizeof(config_dir)); |
| 8290 | snprintf(cp, sizeof(cp), "%s/config.toml", config_dir); |
| 8291 | snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir); |
| 8292 | snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir); |
| 8293 | snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir); |
| 8294 | install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run, |
| 8295 | cbm_upsert_codex_mcp); |
| 8296 | install_agent_skill("Codex CLI", skills_dir, force, dry_run); |
| 8297 | install_tiered_agent_profiles( |
| 8298 | (cbm_tiered_profile_set_t){ |
| 8299 | .label = "Codex CLI", |
| 8300 | .verify_path = ap, |
| 8301 | .binary_path = binary_path, |
| 8302 | .legacy_verify_content = legacy_codex_verify_agent_content, |
| 8303 | .dialect = CBM_GRAPH_DIALECT_CODEX, |
| 8304 | }, |
| 8305 | dry_run); |
| 8306 | /* Choose the hook target: if ~/.codex/hooks.json already exists, the |
| 8307 | * user manages Codex hooks via the JSON representation — write the |
| 8308 | * SessionStart reminder there instead of config.toml. Writing both |
| 8309 | * makes Codex warn about loading hooks from two representations (#570). |
| 8310 | * config.toml remains the mcp_config target above either way. */ |
| 8311 | char hooks_json[CLI_BUF_1K]; |
| 8312 | snprintf(hooks_json, sizeof(hooks_json), "%s/hooks.json", config_dir); |
| 8313 | bool use_hooks_json = cbm_file_exists(hooks_json); |
| 8314 | const char *hook_target = use_hooks_json ? hooks_json : cp; |
| 8315 | if (g_install_plan) { |
| 8316 | plan_record("Codex CLI", "hook", hook_target); |
| 8317 | } else { |
| 8318 | bool hook_ok = true; |
| 8319 | if (!dry_run) { |
| 8320 | char command[CLI_BUF_8K]; |
| 8321 | char command_windows[CLI_BUF_8K]; |
| 8322 | if (cbm_build_augment_command(binary_path, command, sizeof(command)) == CLI_OK && |
| 8323 | cbm_build_augment_command_windows(binary_path, command_windows, |
| 8324 | sizeof(command_windows)) == CLI_OK) { |
| 8325 | if (use_hooks_json) { |
| 8326 | if (cbm_upsert_paired_lifecycle_hooks_json( |
| 8327 | hooks_json, command, command_windows, NULL, CMM_HOOK_TIMEOUT_SEC) == |
| 8328 | CLI_OK) { |
| 8329 | if (cbm_remove_codex_hooks(cp) != CLI_OK) { |
| 8330 | hook_ok = false; |
| 8331 | record_agent_config_error(false, "Codex CLI", "legacy_hook_cleanup", |
| 8332 | cp); |
| 8333 | } |
| 8334 | } else { |
| 8335 | hook_ok = false; |
| 8336 | record_agent_config_error(false, "Codex CLI", "hook_install", |
| 8337 | hooks_json); |
| 8338 | } |
no test coverage detected