diff --git a/codex-rs/tui/src/bottom_pane/hooks_browser_view.rs b/codex-rs/tui/src/bottom_pane/hooks_browser_view.rs index 22abd331e4..26e762e3b5 100644 --- a/codex-rs/tui/src/bottom_pane/hooks_browser_view.rs +++ b/codex-rs/tui/src/bottom_pane/hooks_browser_view.rs @@ -241,27 +241,46 @@ impl HooksBrowserView { ] } - fn handler_header_lines(event_name: HookEventName) -> Vec> { - vec![ - format!("{} hooks", event_label(event_name)).bold().into(), - "Review new or changed hooks, then turn them on or off." - .dim() - .into(), - ] + fn handler_header_lines( + event_name: HookEventName, + review_needed_count: usize, + ) -> Vec> { + let mut lines = vec![format!("{} hooks", event_label(event_name)).bold().into()]; + match review_needed_count { + 0 => {} + 1 => lines.push("1 hook needs review before it can run.".dim().into()), + count => lines.push( + format!("{count} hooks need review before they can run.") + .dim() + .into(), + ), + } + lines + } + + fn review_needed_count(&self, event_name: HookEventName) -> usize { + self.handlers_for_event(event_name) + .filter(|hook| hook_needs_review(hook)) + .count() } fn event_table_lines(&self) -> Vec> { + let rows = self.event_rows(); + let show_review = rows.iter().any(|row| row.needs_review > 0); let mut lines = Vec::new(); - lines.push(Line::from(vec![ + let mut header = vec![ format!("{: self.event_page_lines().len(), HooksBrowserPage::Handlers(event_name) => { let row_count = self.handler_row_lines(event_name, content_width).len(); + let header_line_count = + Self::handler_header_lines(event_name, self.review_needed_count(event_name)) + .len(); if row_count == 0 { - Self::handler_header_lines(event_name).len() + 2 + header_line_count + 2 } else { let visible_row_count = row_count.min(MAX_POPUP_ROWS); - Self::handler_header_lines(event_name).len() + header_line_count + 1 + visible_row_count + 1 @@ -554,7 +586,8 @@ impl Renderable for HooksBrowserView { let lines = match self.page { HooksBrowserPage::Events => self.event_page_lines(), HooksBrowserPage::Handlers(event_name) => { - let mut lines = Self::handler_header_lines(event_name); + let mut lines = + Self::handler_header_lines(event_name, self.review_needed_count(event_name)); let rows = self.handler_row_lines(event_name, width); if rows.is_empty() { lines.push(Line::default()); @@ -872,6 +905,34 @@ mod tests { assert_snapshot!("hooks_browser_events", render_lines(&view, /*width*/ 112)); } + #[test] + fn renders_event_browser_with_review_column_when_needed() { + let (tx_raw, _rx) = unbounded_channel::(); + let mut untrusted_hook = hook( + "path:untrusted", + HookEventName::PreToolUse, + HookSource::User, + /*plugin_id*/ None, + "/tmp/pre-tool-use-check.sh", + /*enabled*/ false, + /*is_managed*/ false, + /*display_order*/ 0, + ); + untrusted_hook.trusted_hash = None; + untrusted_hook.trust_status = HookTrustStatus::Untrusted; + let view = HooksBrowserView::new( + vec![untrusted_hook], + Vec::new(), + Vec::new(), + AppEventSender::new(tx_raw), + ); + + assert_snapshot!( + "hooks_browser_events_with_review_column", + render_lines(&view, /*width*/ 112) + ); + } + #[test] fn renders_event_browser_with_issues() { let (tx_raw, _rx) = unbounded_channel::(); diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_capped_command_details.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_capped_command_details.snap index f6efb4995a..a747e50f2b 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_capped_command_details.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_capped_command_details.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 44)" --- PreToolUse hooks - Review new or changed hooks, then turn t [x] Hook 1 diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_empty_handlers.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_empty_handlers.snap index 753ee2331d..e65f953553 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_empty_handlers.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_empty_handlers.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 112)" --- PermissionRequest hooks - Review new or changed hooks, then turn them on or off. No hooks installed for this event. diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events.snap index 096fb562f8..522105c30d 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events.snap @@ -6,12 +6,12 @@ expression: "render_lines(&view, 112)" Hooks Lifecycle hooks from config and enabled plugins. - Event Installed Active Review Description - PreToolUse 2 1 0 Before a tool executes - PermissionRequest 1 1 0 When permission is requested - PostToolUse 0 0 0 After a tool executes - SessionStart 0 0 0 When a new session starts - UserPromptSubmit 0 0 0 When the user submits a prompt - Stop 0 0 0 Right before Codex ends its turn + Event Installed Active Description + PreToolUse 2 1 Before a tool executes + PermissionRequest 1 1 When permission is requested + PostToolUse 0 0 After a tool executes + SessionStart 0 0 When a new session starts + UserPromptSubmit 0 0 When the user submits a prompt + Stop 0 0 Right before Codex ends its turn Press enter to view hooks; esc to close diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_issues.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_issues.snap index 8d10909d37..18e3b9f849 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_issues.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_issues.snap @@ -10,12 +10,12 @@ expression: "render_lines(&view, 112)" ⚠ skipped invalid matcher for PreToolUse ■ /tmp/hooks.json: failed to parse hooks config - Event Installed Active Review Description - PreToolUse 0 0 0 Before a tool executes - PermissionRequest 0 0 0 When permission is requested - PostToolUse 0 0 0 After a tool executes - SessionStart 0 0 0 When a new session starts - UserPromptSubmit 0 0 0 When the user submits a prompt - Stop 0 0 0 Right before Codex ends its turn + Event Installed Active Description + PreToolUse 0 0 Before a tool executes + PermissionRequest 0 0 When permission is requested + PostToolUse 0 0 After a tool executes + SessionStart 0 0 When a new session starts + UserPromptSubmit 0 0 When the user submits a prompt + Stop 0 0 Right before Codex ends its turn Press enter to view hooks; esc to close diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_review_column.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_review_column.snap new file mode 100644 index 0000000000..85e930c68c --- /dev/null +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_events_with_review_column.snap @@ -0,0 +1,17 @@ +--- +source: tui/src/bottom_pane/hooks_browser_view.rs +expression: "render_lines(&view, 112)" +--- + + Hooks + Lifecycle hooks from config and enabled plugins. + + Event Installed Active Review Description + PreToolUse 1 0 1 Before a tool executes + PermissionRequest 0 0 0 When permission is requested + PostToolUse 0 0 0 After a tool executes + SessionStart 0 0 0 When a new session starts + UserPromptSubmit 0 0 0 When the user submits a prompt + Stop 0 0 0 Right before Codex ends its turn + + Press enter to view hooks; esc to close diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_handlers.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_handlers.snap index 7e5fcf627f..62890612da 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_handlers.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_handlers.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 112)" --- PreToolUse hooks - Review new or changed hooks, then turn them on or off. [x] Hook 1 [ ] Hook 2 diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_managed_handler.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_managed_handler.snap index 48bbd9cd01..39ed8a6cda 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_managed_handler.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_managed_handler.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 112)" --- PermissionRequest hooks - Review new or changed hooks, then turn them on or off. [x] Hook 1 diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_review_needed_handler.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_review_needed_handler.snap index 1b7c45701b..b4a5c117e1 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_review_needed_handler.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_review_needed_handler.snap @@ -4,7 +4,7 @@ expression: "render_lines(&view, 112)" --- PreToolUse hooks - Review new or changed hooks, then turn them on or off. + 1 hook needs review before it can run. [!] Hook 1 · new diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_scrolled_handlers.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_scrolled_handlers.snap index fe896ea59c..c4d42319da 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_scrolled_handlers.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_scrolled_handlers.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 112)" --- PreToolUse hooks - Review new or changed hooks, then turn them on or off. [x] Hook 2 [x] Hook 3 diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_selected_managed_handler.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_selected_managed_handler.snap index 0c5a7ccf7a..ac23f90ff6 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_selected_managed_handler.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__hooks_browser_view__tests__hooks_browser_selected_managed_handler.snap @@ -4,7 +4,6 @@ expression: "render_lines(&view, 112)" --- PreToolUse hooks - Review new or changed hooks, then turn them on or off. [x] Hook 1 [x] Hook 2 diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__hooks_popup_shows_list_diagnostics.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__hooks_popup_shows_list_diagnostics.snap index 1db52419a1..865d19031f 100644 --- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__hooks_popup_shows_list_diagnostics.snap +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__hooks_popup_shows_list_diagnostics.snap @@ -9,12 +9,12 @@ expression: popup ⚠ skipped invalid matcher for PreToolUse ■ /tmp/hooks.json: failed to parse hooks config - Event Installed Active Review Description - PreToolUse 0 0 0 Before a tool executes - PermissionRequest 0 0 0 When permission is requested - PostToolUse 0 0 0 After a tool executes - SessionStart 0 0 0 When a new session starts - UserPromptSubmit 0 0 0 When the user submits a prompt - Stop 0 0 0 Right before Codex ends its turn + Event Installed Active Description + PreToolUse 0 0 Before a tool executes + PermissionRequest 0 0 When permission is requested + PostToolUse 0 0 After a tool executes + SessionStart 0 0 When a new session starts + UserPromptSubmit 0 0 When the user submits a prompt + Stop 0 0 Right before Codex ends its turn Press enter to view hooks; esc to close