diff --git a/AGENTS.md b/AGENTS.md index 3e19801..36305d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,10 +4,12 @@ MoMentry Playground 是一個整合式桌面應用程式,提供: - 多格式媒體播放(視頻、音頻、圖片) -- Markdown/PDF/HTML 檢視 - Frame-精確的視頻控制 +- ASR 字幕顯示(可開關) +- YOLO 檢測框疊加(可開關) +- Chunk 導航標記(可開關) - 與 momentry_core 處理模組的進度監控 -- Database 查詢功能 +- 自然語言搜尋 ## 技術棧 @@ -15,10 +17,11 @@ MoMentry Playground 是一個整合式桌面應用程式,提供: |------|------| | 語言 | Rust 2021 | | 桌面框架 | tao + wry | -| 視頻播放 | SDL2 + FFmpeg-sidecar | +| 視頻播放 | SDL2 + FFmpeg | | 前端 | HTML/CSS/JS (WebView) | | 後端接口 | HTTP API (momentry_core port 3002) | | 數據庫 | PostgreSQL, MongoDB, Qdrant (via API) | +| 緩存 | LRU (YOLO frame cache) | --- @@ -33,10 +36,13 @@ cargo build cargo build --release # 運行 -cargo run +cargo run -- --video "/path/to/video.mov" -# 指定功能運行 -cargo run --features "youtube,cloud" +# 指定參數 +cargo run --release -- \ + --video "/Users/accusys/test_video/Old_Time_Movie_Show_-_Charade_1963.HD.mov" \ + --asr "/Users/accusys/momentry_core_0.1/output/39567a0eb16f39fd.asr.json" \ + --yolo "/Users/accusys/test_video/Old_Time_Movie_Show_-_Charade_1963.HD.yolo.json" ``` ### 測試 @@ -71,22 +77,10 @@ cargo clippy # 類型檢查 cargo check -# 完整檢查(相當於所有以上) +# 完整檢查 cargo build --all-targets ``` -### WASM 目標(如使用 Yew) -```bash -# 添加 WASM 目標 -rustup target add wasm32-unknown-unknown - -# 使用 Trunk 開發 -trunk serve - -# Production 構建 -trunk build --release -``` - --- ## 代碼風格指南 @@ -94,7 +88,6 @@ trunk build --release ### 格式規範 - **最大行長**: 100 字符 - **縮進**: 4 空格(使用 `rustfmt` 自動處理) -- **換行**: Unix 風格 (`\n`) ### 命名慣例 ```rust @@ -106,33 +99,21 @@ trait MediaViewer; // 函數/方法/變量: snake_case fn play_video(); let current_frame = 0; -let is_playing = true; // 常量: SCREAMING_SNAKE_CASE const MAX_FRAME_BUFFER: usize = 10; -const SEEK_DELAY_MS: u64 = 500; - -// 模塊: snake_case -mod video_player; -pub mod ffmpeg; - -// 公開 API: 完整單詞 -fn get_playback_position() -> Duration; -fn set_volume() -> Result<(), PlayerError>; ``` ### 錯誤處理 ```rust -// 使用 anyhow 進行應用級錯誤處理 use anyhow::{Context, Result, anyhow}; fn load_video(path: &str) -> Result { let file = File::open(path) .with_context(|| format!("Failed to open video: {}", path))?; - // ... + Ok(file) } -// 定義專用錯誤枚舉 #[derive(Debug, thiserror::Error)] pub enum PlayerError { #[error("Codec not supported: {0}")] @@ -140,143 +121,175 @@ pub enum PlayerError { #[error("Seek failed: {0}")] SeekFailed(String), - - #[error("FFmpeg error: {stderr}")] - FFmpegError { stderr: String }, } ``` ### 模塊結構 ```rust -// src/lib.rs - 庫入口 +// src/lib.rs pub mod player; -pub mod ui; -pub mod viewer; -pub mod api; +pub mod overlay; +pub mod web; +pub mod config; -// 每個模塊的組織 -mod player { - pub mod video; // 公開子模塊 - mod controls; // 私有實現 - - pub use video::{VideoPlayer, VideoEvent}; -} -``` +// src/player/mod.rs +pub mod video; +pub mod ffmpeg; +pub mod renderer; +pub mod state; -### 並發安全 -```rust -// 使用 Arc> 共享狀態 -let player = Arc::new(Mutex::new(VideoPlayer::new())); - -// 在多線程間共享 Frame buffer -type FrameBuffer = Arc>>; - -// Spawn 線程時克隆 Arc -let player_clone = Arc::clone(&player); -std::thread::spawn(move || { - // ... -}); -``` - -### 文檔注釋 -```rust -/// 視頻播放器核心結構 -/// -/// # Example -/// ``` -/// let player = VideoPlayer::new(); -/// player.open("video.mp4")?; -/// player.play()?; -/// ``` -pub struct VideoPlayer { - // ... -} - -/// 播放事件 -#[derive(Debug, Clone, PartialEq)] -pub enum PlayEvent { - /// 播放開始 - Play, - /// 播放暫停 - Pause, - /// 進度更新 (當前幀, 總幀數) - Progress(u64, u64), - /// 播放結束 - End, -} -``` - -### 依賴管理 -```toml -# 明確版本範圍 -[dependencies] -anyhow = "1.0" -serde = { version = "1.0", features = ["derive"] } - -# 避免使用 * 導入 -# 錯誤: use std::collections::*; -# 正確: use std::collections::{HashMap, HashSet}; -``` - -### API 設計 -```rust -// 使用 Result 明確錯誤 -fn command(&self, cmd: &str) -> Result; - -// 公開方法要有文檔 -/// 發送播放命令 -/// -/// # Arguments -/// * `cmd` - 命令字串 ("play", "pause", "seek