---
import BaseLayout from '../layouts/BaseLayout.astro';

interface FAQ {
  q: string;
  a: string;
}

interface Section {
  title: string;
  // Anchor id so the rest of the site can deep-link to a section
  // (e.g. /install footer points to /faq#setup-troubleshooting).
  id: string;
  items: FAQ[];
}

const sections: Section[] = [
  {
    title: "General",
    id: "general",
    items: [
      {
        q: "What is Kiln?",
        a: "Kiln is open-source infrastructure that lets AI agents design new objects, discover existing models, and autonomously slice, print, and monitor 3D printers. It exposes 800 MCP capabilities (Model Context Protocol), so any compatible AI agent can run full print workflows with safety guardrails built in. Describe what you want or upload a sketch, and Kiln handles everything from generation to the finished print. Think of it as the intelligence layer between an idea and a physical object."
      },
      {
        q: "How is Kiln different from just using OctoPrint or Moonraker?",
        a: "OctoPrint and Moonraker are great printer management interfaces built for humans. Kiln sits on top of them and brand-specific paths like Creality, Bambu Lab, Elegoo, and Prusa Link to provide a unified, AI-friendly interface. It adds safety guardrails, job queues, slicing integration, and a standardized protocol — things you need when an autonomous agent is in the loop, not a person clicking buttons. Multi-printer fleet workflows are Business and Enterprise features."
      },
      {
        q: "How is Kiln different from decentralized manufacturing networks/providers?",
        a: "Kiln is orchestration infrastructure for agents — it does not operate its own marketplace or manufacturing network. Instead, Kiln searches third-party model marketplaces (Thingiverse, MyMiniFactory, Cults3D) and routes fulfillment orders to third-party providers (like Craftcloud). The provider remains merchant of record for any outsourced orders. See the <a href='/boundary'>product boundary page</a> for a direct comparison."
      },
      {
        q: "Is Kiln free?",
        a: "Local printing is free forever — unlimited prints on 1 printer, no strings attached. Pro is also single-printer and personal-use focused. Business adds 3 printers included, team seats, commercial use, and fleet workflows; Enterprise is for larger custom deployments. See the <a href='/pricing'>pricing page</a> for details."
      },
      {
        q: "Is Kiln open source?",
        a: "Yes. Kiln is fully open source under the AGPL-3.0 license. You can self-host, modify, and contribute. Commercial licensing is available for companies that need proprietary use. The source code is on <a href='https://github.com/codeofaxel/Kiln' target='_blank' rel='noopener'>GitHub</a>."
      },
    ]
  },
  {
    title: "Getting Started",
    id: "getting-started",
    items: [
      {
        q: "What printers does Kiln support?",
        a: "Kiln supports printers running OctoPrint, Moonraker (Klipper), Creality K1/K2/Hi/Ender V3 KE-class printers when local Moonraker is reachable, Bambu Lab (X1C, P1S, P1P, A1, A1 Mini), Elegoo (Centauri Carbon, Saturn, Mars via SDCP; Neptune 4 and OrangeStorm Giga via Moonraker), Prusa Link (MK4, MK3.9, Mini, XL), and any Marlin-based printer over USB (Ender 3, CR-10, Prusa MK3, etc.). Creality printers that do not expose local Moonraker can still use OctoPrint or Direct USB when those paths are available."
      },
      {
        q: "How do I install Kiln?",
        a: "Install via pip: <code>pip install kiln3d</code>, then run <code>kiln</code> to start the MCP server. Point your AI agent at the server and you're ready to go. Full instructions are on the <a href='/install'>install page</a>."
      },
      {
        q: "What AI agents work with Kiln?",
        a: "Any AI agent that supports the Model Context Protocol (MCP) can use Kiln — including Claude (via Claude Desktop or Claude Code), custom agents built with the OpenAI API, and any MCP-compatible client. Kiln also provides a REST API and CLI for non-MCP integrations."
      },
      {
        q: "What is MCP? Do I need to understand it?",
        a: "MCP (Model Context Protocol) is an open standard for connecting AI agents to external tools and data sources. You don't need to understand MCP internals to use Kiln — just configure your AI agent to connect to the Kiln MCP server. If you're building custom agents, the <a href='/whitepaper'>whitepaper</a> covers the protocol details."
      },
      {
        q: "Can I use Kiln without AI, just as a CLI or API?",
        a: "Yes. Kiln includes a full command-line interface with 215 commands and a REST API. You can manage printers, queue jobs, slice files, and run print operations entirely from the terminal or your own scripts — no AI agent required."
      },
      {
        q: "Can I version-control my 3D designs in Kiln?",
        a: "Yes — Kiln ships a git-style version control system for 3D designs. Every edit becomes a commit, branches let you iterate in parallel, three-way merges catch conflicts at the mesh level (not just file bytes), and Ed25519-signed releases prove exactly which version of a design shipped (tamper-evident for FDA 21 CFR 820.70 / AS9100 / ISO 13485 handoffs). Works on three artifact types: designs (your mesh), decorations (textures, logos, photo-emboss), and mechanical features (chamfers, fillets, pockets, holes, bosses, ribs). Runs fully offline; Pro+ adds cloud sync for multi-device access. FDM-focused today."
      },
    ]
  },
  {
    title: "Setup & Troubleshooting",
    id: "setup-troubleshooting",
    items: [
      {
        q: '"kiln: command not found" after install',
        a: "Your shell can't find the <code>kiln</code> binary. Add <code>~/.local/bin</code> to your PATH by running <code>pipx ensurepath</code>, then restart your terminal. If you installed with pip into a virtualenv, make sure the virtualenv is activated."
      },
      {
        q: "What Python version do I need?",
        a: "Python 3.10 or newer. Check with <code>python3 --version</code>. If you're below 3.10, install via Homebrew (<code>brew install python@3.12</code>), apt (<code>sudo apt install python3.12</code>), or pyenv."
      },
      {
        q: "Does Kiln work on Windows?",
        a: "Yes. Kiln runs natively on Windows — install Python 3.10+ from <a href='https://python.org/downloads/' target='_blank' rel='noopener'>python.org</a> (or via <code>winget install Python.Python.3.12</code>) and then <code>pip install kiln3d</code>. macOS, Linux, and Windows are all first-class. Some users prefer WSL 2 for a more Unix-like shell experience, and Kiln runs fine inside WSL too — but it's not required. If mDNS printer discovery is flaky on your Windows LAN, connect to your printer by IP address (<code>kiln auth --host http://192.168.1.x:port --type octoprint --api-key YOUR_KEY</code>)."
      },
      {
        q: "WSL 2 can't discover printers on my LAN",
        a: "WSL 2 uses NAT networking, which blocks mDNS (Bonjour) discovery. Connect to your printer by IP address instead:<br><code>kiln auth --name my-printer --host http://192.168.1.x:port --type octoprint --api-key YOUR_KEY</code><br>Works for Ethernet and Wi-Fi LAN setups."
      },
      {
        q: "Can I use Ethernet instead of Wi-Fi?",
        a: "Yes — Kiln works over LAN IP, so Ethernet-only printers are fully supported. If <code>kiln discover</code> doesn't find your printer (firewall, mDNS blocked, etc.), register it directly by IP:<br><code>kiln auth --name my-printer --host http://192.168.1.x:port --type prusaconnect --api-key YOUR_KEY</code>"
      },
      {
        q: "PrusaSlicer (or OrcaSlicer) not found",
        a: "Kiln auto-detects PrusaSlicer and OrcaSlicer on your <code>PATH</code> and in standard macOS app bundle locations. If yours is installed somewhere unusual, point at it explicitly:<br><code>export KILN_SLICER_PATH=/path/to/prusa-slicer</code>"
      },
      {
        q: "How do I uninstall Kiln?",
        a: "If you used pipx: <code>pipx uninstall kiln3d</code><br>If you used pip: <code>pip uninstall kiln3d</code><br>If you used the one-line installer: <code>~/.kiln/src/install.sh --uninstall</code>"
      },
    ]
  },
  {
    title: "Safety & Privacy",
    id: "safety-privacy",
    items: [
      {
        q: "Can the AI damage my printer?",
        a: "Kiln is built around the principle that AI should never have unchecked access to hardware. Every print operation passes through a safety layer that enforces per-printer temperature limits, validates G-code commands, runs pre-flight checks before prints, and blocks dangerous operations. Safety profiles cover popular printer models with manufacturer-specific limits."
      },
      {
        q: "What safety guardrails are in place?",
        a: "Kiln enforces multiple layers: per-printer temperature and speed limits from a validated safety profile database, G-code command validation that blocks unsafe operations, real-time G-code interception for in-flight filtering, mandatory pre-flight checks before every print, and structured error handling that never silently fails. The <a href='/whitepaper'>whitepaper</a> covers the full safety architecture."
      },
      {
        q: "Does Kiln send my data to the cloud?",
        a: "No. Kiln runs entirely on your local machine. Your printer data, G-code files, and print history stay on your network. The only external connections are ones you explicitly configure — like third-party fulfillment providers or third-party marketplace search."
      },
      {
        q: "Can I restrict which tools the AI agent can access?",
        a: "Yes. Kiln supports tool tiers (essential, standard, full) that control which MCP tools are exposed to the agent. You can restrict agents to read-only monitoring, allow standard print operations, or grant full access including fleet management and raw G-code — depending on your trust level."
      },
    ]
  },
  {
    title: "Features & Capabilities",
    id: "features-capabilities",
    items: [
      {
        q: "Can I run multiple printers?",
        a: "Yes, with the right tier. Free and Pro each support 1 printer. Business includes 3 printers, with additional printers available up to 50. Enterprise is custom-quoted for larger fleets."
      },
      {
        q: "Does Kiln handle slicing?",
        a: "Yes. Kiln integrates with PrusaSlicer and OrcaSlicer for local slicing, with bundled slicer profiles optimized per printer model. You can also use pre-sliced G-code files. The AI agent can trigger slicing, adjust settings, and go from STL to print in a single conversation."
      },
      {
        q: "Can I order prints from external services through Kiln?",
        a: "Yes. Kiln routes orders to third-party fulfillment providers — currently Craftcloud — through the hosted fulfillment path or direct mode with your own provider credentials. Your AI agent can compare quotes from 150+ third-party print services across FDM, SLA, SLS, MJF, and metal, select materials, and place orders through the same interface used for local printing. Kiln does not operate its own manufacturing network — it orchestrates the workflow while the third-party provider remains merchant of record."
      },
      {
        q: "Does Kiln support model marketplaces?",
        a: "Yes. Kiln searches third-party model marketplaces — MyMiniFactory (search + download, works out of the box), Cults3D (search only, requires your own API key), and Thingiverse (deprecated). Your AI agent can discover existing models, download from supported sources, and send them to your printer in one workflow."
      },
      {
        q: "Can I automate recurring prints or batch jobs?",
        a: "Yes. Kiln includes a priority job queue with scheduling, so you can queue up multiple prints with different priorities. The scheduler dispatches jobs automatically as printers become available, and you can build fully automated pipelines using the pre-validated print pipeline system (quick_print, calibrate, benchmark)."
      },
      {
        q: "Can Kiln generate 3D models from text or sketches?",
        a: "Yes. Kiln supports text-to-3D generation via Gemini Deep Think, Meshy, Tripo3D, and Stability AI, plus parametric code-as-CAD generation via OpenSCAD. You can also upload a napkin sketch for image-to-3D conversion. Providers are auto-discovered from environment variables — just set your API key and Kiln finds it."
      },
      {
        q: "What is Design Intelligence?",
        a: "Design Intelligence is Kiln's engineering knowledge base — 25 FDM materials with full mechanical/thermal/chemical properties, 45 brand-specific filament profiles, 18 proven design templates (snap-fits, living hinges, threads, press-fits), and structural load estimation. When you describe what you want to print, Kiln uses this knowledge to select the right material, apply proven patterns, and validate that the design will actually work before generating geometry."
      },
      {
        q: "What does the Printability Engine do?",
        a: "Before any model reaches your slicer, Kiln analyzes it across 7 dimensions: overhang detection, thin wall analysis, bridging assessment, bed adhesion estimation, support volume calculation, warping risk, and thermal stress. It scores models 0-100, recommends optimal print orientation, and suggests adhesion settings (brim/raft) based on the geometry, material, and your specific printer."
      },
      {
        q: "Can Kiln design multi-part assemblies?",
        a: "Yes. The assembly module validates clearances between parts, detects joint types (snap-fit, press-fit, threaded, adhesive), checks tolerance stacking, and plans splits for models that exceed your build plate. Free tier supports up to 10 parts per assembly."
      },
      {
        q: "Does Kiln generate assembly manuals for multi-part prints?",
        a: "Yes. Multi-part prints with Kiln Pro auto-generate a printable PDF assembly manual alongside the slice — Bill of Materials, isometric per-step renders, mating-direction arrows, and pause-and-check verification gates. Pro ships a single-language PDF with a 'Made with Kiln' cover. Business adds co-branded covers (your name on the cover, 'Powered by Kiln' in the footer), multilingual single-PDF output (English / German / French / Spanish / Italian sections in one document), and 'what changed' diff manuals — when you ship v1.3 of a kit, buyers of v1.2 get a 5-page diff PDF instead of a 60-page rebuild. Enterprise adds full white-label plus a free buyer-side authenticity verifier so customers can confirm the PDF is the one you signed."
      },
      {
        q: "How does cost estimation work?",
        a: "Kiln calculates the cost of any print before it starts — material cost (by weight and filament type), electricity, and time. It also provides smart recommendations: cheaper filament alternatives that maintain strength, speed profiles that save time, and quality tradeoffs. Use it to budget projects or compare local vs outsourced manufacturing costs."
      },
      {
        q: "Can Kiln add decorations to my prints?",
        a: "Yes. Kiln's multi-modal decoration engine accepts photos, logos, text, SVGs, and brand assets and converts them into embossed or debossed surface features with one command. Free users get 3 decorations per month; Pro unlocks unlimited. Scannable QR codes are a Business-tier feature — they require multicolor printing on Bambu AMS for reliable scanning, and the typical use case (product labels, merch, packaging, inventory tracking) sits above the solo-creator band. The engine handles surface intelligence automatically — it knows which face of a coaster or jewelry tray to decorate and at what depth."
      },
      {
        q: "What are procedural textures?",
        a: "Procedural textures are algorithmically generated surface patterns — tiger stripe, marble, digital camo, snakeskin, wood grain, carbon fiber, honeycomb, lava, and more — that Kiln applies directly to any 3D model for multicolor FDM printing. No UV mapping or texture software needed. Each texture generates the correct AMS color assignments automatically. This is a Pro feature."
      },
      {
        q: "Can I generate products with one command?",
        a: "Yes. Kiln Pro includes product templates for coasters, keychains, ornaments, pet tags, pet bowls, bookmarks, fridge magnets, jewelry trays, wall plaques, and ashtrays. Say \"make me a coaster with my logo\" and Kiln generates the geometry, places the decoration, picks the right colors, and prepares the file for print — including multicolor if your printer has an AMS."
      },
      {
        q: "Can Kiln modify a print that's already running?",
        a: "Yes. Kiln Pro's mid-print modification engine can decorate, add geometric features, or swap materials on a live print — without cancelling and restarting. If the modification goes wrong, an atomic revert path restores the original job. Works across all supported FDM printers."
      },
      {
        q: "What happens if my print gets cancelled or fails mid-job?",
        a: "With Kiln Pro, you don't lose the partial print. The resume system picks up from the exact layer where the print stopped — generating a safe resume sequence that avoids crashing the nozzle into the partial object on the bed. Works on Bambu Lab, OctoPrint, Moonraker/Klipper, Creality when exposed through Moonraker, Prusa Connect, Elegoo, and Serial printers."
      },
      {
        q: "Does Kiln learn from past prints?",
        a: "Yes. Kiln records print outcomes (success, failure, quality grade) and correlates them with the material, printer, settings, and design version used. Over time, it recommends better settings for the same material + printer combination, predicts failure risk before you start, and detects design regressions when a model that used to print well stops working. Pro includes single-printer print learning. Cross-printer learning is a Business and Enterprise fleet feature."
      },
      {
        q: "Does Kiln support Bambu AMS and multi-material printing?",
        a: "Yes. Kiln auto-detects AMS trays, identifies loaded filament colors and types, and routes the correct AMS slot when starting a print. For multicolor prints, Kiln handles automatic color segmentation and multi-gcode merging. Use <code>ams_status()</code> to check loaded materials and <code>slice_and_print</code> for automatic AMS routing."
      },
    ]
  },
  {
    title: "Technical",
    id: "technical",
    items: [
      {
        q: "What's the difference between the litepaper and whitepaper?",
        a: "The <a href='/litepaper'>litepaper</a> is a non-technical overview — it explains what Kiln does, why it exists, and who it's for, without diving into implementation details. The <a href='/whitepaper'>whitepaper</a> is the full technical document covering protocol design, architecture, adapter interfaces, safety models, and system internals."
      },
      {
        q: "What language is Kiln written in?",
        a: "Python. Kiln is distributed as two pip-installable packages: <code>kiln3d</code> (the MCP server) and <code>octoprint-cli</code> (standalone CLI tool). Both use modern Python with full type hints, dataclasses, and async support."
      },
      {
        q: "Can I build my own printer adapter?",
        a: "Yes. Kiln uses an abstract adapter interface (<code>PrinterAdapter</code>) that any new printer backend can implement. If your printer has a REST, MQTT, WebSocket, or serial API, you can write an adapter that normalizes it to Kiln's standard interface. See the existing adapters (OctoPrint, Moonraker, Creality, Bambu, Elegoo, Prusa Link) as reference implementations."
      },
      {
        q: "How do I contribute?",
        a: "Fork the repo, create a branch, and submit a pull request. Kiln uses pytest for testing (14,312 tests across both repos), Ruff for linting, and follows strict patterns documented in the contributing guide. Issues and feature requests are welcome on <a href='https://github.com/codeofaxel/Kiln' target='_blank' rel='noopener'>GitHub</a>."
      },
    ]
  },
];

