Skip to content

Commit 3ae0779

Browse files
sjnimsclaude
andcommitted
fix: add missing test-agent-trigger.sh script
The SKILL.md documentation referenced test-agent-trigger.sh but the script didn't exist, causing confusion for users following the docs. This script helps test agent triggering by: - Extracting <example> blocks from agent descriptions - Parsing user phrases that should trigger the agent - Validating example block formatting - Providing manual testing guidance Fixes #9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 61b1ea6 commit 3ae0779

File tree

1 file changed

+226
-0
lines changed

1 file changed

+226
-0
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/bin/bash
2+
# Agent Trigger Test Helper
3+
# Extracts triggering examples and validates example block formatting
4+
5+
set -euo pipefail
6+
7+
# Usage
8+
if [ $# -eq 0 ]; then
9+
echo "Usage: $0 <path/to/agent.md>"
10+
echo ""
11+
echo "This script helps test agent triggering by:"
12+
echo " - Extracting <example> blocks from description"
13+
echo " - Parsing user phrases that should trigger the agent"
14+
echo " - Validating example block formatting"
15+
echo " - Providing manual testing guidance"
16+
exit 1
17+
fi
18+
19+
AGENT_FILE="$1"
20+
21+
echo "🔍 Analyzing agent triggers: $AGENT_FILE"
22+
echo ""
23+
24+
# Check file exists
25+
if [ ! -f "$AGENT_FILE" ]; then
26+
echo "❌ File not found: $AGENT_FILE"
27+
exit 1
28+
fi
29+
30+
# Check frontmatter exists
31+
FIRST_LINE=$(head -1 "$AGENT_FILE")
32+
if [ "$FIRST_LINE" != "---" ]; then
33+
echo "❌ File must start with YAML frontmatter (---)"
34+
exit 1
35+
fi
36+
37+
# Extract agent name
38+
NAME=$(sed -n '/^---$/,/^---$/p' "$AGENT_FILE" | grep '^name:' | sed 's/name: *//' | sed 's/^"\(.*\)"$/\1/' | head -1)
39+
40+
if [ -z "$NAME" ]; then
41+
echo "❌ Could not extract agent name"
42+
exit 1
43+
fi
44+
45+
echo "📋 Agent: $NAME"
46+
echo ""
47+
48+
# Extract full frontmatter section
49+
FRONTMATTER=$(awk '
50+
/^---$/ { count++; next }
51+
count == 1 { print }
52+
' "$AGENT_FILE")
53+
54+
# Extract description - handles multi-line YAML
55+
# Description ends when we hit another top-level field (model:, color:, tools:, etc.)
56+
DESCRIPTION=$(echo "$FRONTMATTER" | awk '
57+
/^description:/ {
58+
in_desc = 1
59+
sub(/^description: */, "")
60+
if ($0 != "") print
61+
next
62+
}
63+
in_desc && /^(model|color|tools|name):/ { exit }
64+
in_desc { print }
65+
')
66+
67+
if [ -z "$DESCRIPTION" ]; then
68+
echo "❌ Could not extract description"
69+
exit 1
70+
fi
71+
72+
# Count example blocks
73+
EXAMPLE_COUNT=$(echo "$DESCRIPTION" | grep -c '<example>' || echo 0)
74+
75+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
76+
echo "📊 EXAMPLE ANALYSIS"
77+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
78+
echo ""
79+
80+
if [ "$EXAMPLE_COUNT" -eq 0 ]; then
81+
echo "⚠️ No <example> blocks found in description"
82+
echo ""
83+
echo "Agent descriptions should include 2-4 example blocks showing"
84+
echo "when the agent should be triggered."
85+
echo ""
86+
echo "Example format:"
87+
echo " <example>"
88+
echo " Context: [Scenario description]"
89+
echo ' user: "[User request]"'
90+
echo ' assistant: "[How Claude responds]"'
91+
echo " <commentary>"
92+
echo " [Why this triggers the agent]"
93+
echo " </commentary>"
94+
echo " </example>"
95+
exit 1
96+
fi
97+
98+
echo "Found $EXAMPLE_COUNT example block(s)"
99+
echo ""
100+
101+
# Extract and display each example
102+
# Use awk to extract example blocks
103+
echo "$DESCRIPTION" | awk '
104+
/<example>/ { in_example=1; example=""; next }
105+
/<\/example>/ {
106+
in_example=0
107+
example_num++
108+
print "───────────────────────────────────────"
109+
print "Example " example_num ":"
110+
print "───────────────────────────────────────"
111+
print example
112+
print ""
113+
next
114+
}
115+
in_example { example = example $0 "\n" }
116+
' | while IFS= read -r line; do
117+
echo "$line"
118+
done
119+
120+
echo ""
121+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
122+
echo "🎯 TRIGGER PHRASES"
123+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
124+
echo ""
125+
126+
# Extract user phrases from examples
127+
USER_PHRASES=$(echo "$DESCRIPTION" | grep -oE 'user: *"[^"]*"' | sed 's/user: *"//' | sed 's/"$//' || true)
128+
129+
if [ -z "$USER_PHRASES" ]; then
130+
echo "⚠️ Could not extract user phrases from examples"
131+
echo ""
132+
echo "Make sure examples include 'user: \"phrase\"' format"
133+
((error_count++))
134+
else
135+
echo "Use these phrases to test agent triggering:"
136+
echo ""
137+
echo "$USER_PHRASES" | while IFS= read -r phrase; do
138+
echo "$phrase"
139+
done
140+
fi
141+
142+
echo ""
143+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
144+
echo "✅ VALIDATION"
145+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
146+
echo ""
147+
148+
warning_count=0
149+
150+
# Check for "Use this agent when" pattern
151+
if ! echo "$DESCRIPTION" | grep -qi 'use this agent when'; then
152+
echo "⚠️ Description should start with 'Use this agent when...'"
153+
((warning_count++))
154+
else
155+
echo "✅ Has 'Use this agent when' pattern"
156+
fi
157+
158+
# Check example count
159+
if [ "$EXAMPLE_COUNT" -lt 2 ]; then
160+
echo "⚠️ Only $EXAMPLE_COUNT example(s) - recommend 2-4 examples"
161+
((warning_count++))
162+
elif [ "$EXAMPLE_COUNT" -gt 4 ]; then
163+
echo "⚠️ $EXAMPLE_COUNT examples - consider trimming to 2-4"
164+
((warning_count++))
165+
else
166+
echo "✅ Good number of examples ($EXAMPLE_COUNT)"
167+
fi
168+
169+
# Check for commentary in examples
170+
COMMENTARY_COUNT=$(echo "$DESCRIPTION" | grep -c '<commentary>' 2>/dev/null || echo 0)
171+
COMMENTARY_COUNT=$(echo "$COMMENTARY_COUNT" | tr -d '[:space:]')
172+
if [ "$COMMENTARY_COUNT" -lt "$EXAMPLE_COUNT" ]; then
173+
echo "⚠️ Some examples missing <commentary> blocks"
174+
((warning_count++))
175+
else
176+
echo "✅ All examples have commentary"
177+
fi
178+
179+
# Check for Context in examples
180+
CONTEXT_COUNT=$(echo "$DESCRIPTION" | grep -ci 'context:' 2>/dev/null || echo 0)
181+
CONTEXT_COUNT=$(echo "$CONTEXT_COUNT" | tr -d '[:space:]')
182+
if [ "$CONTEXT_COUNT" -lt "$EXAMPLE_COUNT" ]; then
183+
echo "⚠️ Some examples missing Context: lines"
184+
((warning_count++))
185+
else
186+
echo "✅ All examples have context"
187+
fi
188+
189+
# Check for assistant responses
190+
ASSISTANT_COUNT=$(echo "$DESCRIPTION" | grep -c 'assistant:' 2>/dev/null || echo 0)
191+
ASSISTANT_COUNT=$(echo "$ASSISTANT_COUNT" | tr -d '[:space:]')
192+
if [ "$ASSISTANT_COUNT" -lt "$EXAMPLE_COUNT" ]; then
193+
echo "⚠️ Some examples missing assistant: responses"
194+
((warning_count++))
195+
else
196+
echo "✅ All examples have assistant responses"
197+
fi
198+
199+
echo ""
200+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
201+
echo "📖 MANUAL TESTING GUIDE"
202+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
203+
echo ""
204+
echo "To test agent triggering:"
205+
echo ""
206+
echo "1. Load your plugin in Claude Code:"
207+
echo " cc --plugin-dir /path/to/plugin"
208+
echo ""
209+
echo "2. Try the trigger phrases listed above"
210+
echo ""
211+
echo "3. Verify Claude loads the agent (look for agent indicator)"
212+
echo ""
213+
echo "4. Test variations of the phrases to ensure robust triggering"
214+
echo ""
215+
echo "5. Test negative cases - phrases that should NOT trigger"
216+
echo ""
217+
218+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
219+
220+
if [ "$warning_count" -eq 0 ]; then
221+
echo "✅ All validations passed!"
222+
exit 0
223+
else
224+
echo "⚠️ Completed with $warning_count warning(s)"
225+
exit 0
226+
fi

0 commit comments

Comments
 (0)