Shell
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 callinfer_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)
- Edit
core/data/prediction_markets.pyto addinfer_category() - Test via curl:
curl http://127.0.0.1:8000/api/predictions/trending?limit=5&category=Crypto - Verify markets return with correct categories
Step 2: Frontend Component (frontend-developer subagent)
- Invoke ui-builder skill for design context
- Launch frontend-developer subagent to create
PredictionMarketsCompact.tsx - Component uses existing
usePredictionMarketshook
Step 3: HomeWidgets Integration (nextjs-project-manager skill)
- Invoke nextjs-project-manager skill
- Add 'predictions' tab to HomeWidgets
- Conditional render of PredictionMarketsCompact vs chart
Step 4: AI Tool & Chat Integration (ai-engineer subagent)
- Launch ai-engineer subagent to add tool definition
- Invoke api-design skill for chat route context injection
- Invoke state-management skill for navigation updates
Step 5: QA & Verification
- 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
- Launch code-reviewer subagent for final review
Step 6: Commit
- Use
/commit-commands:commitfor atomic commits - Create PR with
/commit-commands:commit-push-pr