Skip to content

Commit 7d4dc77

Browse files
committed
fix(cli): explain Codex hook preflight refusals
Signed-off-by: astandrik <astandrik@yandex-team.ru>
1 parent 6ecbc5f commit 7d4dc77

5 files changed

Lines changed: 318 additions & 38 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,17 +3487,26 @@ bool cbm_optional_hook_supported_for_testing(const char *agent_name, bool window
34873487
}
34883488
#endif
34893489

3490-
static int cbm_reconcile_codex_hooks_command(const char *config_path, const char *command,
3491-
const char *command_windows,
3492-
cbm_toml_codex_hook_action_t action, bool check_only) {
3490+
static int cbm_reconcile_codex_hooks_command_detailed(const char *config_path, const char *command,
3491+
const char *command_windows,
3492+
cbm_toml_codex_hook_action_t action,
3493+
bool check_only,
3494+
cbm_toml_codex_hook_failure_t *failure) {
34933495
if (!config_path || !command || !command_windows) {
34943496
return CLI_ERR;
34953497
}
3496-
return cbm_toml_reconcile_codex_hooks(config_path, CODEX_HOOK_BEGIN, CODEX_HOOK_END, command,
3497-
command_windows, action, check_only ? 1 : 0) == 0
3498+
return cbm_toml_reconcile_codex_hooks_detailed(config_path, CODEX_HOOK_BEGIN, CODEX_HOOK_END,
3499+
command, command_windows, action,
3500+
check_only ? 1 : 0, failure) == 0
34983501
? CLI_OK
34993502
: CLI_ERR;
35003503
}
3504+
static int cbm_reconcile_codex_hooks_command(const char *config_path, const char *command,
3505+
const char *command_windows,
3506+
cbm_toml_codex_hook_action_t action, bool check_only) {
3507+
return cbm_reconcile_codex_hooks_command_detailed(config_path, command, command_windows, action,
3508+
check_only, NULL);
3509+
}
35013510
static int cbm_upsert_codex_hooks_command(const char *config_path, const char *command,
35023511
const char *command_windows) {
35033512
return cbm_reconcile_codex_hooks_command(config_path, command, command_windows,
@@ -7362,15 +7371,25 @@ static void describe_agent_config_target(const char *path, char *out, size_t out
73627371
(void)snprintf(out, out_size, " (target: %s, %lld bytes)", kind, (long long)info.size);
73637372
}
73647373

7365-
static void record_agent_config_error(bool uninstalling, const char *agent, const char *operation,
7366-
const char *path) {
7374+
static void record_agent_config_error_with_reason(bool uninstalling, const char *agent,
7375+
const char *operation, const char *path,
7376+
const char *reason) {
73677377
int *counter = uninstalling ? &g_agent_uninstall_errors : &g_agent_install_errors;
73687378
(*counter)++;
73697379
char detail[160];
73707380
describe_agent_config_target(path, detail, sizeof(detail));
7371-
(void)fprintf(stderr, "error: agent_config agent=%s op=%s path=%s%s\n",
7372-
agent ? agent : "unknown", operation ? operation : "unknown",
7373-
path ? path : "unknown", detail);
7381+
(void)fprintf(stderr, "error: agent_config agent=%s op=%s path=%s", agent ? agent : "unknown",
7382+
operation ? operation : "unknown", path ? path : "unknown");
7383+
if (reason && reason[0]) {
7384+
(void)fprintf(stderr, " reason=%s", reason);
7385+
}
7386+
(void)fputs(detail, stderr);
7387+
(void)fputc('\n', stderr);
7388+
}
7389+
7390+
static void record_agent_config_error(bool uninstalling, const char *agent, const char *operation,
7391+
const char *path) {
7392+
record_agent_config_error_with_reason(uninstalling, agent, operation, path, NULL);
73747393
}
73757394

73767395
static bool prepare_config_parent(const char *path) {
@@ -8507,10 +8526,22 @@ static void install_cli_agent_configs(const cbm_detected_agents_t *agents, const
85078526
sizeof(command_windows)) == CLI_OK;
85088527
cbm_toml_codex_hook_action_t preflight_action =
85098528
use_hooks_json ? CBM_TOML_CODEX_HOOK_REMOVE : CBM_TOML_CODEX_HOOK_UPSERT;
8510-
if (!commands_ok || cbm_reconcile_codex_hooks_command(cp, command, command_windows,
8511-
preflight_action, true) != CLI_OK) {
8512-
record_agent_config_error(false, "Codex CLI",
8513-
commands_ok ? "hook_preflight" : "hook_command_build", cp);
8529+
cbm_toml_codex_hook_failure_t preflight_failure = CBM_TOML_CODEX_HOOK_FAILURE_NONE;
8530+
int preflight_result = commands_ok ? cbm_reconcile_codex_hooks_command_detailed(
8531+
cp, command, command_windows, preflight_action,
8532+
true, &preflight_failure)
8533+
: CLI_ERR;
8534+
if (preflight_result != CLI_OK) {
8535+
if (!g_install_plan) {
8536+
printf("Codex CLI:\n");
8537+
fflush(stdout);
8538+
}
8539+
const char *reason = preflight_failure == CBM_TOML_CODEX_HOOK_FAILURE_NONE
8540+
? NULL
8541+
: cbm_toml_codex_hook_failure_name(preflight_failure);
8542+
record_agent_config_error_with_reason(
8543+
false, "Codex CLI", commands_ok ? "hook_preflight" : "hook_command_build", cp,
8544+
reason);
85148545
goto codex_install_done;
85158546
}
85168547
install_generic_agent_config("Codex CLI", binary_path, cp, ip, dry_run,
@@ -10760,14 +10791,21 @@ static void uninstall_cli_agents(const cbm_detected_agents_t *agents, const char
1076010791
char hook_command_windows[CLI_BUF_8K];
1076110792
bool hook_command_ok = cbm_build_augment_command(installed_binary, hook_command,
1076210793
sizeof(hook_command)) == CLI_OK;
10794+
bool hook_commands_ok = hook_command_ok && cbm_build_augment_command_windows(
10795+
installed_binary, hook_command_windows,
10796+
sizeof(hook_command_windows)) == CLI_OK;
10797+
cbm_toml_codex_hook_failure_t preflight_failure = CBM_TOML_CODEX_HOOK_FAILURE_NONE;
1076310798
bool hook_preflight_ok =
10764-
hook_command_ok &&
10765-
cbm_build_augment_command_windows(installed_binary, hook_command_windows,
10766-
sizeof(hook_command_windows)) == CLI_OK &&
10767-
cbm_reconcile_codex_hooks_command(cp, hook_command, hook_command_windows,
10768-
CBM_TOML_CODEX_HOOK_REMOVE, true) == CLI_OK;
10799+
hook_commands_ok && cbm_reconcile_codex_hooks_command_detailed(
10800+
cp, hook_command, hook_command_windows,
10801+
CBM_TOML_CODEX_HOOK_REMOVE, true, &preflight_failure) == CLI_OK;
1076910802
if (!hook_preflight_ok) {
10770-
record_agent_config_error(true, "Codex CLI", "hook_preflight", cp);
10803+
printf("Codex CLI:\n");
10804+
fflush(stdout);
10805+
const char *reason = preflight_failure == CBM_TOML_CODEX_HOOK_FAILURE_NONE
10806+
? NULL
10807+
: cbm_toml_codex_hook_failure_name(preflight_failure);
10808+
record_agent_config_error_with_reason(true, "Codex CLI", "hook_preflight", cp, reason);
1077110809
goto codex_toml_done;
1077210810
}
1077310811
uninstall_agent_mcp_instr((mcp_uninstall_args_t){"Codex CLI", cp, ip}, dry_run,

0 commit comments

Comments
 (0)