# Bitvid — AI Agent Guide (AGENTS.md) This document tells AI agents how Bitvid works **now** and how to extend it going forward. It focuses on the newly adopted **URL‑first playback with WebTorrent fallback** strategy, minimal code touchpoints, and reliable interop with the Nostr ecosystem. As you work in the repo, please add detailed comments to help others understand what and why your code is doing. --- ## 1) Mission & Product Direction **Goal:** Stream videos reliably and cheaply. * **Primary transport:** a **hosted video URL** (MP4/WebM/HLS/DASH) that plays directly in the browser. * **Secondary transport (fallback & cost control):** a **WebTorrent magnet** enhanced with **`ws=` (web seed)** and **`xs=` (.torrent URL)**. * **Behavior:** Try `url` first. If it’s missing or unreachable, **fallback to WebTorrent** using the same post’s magnet. If the magnet includes `ws`/`xs`, WebTorrent can bootstrap via HTTP and/or peers. * **Nostr interop:** Keep existing kind `30078` events for Bitvid’s app data; optionally **mirror a NIP‑94 kind `1063`** event so other clients can discover the same hosted video URL. * **Resilience:** Light link‑health probing to hide/flag dead URLs and avoid broken playback. --- ## 2) High‑Level Architecture * **Frontend app** (vanilla JS + HTML/CSS) * **Upload modal** accepts: Title (required), **URL or Magnet** (at least one required), Thumbnail, Description. Optional fields for **`ws`** and **`xs`** help P2P bootstrap. * **Feed / Cards** render video posts, each carrying both `data-play-url` and `data-play-magnet` attributes. * **Player** uses `playVideoWithFallback({ url, magnet })`: probe `url`; if OK, play via `