Skip to content
hetpatel-11Public

About

Chrome extension that filters spam on X. Powered by Grok.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GrokGuard: Real-Time AI Safety Platform for X.com

xAI Hackathon 2025

A Chrome extension powered by Grok AI that provides real-time content moderation on X.com, detecting scams, impersonators, and misinformation through instant analysis and multi-agent debate systems.

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • Chrome/Chromium browser
  • Grok API key (set in .env.local)

Installation

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env.local
# Add your GROK_API_KEY to .env.local

Running the System

# Terminal 1: Start the API server
npx tsx api/server.ts

# Terminal 2: Start the dashboard (optional)
npm run dashboard

# Terminal 3: Load the Chrome extension
# 1. Open Chrome โ†’ chrome://extensions/
# 2. Enable "Developer mode"
# 3. Click "Load unpacked"
# 4. Select the `extension/` folder

๐ŸŽฏ What It Does

GrokGuard monitors your X.com feed in real time and:

  • โšก Instant Analysis: Uses grok-3-mini to analyze posts as you scroll
  • ๐Ÿ›ก๏ธ Scam Detection: Collapses dangerous posts with smooth animations
  • โš ๏ธ Misinformation Labeling: Flags false claims with fact-check badges
  • ๐Ÿ“Š Live Dashboard: Track stats (Scanned, Blocked, Flagged, Fact-Checked, Misinfo)
  • ๐Ÿค– Multi-Agent Debate: Deep profile analysis using Prosecutor/Defender/Arbiter agents
  • ๐Ÿ” Fact-Checking: Autonomous investigation with source credibility checks

๐Ÿ—๏ธ Architecture

Real-Time Feed Protection

X.com Feed โ†’ Chrome Extension โ†’ API Server โ†’ Grok AI
                โ†“
         Instant Analysis (grok-3-mini)
                โ†“
    [Scam] โ†’ Collapse Post
    [Suspicious] โ†’ Flag Badge
    [Clean] โ†’ Continue Monitoring

Multi-Agent Profile Analysis

Username Input โ†’ Investigator Agent (plans investigation)
                        โ†“
                  [Fetches X API Data]
                        โ†“
        Prosecutor โš–๏ธ Defender (Multi-turn debate)
              โ†“              โ†“
          Round 1, Round 2, Round 3...
                        โ†“
               [Consensus Reached]
                        โ†“
                  Final Verdict

All agents powered by grok-4-1-fast-reasoning

โœจ Key Features

Chrome Extension

  • โœ… Real-time feed monitoring with MutationObserver and IntersectionObserver
  • โœ… Pre-scanning posts 2000px ahead for better UX
  • โœ… Post state persistence using IndexedDB
  • โœ… Smooth collapse animations for blocked posts
  • โœ… Misinformation badges with confidence scores
  • โœ… Clickable stats sidebar to view filtered posts
  • โœ… Auto-scroll to posts when clicking from dashboard

API Server

  • โœ… Instant post analysis endpoint (/api/analyze-post)
  • โœ… Fact-checking endpoint (/api/fact-check) with claim detection
  • โœ… Stats endpoint (/api/stats) for dashboard data
  • โœ… Multi-agent debate for profile analysis (/api/analyze)
  • โœ… Feedback endpoint (/api/feedback) for learning

Dashboard

  • โœ… Real-time stats (Scanned, Blocked, Flagged, Fact-Checked, Misinfo)
  • โœ… Post filtering by category (All, Blocked, Flagged, Fact-Checked, Misinfo)
  • โœ… Activity logs with timestamps
  • โœ… Black & white theme with glass-morphism effects
  • โœ… Direct links to original X.com posts

๐Ÿค– Agentic AI System

What Makes It Agentic?

  1. Autonomous Tool Use: Investigator agent decides which X API endpoints to call
  2. Multi-Turn Debate: Prosecutor and Defender iterate until consensus
  3. Investigation Planning: AI plans its own data gathering strategy
  4. Consensus Detection: Stops debating when agents converge (cost optimization)
  5. Adaptive Reasoning: Agents adjust confidence based on new evidence

Agent Roles

  • Investigator: Plans investigation and fetches X API data
  • Prosecutor: Builds case that content is harmful
  • Defender: Protects free speech, argues for legitimacy
  • Arbiter: Makes final decision after reviewing debate

๐Ÿ“Š Decision System

Instant Analysis (Feed Posts)

Uses grok-3-mini with conservative prompt:

  • SCAM: Crypto giveaways, phishing links, impersonation, "verify account" scams
  • SUSPICIOUS: Unverified financial claims, suspicious URLs, too-good-to-be-true offers
  • CLEAN: Normal tweets, opinions, news, legitimate promotions

Blocked if: classification === "scam" || classification === "suspicious"

Fact-Checking

Uses grok-4-1-fast-reasoning for:

  • Claim detection
  • Source credibility verification
  • Community context search
  • Confidence scoring

Skipped for: Verified accounts, credible sources (Forbes, BBC, etc.)

