Hide context entries for hidden hooks

This commit is contained in:
Abhinav Vedmala
2026-05-09 23:09:16 -04:00
parent 9f1135d912
commit e75419b47d
3 changed files with 60 additions and 8 deletions

View File

@@ -9,5 +9,8 @@ history:
<empty>
visible history:
• PostToolUse hook (completed)
warning: background hook warning
• PostToolUse hook (failed)
error: hook exited with code 7

View File

@@ -2381,14 +2381,38 @@ async fn hidden_hooks_skip_background_rendering_but_keep_failures_visible() {
let quiet_snapshot = hook_live_and_history_snapshot(&chat, "hidden background hook", "");
assert!(drain_insert_history(&mut rx).is_empty());
let mut hidden_failed = hook_completed_run(
let mut hidden_warning = hook_completed_run(
"post-tool-use:1:/tmp/hooks.json",
codex_app_server_protocol::HookEventName::PostToolUse,
codex_app_server_protocol::HookRunStatus::Completed,
vec![
codex_app_server_protocol::HookOutputEntry {
kind: codex_app_server_protocol::HookOutputEntryKind::Warning,
text: "background hook warning".to_string(),
},
codex_app_server_protocol::HookOutputEntry {
kind: codex_app_server_protocol::HookOutputEntryKind::Context,
text: "verbose hidden context".to_string(),
},
],
);
hidden_warning.visibility_hint = codex_app_server_protocol::HookVisibilityHint::Hidden;
handle_hook_completed(&mut chat, hidden_warning);
let mut hidden_failed = hook_completed_run(
"post-tool-use:2:/tmp/hooks.json",
codex_app_server_protocol::HookEventName::PostToolUse,
codex_app_server_protocol::HookRunStatus::Failed,
vec![codex_app_server_protocol::HookOutputEntry {
kind: codex_app_server_protocol::HookOutputEntryKind::Error,
text: "hook exited with code 7".to_string(),
}],
vec![
codex_app_server_protocol::HookOutputEntry {
kind: codex_app_server_protocol::HookOutputEntryKind::Context,
text: "verbose hidden context".to_string(),
},
codex_app_server_protocol::HookOutputEntry {
kind: codex_app_server_protocol::HookOutputEntryKind::Error,
text: "hook exited with code 7".to_string(),
},
],
);
hidden_failed.visibility_hint = codex_app_server_protocol::HookVisibilityHint::Hidden;
handle_hook_completed(&mut chat, hidden_failed);

View File

@@ -231,12 +231,16 @@ impl HookCell {
status_message,
status,
entries,
visibility_hint,
..
} = run;
let existing = &mut self.runs[index];
existing.event_name = event_name;
existing.status_message = status_message;
existing.state = HookRunState::completed(status, entries);
existing.state = HookRunState::completed(
status,
visible_hook_output_entries(visibility_hint, entries),
);
true
}
@@ -253,13 +257,17 @@ impl HookCell {
status_message,
status,
entries,
visibility_hint,
..
} = run;
self.runs.push(HookRunCell {
id,
event_name,
status_message,
state: HookRunState::completed(status, entries),
state: HookRunState::completed(
status,
visible_hook_output_entries(visibility_hint, entries),
),
});
}
@@ -693,11 +701,28 @@ pub(crate) fn hook_run_is_hidden(run: &HookRunSummary) -> bool {
HookRunStatus::Completed => run
.entries
.iter()
.all(|entry| entry.kind == HookOutputEntryKind::Context),
.all(|entry| !hook_output_entry_is_visible(run.visibility_hint, entry.kind)),
HookRunStatus::Blocked | HookRunStatus::Failed | HookRunStatus::Stopped => false,
}
}
fn visible_hook_output_entries(
visibility_hint: HookVisibilityHint,
entries: Vec<HookOutputEntry>,
) -> Vec<HookOutputEntry> {
entries
.into_iter()
.filter(|entry| hook_output_entry_is_visible(visibility_hint, entry.kind))
.collect()
}
fn hook_output_entry_is_visible(
visibility_hint: HookVisibilityHint,
kind: HookOutputEntryKind,
) -> bool {
visibility_hint != HookVisibilityHint::Hidden || kind != HookOutputEntryKind::Context
}
fn hook_completed_bullet(status: HookRunStatus, entries: &[HookOutputEntry]) -> Span<'static> {
match status {
HookRunStatus::Completed => {