Skip to content

Commit 60540b5

Browse files
committed
feat: added hook to verify no cli workarounds
1 parent ab784f4 commit 60540b5

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# PreToolUse hook: block Bash commands that bypass MCP tools.
3+
# Denies flutter create, dart create, very_good create, very_good test,
4+
# very_good packages, flutter test, dart test.
5+
6+
if ! command -v jq &>/dev/null; then
7+
echo "jq is required for block-cli-workarounds hook but not found" >&2
8+
exit 1
9+
fi
10+
11+
INPUT=$(cat)
12+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
13+
14+
if [ -z "$COMMAND" ]; then
15+
exit 0
16+
fi
17+
18+
deny() {
19+
jq -n \
20+
--arg reason "$1" \
21+
'{
22+
hookSpecificOutput: {
23+
hookEventName: "PreToolUse",
24+
permissionDecision: "deny",
25+
permissionDecisionReason: $reason
26+
}
27+
}'
28+
exit 0
29+
}
30+
31+
# Block project creation via CLI
32+
if echo "$COMMAND" | grep -qE '(flutter|dart)\s+create'; then
33+
deny "Do not use 'flutter create' or 'dart create'. Use the very_good_cli MCP 'create' tool instead. If VeryGoodCLI MCP is not available, install with: dart pub global activate very_good_cli"
34+
fi
35+
36+
if echo "$COMMAND" | grep -qE 'very_good\s+create'; then
37+
deny "Do not use 'very_good create' via shell. Use the very_good_cli MCP 'create' tool instead. If VeryGoodCLI MCP is not available, upgrade with: dart pub global activate very_good_cli"
38+
fi
39+
40+
# Block test runs via CLI
41+
if echo "$COMMAND" | grep -qE '(flutter|dart)\s+test'; then
42+
deny "Do not use 'flutter test' or 'dart test'. Use MCP test tools instead (very_good_cli MCP 'test' or dart MCP 'Run tests')."
43+
fi
44+
45+
# Uncomment this once `very_good_cli` version check is updated to 1.1.0
46+
#if echo "$COMMAND" | grep -qE 'very_good\s+test'; then
47+
# deny "Do not use 'very_good test' via shell. Use the very_good_cli MCP 'test' tool instead."
48+
#fi
49+
50+
# Block license check via CLI
51+
if echo "$COMMAND" | grep -qE 'very_good\s+packages'; then
52+
deny "Do not use 'very_good packages' via shell. Use the very_good_cli MCP 'packages_get' or 'packages_check_licenses' tool instead."
53+
fi
54+
55+
# Not a blocked command — allow
56+
exit 0

0 commit comments

Comments
 (0)