Files
BiliNote/CLAUDE.md
huangjianwu b8f359e7e7 feat(extension): 浏览器插件 P1 MVP
新建 BillNote_extension/ 工作空间(基于 vitesse-webext 骨架,Vue 3 + Vite + UnoCSS + MV3)。

P1 MVP 范围:
- popup:自动读当前 tab URL,识别 Bilibili / YouTube / 抖音 / 快手;提交 /generate_note 后轮询 /task_status;展示 markdown,复制 + 下载 .md
- options:后端地址输入与连通性测试;从 /get_all_providers + /get_models_by_provider 拉供应商/模型列表;默认画质、截图/跳转、笔记风格
- chrome.storage.local 持久化设置与最近 30 个任务,popup 重开恢复进行中任务
- markdown 里的 /static/screenshots 路径在渲染前重写为绝对地址

后端:CORS 改用 regex,新增允许 chrome-extension:// 与 moz-extension:// 源(同时保留 localhost / 127.0.0.1 / tauri.localhost)。无新增 backend endpoint。

P2-P4(content script 悬浮按钮、cookie 直通、side panel、思维导图、RAG 问答)保留 stub 文件,不在本次范围。

去掉 vitesse-webext 自带的 simple-git-hooks postinstall 配置——它会在仓库根装 pre-commit 钩子去跑 pnpm lint-staged,但仓库根没有 package.json,会破坏所有提交流。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 11:40:15 +08:00

6.8 KiB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

BiliNote is an AI video note generation tool. It extracts content from video links (Bilibili, YouTube, Douyin, Kuaishou, local files) and generates structured Markdown notes using LLM models. Full-stack app with a FastAPI backend, React frontend, and optional Tauri desktop packaging.

Development Commands

Backend (Python 3.11 + FastAPI)

cd backend
pip install -r requirements.txt
python main.py                    # Starts on 0.0.0.0:8483

Frontend (React 19 + Vite + TypeScript)

cd BillNote_frontend
pnpm install
pnpm dev          # Dev server on port 3015, proxies /api to backend
pnpm build        # Production build
pnpm lint         # ESLint

Docker

docker-compose up                              # Web stack (backend + frontend + nginx)
docker-compose -f docker-compose.gpu.yml up    # GPU variant

Desktop (Tauri)

cd backend && ./build.sh          # Build PyInstaller backend binary
cd BillNote_frontend && pnpm tauri build

Browser Extension (Vue 3 + vitesse-webext, MV3)

cd BillNote_extension
pnpm install
pnpm dev          # watch mode → ./extension/
pnpm build        # production build → ./extension/
pnpm typecheck

Load unpacked at chrome://extensions/ → select BillNote_extension/extension/. Talks to the same backend at http://localhost:8483 (configurable in the options page). CORS in backend/main.py already accepts chrome-extension:// and moz-extension:// via regex.

Architecture

Backend (backend/) — FastAPI app, entry point main.py:

  • app/routers/ — API routes: note.py (generation), provider.py, model.py, config.py, chat.py (RAG Q&A on generated notes)
  • app/services/ — Business logic:
    • note.pyNoteGenerator orchestrates the full pipeline (download → transcribe → LLM → notes)
    • task_serial_executor.py — task queue
    • chat_service.py + chat_tools.py + vector_store.py — RAG-based AI Q&A with Function Calling, indexing transcripts and video metadata
    • cookie_manager.py — per-platform cookie storage; injected into yt-dlp by downloaders (e.g. Bilibili)
    • transcriber_config_manager.py — persisted transcriber settings
    • worker_registry.pyoptional Nacos registration + heartbeat for distributed worker mode (no-op when NACOS_SERVER_ADDR unset)
  • app/messaging/optional RabbitMQ producer/consumer publishing task progress/results to bilinote.task.feedback exchange. Silently degrades when RABBITMQ_URL is unset; always import-safe.
  • app/downloaders/ — Platform adapters (bilibili, youtube, douyin, kuaishou, local) with shared base.py interface
  • app/transcriber/ — Speech-to-text engines (fast-whisper, groq, bcut, kuaishou, mlx-whisper) with factory in transcriber_provider.py. YouTube path prefers existing subtitles and skips audio download when available.
  • app/gpt/ — LLM integration with factory pattern (gpt_factory.py), prompt templates (prompt.py, prompt_builder.py), and request_chunker.py for long transcripts
  • app/db/ — SQLite + SQLAlchemy: DAO pattern (provider_dao.py, model_dao.py, video_task_dao.py), models in models/
  • app/utils/response.py (ResponseWrapper for consistent JSON), video_helper.py (screenshots via FFmpeg), export.py (PDF/DOCX), ppt_generator.py, minio_client.py
  • app/i18n/ — backend localization
  • events/ (root level) — Blinker signal system for post-processing (e.g., temp file cleanup after transcription)

