---
import Layout from "@/layouts/main.astro"
import { Button } from "@/components/ui/button"
import { Card, CardHeader, CardTitle, CardDescription, CardContent } from "@/components/ui/card"
import { Star } from "lucide-react"

const workflows = [
  { command: "/deepresearch", description: "Multi-agent investigation across papers, web, and code" },
  { command: "/lit", description: "Literature review from primary sources with consensus mapping" },
  { command: "/review", description: "Simulated peer review with severity scores and a revision plan" },
  { command: "/audit", description: "Paper-to-code mismatch audit for reproducibility claims" },
  { command: "/replicate", description: "Replication plan and execution in a sandboxed Docker container" },
  { command: "/compare", description: "Side-by-side source comparison with agreement and conflict matrix" },
  { command: "/draft", description: "Polished paper-style draft with inline citations from findings" },
  { command: "/autoresearch", description: "Autonomous loop: hypothesize, experiment, measure, repeat" },
  { command: "/watch", description: "Recurring monitor for new papers, code, or product updates" },
]

const agents = [
  { name: "Researcher", description: "Hunts for evidence across papers, the web, repos, and docs" },
  { name: "Reviewer", description: "Grades claims by severity, flags gaps, and suggests revisions" },
  { name: "Writer", description: "Structures notes into briefs, drafts, and paper-style output" },
  { name: "Verifier", description: "Checks every citation, verifies URLs, removes dead links" },
]

const sources = [
  { name: "AlphaXiv", description: "Paper search, Q&A, code reading, and persistent annotations", href: "https://alphaxiv.org" },
  { name: "Web search", description: "Searches via Gemini or Perplexity" },
  { name: "Preview", description: "Browser and PDF export of generated artifacts" },
]

const terminalCommands = [
  { command: 'feynman "what do we know about scaling laws"', description: "Cited research brief from papers and web" },
  { command: 'feynman deepresearch "mechanistic interpretability"', description: "Multi-agent deep dive with synthesis and verification" },
  { command: 'feynman lit "RLHF alternatives"', description: "Literature review with consensus and open questions" },
  { command: "feynman audit 2401.12345", description: "Paper claims vs. what the code actually does" },
  { command: 'feynman replicate "chain-of-thought improves math"', description: "Replication plan, compute target, experiment execution" },
]
---

