@hustle-together/api-dev-tools 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/commands/api-research.md +77 -0
- package/hooks/enforce-external-research.py +328 -0
- package/hooks/track-tool-use.py +70 -2
- package/package.json +1 -1
- package/templates/api-dev-state.json +3 -1
- package/templates/settings.json +12 -0
package/README.md
CHANGED
|
@@ -26,8 +26,9 @@ Five powerful slash commands for Claude Code:
|
|
|
26
26
|
- **`/api-status [endpoint]`** - Track implementation progress and phase completion
|
|
27
27
|
|
|
28
28
|
### Enforcement Hooks
|
|
29
|
-
|
|
29
|
+
Six Python hooks that provide **real programmatic guarantees**:
|
|
30
30
|
|
|
31
|
+
- **`enforce-external-research.py`** - (v1.7.0) Detects external API questions and requires research before answering
|
|
31
32
|
- **`enforce-research.py`** - Blocks API code writing until research is complete
|
|
32
33
|
- **`enforce-interview.py`** - Verifies user questions were actually asked (prevents self-answering)
|
|
33
34
|
- **`verify-implementation.py`** - Checks implementation matches interview requirements
|
|
@@ -445,6 +446,30 @@ The workflow now includes automatic detection of common implementation gaps:
|
|
|
445
446
|
|
|
446
447
|
**Fix:** `verify-implementation.py` warns when test files check env vars that don't match interview requirements.
|
|
447
448
|
|
|
449
|
+
### Gap 6: Training Data Reliance (v1.7.0+)
|
|
450
|
+
**Problem:** AI answers questions about external APIs from potentially outdated training data instead of researching first.
|
|
451
|
+
|
|
452
|
+
**Example:**
|
|
453
|
+
- User asks: "What providers does Vercel AI Gateway support?"
|
|
454
|
+
- AI answers from memory: "Groq not in gateway" (WRONG!)
|
|
455
|
+
- Reality: Groq has 4 models in the gateway (Llama variants)
|
|
456
|
+
|
|
457
|
+
**Fix:** New `UserPromptSubmit` hook (`enforce-external-research.py`) that:
|
|
458
|
+
1. Detects questions about external APIs/SDKs using pattern matching
|
|
459
|
+
2. Injects context requiring research before answering
|
|
460
|
+
3. Works for ANY API (Brandfetch, Stripe, Twilio, etc.) - not just specific ones
|
|
461
|
+
4. Auto-allows WebSearch and Context7 without permission prompts
|
|
462
|
+
|
|
463
|
+
```
|
|
464
|
+
USER: "What providers does Brandfetch API support?"
|
|
465
|
+
↓
|
|
466
|
+
HOOK: Detects "Brandfetch", "API", "providers"
|
|
467
|
+
↓
|
|
468
|
+
INJECTS: "RESEARCH REQUIRED: Use Context7/WebSearch before answering"
|
|
469
|
+
↓
|
|
470
|
+
CLAUDE: Researches first → Gives accurate answer
|
|
471
|
+
```
|
|
472
|
+
|
|
448
473
|
## 🔧 Requirements
|
|
449
474
|
|
|
450
475
|
- **Node.js** 14.0.0 or higher
|
package/commands/api-research.md
CHANGED
|
@@ -259,6 +259,83 @@ With thorough research:
|
|
|
259
259
|
- ✅ Robust implementation
|
|
260
260
|
- ✅ Better documentation
|
|
261
261
|
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Research-First Schema Design (MANDATORY)
|
|
265
|
+
|
|
266
|
+
### The Anti-Pattern: Schema-First Development
|
|
267
|
+
|
|
268
|
+
**NEVER DO THIS:**
|
|
269
|
+
- ❌ Define interfaces based on assumptions before researching
|
|
270
|
+
- ❌ Rely on training data for API capabilities
|
|
271
|
+
- ❌ Say "I think it supports..." without verification
|
|
272
|
+
- ❌ Build schemas from memory instead of documentation
|
|
273
|
+
|
|
274
|
+
**Real Example of Failure:**
|
|
275
|
+
- User asked: "What providers does Vercel AI Gateway support?"
|
|
276
|
+
- AI answered from memory: "Groq not in gateway"
|
|
277
|
+
- Reality: Groq has 4 models in the gateway (Llama variants)
|
|
278
|
+
- Root cause: No research was done before answering
|
|
279
|
+
|
|
280
|
+
### The Correct Pattern: Research-First
|
|
281
|
+
|
|
282
|
+
**ALWAYS DO THIS:**
|
|
283
|
+
|
|
284
|
+
**Step 1: Research the Source of Truth**
|
|
285
|
+
- Use Context7 (`mcp__context7__resolve-library-id` + `get-library-docs`) for SDK docs
|
|
286
|
+
- Use WebSearch for official provider documentation
|
|
287
|
+
- Query APIs directly when possible (don't assume)
|
|
288
|
+
- Check GitHub repositories for current implementation
|
|
289
|
+
|
|
290
|
+
**Step 2: Build Schema FROM Research**
|
|
291
|
+
- Interface fields emerge from discovered capabilities
|
|
292
|
+
- Every field has a source (docs, SDK types, API response)
|
|
293
|
+
- Don't guess - verify each capability
|
|
294
|
+
- Document where each field came from
|
|
295
|
+
|
|
296
|
+
**Step 3: Verify with Actual Calls**
|
|
297
|
+
- Test capabilities before marking them supported
|
|
298
|
+
- Investigate skipped tests - they're bugs, not features
|
|
299
|
+
- No "should work" - prove it works
|
|
300
|
+
- All tests must pass, not be skipped
|
|
301
|
+
|
|
302
|
+
### Mandatory Checklist Before Answering ANY External API Question
|
|
303
|
+
|
|
304
|
+
Before responding to questions about APIs, SDKs, or external services:
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
[ ] Did I use Context7 to get current documentation?
|
|
308
|
+
[ ] Did I use WebSearch for official docs?
|
|
309
|
+
[ ] Did I verify the information is current (not training data)?
|
|
310
|
+
[ ] Am I stating facts from research, not memory?
|
|
311
|
+
[ ] Have I cited my sources?
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Research Query Tracking
|
|
315
|
+
|
|
316
|
+
All research is now tracked in `.claude/api-dev-state.json`:
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"research_queries": [
|
|
321
|
+
{
|
|
322
|
+
"timestamp": "2025-12-07T...",
|
|
323
|
+
"tool": "WebSearch",
|
|
324
|
+
"query": "Vercel AI Gateway Groq providers",
|
|
325
|
+
"terms": ["vercel", "gateway", "groq", "providers"]
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"timestamp": "2025-12-07T...",
|
|
329
|
+
"tool": "mcp__context7__get-library-docs",
|
|
330
|
+
"library": "@ai-sdk/gateway",
|
|
331
|
+
"terms": ["@ai-sdk/gateway"]
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
This allows verification that specific topics were actually researched before answering.
|
|
338
|
+
|
|
262
339
|
<claude-commands-template>
|
|
263
340
|
## Research Guidelines
|
|
264
341
|
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Hook: UserPromptSubmit
|
|
4
|
+
Purpose: ALWAYS enforce research before answering technical questions
|
|
5
|
+
|
|
6
|
+
This hook runs BEFORE Claude processes the user's prompt. It aggressively
|
|
7
|
+
detects ANY technical question and requires comprehensive research using
|
|
8
|
+
BOTH Context7 AND multiple WebSearches before answering.
|
|
9
|
+
|
|
10
|
+
Philosophy: "ALWAYS research. Training data is NEVER trustworthy for technical info."
|
|
11
|
+
|
|
12
|
+
The hook triggers on:
|
|
13
|
+
- ANY mention of APIs, SDKs, libraries, packages, frameworks
|
|
14
|
+
- ANY technical "how to" or capability questions
|
|
15
|
+
- ANY code-related questions (functions, methods, parameters, types)
|
|
16
|
+
- ANY questions about tools, services, or platforms
|
|
17
|
+
- ANY request for implementation, editing, or changes
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
- Prints context to stdout (injected into conversation)
|
|
21
|
+
- Exit 0 to allow the prompt to proceed
|
|
22
|
+
"""
|
|
23
|
+
import json
|
|
24
|
+
import sys
|
|
25
|
+
import re
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from datetime import datetime
|
|
28
|
+
|
|
29
|
+
# State file is in .claude/ directory (sibling to hooks/)
|
|
30
|
+
STATE_FILE = Path(__file__).parent.parent / "api-dev-state.json"
|
|
31
|
+
|
|
32
|
+
# ============================================================================
|
|
33
|
+
# AGGRESSIVE DETECTION PATTERNS
|
|
34
|
+
# ============================================================================
|
|
35
|
+
|
|
36
|
+
# Technical terms that ALWAYS trigger research
|
|
37
|
+
TECHNICAL_TERMS = [
|
|
38
|
+
# Code/Development
|
|
39
|
+
r"\b(?:function|method|class|interface|type|schema|model)\b",
|
|
40
|
+
r"\b(?:parameter|argument|option|config|setting|property)\b",
|
|
41
|
+
r"\b(?:import|export|require|module|package|library|dependency)\b",
|
|
42
|
+
r"\b(?:api|sdk|framework|runtime|engine|platform)\b",
|
|
43
|
+
r"\b(?:endpoint|route|url|path|request|response|header)\b",
|
|
44
|
+
r"\b(?:database|query|table|collection|document|record)\b",
|
|
45
|
+
r"\b(?:authentication|authorization|token|key|secret|credential)\b",
|
|
46
|
+
r"\b(?:error|exception|bug|issue|problem|fix)\b",
|
|
47
|
+
r"\b(?:test|spec|coverage|mock|stub|fixture)\b",
|
|
48
|
+
r"\b(?:deploy|build|compile|bundle|publish|release)\b",
|
|
49
|
+
r"\b(?:install|setup|configure|initialize|migrate)\b",
|
|
50
|
+
r"\b(?:provider|service|client|server|handler|middleware)\b",
|
|
51
|
+
r"\b(?:stream|async|await|promise|callback|event)\b",
|
|
52
|
+
r"\b(?:component|widget|element|view|layout|template)\b",
|
|
53
|
+
r"\b(?:state|store|reducer|action|context|hook)\b",
|
|
54
|
+
r"\b(?:validate|parse|serialize|transform|convert)\b",
|
|
55
|
+
|
|
56
|
+
# Package patterns
|
|
57
|
+
r"@[\w-]+/[\w-]+", # @scope/package
|
|
58
|
+
r"\b[\w-]+-(?:sdk|api|js|ts|py|go|rs)\b", # something-sdk, something-api
|
|
59
|
+
|
|
60
|
+
# Version patterns
|
|
61
|
+
r"\bv?\d+\.\d+(?:\.\d+)?(?:-[\w.]+)?\b", # v1.2.3, 2.0.0-beta
|
|
62
|
+
|
|
63
|
+
# File patterns
|
|
64
|
+
r"\b[\w-]+\.(?:ts|js|tsx|jsx|py|go|rs|json|yaml|yml|toml|env)\b",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
# Question patterns that indicate asking about functionality
|
|
68
|
+
QUESTION_PATTERNS = [
|
|
69
|
+
# Direct questions
|
|
70
|
+
r"\b(?:what|which|where|when|why|how)\b",
|
|
71
|
+
r"\b(?:can|could|would|should|will|does|do|is|are)\b.*\?",
|
|
72
|
+
|
|
73
|
+
# Requests
|
|
74
|
+
r"\b(?:show|tell|explain|describe|list|find|get|give)\b",
|
|
75
|
+
r"\b(?:help|need|want|looking for|trying to)\b",
|
|
76
|
+
|
|
77
|
+
# Actions
|
|
78
|
+
r"\b(?:create|make|build|add|implement|write|generate)\b",
|
|
79
|
+
r"\b(?:update|change|modify|edit|fix|refactor|improve)\b",
|
|
80
|
+
r"\b(?:delete|remove|drop|clear|reset)\b",
|
|
81
|
+
r"\b(?:connect|integrate|link|sync|merge)\b",
|
|
82
|
+
r"\b(?:debug|trace|log|monitor|track)\b",
|
|
83
|
+
|
|
84
|
+
# Comparisons
|
|
85
|
+
r"\b(?:difference|compare|versus|vs|between|or)\b",
|
|
86
|
+
r"\b(?:better|best|recommended|preferred|alternative)\b",
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
# Phrases that ALWAYS require research (no exceptions)
|
|
90
|
+
ALWAYS_RESEARCH_PHRASES = [
|
|
91
|
+
r"how (?:to|do|does|can|should|would)",
|
|
92
|
+
r"what (?:is|are|does|can|should)",
|
|
93
|
+
r"(?:does|can|will|should) .+ (?:support|have|handle|work|do)",
|
|
94
|
+
r"(?:list|show|get|find) (?:all|available|supported)",
|
|
95
|
+
r"example (?:of|for|using|with|code)",
|
|
96
|
+
r"(?:implement|add|create|build|write|generate) .+",
|
|
97
|
+
r"(?:update|change|modify|edit|fix) .+",
|
|
98
|
+
r"(?:configure|setup|install|deploy) .+",
|
|
99
|
+
r"(?:error|issue|problem|bug|not working)",
|
|
100
|
+
r"(?:api|sdk|library|package|module|framework)",
|
|
101
|
+
r"(?:documentation|docs|reference|guide)",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
# Exclusion patterns - things that DON'T need research
|
|
105
|
+
EXCLUDE_PATTERNS = [
|
|
106
|
+
r"^(?:hi|hello|hey|thanks|thank you|ok|okay|yes|no|sure)[\s!?.]*$",
|
|
107
|
+
r"^(?:good morning|good afternoon|good evening|goodbye|bye)[\s!?.]*$",
|
|
108
|
+
r"^(?:please|sorry|excuse me)[\s!?.]*$",
|
|
109
|
+
r"^(?:\d+[\s+\-*/]\d+|calculate|math).*$", # Simple math
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
# ============================================================================
|
|
113
|
+
# DETECTION LOGIC
|
|
114
|
+
# ============================================================================
|
|
115
|
+
|
|
116
|
+
def is_excluded(prompt: str) -> bool:
|
|
117
|
+
"""Check if prompt is a simple greeting or non-technical."""
|
|
118
|
+
prompt_clean = prompt.strip().lower()
|
|
119
|
+
|
|
120
|
+
# Very short prompts that are just greetings
|
|
121
|
+
if len(prompt_clean) < 20:
|
|
122
|
+
for pattern in EXCLUDE_PATTERNS:
|
|
123
|
+
if re.match(pattern, prompt_clean, re.IGNORECASE):
|
|
124
|
+
return True
|
|
125
|
+
|
|
126
|
+
return False
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def detect_technical_question(prompt: str) -> dict:
|
|
130
|
+
"""
|
|
131
|
+
Aggressively detect if the prompt is technical and requires research.
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
{
|
|
135
|
+
"detected": bool,
|
|
136
|
+
"terms": list of detected terms,
|
|
137
|
+
"patterns_matched": list of pattern types,
|
|
138
|
+
"confidence": "critical" | "high" | "medium" | "low" | "none"
|
|
139
|
+
}
|
|
140
|
+
"""
|
|
141
|
+
if is_excluded(prompt):
|
|
142
|
+
return {
|
|
143
|
+
"detected": False,
|
|
144
|
+
"terms": [],
|
|
145
|
+
"patterns_matched": [],
|
|
146
|
+
"confidence": "none",
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
prompt_lower = prompt.lower()
|
|
150
|
+
detected_terms = []
|
|
151
|
+
patterns_matched = []
|
|
152
|
+
|
|
153
|
+
# Check for ALWAYS_RESEARCH_PHRASES first (highest priority)
|
|
154
|
+
for pattern in ALWAYS_RESEARCH_PHRASES:
|
|
155
|
+
if re.search(pattern, prompt_lower, re.IGNORECASE):
|
|
156
|
+
patterns_matched.append("always_research")
|
|
157
|
+
# Extract the matched phrase
|
|
158
|
+
match = re.search(pattern, prompt_lower, re.IGNORECASE)
|
|
159
|
+
if match:
|
|
160
|
+
detected_terms.append(match.group(0)[:50])
|
|
161
|
+
|
|
162
|
+
# Check technical terms
|
|
163
|
+
for pattern in TECHNICAL_TERMS:
|
|
164
|
+
matches = re.findall(pattern, prompt_lower, re.IGNORECASE)
|
|
165
|
+
if matches:
|
|
166
|
+
detected_terms.extend(matches[:3]) # Limit per pattern
|
|
167
|
+
patterns_matched.append("technical_term")
|
|
168
|
+
|
|
169
|
+
# Check question patterns
|
|
170
|
+
for pattern in QUESTION_PATTERNS:
|
|
171
|
+
if re.search(pattern, prompt_lower, re.IGNORECASE):
|
|
172
|
+
patterns_matched.append("question_pattern")
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
# Deduplicate
|
|
176
|
+
detected_terms = list(dict.fromkeys(detected_terms))[:10]
|
|
177
|
+
patterns_matched = list(set(patterns_matched))
|
|
178
|
+
|
|
179
|
+
# Determine confidence - MUCH more aggressive
|
|
180
|
+
if "always_research" in patterns_matched:
|
|
181
|
+
confidence = "critical"
|
|
182
|
+
elif "technical_term" in patterns_matched and "question_pattern" in patterns_matched:
|
|
183
|
+
confidence = "high"
|
|
184
|
+
elif "technical_term" in patterns_matched:
|
|
185
|
+
confidence = "high" # Technical terms alone = high
|
|
186
|
+
elif "question_pattern" in patterns_matched and len(prompt) > 30:
|
|
187
|
+
confidence = "medium" # Questions longer than 30 chars
|
|
188
|
+
elif len(prompt) > 50:
|
|
189
|
+
confidence = "low" # Longer prompts default to low (still triggers)
|
|
190
|
+
else:
|
|
191
|
+
confidence = "none"
|
|
192
|
+
|
|
193
|
+
# AGGRESSIVE: Trigger on anything except "none"
|
|
194
|
+
detected = confidence != "none"
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
"detected": detected,
|
|
198
|
+
"terms": detected_terms,
|
|
199
|
+
"patterns_matched": patterns_matched,
|
|
200
|
+
"confidence": confidence,
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def check_active_workflow() -> bool:
|
|
205
|
+
"""Check if there's an active API development workflow."""
|
|
206
|
+
if not STATE_FILE.exists():
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
state = json.loads(STATE_FILE.read_text())
|
|
211
|
+
phases = state.get("phases", {})
|
|
212
|
+
|
|
213
|
+
for phase_key, phase_data in phases.items():
|
|
214
|
+
if isinstance(phase_data, dict):
|
|
215
|
+
status = phase_data.get("status", "")
|
|
216
|
+
if status in ["in_progress", "pending", "complete"]:
|
|
217
|
+
# If ANY phase has been touched, we're in a workflow
|
|
218
|
+
return True
|
|
219
|
+
|
|
220
|
+
return False
|
|
221
|
+
except (json.JSONDecodeError, Exception):
|
|
222
|
+
return False
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def log_detection(prompt: str, detection: dict, injected: bool) -> None:
|
|
226
|
+
"""Log this detection for debugging/auditing."""
|
|
227
|
+
try:
|
|
228
|
+
if STATE_FILE.exists():
|
|
229
|
+
state = json.loads(STATE_FILE.read_text())
|
|
230
|
+
else:
|
|
231
|
+
state = {"prompt_detections": []}
|
|
232
|
+
|
|
233
|
+
if "prompt_detections" not in state:
|
|
234
|
+
state["prompt_detections"] = []
|
|
235
|
+
|
|
236
|
+
state["prompt_detections"].append({
|
|
237
|
+
"timestamp": datetime.now().isoformat(),
|
|
238
|
+
"prompt_preview": prompt[:100] + "..." if len(prompt) > 100 else prompt,
|
|
239
|
+
"detection": detection,
|
|
240
|
+
"injected": injected,
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
# Keep only last 50 detections
|
|
244
|
+
state["prompt_detections"] = state["prompt_detections"][-50:]
|
|
245
|
+
|
|
246
|
+
STATE_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
247
|
+
STATE_FILE.write_text(json.dumps(state, indent=2))
|
|
248
|
+
except Exception:
|
|
249
|
+
pass # Don't fail the hook on logging errors
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# ============================================================================
|
|
253
|
+
# MAIN
|
|
254
|
+
# ============================================================================
|
|
255
|
+
|
|
256
|
+
def main():
|
|
257
|
+
# Read hook input from stdin
|
|
258
|
+
try:
|
|
259
|
+
input_data = json.load(sys.stdin)
|
|
260
|
+
except json.JSONDecodeError:
|
|
261
|
+
sys.exit(0)
|
|
262
|
+
|
|
263
|
+
prompt = input_data.get("prompt", "")
|
|
264
|
+
|
|
265
|
+
if not prompt or len(prompt.strip()) < 5:
|
|
266
|
+
sys.exit(0)
|
|
267
|
+
|
|
268
|
+
# Check if in active workflow mode
|
|
269
|
+
active_workflow = check_active_workflow()
|
|
270
|
+
|
|
271
|
+
# Detect technical questions
|
|
272
|
+
detection = detect_technical_question(prompt)
|
|
273
|
+
|
|
274
|
+
# In active workflow, ALWAYS inject (even for low confidence)
|
|
275
|
+
if active_workflow and detection["confidence"] != "none":
|
|
276
|
+
detection["detected"] = True
|
|
277
|
+
|
|
278
|
+
# Log all detections
|
|
279
|
+
log_detection(prompt, detection, detection["detected"])
|
|
280
|
+
|
|
281
|
+
# Inject context if detected
|
|
282
|
+
if detection["detected"]:
|
|
283
|
+
terms_str = ", ".join(detection["terms"][:5]) if detection["terms"] else "technical question"
|
|
284
|
+
confidence = detection["confidence"]
|
|
285
|
+
|
|
286
|
+
# Build the injection message
|
|
287
|
+
injection = f"""
|
|
288
|
+
<user-prompt-submit-hook>
|
|
289
|
+
RESEARCH REQUIRED - {confidence.upper()} CONFIDENCE
|
|
290
|
+
Detected: {terms_str}
|
|
291
|
+
{"MODE: Active API Development Workflow - STRICT ENFORCEMENT" if active_workflow else ""}
|
|
292
|
+
|
|
293
|
+
MANDATORY BEFORE ANSWERING:
|
|
294
|
+
|
|
295
|
+
1. USE CONTEXT7 FIRST:
|
|
296
|
+
- Call mcp__context7__resolve-library-id to find the library
|
|
297
|
+
- Call mcp__context7__get-library-docs to get CURRENT documentation
|
|
298
|
+
- This gives you the ACTUAL source of truth
|
|
299
|
+
|
|
300
|
+
2. USE WEBSEARCH (2-3 SEARCHES MINIMUM):
|
|
301
|
+
- Search for official documentation
|
|
302
|
+
- Search with different phrasings to get comprehensive coverage
|
|
303
|
+
- Search for recent updates, changes, or known issues
|
|
304
|
+
- Example searches:
|
|
305
|
+
* "[topic] official documentation"
|
|
306
|
+
* "[topic] API reference guide"
|
|
307
|
+
* "[topic] latest updates 2024 2025"
|
|
308
|
+
|
|
309
|
+
3. NEVER TRUST TRAINING DATA:
|
|
310
|
+
- Training data can be months or years outdated
|
|
311
|
+
- APIs change constantly
|
|
312
|
+
- Features get added, deprecated, or modified
|
|
313
|
+
- Parameter names and types change
|
|
314
|
+
|
|
315
|
+
4. CITE YOUR SOURCES:
|
|
316
|
+
- After researching, mention where the information came from
|
|
317
|
+
- Include links when available
|
|
318
|
+
|
|
319
|
+
RESEARCH FIRST. ANSWER SECOND.
|
|
320
|
+
</user-prompt-submit-hook>
|
|
321
|
+
"""
|
|
322
|
+
print(injection)
|
|
323
|
+
|
|
324
|
+
sys.exit(0)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
if __name__ == "__main__":
|
|
328
|
+
main()
|
package/hooks/track-tool-use.py
CHANGED
|
@@ -147,6 +147,29 @@ def main():
|
|
|
147
147
|
# Add to sources list
|
|
148
148
|
sources.append(source_entry)
|
|
149
149
|
|
|
150
|
+
# Also add to research_queries for prompt verification
|
|
151
|
+
research_queries = state.setdefault("research_queries", [])
|
|
152
|
+
query_entry = {
|
|
153
|
+
"timestamp": timestamp,
|
|
154
|
+
"tool": tool_name,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# Extract query/term based on tool type
|
|
158
|
+
if tool_name == "WebSearch":
|
|
159
|
+
query_entry["query"] = tool_input.get("query", "")
|
|
160
|
+
query_entry["terms"] = extract_terms(tool_input.get("query", ""))
|
|
161
|
+
elif tool_name == "WebFetch":
|
|
162
|
+
query_entry["url"] = tool_input.get("url", "")
|
|
163
|
+
query_entry["terms"] = extract_terms_from_url(tool_input.get("url", ""))
|
|
164
|
+
elif "context7" in tool_name.lower():
|
|
165
|
+
query_entry["library"] = tool_input.get("libraryName", tool_input.get("libraryId", ""))
|
|
166
|
+
query_entry["terms"] = [tool_input.get("libraryName", "").lower()]
|
|
167
|
+
|
|
168
|
+
research_queries.append(query_entry)
|
|
169
|
+
|
|
170
|
+
# Keep only last 50 queries
|
|
171
|
+
state["research_queries"] = research_queries[-50:]
|
|
172
|
+
|
|
150
173
|
# Update last activity timestamp
|
|
151
174
|
research["last_activity"] = timestamp
|
|
152
175
|
research["source_count"] = len(sources)
|
|
@@ -190,7 +213,7 @@ def main():
|
|
|
190
213
|
def create_initial_state():
|
|
191
214
|
"""Create initial state structure"""
|
|
192
215
|
return {
|
|
193
|
-
"version": "1.
|
|
216
|
+
"version": "1.1.0",
|
|
194
217
|
"created_at": datetime.now().isoformat(),
|
|
195
218
|
"phases": {
|
|
196
219
|
"scope": {"status": "not_started"},
|
|
@@ -209,7 +232,9 @@ def create_initial_state():
|
|
|
209
232
|
"schema_matches_docs": False,
|
|
210
233
|
"tests_cover_params": False,
|
|
211
234
|
"all_tests_passing": False
|
|
212
|
-
}
|
|
235
|
+
},
|
|
236
|
+
"research_queries": [],
|
|
237
|
+
"prompt_detections": []
|
|
213
238
|
}
|
|
214
239
|
|
|
215
240
|
|
|
@@ -225,5 +250,48 @@ def sanitize_input(tool_input):
|
|
|
225
250
|
return sanitized
|
|
226
251
|
|
|
227
252
|
|
|
253
|
+
def extract_terms(query: str) -> list:
|
|
254
|
+
"""Extract searchable terms from a query string."""
|
|
255
|
+
import re
|
|
256
|
+
# Remove common words and extract meaningful terms
|
|
257
|
+
stop_words = {"the", "a", "an", "is", "are", "was", "were", "be", "been",
|
|
258
|
+
"how", "to", "do", "does", "what", "which", "for", "and", "or",
|
|
259
|
+
"in", "on", "at", "with", "from", "this", "that", "it"}
|
|
260
|
+
|
|
261
|
+
# Extract words
|
|
262
|
+
words = re.findall(r'\b[\w@/-]+\b', query.lower())
|
|
263
|
+
|
|
264
|
+
# Filter and return
|
|
265
|
+
terms = [w for w in words if w not in stop_words and len(w) > 2]
|
|
266
|
+
return terms[:10] # Limit to 10 terms
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def extract_terms_from_url(url: str) -> list:
|
|
270
|
+
"""Extract meaningful terms from a URL."""
|
|
271
|
+
import re
|
|
272
|
+
from urllib.parse import urlparse
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
parsed = urlparse(url)
|
|
276
|
+
# Get domain parts and path parts
|
|
277
|
+
domain_parts = parsed.netloc.replace("www.", "").split(".")
|
|
278
|
+
path_parts = [p for p in parsed.path.split("/") if p]
|
|
279
|
+
|
|
280
|
+
# Combine and filter
|
|
281
|
+
all_parts = domain_parts + path_parts
|
|
282
|
+
terms = []
|
|
283
|
+
for part in all_parts:
|
|
284
|
+
# Split by common separators
|
|
285
|
+
sub_parts = re.split(r'[-_.]', part.lower())
|
|
286
|
+
terms.extend(sub_parts)
|
|
287
|
+
|
|
288
|
+
# Filter short/common terms
|
|
289
|
+
stop_terms = {"com", "org", "io", "dev", "api", "docs", "www", "http", "https"}
|
|
290
|
+
terms = [t for t in terms if t not in stop_terms and len(t) > 2]
|
|
291
|
+
return terms[:10]
|
|
292
|
+
except Exception:
|
|
293
|
+
return []
|
|
294
|
+
|
|
295
|
+
|
|
228
296
|
if __name__ == "__main__":
|
|
229
297
|
main()
|
package/package.json
CHANGED
package/templates/settings.json
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"WebSearch",
|
|
5
5
|
"WebFetch",
|
|
6
6
|
"mcp__context7",
|
|
7
|
+
"mcp__context7__resolve-library-id",
|
|
8
|
+
"mcp__context7__get-library-docs",
|
|
7
9
|
"mcp__github",
|
|
8
10
|
"Bash(claude mcp:*)",
|
|
9
11
|
"Bash(pnpm test:*)",
|
|
@@ -14,6 +16,16 @@
|
|
|
14
16
|
]
|
|
15
17
|
},
|
|
16
18
|
"hooks": {
|
|
19
|
+
"UserPromptSubmit": [
|
|
20
|
+
{
|
|
21
|
+
"hooks": [
|
|
22
|
+
{
|
|
23
|
+
"type": "command",
|
|
24
|
+
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/enforce-external-research.py"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
],
|
|
17
29
|
"PreToolUse": [
|
|
18
30
|
{
|
|
19
31
|
"matcher": "Write|Edit",
|