Files
withgraphite__agent-skills/plugins/claude-code/scripts/require-graphite-skill.sh
2026-02-18 02:40:12 +00:00

38 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
# Fast path: only gate gt commands
if ! echo "$COMMAND" | grep -qE '\bgt\b'; then
exit 0
fi
# Session-scoped marker
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')
if [ -z "$SESSION_ID" ]; then
jq -n '{
hookSpecificOutput: {
hookEventName: "PreToolUse",
permissionDecision: "deny",
permissionDecisionReason: "GRAPHITE SKILL REQUIRED: Missing session_id; cannot enforce per-session Graphite skill loading."
}
}'
exit 0
fi
MARKER="/tmp/.graphite-skill-loaded-${SESSION_ID}"
if [ -f "$MARKER" ]; then
exit 0
fi
# Deny — instruct agent to load the graphite skill
jq -n --arg sid "$SESSION_ID" '{
hookSpecificOutput: {
hookEventName: "PreToolUse",
permissionDecision: "deny",
permissionDecisionReason: ("GRAPHITE SKILL REQUIRED: Before running any gt commands, you MUST load the graphite skill.\n1. Use the Skill tool: skill=\"graphite\"\n2. Run: touch /tmp/.graphite-skill-loaded-" + $sid + "\nThen retry your gt command.")
}
}'