Skip to content

Commit f04d64e

Browse files
committed
feat(overlay): session context header, 300s hook timeout
1 parent 45febd3 commit f04d64e

5 files changed

Lines changed: 39 additions & 11 deletions

File tree

hooks/handlers/pre-tool-use.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ fi
608608
export PASSTHRU_OVERLAY_RESULT_FILE="$OVERLAY_RESULT"
609609
export PASSTHRU_OVERLAY_TOOL_NAME="$TOOL_NAME"
610610
export PASSTHRU_OVERLAY_TOOL_INPUT_JSON="$TOOL_INPUT"
611+
export PASSTHRU_OVERLAY_CWD="$CC_CWD"
611612

612613
# Invoke the overlay and capture its exit code. We have an ERR trap in place
613614
# (converts unexpected errors to fail-open passthrough), so we cannot rely on

hooks/hooks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"type": "command",
1010
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/handlers/pre-tool-use.sh",
11-
"timeout": 75
11+
"timeout": 300
1212
}
1313
]
1414
}

scripts/overlay-dialog.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ TOOL_NAME="${PASSTHRU_OVERLAY_TOOL_NAME:-}"
5454
TOOL_INPUT_JSON="${PASSTHRU_OVERLAY_TOOL_INPUT_JSON:-}"
5555
RESULT_FILE="${PASSTHRU_OVERLAY_RESULT_FILE:-}"
5656
TIMEOUT="${PASSTHRU_OVERLAY_TIMEOUT:-60}"
57+
OVERLAY_CWD="${PASSTHRU_OVERLAY_CWD:-${PWD}}"
5758
TEST_ANSWER="${PASSTHRU_OVERLAY_TEST_ANSWER:-}"
5859

5960
# Without a result file path we have nowhere to write. Bail silently (caller
@@ -272,9 +273,34 @@ if [ "${#preview_lines[@]}" -eq 0 ]; then
272273
preview_lines+=("$(_truncate "$TOOL_INPUT_JSON" 120)")
273274
fi
274275

276+
# Session context for the header (helps distinguish multiple CC sessions).
277+
_display_cwd="$OVERLAY_CWD"
278+
case "$_display_cwd" in
279+
"$HOME"/*) _display_cwd="~${_display_cwd#"$HOME"}" ;;
280+
"$HOME") _display_cwd="~" ;;
281+
esac
282+
# Session label: prefer CC session name (CLAUDE_SESSION_NAME) if set,
283+
# fall back to tmux window name, then omit.
284+
_session_label=""
285+
if [ -n "${CLAUDE_SESSION_NAME:-}" ]; then
286+
_session_label="$CLAUDE_SESSION_NAME"
287+
elif [ -n "${TMUX:-}" ]; then
288+
_w="$(tmux display-message -p '#W' 2>/dev/null || true)"
289+
[ -n "$_w" ] && _session_label="$_w"
290+
fi
291+
292+
_render_header() {
293+
printf "${BOLD}Passthru Permission Prompt${RESET}\n"
294+
printf "\033[2mcwd: %s\033[0m\n" "$_display_cwd"
295+
if [ -n "$_session_label" ]; then
296+
printf "\033[2msession: %s\033[0m\n" "$_session_label"
297+
fi
298+
printf '\n'
299+
}
300+
275301
render_main_menu() {
276302
printf '\033[H\033[2J'
277-
printf "${BOLD}Passthru Permission Prompt${RESET}\n\n"
303+
_render_header
278304
printf "Tool: ${CYAN}%s${RESET}\n" "${TOOL_NAME:-(unknown)}"
279305
# Render preview lines.
280306
local first=1
@@ -375,7 +401,7 @@ prop_match_val="$(jq -r '.match // empty | to_entries[0].value // empty' <<<"$pr
375401

376402
render_rule_editor() {
377403
printf '\033[H\033[2J'
378-
printf "${BOLD}Passthru Permission Prompt${RESET}\n\n"
404+
_render_header "$_display_cwd"
379405
printf "Tool: ${CYAN}%s${RESET}\n" "${TOOL_NAME:-(unknown)}"
380406
local _first=1
381407
for _pl in "${preview_lines[@]}"; do

scripts/overlay.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ _write_env_file() {
131131
printf 'export PASSTHRU_OVERLAY_TOOL_NAME=%q\n' "${PASSTHRU_OVERLAY_TOOL_NAME:-}" >> "$_ENV_FILE"
132132
printf 'export PASSTHRU_OVERLAY_TOOL_INPUT_JSON=%q\n' "${PASSTHRU_OVERLAY_TOOL_INPUT_JSON:-}" >> "$_ENV_FILE"
133133
printf 'export PASSTHRU_OVERLAY_TIMEOUT=%q\n' "$TIMEOUT" >> "$_ENV_FILE"
134+
printf 'export PASSTHRU_OVERLAY_CWD=%q\n' "${PASSTHRU_OVERLAY_CWD:-${PWD}}" >> "$_ENV_FILE"
134135
if [ -n "${PASSTHRU_OVERLAY_TEST_ANSWER:-}" ]; then
135136
printf 'export PASSTHRU_OVERLAY_TEST_ANSWER=%q\n' "$PASSTHRU_OVERLAY_TEST_ANSWER" >> "$_ENV_FILE"
136137
fi
@@ -156,7 +157,8 @@ case "$_tool" in
156157
[ "$_jlines" -gt 10 ] && _jlines=10
157158
_extra=$((_jlines)) ;;
158159
esac
159-
_popup_height=$((13 + _extra))
160+
# +2 for cwd line + optional window/session line in header
161+
_popup_height=$((15 + _extra))
160162
[ "$_popup_height" -gt 30 ] && _popup_height=30
161163

162164
launch_tmux() {

tests/plugin_loads.bats

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ setup() {
9999
[[ "$output" == *'pre-tool-use.sh' ]]
100100
}
101101

102-
@test "hooks/hooks.json PreToolUse timeout is 75 (overlay + margin)" {
103-
# Task 8 bumped the PreToolUse timeout from 10s to 75s because the hook
104-
# may block synchronously while the overlay dialog waits for user input.
105-
# The overlay's own timeout is 60s, so 75s leaves 15s of margin for
106-
# overlay.sh startup + post-dialog rule write. CC's hook timeout is
107-
# wall-clock, so anything < 60s would kill the hook mid-dialog.
102+
@test "hooks/hooks.json PreToolUse timeout is 300 (overlay interactive budget)" {
103+
# The hook blocks while the overlay dialog waits for user input. The user
104+
# may navigate menus, review rules, and edit regex fields. 300s (5 min)
105+
# gives generous interactive time. The overlay's per-read timeout (60s)
106+
# provides the inner limit.
108107
run jq -r '.hooks.PreToolUse[0].hooks[0].timeout' "$REPO_ROOT/hooks/hooks.json"
109108
[ "$status" -eq 0 ]
110-
[ "$output" = "75" ]
109+
[ "$output" = "300" ]
111110
}
112111

113112
@test "hooks/hooks.json has exactly one PostToolUse entry" {

0 commit comments

Comments
 (0)