const stripHtml = (html: string): string =>
  html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();

const faqSchema = {
  '@type': 'FAQPage',
  mainEntity: sections.flatMap((section) =>
    section.items.map((item) => ({
      '@type': 'Question',
      name: item.q,
      acceptedAnswer: {
        '@type': 'Answer',
        text: stripHtml(item.a),
      },
    })),
  ),
};
---

<BaseLayout
  title="FAQ — Kiln 3D Printing Infrastructure"
  description="Frequently asked questions about Kiln 3D: open-source infrastructure that lets AI agents safely control 3D printers, manage fleets, and run print workflows."
  current="faq"
  keywords={['kiln faq', 'kiln 3d faq', '3d printing infrastructure faq']}
  schema={faqSchema}
>
  <section class="faq-hero">
    <div class="container">
      <h1>Frequently Asked Questions</h1>
      <p class="lead">Everything you need to know about Kiln. Can't find your answer? <a href="https://github.com/codeofaxel/Kiln/issues" target="_blank" rel="noopener">Open an issue</a> on GitHub.</p>
    </div>
  </section>

  <section class="faq-body">
    <div class="container">
      {sections.map((section) => (
        <div class="faq-section" id={section.id}>
          <h2 class="section-title">{section.title}</h2>
          <div class="faq-list">
            {section.items.map((item) => (
              <details class="faq-item">
                <summary class="faq-question">
                  <span>{item.q}</span>
                  <svg class="faq-chevron" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
                    <polyline points="6 9 12 15 18 9" />
                  </svg>
                </summary>
                <div class="faq-answer" set:html={item.a} />
              </details>
            ))}
          </div>
        </div>
      ))}
    </div>
  </section>
