"""Debug SGR plan generation."""
import json
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from searchers.sgr_searcher import SGRSearcher, LLMProvider
from searchers.sgr import QuestionAnalysis, SearchPlan
# Create searcher
searcher = SGRSearcher(
provider=LLMProvider.GEMINI,
model="gemini-2.5-flash-lite",
verbose=False,
)
query = "My custom middleware adds a header but sometimes it's missing in the final response."
repo_hint = "django"
# Step 1: Analyze
print("=== STEP 1: Question Analysis ===")
analysis = searcher._analyze_question(query, repo_hint)
print(f"Key terms: {analysis.key_terms}")
print(f"Concepts: {analysis.concepts}")
print(f"Likely locations: {analysis.likely_locations}")
print()
# Step 2: Create plan
print("=== STEP 2: Search Plan ===")
plan = searcher._create_plan(query, analysis)
print(f"Strategy: {plan.strategy}")
print(f"Actions ({len(plan.actions)}):")
for i, action in enumerate(plan.actions):
print(f" {i+1}. tool={action.tool}")
print(f" params={json.dumps(action.params, indent=6)}")
print(f" purpose={action.purpose[:80]}...")