-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_key_lookup.py
More file actions
67 lines (59 loc) · 2.01 KB
/
api_key_lookup.py
File metadata and controls
67 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# @bigd-hook-meta
# name: api_key_lookup
# fires_on: PreToolUse
# relevant_intents: [code, meta, debug]
# irrelevant_intents: [bigd, pm, telegram, docx, x_tweet, vps, sync, memory]
# cost_score: 1
# always_fire: false
"""PreToolUse hook: remind to check reference_api_keys_locations.md before searching for keys."""
import io
import json
import os
import re
import sys
def main():
try:
input_data = json.load(sys.stdin)
except (json.JSONDecodeError, EOFError):
print("{}")
return
tool_name = input_data.get("tool_name", "")
tool_input = input_data.get("tool_input", {})
# Check Bash grep/find for env vars or .env files
if tool_name == "Bash":
cmd = tool_input.get("command", "")
if re.search(r'grep.*(_API_KEY|_TOKEN|_SECRET|\.env)|find.*\.env|cat.*\.env', cmd):
print(json.dumps({
"systemMessage": (
"📋 **Check `reference_api_keys_locations.md` first** — "
"it has all API keys, worker code, credentials, and where everything lives. "
"No need to grep."
)
}))
return
# Check Grep tool for env var patterns
if tool_name == "Grep":
pattern = tool_input.get("pattern", "")
if re.search(r'_API_KEY|_TOKEN|_SECRET|\.env', pattern):
print(json.dumps({
"systemMessage": (
"📋 **Check `reference_api_keys_locations.md` first** — "
"it has all API keys and locations indexed."
)
}))
return
print("{}")
if __name__ == "__main__":
sys.path.insert(0, os.path.dirname(__file__))
_raw = sys.stdin.read()
try:
_prompt = json.loads(_raw).get("prompt", "") if _raw else ""
except Exception:
_prompt = ""
from _semantic_router import should_fire
if not should_fire(__file__, _prompt):
print("{}")
sys.exit(0)
sys.stdin = io.StringIO(_raw)
main()