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:
+27
-19
@@ -1,23 +1,31 @@
|
||||
{
|
||||
"hooks": {
|
||||
"SessionStart": [{
|
||||
"matcher": "startup|clear|compact",
|
||||
"hooks": [{
|
||||
"type": "command",
|
||||
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-project.sh\"",
|
||||
"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\"",
|
||||
"shell": "bash",
|
||||
"timeout": 10
|
||||
}]
|
||||
}]
|
||||
"SessionStart": [
|
||||
{
|
||||
"matcher": "startup|resume|compact",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-project.sh\"",
|
||||
"shell": "bash",
|
||||
"timeout": 10,
|
||||
"async": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"PreToolUse": [
|
||||
{
|
||||
"matcher": "Write|Edit",
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/scripts/detect-file-type.sh\"",
|
||||
"shell": "bash",
|
||||
"timeout": 10
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -9,7 +9,6 @@ SKILL_NAMES=""
|
||||
|
||||
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
|
||||
SKILL_NAMES="$SKILL_NAMES, monorepo"
|
||||
fi
|
||||
@@ -41,11 +40,8 @@ fi
|
||||
MANDATORY="engineering-principles clean-code clean-architecture testing error-handling security git-workflow api-design"
|
||||
SKILL_NAMES="${SKILL_NAMES#, }"
|
||||
|
||||
# --- output: plain text only, no emoji, no JSON ---
|
||||
echo "[hub-guide] session: ${PROJECT_DIR}"
|
||||
echo "[hub-guide] mandatory: ${MANDATORY}"
|
||||
if [ -n "$SKILL_NAMES" ]; then
|
||||
echo "[hub-guide] active: ${SKILL_NAMES}"
|
||||
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."
|
||||
|
||||
Reference in New Issue
Block a user