Frontend (BillNote_frontend/src/) — React 19 + Vite + Tailwind + shadcn/ui:

  • pages/HomePage/ — Main note generation UI: NoteForm.tsx (input), MarkdownViewer.tsx (preview), MarkmapComponent.tsx (mind map)
  • pages/SettingPage/ — LLM provider management, system monitoring, transcriber config
  • store/ — Zustand stores: taskStore, modelStore, configStore, providerStore. Persists to IndexedDB.
  • services/ — Axios API clients matching backend routes
  • hooks/useTaskPolling.ts — Polls task status every 3 seconds
  • components/ui/ — shadcn/ui (Radix-based) components
  • i18n/react-i18next setup with locale JSON in i18n/locales/; toggled via components/LanguageSwitcher.tsx
  • Path alias: @./src

Core Workflow: User submits URL → task queued → download video → extract audio (FFmpeg) → transcribe (Whisper/Groq/etc) → generate notes (LLM) → frontend polls for completion → display Markdown + mind map.

Browser Extension (BillNote_extension/) — Vue 3 + Vite + UnoCSS + webextension-polyfill, MV3:

  • src/popup/Popup.vue — main entry: detects platform from active tab URL, drives generate flow, shows progress + markdown
  • src/options/Options.vue — settings: backend URL, default provider/model (loaded from /get_all_providers + /get_models_by_provider/{id}), quality, screenshot/link toggles, style
  • src/logic/api.ts — backend API client (uses settings.backendUrl, unwraps ResponseWrapper, absolutizes /static/screenshots/... image paths)
  • src/logic/storage.tschrome.storage.local-backed Pinia-like state via useWebExtensionStorage for settings + last 30 tasks
  • src/logic/platform.ts — URL → platform detection mirroring backend/app/validators/video_url_validator.py
  • src/sidepanel/, src/contentScripts/ — placeholders for P2/P3 (floating button, side panel mind map, RAG chat); not wired into MVP UX
  • src/manifest.ts — MV3 manifest, popup is default action; host_permissions: *://*/*
  • Polling lives client-side in popup (3 s interval while open); MV3 service worker is intentionally thin in P1

Key Configuration

  • Ports: Backend 8483, Frontend dev 3015, Docker maps 3015→80
  • Environment: Root .env (copy from .env.example). LLM API keys are configured through the UI, not env vars.
  • Database: SQLite at backend/app/db/bili_note.db, auto-initialized on first run
  • FFmpeg: Required system dependency for video/audio processing
  • Vite proxy: Dev server proxies /api and /static to backend (configured in vite.config.ts, reads env from parent dir)
  • Distributed mode (optional): Setting NACOS_SERVER_ADDR enables Nacos worker registration; setting RABBITMQ_URL enables MQ feedback. Both are no-ops when unset — single-node deployment works without either. Other knobs: WORKER_ID, WORKER_SELF_URL, WORKER_MAX_CONCURRENT, TASK_MAX_WORKERS.

Code Style

  • Frontend: ESLint + Prettier (2 spaces, single quotes, 100 char width, Tailwind plugin). TypeScript strict mode.
  • Backend: Python with type hints. No configured linter. Uses Pydantic models for validation.
  • Note: The frontend directory is named BillNote_frontend (not "Bili").