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
+27 -19
View File
@@ -1,23 +1,31 @@
{ {
"hooks": { "hooks": {
"SessionStart": [{ "SessionStart": [
"matcher": "startup|clear|compact", {
"hooks": [{ "matcher": "startup|resume|compact",
"type": "command", "hooks": [
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-project.sh\"", {
"shell": "bash", "type": "command",
"timeout": 10, "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-project.sh\"",
"async": false "shell": "bash",
}] "timeout": 10,
}], "async": false
"PreToolUse": [{ }
"matcher": "Write|Edit", ]
"hooks": [{ }
"type": "command", ],
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-file-type.sh\" \"$TOOL_INPUT\"", "PreToolUse": [
"shell": "bash", {
"timeout": 10 "matcher": "Write|Edit",
}] "hooks": [
}] {
"type": "command",
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-file-type.sh\"",
"shell": "bash",
"timeout": 10
}
]
}
]
} }
} }
+12 -27
View File
@@ -1,33 +1,18 @@
#!/bin/bash #!/bin/bash
# hub-guide: detect file extension from tool input and suggest language-specific rules # hub-guide: detect file extension and suggest language-specific rules
# Runs before Write/Edit to inject best-practice context # Reads PreToolUse event JSON from stdin.
set -euo pipefail
TOOL_INPUT="$1" INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | grep -o '"file_path"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\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/')
EXT="${FILE_PATH##*.}" EXT="${FILE_PATH##*.}"
case "$EXT" in case "$EXT" in
ts|tsx) ts|tsx) echo "[hub-guide] .${EXT} -> typescript" ;;
echo "[hub-guide] TypeScript file — apply typescript skill rules (strict types, no-any, proper generics)" py) echo "[hub-guide] .py -> python" ;;
;; rs) echo "[hub-guide] .rs -> rust" ;;
py) go) echo "[hub-guide] .go -> go" ;;
echo "[hub-guide] Python file — apply python skill rules (type hints, PEP 8, no wildcard imports)" js|jsx) echo "[hub-guide] .${EXT} -> typescript" ;;
;; Dockerfile|dockerfile) echo "[hub-guide] Dockerfile -> docker" ;;
rs) yml|yaml) echo "[hub-guide] .${EXT} -> ci-cd+docker" ;;
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"
;;
esac esac
-4
View File
@@ -9,7 +9,6 @@ SKILL_NAMES=""
has_dep() { local n="$1"; grep -q "\"$n\"" package.json 2>/dev/null; } has_dep() { local n="$1"; grep -q "\"$n\"" package.json 2>/dev/null; }
# --- project detection ---
if [ -f "pnpm-workspace.yaml" ] || [ -f "lerna.json" ] || [ -f "nx.json" ] || [ -f "rush.json" ] || [ -f "turborepo.json" ]; then if [ -f "pnpm-workspace.yaml" ] || [ -f "lerna.json" ] || [ -f "nx.json" ] || [ -f "rush.json" ] || [ -f "turborepo.json" ]; then
SKILL_NAMES="$SKILL_NAMES, monorepo" SKILL_NAMES="$SKILL_NAMES, monorepo"
fi fi
@@ -41,11 +40,8 @@ fi
MANDATORY="engineering-principles clean-code clean-architecture testing error-handling security git-workflow api-design" MANDATORY="engineering-principles clean-code clean-architecture testing error-handling security git-workflow api-design"
SKILL_NAMES="${SKILL_NAMES#, }" SKILL_NAMES="${SKILL_NAMES#, }"
# --- output: plain text only, no emoji, no JSON ---
echo "[hub-guide] session: ${PROJECT_DIR}" echo "[hub-guide] session: ${PROJECT_DIR}"
echo "[hub-guide] mandatory: ${MANDATORY}" echo "[hub-guide] mandatory: ${MANDATORY}"
if [ -n "$SKILL_NAMES" ]; then if [ -n "$SKILL_NAMES" ]; then
echo "[hub-guide] active: ${SKILL_NAMES}" echo "[hub-guide] active: ${SKILL_NAMES}"
fi fi
echo ""
echo "EXTREMELY_IMPORTANT: The hub-guide skills listed above are loaded and active. They apply to every code decision in this session. Never suppress lints. Never assume — show evidence. All skills work regardless of spoken language."