#!/usr/bin/env python3
"""
π Diagnostic Script: Check Goals Flow and Updates
"""
def diagnose_goals_flow():
"""Diagnose why the goals flow is broken"""
print("π DIAGNOSING GOALS FLOW AND UPDATES")
print("=" * 60)
try:
# Test 1: Check if prompt generator is working
print("1οΈβ£ Testing prompt generator availability...")
from prompt_generator import PromptGenerator
generator = PromptGenerator()
print("β
PromptGenerator available")
# Test 2: Check context gathering
print("\n2οΈβ£ Testing context gathering...")
try:
context = generator._gather_context_data("test goals flow", "smart")
print("β
Context gathering successful")
print(f"π Context type: {type(context)}")
# Check specific fields
print(f"π¬ Conversation summary: {hasattr(context, 'conversation_summary')}")
print(f"π Action history: {hasattr(context, 'action_history')}")
print(f"π― Project plans: {hasattr(context, 'project_plans')}")
if hasattr(context, 'project_plans'):
print(f"π― Project plans content: {context.project_plans[:100]}...")
else:
print("β Project plans field missing!")
except Exception as e:
print(f"β Context gathering failed: {e}")
return
# Test 3: Check optimized prompt generator
print("\n3οΈβ£ Testing optimized prompt generator...")
try:
from optimized_prompt_generator import OptimizedPromptGenerator
opt_generator = OptimizedPromptGenerator()
print("β
OptimizedPromptGenerator available")
# Test context conversion
context_dict = opt_generator._context_to_dict(context)
print(f"β
Context conversion successful")
print(f"π Available keys: {list(context_dict.keys())}")
print(f"π― Project plans in dict: {'project_plans' in context_dict}")
except Exception as e:
print(f"β Optimized prompt generator failed: {e}")
return
# Test 4: Check intent classification
print("\n4οΈβ£ Testing intent classification...")
try:
if opt_generator.intent_selector:
relevant_context, intent_analysis = opt_generator.intent_selector.select_relevant_context(
"test goals flow and updates",
context_dict
)
print(f"β
Intent classification successful")
print(f"π― Intent: {intent_analysis.primary_intent.value}")
print(f"π Context requirements: {intent_analysis.context_requirements}")
print(f"π§ Selected context: {list(relevant_context.keys())}")
print(f"π― Project plans in selected: {'project_plans' in relevant_context}")
else:
print("β οΈ Intent selector not available")
except Exception as e:
print(f"β Intent classification failed: {e}")
# Test 5: Check conversation context formatting
print("\n5οΈβ£ Testing conversation context formatting...")
try:
conversation_context = opt_generator._format_phase1_conversation_context(context_dict)
print(f"β
Conversation context formatting successful")
print(f"π Result length: {len(conversation_context)}")
print(f"π¬ Contains context: {'π¬ CONTEXT:' in conversation_context}")
print(f"π Contains recent: {'π RECENT:' in conversation_context}")
print(f"π― Contains goals: {'π― GOALS:' in conversation_context}")
print(f"π Formatted result:\n{conversation_context}")
except Exception as e:
print(f"β Conversation context formatting failed: {e}")
# Test 6: Check essential context safeguard
print("\n6οΈβ£ Testing essential context safeguard...")
try:
# Create a filtered context that's missing some sections
filtered_context = {'user_preferences': 'test', 'agent_metadata': 'test'}
safeguarded_context = opt_generator._ensure_essential_context(filtered_context, context_dict)
print(f"β
Essential context safeguard successful")
print(f"π Safeguarded keys: {list(safeguarded_context.keys())}")
print(f"π― Project plans safeguarded: {'project_plans' in safeguarded_context}")
except Exception as e:
print(f"β Essential context safeguard failed: {e}")
print("\n" + "=" * 60)
print("π DIAGNOSIS COMPLETE")
# Final assessment
if 'π― GOALS:' in conversation_context:
print("π SUCCESS: Goals flow is working!")
else:
print("β FAILURE: Goals flow is broken!")
print("π Check the diagnostic output above for issues")
except Exception as e:
print(f"β Error during diagnosis: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
diagnose_goals_flow()