<Layout title="Feynman — The open source AI research agent" active="home">
  <div class="mx-auto max-w-5xl px-6">

    <section class="flex flex-col items-center gap-8 pb-16 pt-20 text-center">
      <div class="flex max-w-3xl flex-col gap-4">
        <h1 class="text-4xl font-bold tracking-tight sm:text-5xl lg:text-6xl">
          The open source AI<br />research agent
        </h1>
        <p class="mx-auto max-w-2xl text-lg text-muted-foreground">
          Reads papers, searches the web, runs experiments, and cites every claim. All locally on your computer.
        </p>
      </div>

      <div class="flex flex-col items-center gap-4">
        <button
          id="install-cmd"
          class="group flex items-center gap-3 rounded-lg bg-muted px-4 py-2.5 font-mono text-sm transition-colors hover:bg-muted/80 cursor-pointer"
        >
          <span>curl -fsSL https://feynman.is/install | bash</span>
          <svg id="copy-icon" class="size-4 shrink-0 text-muted-foreground transition-colors group-hover:text-foreground" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>
          <svg id="check-icon" class="hidden size-4 shrink-0 text-primary" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path d="M20 6L9 17l-5-5"/></svg>
        </button>

        <div class="flex items-center gap-3">
          <a href="/docs/getting-started/installation">
            <Button client:load size="lg">Get Started</Button>
          </a>
          <a href="https://github.com/getcompanion-ai/feynman" target="_blank" rel="noopener noreferrer" class="inline-flex h-10 items-center justify-center gap-2 rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground">
            GitHub
            <span id="star-badge" class="hidden inline-flex items-center gap-1 text-muted-foreground">
              <span id="star-count"></span>
              <Star client:load size={14} fill="currentColor" />
            </span>
          </a>
        </div>
      </div>

      <img src="/hero.png" class="w-full" alt="Feynman CLI" />
    </section>

    <section class="py-16">
      <div class="flex flex-col items-center gap-8 text-center">
        <div class="flex flex-col gap-2">
          <h2 class="text-2xl font-bold tracking-tight sm:text-3xl">What you type &rarr; what happens</h2>
          <p class="text-muted-foreground">Ask a question or run a workflow. Every answer is cited.</p>
        </div>
        <Card client:load className="w-full text-left">
          <CardContent client:load>
            <div class="flex flex-col gap-3 font-mono text-sm">
              {terminalCommands.map((cmd) => (
                <div class="flex flex-col gap-0.5">
                  <span class="text-primary">{cmd.command}</span>
                  <span class="text-xs text-muted-foreground">{cmd.description}</span>
                </div>
              ))}
            </div>
          </CardContent>
        </Card>
      </div>
    </section>

    <section class="py-16">
      <div class="flex flex-col items-center gap-8 text-center">
        <div class="flex flex-col gap-2">
          <h2 class="text-2xl font-bold tracking-tight sm:text-3xl">Workflows</h2>
          <p class="text-muted-foreground">Slash commands or natural language. Your call.</p>
        </div>
        <div class="grid w-full gap-4 sm:grid-cols-2 lg:grid-cols-3">
          {workflows.map((wf) => (
            <Card client:load size="sm">
              <CardHeader client:load>
                <CardTitle client:load className="font-mono text-sm text-primary">{wf.command}</CardTitle>
                <CardDescription client:load>{wf.description}</CardDescription>
              </CardHeader>
            </Card>
          ))}
        </div>
      </div>
    </section>

    <section class="py-16">
      <div class="flex flex-col items-center gap-8 text-center">
        <div class="flex flex-col gap-2">
          <h2 class="text-2xl font-bold tracking-tight sm:text-3xl">Agents</h2>
          <p class="text-muted-foreground">You ask a question. The right team assembles.</p>
        </div>
        <div class="grid w-full gap-4 sm:grid-cols-2 lg:grid-cols-4">
          {agents.map((agent) => (
            <Card client:load size="sm" className="text-center">
              <CardHeader client:load className="items-center">
                <CardTitle client:load>{agent.name}</CardTitle>
                <CardDescription client:load>{agent.description}</CardDescription>
              </CardHeader>
            </Card>
          ))}
        </div>
      </div>
    </section>

    <section class="py-16">
      <div class="flex flex-col items-center gap-8 text-center">
        <div class="flex flex-col gap-2">
          <h2 class="text-2xl font-bold tracking-tight sm:text-3xl">Sources</h2>
          <p class="text-muted-foreground">Where Feynman finds information.</p>
        </div>
        <div class="grid w-full gap-4 sm:grid-cols-3">
          {sources.map((source) => (
            <Card client:load size="sm" className="text-center">
              <CardHeader client:load className="items-center">
                <CardTitle client:load>
                  {source.href ? (
                    <a href={source.href} target="_blank" rel="noopener noreferrer" class="text-primary hover:underline">
                      {source.name}
                    </a>
                  ) : (
                    source.name
                  )}
                </CardTitle>
                <CardDescription client:load>{source.description}</CardDescription>
              </CardHeader>
            </Card>
          ))}
        </div>
      </div>
    </section>

    <section class="py-16">
      <div class="flex flex-col items-center gap-8 text-center">
        <div class="flex flex-col gap-2">
          <h2 class="text-2xl font-bold tracking-tight sm:text-3xl">Compute</h2>
          <p class="text-muted-foreground">Experiments run in sandboxed Docker containers. Your code stays local.</p>
        </div>
        <Card client:load size="sm" className="w-full max-w-md text-center">
          <CardHeader client:load className="items-center">
            <CardTitle client:load><a href="https://www.docker.com/" target="_blank" rel="noopener noreferrer" class="text-primary hover:underline">Docker</a></CardTitle>
            <CardDescription client:load>Isolated container execution for safe local experiments</CardDescription>
          </CardHeader>
        </Card>
      </div>
    </section>

    <section class="flex flex-col items-center gap-6 py-20 text-center">
      <p class="text-muted-foreground">
        Built on <a href="https://github.com/badlogic/pi-mono" class="text-primary hover:underline">Pi</a> and <a href="https://www.alphaxiv.org/" class="text-primary hover:underline">alphaXiv</a>. MIT licensed.
      </p>
      <div class="flex items-center gap-3">
        <a href="/docs/getting-started/installation">
          <Button client:load size="lg">Get Started</Button>
        </a>
        <a href="https://github.com/getcompanion-ai/feynman" target="_blank" rel="noopener noreferrer">
          <Button client:load variant="outline" size="lg">View on GitHub</Button>
        </a>
      </div>
    </section>

  </div>
</Layout>

<script is:inline>
  function initCopyBtn() {
    var btn = document.getElementById("install-cmd")
    if (btn && !btn._bound) {
      btn._bound = true
      btn.addEventListener("click", function () {
        navigator.clipboard.writeText("curl -fsSL https://feynman.is/install | bash").then(function () {
          var copyIcon = document.getElementById("copy-icon")
          var checkIcon = document.getElementById("check-icon")
          copyIcon.classList.add("hidden")
          checkIcon.classList.remove("hidden")
          setTimeout(function () {
            copyIcon.classList.remove("hidden")
            checkIcon.classList.add("hidden")
          }, 2000)
        })
      })
    }
  }
  initCopyBtn()
  document.addEventListener("astro:after-swap", initCopyBtn)

  fetch("https://api.github.com/repos/getcompanion-ai/feynman")
    .then(function(r) { return r.json() })
    .then(function(d) {
      if (d.stargazers_count !== undefined) {
        var el = document.getElementById("star-count")
        if (el) {
          el.textContent = d.stargazers_count >= 1000 ? (d.stargazers_count / 1000).toFixed(1) + "k" : String(d.stargazers_count)
          var badge = document.getElementById("star-badge")
          if (badge) badge.classList.remove("hidden")
        }
      }
    })
    .catch(function() {})
</script>
