mirror of
https://github.com/withgraphite/agent-skills.git
synced 2026-09-14 13:39:16 +08:00
38 lines
1.1 KiB
Bash
Executable File
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.")
|
|
}
|
|
}'
|