fix(hooks): restore with proper SessionStart matchers

- Add matcher: startup|resume|compact for SessionStart (per docs)
- PreToolUse reads from stdin per documented hook input format
- Remove  arg, use stdin-based approach
- Scripts read event JSON from stdin as documented
- Plain text output, no special characters
This commit is contained in:
asepharyana
2026-07-26 12:03:49 +07:00
parent d324c1b3c0
commit 95a91d7bf5
3 changed files with 39 additions and 50 deletions
+12 -27
View File
@@ -1,33 +1,18 @@
#!/bin/bash
# hub-guide: detect file extension from tool input and suggest language-specific rules
# Runs before Write/Edit to inject best-practice context
# hub-guide: detect file extension and suggest language-specific rules
# Reads PreToolUse event JSON from stdin.
set -euo pipefail
TOOL_INPUT="$1"
# Extract file path from tool input (looks for "file_path" in JSON)
FILE_PATH=$(echo "$TOOL_INPUT" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
EXT="${FILE_PATH##*.}"
case "$EXT" in
ts|tsx)
echo "[hub-guide] TypeScript file — apply typescript skill rules (strict types, no-any, proper generics)"
;;
py)
echo "[hub-guide] Python file — apply python skill rules (type hints, PEP 8, no wildcard imports)"
;;
rs)
echo "[hub-guide] Rust file — apply rust skill rules (ownership, error handling, clippy clean)"
;;
go)
echo "[hub-guide] Go file — apply go skill rules (idiomatic Go, interfaces, error handling)"
;;
js|jsx)
echo "[hub-guide] JavaScript file — apply typescript skill rules (ESM, modern JS)"
;;
dockerfile|Dockerfile)
echo "[hub-guide] Dockerfile — apply docker skill rules (multi-stage, minimal layers, no root)"
;;
yml|yaml)
echo "[hub-guide] YAML file — check ci-cd and docker skill rules"
;;
ts|tsx) echo "[hub-guide] .${EXT} -> typescript" ;;
py) echo "[hub-guide] .py -> python" ;;
rs) echo "[hub-guide] .rs -> rust" ;;
go) echo "[hub-guide] .go -> go" ;;
js|jsx) echo "[hub-guide] .${EXT} -> typescript" ;;
Dockerfile|dockerfile) echo "[hub-guide] Dockerfile -> docker" ;;
yml|yaml) echo "[hub-guide] .${EXT} -> ci-cd+docker" ;;
esac