Looking at the logs, I can see the system is successfully calling your API endpoints, but there are issues with the Reddit integration. The main problems are:

Rules not being fetched from the selected subreddit
Modqueue items not appearing

Let me help you debug and fix these issues:
Debug Steps
1. Check Reddit OAuth Token
First, verify your Reddit access token is valid and has the right permissions:
javascript// Add this debug endpoint to test your Reddit connection
app.get('/api/debug/reddit-connection', async (req, res) => {
  try {
    const { accessToken } = req.headers;
    
    if (!accessToken) {
      return res.status(401).json({ error: 'No access token provided' });
    }

    // Test basic Reddit API access
    const response = await fetch('https://oauth.reddit.com/api/v1/me', {
      headers: {
        'Authorization': `bearer ${accessToken}`,
        'User-Agent': process.env.REDDIT_USER_AGENT || 'RedditModerationApp/1.0'
      }
    });

    if (!response.ok) {
      return res.status(response.status).json({ 
        error: 'Reddit API error', 
        status: response.status,
        statusText: response.statusText 
      });
    }

    const userData = await response.json();
    
    res.json({
      success: true,
      user: userData,
      scopes: userData.oauth_scope || 'Unknown scopes'
    });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});
2. Fix the Rules Endpoint
Update your rules endpoint with better error handling:
javascriptapp.get('/api/subreddits/:subreddit/rules', async (req, res) => {
  try {
    const { subreddit } = req.params;
    const accessToken = req.headers.authorization?.replace('Bearer ', '') || req.headers.accesstoken;
    
    console.log(`[DEBUG] Fetching rules for r/${subreddit}`);
    console.log(`[DEBUG] Access token present: ${!!accessToken}`);
    
    if (!accessToken) {
      return res.status(401).json({ error: 'No access token provided' });
    }

    // Method 1: Try Reddit's rules API first
    try {
      const rulesResponse = await fetch(`https://oauth.reddit.com/r/${subreddit}/about/rules`, {
        headers: {
          'Authorization': `bearer ${accessToken}`,
          'User-Agent': process.env.REDDIT_USER_AGENT || 'RedditModerationApp/1.0'
        }
      });

      if (rulesResponse.ok) {
        const rulesData = await rulesResponse.json();
        console.log(`[DEBUG] Rules fetched successfully: ${rulesData.rules?.length || 0} rules`);
        
        return res.json({
          rules: rulesData.rules || [],
          description: rulesData.site_rules_flow || '',
          source: 'reddit_rules_api'
        });
      } else {
        console.log(`[DEBUG] Rules API failed: ${rulesResponse.status}`);
      }
    } catch (rulesError) {
      console.log(`[DEBUG] Rules API error:`, rulesError.message);
    }

    // Method 2: Fallback to subreddit about page
    const aboutResponse = await fetch(`https://oauth.reddit.com/r/${subreddit}/about`, {
      headers: {
        'Authorization': `bearer ${accessToken}`,
        'User-Agent': process.env.REDDIT_USER_AGENT || 'RedditModerationApp/1.0'
      }
    });

    if (!aboutResponse.ok) {
      const errorText = await aboutResponse.text();
      console.log(`[DEBUG] About API failed:`, aboutResponse.status, errorText);
      
      return res.status(aboutResponse.status).json({ 
        error: 'Failed to fetch subreddit info',
        status: aboutResponse.status,
        details: errorText
      });
    }

    const aboutData = await aboutResponse.json();
    console.log(`[DEBUG] About data fetched, parsing rules from description`);
    
    // Parse rules from description if available
    const description = aboutData.data?.description || '';
    const sidebar = aboutData.data?.description_html || '';
    
    // Basic rule extraction from description
    const rules = extractRulesFromDescription(description);
    
    res.json({
      rules: rules,
      description: description,
      sidebar: sidebar,
      subreddit_type: aboutData.data?.subreddit_type,
      submission_type: aboutData.data?.submission_type,
      source: 'subreddit_about'
    });

  } catch (error) {
    console.error('[ERROR] Rules endpoint error:', error);
    res.status(500).json({ 
      error: 'Failed to fetch subreddit rules',
      details: error.message 
    });
  }
});

// Helper function to extract rules from description
function extractRulesFromDescription(description) {
  if (!description) return [];
  
  const rules = [];
  const lines = description.split('\n');
  
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i].trim();
    
    // Look for numbered rules like "1. Rule name" or "Rule 1:"
    const ruleMatch = line.match(/^(\d+\.?\s*)(.*?)[:.]?\s*$/);
    if (ruleMatch && ruleMatch[2]) {
      rules.push({
        short_name: `Rule ${ruleMatch[1].replace(/[^\d]/g, '')}`,
        description: ruleMatch[2].trim(),
        kind: 'all'
      });
    }
  }
  
  // If no numbered rules found, create generic ones
  if (rules.length === 0) {
    rules.push({
      short_name: 'General Rules',
      description: 'Follow Reddit content policy and be respectful',
      kind: 'all'
    });
  }
  
  return rules;
}
3. Fix the Modqueue Endpoint
Update your modqueue endpoint:
javascriptapp.get('/api/subreddits/:subreddit/modqueue', async (req, res) => {
  try {
    const { subreddit } = req.params;
    const { limit = 25, after } = req.query;
    const accessToken = req.headers.authorization?.replace('Bearer ', '') || req.headers.accesstoken;
    
    console.log(`[DEBUG] Fetching modqueue for r/${subreddit}`);
    console.log(`[DEBUG] Limit: ${limit}, After: ${after || 'none'}`);
    
    if (!accessToken) {
      return res.status(401).json({ error: 'No access token provided' });
    }

    const params = new URLSearchParams({
      limit: limit.toString(),
      show: 'all'
    });
    
    if (after) params.append('after', after);

    const modqueueResponse = await fetch(
      `https://oauth.reddit.com/r/${subreddit}/about/modqueue?${params}`,
      {
        headers: {
          'Authorization': `bearer ${accessToken}`,
          'User-Agent': process.env.REDDIT_USER_AGENT || 'RedditModerationApp/1.0'
        }
      }
    );

    if (!modqueueResponse.ok) {
      const errorText = await modqueueResponse.text();
      console.log(`[DEBUG] Modqueue API failed:`, modqueueResponse.status, errorText);
      
      return res.status(modqueueResponse.status).json({ 
        error: 'Failed to fetch modqueue',
        status: modqueueResponse.status,
        details: errorText
      });
    }

    const modqueueData = await modqueueResponse.json();
    console.log(`[DEBUG] Modqueue response:`, {
      kind: modqueueData.kind,
      children_count: modqueueData.data?.children?.length || 0,
      after: modqueueData.data?.after
    });

    const items = (modqueueData.data?.children || []).map(child => {
      const item = child.data;
      
      return {
        id: item.id,
        fullname: item.name,
        type: child.kind === 't3' ? 'submission' : 'comment',
        author: item.author || '[deleted]',
        created_utc: item.created_utc,
        subreddit: item.subreddit,
        permalink: item.permalink,
        score: item.score || 0,
        reports: item.user_reports || [],
        mod_reports: item.mod_reports || [],
        num_reports: item.num_reports || 0,
        
        // Submission-specific fields
        ...(child.kind === 't3' && {
          title: item.title,
          selftext: item.selftext,
          url: item.url,
          is_self: item.is_self,
          thumbnail: item.thumbnail,
          num_comments: item.num_comments
        }),
        
        // Comment-specific fields
        ...(child.kind === 't1' && {
          body: item.body,
          link_title: item.link_title,
          link_id: item.link_id,
          parent_id: item.parent_id
        })
      };
    });

    console.log(`[DEBUG] Processed ${items.length} modqueue items`);

    res.json({
      items,
      after: modqueueData.data?.after || null,
      total_count: items.length
    });

  } catch (error) {
    console.error('[ERROR] Modqueue endpoint error:', error);
    res.status(500).json({ 
      error: 'Failed to fetch modqueue',
      details: error.message 
    });
  }
});
4. Update Frontend to Handle Errors
Add better error handling in your React components:
javascript// In your useQuery for rules
const { data: rules, isLoading: loadingRules, error: rulesError } = useQuery({
  queryKey: ['subreddit-rules', selectedSubreddit],
  queryFn: async () => {
    if (!selectedSubreddit) return null;
    
    const token = localStorage.getItem('reddit_access_token');
    if (!token) throw new Error('No Reddit access token');
    
    const response = await fetch(`/api/subreddits/${selectedSubreddit}/rules`, {
      headers: {
        'Authorization': `Bearer ${token}`,
        'accessToken': token // Fallback header
      }
    });
    
    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(errorData.error || 'Failed to fetch rules');
    }
    
    return response.json();
  },
  enabled: !!selectedSubreddit,
  retry: 2
});

