@@ -5,6 +5,7 @@ use std::process::Command;
55use anyhow:: { Context , Result } ;
66
77use crate :: app:: { ContextWithRepoRoot , HasRepoRoot } ;
8+ use crate :: services:: codex_hook_policy;
89use crate :: services:: default_paths:: { resolve_sce_default_locations, resolve_state_data_root} ;
910use crate :: services:: lifecycle:: {
1011 lifecycle_providers, FixOutcome , HealthCategory , HealthFixability , HealthProblem ,
@@ -52,6 +53,13 @@ struct DoctorDependencies<'a> {
5253 resolve_state_root : & ' a dyn Fn ( ) -> Result < PathBuf > ,
5354 resolve_global_config_path : & ' a dyn Fn ( ) -> Result < PathBuf > ,
5455 validate_config_file : & ' a dyn Fn ( & Path ) -> Result < ( ) > ,
56+ /// Probes Codex's effective hook-discovery policy
57+ /// (`allow_managed_hooks_only`). Invoked exactly once per doctor
58+ /// invocation (see `execute_doctor_with_lifecycle_providers`) and reused
59+ /// for every Codex integration inspection within that invocation —
60+ /// initial report, `--fix`, and final report alike — never once per
61+ /// registration.
62+ probe_codex_hook_policy : & ' a dyn Fn ( ) -> codex_hook_policy:: CodexHookPolicyReadiness ,
5563}
5664
5765struct DoctorExecution {
@@ -98,6 +106,7 @@ fn execute_doctor_with_context(
98106 Ok ( resolve_sce_default_locations ( ) ?. global_config_file ( ) )
99107 } ,
100108 validate_config_file : & crate :: services:: config:: validate_config_file,
109+ probe_codex_hook_policy : & codex_hook_policy:: probe_default,
101110 } ,
102111 )
103112}
@@ -108,6 +117,11 @@ fn execute_doctor_with_lifecycle_providers(
108117 context : & impl HasRepoRoot ,
109118 dependencies : & DoctorDependencies < ' _ > ,
110119) -> DoctorExecution {
120+ // Probed exactly once per doctor invocation, then reused for every
121+ // Codex integration inspection below (initial report, `--fix`, and final
122+ // report alike) instead of once per registration or once per report.
123+ let policy_readiness = ( dependencies. probe_codex_hook_policy ) ( ) ;
124+
111125 let providers = lifecycle_providers ( true ) ;
112126 let initial_problems = diagnose_lifecycle_providers ( context, & providers) ;
113127 let initial_doctor_problems = initial_problems
@@ -119,6 +133,7 @@ fn execute_doctor_with_lifecycle_providers(
119133 repository_root,
120134 dependencies,
121135 initial_doctor_problems,
136+ & policy_readiness,
122137 ) ;
123138
124139 if request. mode != DoctorMode :: Fix {
@@ -129,7 +144,10 @@ fn execute_doctor_with_lifecycle_providers(
129144 }
130145
131146 let mut fix_results = fix_lifecycle_providers ( context, & providers, & initial_problems) ;
132- fix_results. extend ( repair_merge_target_configs ( repository_root) ) ;
147+ fix_results. extend ( repair_merge_target_configs (
148+ repository_root,
149+ & policy_readiness,
150+ ) ) ;
133151 let final_problems = diagnose_lifecycle_providers ( context, & providers) ;
134152 let final_doctor_problems = final_problems
135153 . into_iter ( )
@@ -140,6 +158,7 @@ fn execute_doctor_with_lifecycle_providers(
140158 repository_root,
141159 dependencies,
142160 final_doctor_problems,
161+ & policy_readiness,
143162 ) ;
144163 fix_results. extend ( build_manual_fix_results ( & final_report) ) ;
145164
@@ -335,6 +354,12 @@ fn doctor_problem_kind(kind: HealthProblemKind) -> ProblemKind {
335354 HealthProblemKind :: CodexHookRegistrationNotTrusted => {
336355 ProblemKind :: CodexHookRegistrationNotTrusted
337356 }
357+ HealthProblemKind :: CodexHookRegistrationPolicyBlocked => {
358+ ProblemKind :: CodexHookRegistrationPolicyBlocked
359+ }
360+ HealthProblemKind :: CodexHookRegistrationPolicyUnknown => {
361+ ProblemKind :: CodexHookRegistrationPolicyUnknown
362+ }
338363 HealthProblemKind :: AgentTraceDbConnectionFailed => {
339364 ProblemKind :: AgentTraceDbConnectionFailed
340365 }
@@ -403,6 +428,12 @@ fn health_problem_kind(kind: ProblemKind) -> HealthProblemKind {
403428 ProblemKind :: CodexHookRegistrationNotTrusted => {
404429 HealthProblemKind :: CodexHookRegistrationNotTrusted
405430 }
431+ ProblemKind :: CodexHookRegistrationPolicyBlocked => {
432+ HealthProblemKind :: CodexHookRegistrationPolicyBlocked
433+ }
434+ ProblemKind :: CodexHookRegistrationPolicyUnknown => {
435+ HealthProblemKind :: CodexHookRegistrationPolicyUnknown
436+ }
406437 ProblemKind :: AgentTraceDbConnectionFailed => {
407438 HealthProblemKind :: AgentTraceDbConnectionFailed
408439 }
0 commit comments