CodeBug / templates /index.html
vinith17's picture
improve: add debugging and fix fallback confidence field
f971627
Raw History Blame
49 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>CodeBug β€” AI Code Review</title> <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;0,900;1,700&family=DM+Mono:wght@400;500&family=Syne:wght@400;600;700;800&display=swap" rel="stylesheet" /> <style> /* ── TOKENS ─────────────────────────────────────────────── */ :root { --ink: #0e0e0c; --paper: #f2efe8; --surface:#e8e4dc; --mid: #b8b3aa; --dim: #7a756c; --mono: 'DM Mono', monospace; --serif: 'Playfair Display', serif; --sans: 'Syne', sans-serif; } /* ── RESET ──────────────────────────────────────────────── */ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } html { scroll-behavior: smooth; } body { background: var(--paper); color: var(--ink); font-family: var(--sans); overflow-x: hidden; } /* subtle grain β€” opacity kept very low so it doesn't fight text */ body::before { content: ''; position: fixed; inset: 0; z-index: 9000; pointer-events: none; opacity: .09; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); background-size: 200px 200px; } /* ── NAV ─────────────────────────────────────────────────── */ nav { position: fixed; top: 0; left: 0; right: 0; z-index: 500; display: flex; align-items: center; justify-content: space-between; padding: 20px 56px; border-bottom: 1px solid rgba(14,14,12,.08); backdrop-filter: blur(14px); background: rgba(242,239,232,.92); } .nav-logo { font-family: var(--serif); font-size: 1.25rem; font-weight: 900; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; } .nav-logo sup { font-family: var(--mono); font-size: .5rem; background: var(--ink); color: var(--paper); padding: 2px 6px; border-radius: 2px; letter-spacing: .06em; vertical-align: super; } .nav-links { display: flex; gap: 36px; list-style: none; } .nav-links a { font-size: .72rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; text-decoration: none; color: var(--dim); transition: color .2s; } .nav-links a:hover { color: var(--ink); } .nav-cta { background: var(--ink); color: var(--paper); font-family: var(--sans); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; border: none; padding: 10px 24px; border-radius: 2px; cursor: pointer; transition: background .2s, transform .15s; } .nav-cta:hover { background: #2a2a28; transform: translateY(-1px); } /* ── HERO ────────────────────────────────────────────────── */ #hero { min-height: 100vh; display: grid; align-items: center; padding: 140px 56px 80px; } .hero-inner { max-width: 1160px; margin: 0 auto; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 72px; align-items: center; } .hero-eyebrow { font-family: var(--mono); font-size: .65rem; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); display: flex; align-items: center; gap: 10px; margin-bottom: 24px; animation: fadeUp .7s ease both; } .hero-eyebrow::before { content: ''; width: 24px; height: 1px; background: var(--mid); } .hero-headline { font-family: var(--serif); font-size: clamp(3rem, 5.2vw, 5.4rem); font-weight: 900; line-height: .96; letter-spacing: -.03em; margin-bottom: 24px; animation: fadeUp .7s .08s ease both; } .hero-headline em { font-style: italic; color: var(--dim); } .hero-sub { font-size: 1rem; line-height: 1.7; color: var(--dim); max-width: 380px; margin-bottom: 40px; animation: fadeUp .7s .16s ease both; } .hero-btns { display: flex; gap: 12px; animation: fadeUp .7s .24s ease both; } .btn-primary { background: var(--ink); color: var(--paper); font-family: var(--sans); font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; border: none; padding: 13px 28px; border-radius: 2px; cursor: pointer; transition: background .2s, transform .15s; } .btn-primary:hover { background: #2a2a28; transform: translateY(-2px); } .btn-secondary { background: transparent; color: var(--ink); font-family: var(--sans); font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; border: 1.5px solid var(--mid); padding: 13px 28px; border-radius: 2px; cursor: pointer; transition: border-color .2s, transform .15s; } .btn-secondary:hover { border-color: var(--ink); transform: translateY(-2px); } /* terminal card */ .hero-terminal { background: var(--ink); border-radius: 8px; overflow: hidden; box-shadow: 0 32px 64px rgba(0,0,0,.16); animation: fadeUp .7s .1s ease both; } .t-bar { background: #181816; padding: 13px 18px; display: flex; align-items: center; gap: 7px; } .t-dot { width: 10px; height: 10px; border-radius: 50%; } .t-dot:nth-child(1) { background: #ff5f57; } .t-dot:nth-child(2) { background: #febc2e; } .t-dot:nth-child(3) { background: #28c840; } .t-lbl { margin-left: auto; font-family: var(--mono); font-size: .6rem; color: #4a4a48; letter-spacing: .08em; } .t-body { padding: 24px 22px; font-family: var(--mono); font-size: .75rem; line-height: 1.85; color: #b0aba2; } .tc { color: #484840; } .tk { color: #7eb8d4; } .ts { color: #b8d47e; } .tn { color: #d4b47e; } .te { color: #d47e7e; } .tg { color: #7ed4a0; } .tbadge { display: inline-block; padding: 2px 8px; border-radius: 2px; font-size: .58rem; margin-left: 8px; } .tbadge.err { background: #d47e7e14; border: 1px solid #d47e7e40; color: #d47e7e; } .tbadge.ok { background: #7ed4a014; border: 1px solid #7ed4a040; color: #7ed4a0; } .blink { animation: blink 1.1s step-end infinite; } @keyframes blink { 50% { opacity: 0; } } /* hero stats */ .hero-stats { grid-column: 1 / -1; display: flex; gap: 52px; border-top: 1px solid var(--mid); padding-top: 36px; animation: fadeUp .7s .3s ease both; } .stat-num { font-family: var(--serif); font-size: 2.2rem; font-weight: 900; letter-spacing: -.04em; line-height: 1; } .stat-lbl { font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin-top: 5px; } /* ── DIVIDER LINE ────────────────────────────────────────── */ .divider { border: none; border-top: 1px solid var(--mid); margin: 0; } /* ── SECTIONS ────────────────────────────────────────────── */ section { padding: 96px 56px; } .si { max-width: 1160px; margin: 0 auto; } /* section header */ .s-eyebrow { font-family: var(--mono); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); display: flex; align-items: center; gap: 8px; margin-bottom: 14px; } .s-eyebrow::before { content: ''; width: 18px; height: 1px; background: var(--mid); } .s-title { font-family: var(--serif); font-size: clamp(2rem, 3.6vw, 3.2rem); font-weight: 900; line-height: 1.05; letter-spacing: -.025em; margin-bottom: 16px; } .s-body { font-size: .95rem; line-height: 1.72; color: var(--dim); max-width: 540px; } /* dark section overrides */ .dark { background: var(--ink); color: var(--paper); } .dark .s-eyebrow { color: #666; } .dark .s-eyebrow::before { background: #333; } .dark .s-title { color: var(--paper); } .dark .s-body { color: #999; } /* ── REVIEW SECTION ──────────────────────────────────────── */ .review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 48px; } .panel { border: 1px solid #262622; border-radius: 6px; overflow: hidden; } .panel-head { padding: 12px 20px; background: #161614; border-bottom: 1px solid #262622; display: flex; align-items: center; justify-content: space-between; } .panel-label { font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: #666; } .panel-meta { font-family: var(--mono); font-size: .6rem; color: #3e3e3a; } textarea#codeInput { display: block; width: 100%; height: 260px; background: transparent; border: none; outline: none; resize: none; font-family: var(--mono); font-size: .78rem; line-height: 1.7; color: #c8c3ba; caret-color: #7eb8d4; padding: 20px; } .panel-footer { display: flex; gap: 10px; align-items: center; padding: 12px 20px; border-top: 1px solid #262622; } .lang-sel { background: #1a1a18; border: 1px solid #303030; border-radius: 2px; color: #999; font-family: var(--mono); font-size: .68rem; padding: 7px 12px; cursor: pointer; outline: none; } .run-btn { margin-left: auto; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; border: none; padding: 9px 22px; border-radius: 2px; cursor: pointer; transition: background .2s, transform .15s; } .run-btn:hover { background: #ddd8d0; transform: translateY(-1px); } .run-btn:disabled { opacity: .5; pointer-events: none; } /* result area */ .result-body { padding: 20px; min-height: 316px; position: relative; } .r-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 276px; gap: 10px; color: #333; } .r-empty p { font-family: var(--mono); font-size: .65rem; color: #3e3e3a; } .r-loading { display: none; flex-direction: column; align-items: center; justify-content: center; height: 276px; gap: 16px; } .r-loading.on { display: flex; } .spinner { width: 20px; height: 20px; border: 2px solid #2a2a28; border-top-color: #888; border-radius: 50%; animation: spin .8s linear infinite; } .spinner-lbl { font-family: var(--mono); font-size: .65rem; color: #555; } @keyframes spin { to { transform: rotate(360deg); } } .r-card { display: none; } .r-card.on { display: block; } .bug-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid #262622; } .bug-counter { font-family: var(--mono); font-size: .65rem; letter-spacing: .08em; text-transform: uppercase; color: #666; } .bug-nav { display: flex; gap: 8px; align-items: center; } .bug-nav-btn { background: #161614; border: 1px solid #262622; border-radius: 2px; color: #999; font-family: var(--mono); font-size: .65rem; padding: 6px 12px; cursor: pointer; transition: all .2s; } .bug-nav-btn:hover:not(:disabled) { background: #262622; border-color: #3a3a38; color: #ccc; } .bug-nav-btn:disabled { opacity: .4; cursor: not-allowed; } .bug-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 20px; padding: 12px; background: #0a0a08; border: 1px solid #262622; border-radius: 4px; } .bug-mini-card { padding: 10px; border-radius: 2px; cursor: pointer; transition: all .2s; border: 1px solid #262622; font-size: .65rem; font-family: var(--mono); text-align: center; } .bug-mini-card:hover { border-color: #3a3a38; background: #161614; } .bug-mini-card.current { border-color: #7eb8d4; background: #1a2a3a; } .r-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 2px; margin-bottom: 20px; font-family: var(--mono); font-size: .62rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; } .r-badge.sec { background: #d47e7e14; border: 1px solid #d47e7e40; color: #d47e7e; } .r-badge.lgc { background: #d4c27e14; border: 1px solid #d4c27e40; color: #d4c27e; } .r-badge.sty { background: #7eb8d414; border: 1px solid #7eb8d440; color: #7eb8d4; } .r-badge.apr { background: #7ed4a014; border: 1px solid #7ed4a040; color: #7ed4a0; } .r-field { margin-bottom: 16px; } .r-field-label { font-family: var(--mono); font-size: .58rem; letter-spacing: .12em; text-transform: uppercase; color: #4a4a48; margin-bottom: 5px; } .r-field-value { font-family: var(--mono); font-size: .78rem; color: #c0bbb2; line-height: 1.6; } .confidence-bar { display: flex; align-items: center; gap: 8px; margin-top: 4px; } .confidence-meter { width: 100px; height: 6px; background: #262622; border-radius: 2px; overflow: hidden; } .confidence-fill { height: 100%; background: linear-gradient(90deg, #d47e7e, #d4c27e, #7ed4a0); transition: width .3s; } .confidence-pct { font-size: .65rem; color: #888; font-family: var(--mono); } .sev-dots { display: flex; gap: 5px; margin-top: 4px; } .sd { width: 9px; height: 9px; border-radius: 50%; background: #2a2a28; } .sd.on { background: #d47e7e; } .r-fix { background: #161614; border: 1px solid #262622; border-radius: 4px; padding: 14px 16px; margin-top: 6px; font-family: var(--mono); font-size: .73rem; color: #7ed4a0; white-space: pre-wrap; line-height: 1.65; } .export-btn { display: inline-flex; align-items: center; gap: 6px; background: #161614; border: 1px solid #262622; border-radius: 2px; color: #999; font-family: var(--mono); font-size: .65rem; padding: 6px 12px; cursor: pointer; transition: all .2s; margin-top: 12px; } .export-btn:hover { background: #262622; border-color: #3a3a38; color: #ccc; } /* ── FEATURES ────────────────────────────────────────────── */ #features { background: var(--surface); } .feat-grid { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--mid); border-radius: 6px; overflow: hidden; margin-top: 48px; } .fc { padding: 36px 30px; position: relative; border-right: 1px solid var(--mid); border-bottom: 1px solid var(--mid); transition: background .2s; } .fc:hover { background: var(--paper); } .fc:nth-child(3n) { border-right: none; } .fc:nth-last-child(-n+3) { border-bottom: none; } .fc-num { position: absolute; top: 14px; right: 18px; font-family: var(--mono); font-size: .56rem; color: var(--mid); } .fc-icon { width: 36px; height: 36px; background: var(--ink); border-radius: 3px; display: flex; align-items: center; justify-content: center; margin-bottom: 18px; } .fc-icon svg { width: 16px; height: 16px; } .fc-title { font-size: .95rem; font-weight: 700; margin-bottom: 9px; } .fc-desc { font-size: .88rem; line-height: 1.65; color: var(--dim); } /* ── API TABLE ───────────────────────────────────────────── */ .ep-table { margin-top: 44px; width: 100%; border-collapse: collapse; } .ep-table th { text-align: left; font-family: var(--mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); padding: 10px 16px; border-bottom: 1.5px solid var(--mid); background: var(--surface); } .ep-table td { padding: 15px 16px; border-bottom: 1px solid #ddd8d0; vertical-align: top; } .ep-table tr:last-child td { border-bottom: none; } .ep-table tr:hover td { background: rgba(0,0,0,.018); } .method { display: inline-block; padding: 3px 9px; border-radius: 2px; font-family: var(--mono); font-size: .62rem; font-weight: 600; } .mget { background: #7eb8d410; border: 1px solid #7eb8d440; color: #3a7fa0; } .mpost { background: #7ed4a010; border: 1px solid #7ed4a040; color: #2a8050; } .ep-route { font-family: var(--mono); font-size: .78rem; font-weight: 500; color: var(--ink); } .ep-desc { font-size: .9rem; color: var(--dim); } .ep-param { font-family: var(--mono); font-size: .68rem; color: var(--dim); } /* ── TRAINING ────────────────────────────────────────────── */ .train-layout { display: grid; grid-template-columns: 1fr 1.5fr; gap: 56px; align-items: start; margin-top: 48px; } .ctrl-label { font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: #666; display: block; margin-bottom: 10px; } .ep-display { font-family: var(--serif); font-size: 3.4rem; font-weight: 900; letter-spacing: -.04em; line-height: 1; margin-bottom: 12px; } input[type=range] { width: 100%; accent-color: var(--paper); } .train-btn { display: block; width: 100%; margin-top: 20px; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; border: none; padding: 14px; border-radius: 2px; cursor: pointer; transition: background .2s, transform .15s; } .train-btn:hover { background: #ddd8d0; transform: translateY(-1px); } .train-status { margin-top: 12px; font-family: var(--mono); font-size: .68rem; color: #555; min-height: 20px; } .rew-card { border: 1px solid #262622; border-radius: 6px; overflow: hidden; } .rew-head { padding: 14px 20px; background: #161614; border-bottom: 1px solid #262622; font-family: var(--mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: #666; } .rew-list { padding: 4px 0; } .rew-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; font-family: var(--mono); font-size: .75rem; color: #888; border-bottom: 1px solid #1c1c1a; } .rew-row:last-child { border-bottom: none; } .rv { font-weight: 500; } .rv.pos { color: #7ed4a0; } .rv.neg { color: #d47e7e; } /* ── FOOTER ──────────────────────────────────────────────── */ footer { background: var(--ink); border-top: 1px solid #1c1c1a; padding: 44px 56px 32px; } .footer-inner { max-width: 1160px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; } .f-logo { font-family: var(--serif); font-size: 1.4rem; font-weight: 900; color: var(--paper); letter-spacing: -.02em; } .f-copy { font-family: var(--mono); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: #4a4a48; } .f-links { display: flex; gap: 24px; list-style: none; } .f-links a { font-family: var(--mono); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; text-decoration: none; color: #4a4a48; transition: color .2s; } .f-links a:hover { color: var(--mid); } /* ── ANIMATIONS ──────────────────────────────────────────── */ @keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } } .reveal { opacity: 0; transform: translateY(16px); transition: opacity .65s ease, transform .65s ease; } .reveal.v { opacity: 1; transform: none; } /* ── SCROLLBAR ───────────────────────────────────────────── */ ::-webkit-scrollbar { width: 4px; } ::-webkit-scrollbar-thumb { background: var(--mid); border-radius: 2px; } /* ── RESPONSIVE ──────────────────────────────────────────── */ @media (max-width: 860px) { nav { padding: 16px 24px; } .nav-links { display: none; } section { padding: 72px 24px; } #hero { padding: 120px 24px 64px; } .hero-inner { grid-template-columns: 1fr; gap: 40px; } .hero-stats { flex-wrap: wrap; gap: 28px; } .review-grid { grid-template-columns: 1fr; } .feat-grid { grid-template-columns: 1fr; } .fc { border-right: none; } .train-layout { grid-template-columns: 1fr; } .footer-inner { flex-direction: column; gap: 20px; text-align: center; } .f-links { display: none; } } </style> </head> <body> <!-- ── NAV ──────────────────────────────────────────────── --> <nav> <div class="nav-logo">CodeBug<sup>Ξ²</sup></div> <ul class="nav-links"> <li><a href="#review">Review</a></li> <li><a href="#features">Features</a></li> <li><a href="#api">API</a></li> <li><a href="#train">Training</a></li> </ul> <button class="nav-cta" onclick="scroll2('review')">Try Now β†—</button> </nav> <!-- ── HERO ─────────────────────────────────────────────── --> <section id="hero"> <div class="hero-inner"> <div> <div class="hero-eyebrow">AI-Powered Code Review</div> <h1 class="hero-headline">Bugs Found.<br><em>Before They</em><br>Ship.</h1> <p class="hero-sub">CodeBug combines Claude + GPT-4o to catch security flaws, logic errors, and style issues β€” with a reinforcement-learning grader that improves over time.</p> <div class="hero-btns"> <button class="btn-primary" onclick="scroll2('review')">Review Code β†—</button> <button class="btn-secondary" onclick="scroll2('api')">View API</button> </div> </div> <div class="hero-terminal"> <div class="t-bar"> <div class="t-dot"></div> <div class="t-dot"></div> <div class="t-dot"></div> <span class="t-lbl">codebug β€” review</span> </div> <div class="t-body"> <span class="tc"># POST /api/review</span> <span class="tc">──────────────────────</span> <span class="tk">language</span> <span class="ts">"python"</span> <span class="tk">analyzing</span> <span class="tc">get_user.py …</span> <span class="tk">type</span> <span class="te">bug</span><span class="tbadge err">security</span> <span class="tk">severity</span> <span class="te">5 / 5</span> <span class="tk">line</span> <span class="tn">14</span> <span class="tk">comment</span> SQL injection via f-string interpolation <span class="tk">fix</span> <span class="ts">cursor.execute(</span> <span class="ts"> "SELECT * FROM users</span> <span class="ts"> WHERE id = ?", (uid,))</span> <span class="tk">reward</span> <span class="tg">+43</span><span class="tbadge ok">correct</span> <span class="blink">β–ˆ</span> </div> </div> <div class="hero-stats"> <div><div class="stat-num">15+</div><div class="stat-lbl">Bug Patterns</div></div> <div><div class="stat-num">3</div><div class="stat-lbl">Languages</div></div> <div><div class="stat-num">2</div><div class="stat-lbl">LLM Backends</div></div> <div><div class="stat-num">RL</div><div class="stat-lbl">Self-Improving</div></div> </div> </div> </section> <hr class="divider" /> <!-- ── LIVE REVIEW ───────────────────────────────────────── --> <section id="review" class="dark"> <div class="si"> <div class="s-eyebrow">Live Demo</div> <h2 class="s-title">Review Your Code.</h2> <p class="s-body">Paste any snippet. CodeBug calls <code style="font-family:var(--mono)">POST /api/review</code> and returns a structured result β€” type, severity, comment, and a fix snippet.</p> <div class="review-grid reveal"> <!-- input panel --> <div class="panel"> <div class="panel-head"> <span class="panel-label">Input</span> <span class="panel-meta">max 5 000 chars</span> </div> <textarea id="codeInput" placeholder="# Paste your code here… # e.g.: def get_user(uid): q = f&quot;SELECT * FROM users WHERE id={uid}&quot; cursor.execute(q) return cursor.fetchone()"></textarea> <div class="panel-footer"> <select class="lang-sel" id="langSel" required> <option value="">β€” Select Language β€”</option> <option value="python">Python</option> <option value="javascript">JavaScript</option> <option value="typescript">TypeScript</option> <option value="java">Java</option> <option value="go">Go</option> <option value="cpp">C++</option> </select> <button class="run-btn" id="runBtn" onclick="doReview()"> <span id="runLbl">Analyze β†—</span> </button> </div> </div> <!-- output panel --> <div class="panel"> <div class="panel-head"> <span class="panel-label">Result</span> <span class="panel-meta" id="rTs"></span> </div> <div class="result-body"> <div class="r-empty" id="rEmpty"> <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="#333" stroke-width="1.2"> <circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35M11 8v6M8 11h6"/> </svg> <p>Awaiting analysis…</p> </div> <div class="r-loading" id="rLoading"> <div class="spinner"></div> <span class="spinner-lbl">Calling Claude API…</span> </div> <div class="r-card" id="rCard"> <div class="bug-header"> <div id="rBadge" class="r-badge"></div> <div class="bug-nav"> <button class="bug-nav-btn" id="prevBtn" onclick="prevBug()">← Prev</button> <span class="bug-counter" id="bugCounter"></span> <button class="bug-nav-btn" id="nextBtn" onclick="nextBug()">Next β†’</button> </div> </div> <div id="bugSummary" class="bug-summary-grid" style="display: none;"></div> <div class="r-field"> <div class="r-field-label">Category</div> <div class="r-field-value" id="rCat">β€”</div> </div> <div class="r-field"> <div class="r-field-label">Severity</div> <div class="sev-dots" id="rSev"></div> </div> <div class="r-field"> <div class="r-field-label">Confidence</div> <div class="confidence-bar"> <div class="confidence-meter"> <div class="confidence-fill" id="rConfidence" style="width: 0%"></div> </div> <span class="confidence-pct" id="rConfidencePct">β€”</span> </div> </div> <div class="r-field"> <div class="r-field-label">Line Hint</div> <div class="r-field-value" id="rLine">β€”</div> </div> <div class="r-field"> <div class="r-field-label">Comment</div> <div class="r-field-value" id="rComment">β€”</div> </div> <div class="r-field"> <div class="r-field-label">Suggested Fix</div> <pre class="r-fix" id="rFix"></pre> <button class="export-btn" onclick="exportBugReport()">πŸ“₯ Export to JSON</button> </div> </div> </div> </div> </div> </div> </section> <!-- ── FEATURES ─────────────────────────────────────────── --> <section id="features"> <div class="si"> <div class="s-eyebrow">Capabilities</div> <h2 class="s-title">Every Layer,<br>Covered.</h2> <div class="feat-grid reveal"> <div class="fc"> <span class="fc-num">01</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/> </svg> </div> <div class="fc-title">Security Detection</div> <p class="fc-desc">Catches SQL injection, hardcoded secrets, and plain-text passwords β€” each severity-scored from 1 to 5.</p> </div> <div class="fc"> <span class="fc-num">02</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <circle cx="12" cy="12" r="10"/><path d="M12 8v4l3 3"/> </svg> </div> <div class="fc-title">Logic Analysis</div> <p class="fc-desc">Off-by-one errors, wrong comparisons, missing null checks, and divide-by-zero traps across all supported languages.</p> </div> <div class="fc"> <span class="fc-num">03</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/> </svg> </div> <div class="fc-title">Multi-Language</div> <p class="fc-desc">Python, JavaScript, and Java β€” each with language-idiomatic bug patterns in the bug bank.</p> </div> <div class="fc"> <span class="fc-num">04</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/> </svg> </div> <div class="fc-title">Dual LLM Fallback</div> <p class="fc-desc">Claude Haiku runs first. Any exception silently falls back to GPT-4o-mini with no disruption to the API response.</p> </div> <div class="fc"> <span class="fc-num">05</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <line x1="18" y1="20" x2="18" y2="10"/> <line x1="12" y1="20" x2="12" y2="4"/> <line x1="6" y1="20" x2="6" y2="14"/> </svg> </div> <div class="fc-title">RL Reward Grading</div> <p class="fc-desc">Every review earns a reward score. +25 for critical security catches, βˆ’25 for missed criticals. The model learns.</p> </div> <div class="fc"> <span class="fc-num">06</span> <div class="fc-icon"> <svg viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2"> <ellipse cx="12" cy="5" rx="9" ry="3"/> <path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/> <path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/> </svg> </div> <div class="fc-title">Review History</div> <p class="fc-desc">All reviews and training runs stored in SQLite. Query via /api/history and /api/stats endpoints.</p> </div> </div> </div> </section> <!-- ── API REFERENCE ─────────────────────────────────────── --> <section id="api"> <div class="si"> <div class="s-eyebrow">REST API</div> <h2 class="s-title">Five Endpoints.<br>Zero Config.</h2> <p class="s-body">Rate-limited to 20 req/min per IP. All responses are JSON. Start the server with <code style="font-family:var(--mono)">python app.py</code>.</p> <table class="ep-table reveal"> <thead> <tr> <th>Method</th> <th>Route</th> <th>Description</th> <th>Params</th> </tr> </thead> <tbody> <tr> <td><span class="method mpost">POST</span></td> <td class="ep-route">/api/review</td> <td class="ep-desc">Submit code for AI review. Returns type, category, severity, comment, and fix snippet.</td> <td class="ep-param">code, language?</td> </tr> <tr> <td><span class="method mpost">POST</span></td> <td class="ep-route">/api/train</td> <td class="ep-desc">Run N RL training episodes. Auto-saves checkpoint. Returns full stats dict.</td> <td class="ep-param">episodes? (≀ 100)</td> </tr> <tr> <td><span class="method mget">GET</span></td> <td class="ep-route">/api/history</td> <td class="ep-desc">Returns paginated list of past reviews from the SQLite database.</td> <td class="ep-param">limit? (≀ 200)</td> </tr> <tr> <td><span class="method mget">GET</span></td> <td class="ep-route">/api/stats</td> <td class="ep-desc">Aggregate stats: training runs, review counts, average reward, top bug categories.</td> <td class="ep-param">β€”</td> </tr> <tr> <td><span class="method mget">GET</span></td> <td class="ep-route">/api/health</td> <td class="ep-desc">Health check. Returns model name and DB connection status.</td> <td class="ep-param">β€”</td> </tr> </tbody> </table> </div> </section> <!-- ── TRAINING ──────────────────────────────────────────── --> <section id="train" class="dark"> <div class="si"> <div class="s-eyebrow">Reinforcement Learning</div> <h2 class="s-title">Train the<br>Reviewer.</h2> <p class="s-body">Run RL episodes against the bug bank. The grader rewards precision and penalises misses. Checkpoints auto-save and are fully resumable.</p> <div class="train-layout reveal"> <div> <label class="ctrl-label">Episodes to run</label> <div class="ep-display" id="epDisplay">20</div> <input type="range" min="1" max="100" value="20" id="epRange" oninput="document.getElementById('epDisplay').textContent = this.value" /> <button class="train-btn" onclick="doTrain()">Run Training β†—</button> <div class="train-status" id="trainStatus"></div> </div> <div class="rew-card"> <div class="rew-head">Reward Schedule</div> <div class="rew-list"> <div class="rew-row"><span>Correct β€” Security</span> <span class="rv pos">+25</span></div> <div class="rew-row"><span>Correct β€” Logic</span> <span class="rv pos">+15</span></div> <div class="rew-row"><span>Correct β€” Other</span> <span class="rv pos">+10</span></div> <div class="rew-row"><span>Correct β€” Approve</span> <span class="rv pos">+5</span></div> <div class="rew-row"><span>Severity exact match</span><span class="rv pos">+5</span></div> <div class="rew-row"><span>Detailed comment</span> <span class="rv pos">+5</span></div> <div class="rew-row"><span>Non-empty fix field</span> <span class="rv pos">+3</span></div> <div class="rew-row"><span>Line hint provided</span> <span class="rv pos">+3</span></div> <div class="rew-row"><span>False positive</span> <span class="rv neg">βˆ’10</span></div> <div class="rew-row"><span>Missed critical bug</span> <span class="rv neg">βˆ’25</span></div> <div class="rew-row"><span>Missed high severity</span><span class="rv neg">βˆ’20</span></div> </div> </div> </div> </div> </section> <!-- ── FOOTER ────────────────────────────────────────────── --> <footer> <div class="footer-inner"> <div class="f-logo">CodeBug</div> <span class="f-copy">Β© 2025 β€” Flask Β· Claude Β· SQLite</span> <ul class="f-links"> <li><a href="#review">Review</a></li> <li><a href="#api">API</a></li> <li><a href="#train">Train</a></li> </ul> </div> </footer> <script> /* scroll helper */ function scroll2(id) { document.getElementById(id).scrollIntoView({ behavior: 'smooth' }); } /* reveal on scroll */ const revealObs = new IntersectionObserver(entries => { entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add('v'); revealObs.unobserve(e.target); } }); }, { threshold: 0.1 }); document.querySelectorAll('.reveal').forEach(el => revealObs.observe(el)); /* ── REVIEW ─────────────────────────────────────────────── */ let allBugs = []; let currentBugIndex = 0; function prevBug() { if (currentBugIndex > 0) { currentBugIndex--; displayBug(allBugs[currentBugIndex]); updateBugNav(); } } function nextBug() { if (currentBugIndex < allBugs.length - 1) { currentBugIndex++; displayBug(allBugs[currentBugIndex]); updateBugNav(); } } function updateBugNav() { const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const counter = document.getElementById('bugCounter'); prevBtn.disabled = currentBugIndex === 0; nextBtn.disabled = currentBugIndex >= allBugs.length - 1; counter.textContent = `Bug ${currentBugIndex + 1} / ${allBugs.length}`; } function displayBug(bug) { const badgeCls = bug.category === 'security' ? 'sec' : bug.category === 'logic' ? 'lgc' : bug.type === 'approve' ? 'apr' : 'sty'; const badge = document.getElementById('rBadge'); badge.className = 'r-badge ' + badgeCls; if (bug.type === 'approve') { badge.textContent = 'βœ“ Approved'; } else { badge.textContent = '⚠ ' + (bug.category || bug.type); } document.getElementById('rCat').textContent = bug.category || bug.type || 'β€”'; document.getElementById('rLine').textContent = bug.line_hint ? 'Line ' + bug.line_hint : 'Not specified'; document.getElementById('rComment').textContent = bug.comment || 'β€”'; // Display confidence with progress bar const confidence = bug.confidence || 0.5; const confPercent = Math.round(confidence * 100); document.getElementById('rConfidence').style.width = (confidence * 100) + '%'; document.getElementById('rConfidencePct').textContent = confPercent + '%'; const fixString = (bug.fix && bug.fix.fixed_code) ? bug.fix.fixed_code : bug.fix; document.getElementById('rFix').textContent = fixString || (bug.type === 'approve' ? '(no fix required)' : 'β€”'); const dotsEl = document.getElementById('rSev'); dotsEl.innerHTML = ''; for (let i = 1; i <= 5; i++) { const dot = document.createElement('div'); dot.className = 'sd' + (i <= (bug.severity || 0) ? ' on' : ''); dotsEl.appendChild(dot); } } async function doReview() { const code = document.getElementById('codeInput').value.trim(); const lang = document.getElementById('langSel').value; const btn = document.getElementById('runBtn'); if (!code) { showFlash('Paste some code first.'); return; } if (!lang) { showFlash('Please select a language.'); return; } if (code.length > 5000) { showFlash('Code exceeds 5 000 characters.'); return; } btn.disabled = true; document.getElementById('runLbl').textContent = 'Analyzing…'; document.getElementById('rEmpty').style.display = 'none'; document.getElementById('rCard').classList.remove('on'); document.getElementById('rLoading').classList.add('on'); try { const res = await fetch('/api/review', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ code, language: lang }) }); if (!res.ok) { const errData = await res.json().catch(() => ({})); throw new Error(errData.detail || errData.error || `API error: ${res.status}`); } const data = await res.json(); console.log('βœ“ Real API response received:', data); renderResult(data); } catch (err) { console.error('⚠ API call failed:', err.message); console.warn('Using fallback local analysis...'); const mockData = mockReview(code, lang); console.log('Fallback result:', mockData); renderResult(mockData); } finally { btn.disabled = false; document.getElementById('runLbl').textContent = 'Analyze β†—'; document.getElementById('rLoading').classList.remove('on'); } } function mockReview(code, lang) { // Comprehensive pattern-based bug detection // === SECURITY BUGS (Highest Priority) === if (/f["'`].*?\$\{.*?\}|f["'`].*?{.*?}/.test(code) && /(select|insert|delete|update|from|where)/i.test(code)) { return { type: 'bug', category: 'security', severity: 5, line_hint: 3, comment: 'SQL injection: User input in f-string flows directly to database query.', fix: 'Use parameterized queries: cursor.execute("SELECT * FROM users WHERE id = ?", (uid,))' }; } if (/(password|passwd|pwd)\s*[:=]\s*["'].*["']|".*password.*":\s*".*"/i.test(code)) { return { type: 'bug', category: 'security', severity: 5, line_hint: 2, comment: 'Hardcoded password detected. Never store credentials in source code.', fix: 'Use environment variables: password = os.getenv("DB_PASSWORD")' }; } if (/(api_key|apikey|secret|token|private|private_key|secret_key)\s*[:=]\s*["'][a-zA-Z0-9]{8,}["']/i.test(code)) { return { type: 'bug', category: 'security', severity: 4, line_hint: 1, comment: 'Hardcoded API key/secret detected. Move to environment variables.', fix: 'api_key = os.getenv("API_KEY")\nif not api_key:\n raise ValueError("API_KEY not set")' }; } if (/eval\s*\(|exec\s*\(|pickle\.load|yaml\.load\s*\(|\$\{\s*.*?\s*\}/.test(code)) { return { type: 'bug', category: 'security', severity: 5, line_hint: 2, comment: 'Arbitrary code execution vulnerability. eval() and exec() are dangerous.', fix: 'Use safe alternatives: json.loads(), ast.literal_eval(), or parameterized logic.' }; } // === LOGIC BUGS === if (/(while\s+true|for\s+\(\s*;\s*;\s*\)|while\s*\(.*\))/.test(code) && !/(break|return|exit)/.test(code)) { return { type: 'bug', category: 'logic', severity: 3, line_hint: 2, comment: 'Infinite loop detected. Loop never breaks or returns.', fix: 'Add break condition: while condition: {...; break}' }; } if (/range\s*\(\s*len\s*\(\s*.*?\s*\)\s*-\s*1\s*\)/.test(code)) { return { type: 'bug', category: 'logic', severity: 3, line_hint: 2, comment: 'Off-by-one error: range(len(x) - 1) skips the last element.', fix: 'Use: for i in range(len(items)): or simply: for item in items:' }; } if (/if\s+(len\s*\(\s*\w+\s*\)\s*[>!=<]=?\s*0|len\s*\(\s*\w+\s*\)\s*!=\s*0)/.test(code)) { return { type: 'bug', category: 'logic', severity: 2, line_hint: 1, comment: 'Redundant length check. Empty sequences are falsy in Python.', fix: 'Use: if items: instead of if len(items) != 0:' }; } if (/===|!==/.test(code) && lang === 'javascript') { // This is actually GOOD in JS, so check for == instead if (/[^=!=]\s*==\s*[^=]|[^=]\s*!=\s*[^=]/.test(code)) { return { type: 'bug', category: 'logic', severity: 2, line_hint: 3, comment: 'Use strict equality (===) instead of ==. Subject to type coercion bugs.', fix: 'Replace == with === and != with !==' }; } } // === STYLE/BEST PRACTICES === if (/var\s+\w+\s*=/.test(code) && lang === 'javascript') { return { type: 'bug', category: 'style', severity: 2, line_hint: 1, comment: 'Use const/let instead of var. var has scope issues.', fix: 'Replace var with const (or let if reassignment needed)' }; } if (/print\s*\(/.test(code) && lang === 'python') { // Check for simple print, could suggest logging if (!/import logging|logger\./. test(code)) { return { type: 'approve', category: 'style', severity: 1, line_hint: null, comment: 'Consider using logging module for production code instead of print().', fix: 'import logging\nlogging.info("message")' }; } } // === DEFAULT: NO BUGS === return { type: 'approve', category: 'style', severity: 1, line_hint: null, comment: 'No obvious bugs detected. Code looks clean.', fix: '', confidence: 1.0 }; } function renderResult(d) { // Handle both old (single bug) and new (multiple bugs) formats allBugs = []; currentBugIndex = 0; if (d.bugs && d.bugs.length > 0) { // New format: multiple bugs detected allBugs = d.bugs; } else if (d.primary_bug) { // Fallback: single primary bug allBugs = [d.primary_bug]; } else if (d.ai_action) { // Old format: single bug response allBugs = [d.ai_action]; } else { // Direct bug object (from mockReview) allBugs = [d]; } // Hide summary grid and update main display const summaryGrid = document.getElementById('bugSummary'); summaryGrid.style.display = allBugs.length > 1 ? 'grid' : 'none'; if (allBugs.length > 1) { // Build summary grid for quick navigation summaryGrid.innerHTML = ''; allBugs.forEach((bug, idx) => { const miniCard = document.createElement('div'); miniCard.className = 'bug-mini-card' + (idx === 0 ? ' current' : ''); const sevText = bug.severity ? '●'.repeat(bug.severity) : 'β€”'; miniCard.innerHTML = `<div>${bug.category || 'other'}</div><div style="opacity:.6;margin-top:2px;">${sevText}</div>`; miniCard.onclick = () => { currentBugIndex = idx; displayBug(allBugs[idx]); updateBugNav(); // Update all mini cards document.querySelectorAll('.bug-mini-card').forEach((c, i) => { c.classList.toggle('current', i === idx); }); }; summaryGrid.appendChild(miniCard); }); } // Display first bug displayBug(allBugs[0]); updateBugNav(); document.getElementById('rTs').textContent = new Date().toLocaleTimeString(); document.getElementById('rCard').classList.add('on'); } function showFlash(msg) { const el = document.getElementById('rEmpty'); el.style.display = 'flex'; el.innerHTML = ` <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#d47e7e" stroke-width="1.4"> <circle cx="12" cy="12" r="10"/> <line x1="12" y1="8" x2="12" y2="12"/> <line x1="12" y1="16" x2="12.01" y2="16"/> </svg> <p style="color:#d47e7e">${msg}</p>`; } /* Export bug report as JSON */ function exportBugReport() { if (allBugs.length === 0) { showFlash('No bugs to export. Run analysis first.'); return; } const code = document.getElementById('codeInput').value; const lang = document.getElementById('langSel').value; const report = { timestamp: new Date().toISOString(), language: lang, code_length: code.length, bugs_found: allBugs.length, bugs: allBugs, export_version: "2.0" }; const dataStr = JSON.stringify(report, null, 2); const dataBlob = new Blob([dataStr], { type: 'application/json' }); const url = URL.createObjectURL(dataBlob); const link = document.createElement('a'); link.href = url; link.download = `codebug-report-${new Date().toISOString().slice(0,10)}.json`; document.body.appendChild(link); link.click(); document.body.removeChild(link); URL.revokeObjectURL(url); showFlash('βœ“ Report exported successfully!'); } /* ── TRAINING ───────────────────────────────────────────── */ async function doTrain() { const ep = parseInt(document.getElementById('epRange').value); const btn = document.querySelector('.train-btn'); const st = document.getElementById('trainStatus'); btn.disabled = true; btn.textContent = 'Running…'; st.textContent = `Starting ${ep} episodes…`; st.style.color = '#555'; try { const res = await fetch('/api/train', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ episodes: ep }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error); st.textContent = `βœ“ Done β€” reward: ${(data.total_reward || 0).toFixed(1)}, accuracy: ${((data.accuracy || 0) * 100).toFixed(0)}%`; st.style.color = '#7ed4a0'; } catch { st.textContent = 'Connect Flask backend to run real training.'; st.style.color = '#555'; } finally { btn.disabled = false; btn.textContent = 'Run Training β†—'; } } /* Cmd/Ctrl+Enter to run review */ document.addEventListener('keydown', e => { if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') doReview(); }); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CodeBug β€” AI Code Review</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;0,900;1,700&family=DM+Mono:wght@400;500&family=Syne:wght@400;600;700;800&display=swap" rel="stylesheet" />
<style>
/* ── TOKENS ─────────────────────────────────────────────── */
:root {
--ink: #0e0e0c;
--paper: #f2efe8;
--surface:#e8e4dc;
--mid: #b8b3aa;
--dim: #7a756c;
--mono: 'DM Mono', monospace;
--serif: 'Playfair Display', serif;
--sans: 'Syne', sans-serif;
}
/* ── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
background: var(--paper);
color: var(--ink);
font-family: var(--sans);
overflow-x: hidden;
}
/* subtle grain β€” opacity kept very low so it doesn't fight text */
body::before {
content: '';
position: fixed; inset: 0; z-index: 9000;
pointer-events: none;
opacity: .09;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
background-size: 200px 200px;
}
/* ── NAV ─────────────────────────────────────────────────── */
nav {
position: fixed; top: 0; left: 0; right: 0; z-index: 500;
display: flex; align-items: center; justify-content: space-between;
padding: 20px 56px;
border-bottom: 1px solid rgba(14,14,12,.08);
backdrop-filter: blur(14px);
background: rgba(242,239,232,.92);
}
.nav-logo {
font-family: var(--serif);
font-size: 1.25rem; font-weight: 900; letter-spacing: -.02em;
display: flex; align-items: center; gap: 8px;
}
.nav-logo sup {
font-family: var(--mono); font-size: .5rem;
background: var(--ink); color: var(--paper);
padding: 2px 6px; border-radius: 2px; letter-spacing: .06em;
vertical-align: super;
}
.nav-links { display: flex; gap: 36px; list-style: none; }
.nav-links a {
font-size: .72rem; font-weight: 600;
letter-spacing: .1em; text-transform: uppercase;
text-decoration: none; color: var(--dim);
transition: color .2s;
}
.nav-links a:hover { color: var(--ink); }
.nav-cta {
background: var(--ink); color: var(--paper);
font-family: var(--sans); font-size: .72rem; font-weight: 700;
letter-spacing: .08em; text-transform: uppercase;
border: none; padding: 10px 24px; border-radius: 2px; cursor: pointer;
transition: background .2s, transform .15s;
}
.nav-cta:hover { background: #2a2a28; transform: translateY(-1px); }
/* ── HERO ────────────────────────────────────────────────── */
#hero {
min-height: 100vh;
display: grid; align-items: center;
padding: 140px 56px 80px;
}
.hero-inner {
max-width: 1160px; margin: 0 auto; width: 100%;
display: grid; grid-template-columns: 1fr 1fr;
gap: 72px; align-items: center;
}
.hero-eyebrow {
font-family: var(--mono); font-size: .65rem;
letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
display: flex; align-items: center; gap: 10px;
margin-bottom: 24px;
animation: fadeUp .7s ease both;
}
.hero-eyebrow::before { content: ''; width: 24px; height: 1px; background: var(--mid); }
.hero-headline {
font-family: var(--serif);