</BaseLayout>

<style>
  /* ── Hero ── */
  .faq-hero {
    padding: 80px 0 48px;
    text-align: center;
  }

  .faq-hero h1 {
    font-size: 40px;
    font-weight: 700;
    margin-bottom: 16px;
  }

  .faq-hero .lead {
    font-size: 17px;
    color: var(--text-muted);
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.6;
  }

  .faq-hero .lead a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(255, 107, 43, 0.3);
    text-underline-offset: 3px;
  }

  .faq-hero .lead a:hover {
    text-decoration-color: var(--accent);
  }

  /* ── Body ── */
  .faq-body {
    padding: 0 0 96px;
  }

  .faq-body .container {
    max-width: 800px;
  }

  /* ── Sections ── */
  .faq-section {
    margin-bottom: 48px;
  }

  .faq-section:last-child {
    margin-bottom: 0;
  }

  .section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  /* ── FAQ Items ── */
  .faq-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .faq-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.15s ease;
  }

  .faq-item:hover {
    border-color: rgba(255, 255, 255, 0.12);
  }

  .faq-item[open] {
    border-color: rgba(255, 107, 43, 0.2);
  }

  .faq-question {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    list-style: none;
    user-select: none;
  }

  .faq-question::-webkit-details-marker {
    display: none;
  }

  .faq-question::marker {
    content: '';
  }

  .faq-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.2s ease, color 0.15s ease;
  }

  .faq-item[open] .faq-chevron {
    transform: rotate(180deg);
    color: var(--accent);
  }

  .faq-answer {
    padding: 0 20px 20px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-muted);
  }

  .faq-answer :global(a) {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(255, 107, 43, 0.3);
    text-underline-offset: 3px;
  }

  .faq-answer :global(a:hover) {
    text-decoration-color: var(--accent);
  }

  .faq-answer :global(code) {
    font-family: var(--mono);
    font-size: 0.85em;
    background: var(--bg-code);
    border: 1px solid var(--border);
    padding: 2px 7px;
    border-radius: 4px;
    color: #ccc;
  }

  /* ── Responsive ── */
  @media (max-width: 768px) {
    .faq-hero {
      padding: 56px 0 32px;
    }

    .faq-hero h1 {
      font-size: 28px;
    }

    .faq-question {
      font-size: 15px;
      padding: 16px;
    }

    .faq-answer {
      padding: 0 16px 16px;
      font-size: 14px;
    }
  }

  @media (max-width: 480px) {
    .faq-hero h1 {
      font-size: 24px;
    }

    .faq-hero .lead {
      font-size: 15px;
    }
  }
</style>
