show-test-conversation.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # Show full conversation from a test session
  3. # Usage: ./show-test-conversation.sh <session_id>
  4. SESSION_ID=$1
  5. if [ -z "$SESSION_ID" ]; then
  6. echo "Usage: $0 <session_id>"
  7. echo ""
  8. echo "Get session ID from test output (look for 'Session created: ses_...')"
  9. exit 1
  10. fi
  11. SESSION_DIR="$HOME/.local/share/opencode/storage/message/$SESSION_ID"
  12. PART_DIR="$HOME/.local/share/opencode/storage/part"
  13. if [ ! -d "$SESSION_DIR" ]; then
  14. echo "Session not found: $SESSION_ID"
  15. exit 1
  16. fi
  17. echo "========================================================================"
  18. echo "SESSION: $SESSION_ID"
  19. echo "========================================================================"
  20. echo ""
  21. # Process messages in order
  22. for msg_file in "$SESSION_DIR"/*.json; do
  23. if [ -f "$msg_file" ]; then
  24. MSG_ID=$(cat "$msg_file" | jq -r '.id')
  25. ROLE=$(cat "$msg_file" | jq -r '.role')
  26. SUMMARY=$(cat "$msg_file" | jq -r '.summary.body // empty')
  27. if [ "$ROLE" = "user" ]; then
  28. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  29. echo "👤 USER PROMPT"
  30. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  31. # Get actual user prompt from parts (not summary which is auto-generated)
  32. if [ -d "$PART_DIR/$MSG_ID" ]; then
  33. for part_file in "$PART_DIR/$MSG_ID"/*.json; do
  34. if [ -f "$part_file" ]; then
  35. PART_TYPE=$(cat "$part_file" | jq -r '.type')
  36. if [ "$PART_TYPE" = "text" ]; then
  37. TEXT=$(cat "$part_file" | jq -r '.text // empty')
  38. if [ -n "$TEXT" ]; then
  39. echo "$TEXT"
  40. fi
  41. fi
  42. fi
  43. done
  44. else
  45. # Fallback to summary if no parts (shouldn't happen)
  46. if [ -n "$SUMMARY" ]; then
  47. echo "$SUMMARY"
  48. fi
  49. fi
  50. echo ""
  51. elif [ "$ROLE" = "assistant" ]; then
  52. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  53. echo "🤖 ASSISTANT"
  54. echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
  55. # Read parts from the part directory
  56. if [ -d "$PART_DIR/$MSG_ID" ]; then
  57. for part_file in "$PART_DIR/$MSG_ID"/*.json; do
  58. if [ -f "$part_file" ]; then
  59. PART_TYPE=$(cat "$part_file" | jq -r '.type')
  60. if [ "$PART_TYPE" = "text" ]; then
  61. TEXT=$(cat "$part_file" | jq -r '.text // empty')
  62. if [ -n "$TEXT" ]; then
  63. echo "$TEXT"
  64. echo ""
  65. fi
  66. elif [ "$PART_TYPE" = "tool" ]; then
  67. TOOL=$(cat "$part_file" | jq -r '.tool')
  68. INPUT=$(cat "$part_file" | jq -c '.input // {}')
  69. echo "🔧 TOOL CALL: $TOOL"
  70. echo " Input: $INPUT"
  71. echo ""
  72. elif [ "$PART_TYPE" = "tool_result" ]; then
  73. RESULT=$(cat "$part_file" | jq -r '.result // empty')
  74. if [ -n "$RESULT" ]; then
  75. # Show first 500 chars of result
  76. echo "📊 TOOL RESULT:"
  77. echo "$RESULT" | head -c 500
  78. if [ ${#RESULT} -gt 500 ]; then
  79. echo "..."
  80. fi
  81. echo ""
  82. fi
  83. fi
  84. fi
  85. done
  86. fi
  87. echo ""
  88. fi
  89. fi
  90. done
  91. echo "========================================================================"