Refine hook activity rendering in the TUI (#42118)

## What changed

- Show revealed running hooks in the bottom activity area instead of the conversation viewport or transcript overlay. Fold the hook message into the active status row when space permits and reflow it below the row without displacing background-process controls or status details.
- Keep fast hooks hidden, collapse concurrent hooks to a shared summary when needed, and support hook activity outside an active agent turn.
- Simplify durable hook output into user-facing messages and actionable failure, block, and stop states. Suppress model-facing context and quiet successful completions from all TUI history surfaces.

## Testing

- Add lifecycle, layout, narrow-width, multi-width Unicode, transcript, restart, and completion-output coverage for hook status and history rendering.

GitOrigin-RevId: 4c52b7a736e9e466e109107eb3c04a39d089597f
This commit is contained in:
Abhinav authored and copyberry committed 2026-09-01 19:06:32 +00:00
1 parent ea7e0714da
commit bc39b0ed59
35 files changed
+903 -945

No files matched your search

@@ -1,11 +1,8 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"active hooks:\\n{}history:\\n{history}\", active_hook_blob(&chat))"
expression: history
---
active hooks:
<empty>
history:
• PreToolUse hook (blocked)
feedback: command blocked by policy
• Blocked by hook
└ command blocked by policy
• The hook feedback was applied.
@@ -3,14 +3,24 @@ source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"{running_snapshot}\\n\\n{completed_snapshot}\")"
---
running
live hooks:
• Running PreToolUse hook: checking command
activity:
" "
"• Checking command "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
<empty>
completed
live hooks:
<empty>
activity:
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
• PreToolUse hook (blocked)
feedback: command blocked by policy
• Blocked by hook
└ command blocked by policy
@@ -1,9 +1,16 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"active hooks:\\n{}history:\\n{history}\", active_hook_blob(&chat))"
expression: "hook_status_and_history_snapshot(&chat, \"restarted\", &history)"
---
active hooks:
• Running Stop hook: checking stop condition
restarted
activity:
" "
"• Checking stop condition "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
• Stop hook (stopped)
stop: continue with more context
• Hook stopped
└ continue with more context
@@ -1,8 +1,18 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"before completion:\\n{before_completion}after completion:\\n{}\",\nactive_hook_blob(&chat))"
expression: "format!(\"before completion:\\n{before_completion}\\nafter completion:\\n{}\",\nhook_status_frame(&chat, 80))"
---
before completion:
• Running PostToolUse hook
" "
"• Working (0s • esc to interrupt) · Running hook "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
after completion:
<empty>
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -2,8 +2,8 @@
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: rendered
---
• PreToolUse hook (blocked)
feedback: run tests before touching the fixture
• Blocked by hook
└ run tests before touching the fixture
• PostToolUse hook (failed)
error: hook exited with code 7
• Hook failed
└ hook exited with code 7
@@ -1,10 +0,0 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"started hidden:\\n{started_hidden_snapshot}\\nhistory:\\n{history}\")"
---
started hidden:
history:
• SessionStart hook (completed)
hook context: session context
second line
@@ -1,21 +0,0 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"{running_snapshot}\\n\\n{completed_lingering_snapshot}\\n\\n{completed_snapshot}\")"
---
running
live hooks:
• Running PostToolUse hook
history:
<empty>
completed lingering
live hooks:
• Running PostToolUse hook
history:
<empty>
completed after linger
live hooks:
<empty>
history:
<empty>
@@ -1,25 +1,37 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"exec running:\\n{exec_running}\\nexec and hook running:\\n{exec_and_hook_running}\\nhistory after exec:\\n{history_after_exec}\\nhook running after exec:\\n{hook_running_after_exec}\\nquiet hook completed lingering:\\n{quiet_hook_completed_lingering}\\nquiet hook completed:\\n{quiet_hook_completed}\")"
expression: "format!(\"exec running:\\n{exec_running}\\nexec and hook running:\\n{exec_and_hook_running}\\nhistory after exec:\\n{history_after_exec}\\nhook running after exec:\\n{hook_running_after_exec}\\nquiet hook completed:\\n{quiet_hook_completed}\")"
---
exec running:
• Running echo done
exec and hook running:
active exec:
• Running echo done
active hooks:
• Running PostToolUse hook: checking output policy
" "
"• Running echo done "
" "
"• Working (0s • esc to interrupt) · checking output policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history after exec:
• Ran echo done
└ done
hook running after exec:
• Running PostToolUse hook: checking output policy
quiet hook completed lingering:
• Running PostToolUse hook: checking output policy
" "
"• Working (0s • esc to interrupt) · checking output policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
quiet hook completed:
<empty>
" "
"• Working (0s • esc to interrupt) "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -1,9 +0,0 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "hook_live_and_history_snapshot(&chat, \"running\", \"\")"
---
running
live hooks:
• Running 3 PreToolUse hooks: checking command policy
history:
<empty>
@@ -2,4 +2,4 @@
source: tui/src/chatwidget/tests/helpers.rs
expression: combined
---
• Interrupt (completed) says: Heads up from the hook
↳ Hook · Heads up from the hook
@@ -1,8 +1,18 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"before interrupt:\\n{before_interrupt}after interrupt:\\n{}\",\nactive_hook_blob(&chat))"
expression: "format!(\"before interrupt:\\n{before_interrupt}\\nafter interrupt:\\n{}\",\nhook_status_frame(&chat, 80))"
---
before interrupt:
• Running PreToolUse hook: checking command policy
" "
"• Working (0s • esc to interrupt) · checking command policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
after interrupt:
<empty>
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -1,10 +0,0 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: history
---
• SessionStart hook (stopped)
hook context: This hook context is intentionally long enough to wrap across
several terminal rows while keeping the complete value available in the
… +2 lines (ctrl + t to view transcript)
stop: The hook stopped this turn for an important reason.
This second line must remain visible in full.
@@ -0,0 +1,22 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"80 columns:\\n{}\\n120 columns:\\n{}\", hook_status_frame(&chat, 80),\nhook_status_frame(&chat, 120),)"
---
80 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view…"
" └ checking command policy for deployment commands, production credentials, an…"
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
120 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view · /stop to close "
" └ checking command policy for deployment commands, production credentials, and paths containing 日本語 before continu…" Hidden by multi-width symbols: [(99, " "), (101, " "), (103, " ")]
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -0,0 +1,21 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"80 columns:\\n{}\\n120 columns:\\n{}\", hook_status_frame(&chat, 80),\nhook_status_frame(&chat, 120),)"
---
80 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view…"
" └ Running hooks "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
120 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view · /stop to close · Running hooks "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -1,43 +1,51 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"{first_running_snapshot}\\n\\n{second_running_snapshot}\\n\\n{older_completed_snapshot}\\n\\n{older_completed_expired_snapshot}\\n\\n{all_completed_lingering_snapshot}\\n\\n{all_completed_snapshot}\")"
expression: "format!(\"{first_running_snapshot}\\n\\n{second_running_snapshot}\\n\\n{older_completed_snapshot}\\n\\n{all_completed_snapshot}\")"
---
pre running
live hooks:
• Running PreToolUse hook: checking command policy
activity:
" "
"• Thinking (0s • esc to interrupt) · checking command policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
<empty>
post running
live hooks:
• Running PreToolUse hook: checking command policy
• Running PostToolUse hook: checking output policy
activity:
" "
"• Thinking (0s • esc to interrupt) · Running hooks "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
<empty>
pre completed lingering
live hooks:
• Running PreToolUse hook: checking command policy
• Running PostToolUse hook: checking output policy
history:
<empty>
pre completed after linger
live hooks:
• Running PostToolUse hook: checking output policy
history:
<empty>
all completed lingering
live hooks:
• Running PostToolUse hook: checking output policy
pre completed
activity:
" "
"• Thinking (0s • esc to interrupt) · checking output policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
<empty>
all completed
live hooks:
<empty>
activity:
" "
"• Thinking (0s • esc to interrupt) "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
history:
<empty>
@@ -2,5 +2,4 @@
source: tui/src/chatwidget/tests/helpers.rs
expression: combined
---
• PostToolUse (completed) says: Heads up from the hook
hook context: Remember the startup checklist.
↳ Hook · Heads up from the hook
@@ -2,5 +2,4 @@
source: tui/src/chatwidget/tests/helpers.rs
expression: combined
---
• PreToolUse (completed) says: Heads up from the hook
hook context: Remember the startup checklist.
↳ Hook · Heads up from the hook
@@ -0,0 +1,22 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"80 columns:\\n{}\\n120 columns:\\n{}\", hook_status_frame(&chat, 80),\nhook_status_frame(&chat, 120),)"
---
80 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view…"
" └ checking command policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
120 columns:
" "
"• Working (0s • esc to interrupt) · 1 background terminal running · /ps to view · /stop to close "
" └ checking command policy "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -0,0 +1,24 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"before reveal:\\n{hidden}\\nrunning:\\n{running}\\ncompleted:\\n{}\",\nhook_status_frame(&chat, 80),)"
---
before reveal:
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
running:
" "
"• Saving session summary "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
completed:
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -0,0 +1,24 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: "format!(\"before reveal:\\n{hidden}\\nrunning:\\n{running}\\ncompleted:\\n{}\",\nhook_status_frame(&chat, 80),)"
---
before reveal:
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
running:
" "
"• Running hook "
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
completed:
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.6-sol default · /tmp/project "
@@ -2,5 +2,4 @@
source: tui/src/chatwidget/tests/helpers.rs
expression: combined
---
• SessionStart (completed) says: Heads up from the hook
hook context: Remember the startup checklist.
↳ Hook · Heads up from the hook
@@ -0,0 +1,7 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: history
---
• Hook stopped
└ The hook stopped this turn for an important reason.
This second line must remain visible in full.
@@ -2,5 +2,6 @@
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: combined
---
• UserPromptSubmit (stopped) says: go-workflow must start from PlanMode
stop: prompt blocked
• Hook stopped
└ go-workflow must start from PlanMode
└ prompt blocked