๐ŸŽจ User Experience

  • Collapse Animation: Blocked posts smoothly collapse with 1.2s animation
  • Badge System:
    • ๐ŸŸข Clean badge for legitimate posts
    • โš ๏ธ Warning badge for suspicious posts
    • ๐Ÿ”ด Misinformation badge for false claims
  • Stats Banner: Fixed position showing real-time counts
  • Sidebar: Click stats to view filtered posts
  • Toast Messages: User feedback for actions

๐Ÿ“ API Endpoints

POST /api/analyze-post

Instant analysis for feed posts.

Request:

{
  "username": "example_user",
  "text": "Post content here"
}

Response:

{
  "verdict": {
    "classification": "scam" | "suspicious" | "legitimate",
    "confidence": 0-100,
    "recommendedAction": "quarantine" | "flag" | "no_action",
    "reasoning": "Brief explanation"
  }
}

POST /api/fact-check

Fact-checking with claim detection.

Request:

{
  "username": "example_user",
  "text": "Post content here",
  "tweetUrl": "https://x.com/user/status/123"
}

Response:

{
  "hasClaim": true,
  "claim": "Detected claim text",
  "verdict": "true" | "false" | "unverifiable",
  "confidence": 0-100,
  "reasoning": "Explanation",
  "sources": ["source1", "source2"]
}

GET /api/stats

Real-time dashboard statistics.

Response:

{
  "stats": {
    "scanned": 100,
    "blocked": 5,
    "flagged": 3,
    "factChecked": 10,
    "misinformation": 2
  },
  "recentPosts": [...],
  "activityLog": [...]
}

๐Ÿ› ๏ธ Development

Project Structure

.
โ”œโ”€โ”€ extension/          # Chrome extension (Manifest V3)
โ”‚   โ”œโ”€โ”€ manifest.json
โ”‚   โ”œโ”€โ”€ background.js  # Service worker
โ”‚   โ”œโ”€โ”€ feed-monitor.js # Content script
โ”‚   โ””โ”€โ”€ content.css     # Extension styles
โ”œโ”€โ”€ api/               # Express.js API server
โ”‚   โ””โ”€โ”€ server.ts
โ”œโ”€โ”€ lib/               # Core libraries
โ”‚   โ”œโ”€โ”€ agents/        # AI agents
โ”‚   โ”‚   โ”œโ”€โ”€ instant-analyzer.ts
โ”‚   โ”‚   โ”œโ”€โ”€ fact-checker.ts
โ”‚   โ”‚   โ”œโ”€โ”€ investigator.ts
โ”‚   โ”‚   โ”œโ”€โ”€ prosecutor.ts
โ”‚   โ”‚   โ”œโ”€โ”€ defender.ts
โ”‚   โ”‚   โ”œโ”€โ”€ arbiter.ts
โ”‚   โ”‚   โ””โ”€โ”€ debate-orchestrator.ts
โ”‚   โ”œโ”€โ”€ grok/          # Grok API client
โ”‚   โ””โ”€โ”€ x-api/         # X API client
โ”œโ”€โ”€ app/               # Next.js dashboard
โ”‚   โ”œโ”€โ”€ page.tsx       # Main dashboard
โ”‚   โ”œโ”€โ”€ layout.tsx
โ”‚   โ””โ”€โ”€ globals.css
โ””โ”€โ”€ SUBMISSION.md      # Hackathon submission doc

Commands

# Start API server
npx tsx api/server.ts

# Start dashboard
npm run dashboard

# Test agentic system
npx tsx test-agentic-real.ts

# Test instant analyzer
npx tsx test-apis.ts

๐ŸŽฏ Challenges & Solutions

False Positives

  • Problem: AI flagging legitimate accounts
  • Solution: Multi-factor legitimacy scoring, source credibility checks, conservative prompts

Real-Time Performance

  • Problem: Need fast analysis for feed scrolling
  • Solution: Hybrid approach - grok-3-mini for instant, grok-4-1-fast-reasoning for deep analysis

Extension Context Invalidation

  • Problem: UI disappearing after page navigation
  • Solution: Heartbeat checks, state recovery, MutationObserver for navigation detection

๐Ÿ† Accomplishments

  • โœ… Truly agentic: Autonomous investigation + multi-turn debate
  • โœ… Zero false positives on verified accounts
  • โœ… Real-time feed protection with instant AI analysis
  • โœ… Production-ready Chrome extension with smooth UX
  • โœ… Comprehensive dashboard for monitoring and analytics

๐Ÿ“š Built With

  • Grok AI (grok-3-mini, grok-4-1-fast-reasoning)
  • Chrome Extension API (Manifest V3)
  • TypeScript
  • Express.js
  • Next.js
  • React

๐Ÿ”ฎ What's Next

  • Human-in-the-loop learning from feedback
  • Supabase integration for persistent analytics
  • Web search integration for advanced fact-checking
  • Mobile browser support
  • Community notes integration
  • Advanced source credibility database

Powered by Grok AI | Real-time protection for X.com

About

Chrome extension that filters spam on X. Powered by Grok.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages