Skip to content
Shell
7.4 KB
Raw Blame

Prediction Markets Fix + Front Page Integration Plan

Decisions Made

  • ✅ Grid/list view only (no probability chart)
  • ✅ Research input for stock trades (no direct Kalshi/Polymarket trading)
  • ✅ Separate watchlists (prediction markets independent from stocks)

Tool Assignments

Phase Task Assigned Tool
1 Backend category fix backend-architect subagent
2 PredictionMarketsCompact component ui-builder skill + frontend-developer subagent
2 HomeWidgets tab integration nextjs-project-manager skill
3 AI tool definition ai-engineer subagent
3 Chat context injection api-design skill
3 Panel navigation state-management skill
QA Visual testing Playwright MCP
QA Code review code-reviewer subagent

Phase 1: Fix Bug - Category Detection (Priority: HIGH)

Root Cause

Backend returns category: "Unknown" for all Polymarket data. UI sends category=Economics filter → 0 results.

Solution

Add intelligent category inference in normalize_market():

def infer_category(title: str, description: str) -> str:
    text = (title + " " + (description or "")).lower()

    if any(kw in text for kw in ["fed", "rate", "inflation", "gdp", "cpi", "fomc", "interest"]):
        return "Economics"
    if any(kw in text for kw in ["bitcoin", "btc", "ethereum", "eth", "crypto", "solana"]):
        return "Crypto"
    if any(kw in text for kw in ["stock", "share", "earnings", "aapl", "nvda", "tsla", "price target"]):
        return "Stocks"
    if any(kw in text for kw in ["election", "president", "congress", "senate", "vote"]):
        return "Politics"
    if any(kw in text for kw in ["nfl", "nba", "mlb", "super bowl", "championship"]):
        return "Sports"
    return "Other"

File: core/data/prediction_markets.py

  • Modify normalize_market() to call infer_category()

Phase 2: Front Page Predictions Tab

Target State

HomeWidgets.tsx
├── Tabs: Market | Crypto | Predictions | Watchlist | Custom
├── Content:
│   ├── [Market/Crypto/Watchlist/Custom] → LineChart
│   └── [Predictions] → PredictionMarketsCompact
└── Legend/Market Cards

New Component: PredictionMarketsCompact

File: web/src/components/prediction-markets/PredictionMarketsCompact.tsx

Features:

  • Compact 2-col grid of top markets (by volume)
  • Each card shows: title (truncated), YES%, NO%, volume
  • Source filter pills (All | Kalshi | Polymarket)
  • Click card → sets activeContent='prediction-markets' with selectedMarket
  • "View All" button → opens full panel

UI Design:

┌─────────────────────────────────────────────────┐
│ [All] [Kalshi] [Polymarket]        [View All →] │
├─────────────────────────────────────────────────┤
│ ┌──────────────────┐ ┌──────────────────┐       │
│ │ Fed Rate Cuts    │ │ Bitcoin $200k    │       │
│ │ YES: 0.05%       │ │ YES: 0.25%       │       │
│ │ $5.7M volume     │ │ $11.1M volume    │       │
│ └──────────────────┘ └──────────────────┘       │
│ ┌──────────────────┐ ┌──────────────────┐       │
│ │ ETH $7,000       │ │ SPY All-Time High│       │
│ │ YES: 0.4%        │ │ YES: 65%         │       │
│ │ $6.6M volume     │ │ $2.1M volume     │       │
│ └──────────────────┘ └──────────────────┘       │
└─────────────────────────────────────────────────┘

File: web/src/components/chat/HomeWidgets.tsx

  • Add 'predictions' to tab type
  • Render PredictionMarketsCompact when tab is active

Phase 3: Chat Integration

3A. Add AI Tool

File: web/src/lib/llm/tools.ts

{
  name: 'get_prediction_market',
  description: 'Get details about a prediction market to discuss with user',
  parameters: {
    platform: { type: 'string', enum: ['kalshi', 'polymarket'] },
    market_id: { type: 'string' }
  }
}

3B. Context Injection

File: web/src/app/api/chat/route.ts

When activeContent === 'prediction-markets' and selectedMarket exists:

  • Include market title, description, yes/no prices in system prompt
  • Suggest related stock symbols for trading ideas

3C. Panel Navigation

File: web/src/components/chat/ConversationView.tsx

  • Intent detection: "prediction" → setActiveContent('prediction-markets')
  • Tool result handling: show_prediction_markets → navigate to panel

Implementation Order

Step Task File(s) Est.
1 Fix category detection core/data/prediction_markets.py 15m
2 Create PredictionMarketsCompact web/src/components/prediction-markets/PredictionMarketsCompact.tsx 30m
3 Add Predictions tab to HomeWidgets web/src/components/chat/HomeWidgets.tsx 15m
4 Add prediction market tool web/src/lib/llm/tools.ts 10m
5 Add context injection web/src/app/api/chat/route.ts 15m
6 Panel navigation web/src/components/chat/ConversationView.tsx 10m

Total: ~1.5 hours


Files Summary

File Action
core/data/prediction_markets.py MODIFY - Add infer_category()
web/src/components/prediction-markets/PredictionMarketsCompact.tsx CREATE
web/src/components/chat/HomeWidgets.tsx MODIFY - Add tab
web/src/lib/llm/tools.ts MODIFY - Add tool
web/src/app/api/chat/route.ts MODIFY - Context
web/src/components/chat/ConversationView.tsx MODIFY - Navigation

Execution Workflow

Step 1: Backend Fix (Me + backend-architect verification)

  1. Edit core/data/prediction_markets.py to add infer_category()
  2. Test via curl: curl http://127.0.0.1:8000/api/predictions/trending?limit=5&category=Crypto
  3. Verify markets return with correct categories

Step 2: Frontend Component (frontend-developer subagent)

  1. Invoke ui-builder skill for design context
  2. Launch frontend-developer subagent to create PredictionMarketsCompact.tsx
  3. Component uses existing usePredictionMarkets hook

Step 3: HomeWidgets Integration (nextjs-project-manager skill)

  1. Invoke nextjs-project-manager skill
  2. Add 'predictions' tab to HomeWidgets
  3. Conditional render of PredictionMarketsCompact vs chart

Step 4: AI Tool & Chat Integration (ai-engineer subagent)

  1. Launch ai-engineer subagent to add tool definition
  2. Invoke api-design skill for chat route context injection
  3. Invoke state-management skill for navigation updates

Step 5: QA & Verification

  1. Use Playwright MCP to visually test:
    • Navigate to home page
    • Click Predictions tab
    • Verify markets load with categories
    • Click a market card
    • Verify panel opens
  2. Launch code-reviewer subagent for final review

Step 6: Commit

  1. Use /commit-commands:commit for atomic commits
  2. Create PR with /commit-commands:commit-push-pr