feat(hooks): skill injection with EXTREMELY_IMPORTANT framing

- Follow obra/superpowers pattern: <EXTREMELY_IMPORTANT> wrapper
- Clear instruction that these are loaded skills, not passive text
- 8 mandatory skill contents injected before any user interaction
- Detected skills listed for on-demand loading via Skill tool
- SessionStart hook now properly primes Claude with all rules
This commit is contained in:
asepharyana
2026-07-25 17:51:51 +07:00
parent 0604df8fe2
commit abd60c607d
+30 -19
View File
@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# hub-guide: load best-practice skills at session start # hub-guide: inject best-practice skills into context at session start
set -euo pipefail set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -7,7 +7,6 @@ PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
PROJECT_DIR="$(pwd)" PROJECT_DIR="$(pwd)"
SKILL_NAMES="" SKILL_NAMES=""
# Helper: check if a package.json field contains a dependency name
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 --- # --- project detection ---
@@ -42,33 +41,45 @@ 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#, }"
# --- load skill content for context injection --- # --- read skill content ---
load_skill() { read_skill() {
local f="${PLUGIN_ROOT}/skills/${1}/SKILL.md" local f="${PLUGIN_ROOT}/skills/${1}/SKILL.md"
[ -f "$f" ] && cat "$f" || echo "(skill $1 not found)" [ -f "$f" ] && cat "$f" || echo ""
} }
# Output summary (visible in session) # Summary header (visible in session)
echo "📐 [hub-guide] detected: ${PROJECT_DIR}" echo "📐 [hub-guide] detected: ${PROJECT_DIR}"
echo "📐 mandatory: ${MANDATORY}" echo "📐 mandatory: ${MANDATORY}"
[ -n "$SKILL_NAMES" ] && echo "📐 active: ${SKILL_NAMES}" [ -n "$SKILL_NAMES" ] && echo "📐 active: ${SKILL_NAMES}"
echo "📐 When in doubt — ask instead of assuming."
# Inject full skill content into conversation context.
# Everything printed here is visible to Claude at session start.
echo "" echo ""
echo "<hub-guide-skills>"
# ─────────────────────────────────────────────────────────────────
# SKILL INJECTION — hub-guide best-practice rules
# This content is loaded into context before any user interaction.
# Claude MUST treat these as active skill instructions for every
# code decision throughout this session.
# ─────────────────────────────────────────────────────────────────
echo "<EXTREMELY_IMPORTANT>"
echo "You have the following hub-guide skills loaded and active. They apply to every code decision, review, and architecture discussion in this session — regardless of what language the user speaks."
# Inject full MANDATORY skill content
for skill in $MANDATORY; do for skill in $MANDATORY; do
echo "<skill name=\"${skill}\">" content=$(read_skill "$skill")
load_skill "$skill" if [ -n "$content" ]; then
echo "</skill>" echo ""
echo "=== hub-guide:${skill} ==="
echo "$content"
fi
done done
# List detected skills (their content loads on demand via Skill tool)
if [ -n "$SKILL_NAMES" ]; then if [ -n "$SKILL_NAMES" ]; then
echo "<detected-skills>${SKILL_NAMES}</detected-skills>"
fi
echo "</hub-guide-skills>"
echo "" echo ""
echo "Skills above are loaded. Apply these best-practice rules throughout this session." echo "=== hub-guide:detected ==="
echo "When in doubt about intent or approach — ask instead of assuming." echo "The following skills are relevant to this project's tech stack."
echo "Load them with the Skill tool when their topics come up: ${SKILL_NAMES}"
fi
echo ""
echo "For any skill not loaded above, use the Skill tool to load it."
echo "</EXTREMELY_IMPORTANT>"