// Add error display
{rulesError && (
  <Alert variant="destructive">
    <AlertTriangle className="h-4 w-4" />
    <AlertDescription>
      Failed to load rules: {rulesError.message}
    </AlertDescription>
  </Alert>
)}
5. Test the Connection
Add this test button to your frontend:
javascriptconst testRedditConnection = async () => {
  try {
    const token = localStorage.getItem('reddit_access_token');
    const response = await fetch('/api/debug/reddit-connection', {
      headers: { 'accessToken': token }
    });
    const data = await response.json();
    console.log('Reddit connection test:', data);
    alert(`Connection ${data.success ? 'successful' : 'failed'}: ${JSON.stringify(data)}`);
  } catch (error) {
    console.error('Connection test failed:', error);
    alert(`Test failed: ${error.message}`);
  }
};

// Add this button to your UI
<Button onClick={testRedditConnection}>Test Reddit Connection</Button>
Quick Checklist

Verify OAuth token is being stored correctly in localStorage
Check Reddit app permissions include modposts and read scopes
Confirm you're a moderator of the selected subreddit
Test with a small/active subreddit first
Check browser network tab for actual API response details

Try these fixes and let me know what the debug outputs show. This should help us identify exactly where the Reddit integration is failing.RetryClaude can make mistakes. Please double-check responses.