| 8422 | } |
| 8423 | |
| 8424 | static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const char *home, |
| 8425 | const char *binary_path, bool force, bool dry_run) { |
| 8426 | if (agents->codex) { |
| 8427 | char config_dir[CLI_BUF_1K]; |
| 8428 | char cp[CLI_BUF_1K]; |
| 8429 | char ip[CLI_BUF_1K]; |
| 8430 | char skills_dir[CLI_BUF_1K]; |
| 8431 | char ap[CLI_BUF_1K]; |
| 8432 | cbm_codex_config_dir(home, config_dir, sizeof(config_dir)); |
| 8433 | snprintf(cp, sizeof(cp), "%s/config.toml", config_dir); |
| 8434 | snprintf(ip, sizeof(ip), "%s/AGENTS.md", config_dir); |
| 8435 | snprintf(skills_dir, sizeof(skills_dir), "%s/skills", config_dir); |
| 8436 | snprintf(ap, sizeof(ap), "%s/agents/codebase-memory.toml", config_dir); |
| 8437 | char command[CLI_BUF_8K]; |
| 8438 | char command_windows[CLI_BUF_8K]; |
| 8439 | char hooks_json[CLI_BUF_1K]; |
| 8440 | snprintf(hooks_json, sizeof(hooks_json), "%s/hooks.json", config_dir); |
| 8441 | bool use_hooks_json = cbm_file_exists(hooks_json); |
| 8442 | bool commands_ok = |
| 8443 | cbm_build_augment_command(binary_path, command, sizeof(command)) == CLI_OK && |
| 8444 | cbm_build_augment_command_windows(binary_path, command_windows, |
| 8445 | sizeof(command_windows)) == CLI_OK; |
| 8446 | cbm_toml_codex_hook_action_t preflight_action = |
| 8447 | use_hooks_json ? CBM_TOML_CODEX_HOOK_REMOVE : CBM_TOML_CODEX_HOOK_UPSERT; |
| 8448 | if (!commands_ok || cbm_reconcile_codex_hooks_command(cp, command, command_windows, |
| 8449 | preflight_action, true) != CLI_OK) { |
| 8450 | record_agent_config_error(false, "Codex CLI", |
| 8451 | commands_ok ? "hook_preflight" : "hook_command_build", cp); |
| 8452 | goto codex_install_done; |
| 8453 | } |
| 8454 | install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run, |
| 8455 | cbm_upsert_codex_mcp); |
| 8456 | install_agent_skill("Codex CLI", skills_dir, force, dry_run); |
| 8457 | install_tiered_agent_profiles( |
| 8458 | (cbm_tiered_profile_set_t){ |
| 8459 | .label = "Codex CLI", |
| 8460 | .verify_path = ap, |
| 8461 | .binary_path = binary_path, |
| 8462 | .legacy_verify_content = legacy_codex_verify_agent_content, |
| 8463 | .dialect = CBM_GRAPH_DIALECT_CODEX, |
| 8464 | }, |
| 8465 | dry_run); |
| 8466 | /* Choose the hook target: if ~/.codex/hooks.json already exists, the |
| 8467 | * user manages Codex hooks via the JSON representation — write the |
| 8468 | * SessionStart reminder there instead of config.toml. Writing both |
| 8469 | * makes Codex warn about loading hooks from two representations (#570). |
| 8470 | * config.toml remains the mcp_config target above either way. */ |
| 8471 | const char *hook_target = use_hooks_json ? hooks_json : cp; |
| 8472 | if (g_install_plan) { |
| 8473 | plan_record("Codex CLI", "hook", hook_target); |
| 8474 | } else { |
| 8475 | bool hook_ok = true; |
| 8476 | if (!dry_run && use_hooks_json) { |
| 8477 | hook_ok = |
| 8478 | cbm_upsert_paired_lifecycle_hooks_json(hooks_json, command, command_windows, |
| 8479 | NULL, CMM_HOOK_TIMEOUT_SEC) == CLI_OK && |
| 8480 | cbm_reconcile_codex_hooks_command(cp, command, command_windows, |
| 8481 | CBM_TOML_CODEX_HOOK_REMOVE, false) == CLI_OK; |
no test coverage detected