Initial commit — tg-stream, tg-task, Claude Code hooks
This commit is contained in:
35
hooks/bash-heartbeat-post.sh
Executable file
35
hooks/bash-heartbeat-post.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
# PostToolUse hook on the Bash tool — if the wrapped command took longer than
|
||||
# DURATION_FLOOR seconds, send a "done in Ns · <label>" completion ping so the
|
||||
# user always knows when the long thing finished.
|
||||
#
|
||||
# Pairs with bash-heartbeat-pre.sh which writes /tmp/.bash-hb-<PPID>.
|
||||
#
|
||||
# Input: JSON {"tool_name":"Bash","tool_input":{...},"tool_response":{...}}
|
||||
# Output: always exit 0.
|
||||
|
||||
set -u
|
||||
INPUT=$(cat) >/dev/null
|
||||
|
||||
DURATION_FLOOR=5
|
||||
STATE_FILE="/tmp/.bash-hb-$PPID"
|
||||
|
||||
if [[ ! -f "$STATE_FILE" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
START=$(cut -d'|' -f1 "$STATE_FILE")
|
||||
LABEL=$(cut -d'|' -f2- "$STATE_FILE")
|
||||
rm -f "$STATE_FILE"
|
||||
|
||||
NOW=$(date +%s)
|
||||
ELAPSED=$((NOW - START))
|
||||
|
||||
if (( ELAPSED < DURATION_FLOOR )); then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Fire the completion ping (no-stream so it lands instantly)
|
||||
/host/root/openclaw/tg-stream --no-stream "✅ done in ${ELAPSED}s · $LABEL" >/dev/null 2>&1 &
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user