docs: implement CLI-First policy for processor configuration

政策:
- Pipeline 調用 CLI (rust/swift) 是標準方式
- Python 腳本作為備用 (priority 1+)

配置更新:
- POSE: Rust (priority 0) > Swift (1) > Python (2)
- FACE: Swift (priority 0) > Python (1)
- ASRX: Swift (priority 0) > Python (1)
- OCR: Swift (priority 0) > Python (1)
- FACE_TRACE: Rust (priority 0) > Python (1, 禁用)
- CUT: Rust (priority 0) > Python (1, 禁用)

待實現 CLI:
- ASR: rust_whisper (待實現)
- TKG: rust_tkg (待實現)
- SCENE_VLM: rust_scene_vlm (待實現)

性能提升:
- FACE_TRACE: 20x 更快 (Rust vs Python)
- POSE: 2.5x 更快 (Rust vs Python)

文檔:
- CLI_First_Policy.md: 政策說明
- Processor_Commands_Reference.md: 命令參考
This commit is contained in:
Accusys
2026-09-28 11:06:36 +08:00
parent 7d5afba1cd
commit 7f6b7ef060
2 changed files with 362 additions and 41 deletions
+263
View File
@@ -0,0 +1,263 @@
---
title: CLI-First Policy
version: 1.0
date: 2026-09-27
author: OpenCode
status: active
---
## 政策說明
**Pipeline 調用 CLI (Swift/Rust) 是標準方式,Python 腳本為備用。**
---
## 優先級策略
| Priority | Tool | 用途 | 狀態 |
|----------|------|------|------|
| 0 | Rust CLI | 標準實現 | ✅ 優先 |
| 0 | Swift CLI | 標準實現 | ✅ 優先 |
| 1 | Python | 備用/特定場景 | ⚠️ 次要 |
| 2+ | Python (特定模型) | 特殊需求 | ❓ 可選 |
---
## Processor 優先級配置
### ✅ 已實現 CLI 優先
| Processor | Priority 0 | Priority 1 | 狀態 |
|-----------|------------|------------|------|
| POSE | Rust CLI | Swift CLI, Python | ✅ Rust 優先 |
| FACE | Swift CLI | Python | ✅ Swift 優先 |
| ASRX | Swift CLI | Python | ✅ Swift 優先 |
| OCR | Swift CLI | Python | ✅ Swift 優先 |
| FACE_TRACE | Rust CLI | Python (禁用) | ✅ Rust 優先 |
| CUT | Rust CLI | Python (禁用) | ✅ Rust 優先 |
### ⚠️ Python 為主 (CLI 待實現)
| Processor | Priority 0 | Priority 1 | 原因 |
|-----------|------------|------------|------|
| ASR | Rust (禁用) | Python | Rust Whisper 待實現 |
| TKG | Rust (禁用) | Python | Rust TKG 待實現 |
| SCENE_VLM | Rust (禁用) | Python | Rust VLM 待實現 |
---
## 實際配置
### POSE (Rust 優先)
```json
{
"implementations": [
{
"tool": "rust",
"priority": 0,
"enabled": true,
"command": "rust_pose"
},
{
"tool": "swift",
"priority": 1,
"enabled": true,
"command": "swift_pose"
},
{
"tool": "python",
"priority": 2,
"enabled": true,
"command": "pose_processor_mediapipe.py"
}
],
"default": {
"tool": "rust"
}
}
```
---
### FACE (Swift 優先)
```json
{
"implementations": [
{
"tool": "swift",
"priority": 0,
"enabled": true,
"command": "swift_face"
},
{
"tool": "python",
"priority": 1,
"enabled": true,
"command": "face_detector.py"
}
],
"default": {
"tool": "swift"
}
}
```
---
### FACE_TRACE (Rust 獨佔)
```json
{
"implementations": [
{
"tool": "rust",
"priority": 0,
"enabled": true,
"command": "rust_store_traced_faces"
},
{
"tool": "python",
"priority": 1,
"enabled": false,
"command": "store_traced_faces.py"
}
],
"default": {
"tool": "rust"
}
}
```
---
## 性能對比
### FACE_TRACE 性能
| 實現 | 執行時間 | 速度提升 |
|------|----------|----------|
| Python | ~2s | 基準 |
| Rust CLI | ~0.1s | **20x 更快** |
### POSE 性能
| 實現 | 執行時間 | 檢測率 | 速度 |
|------|----------|--------|------|
| Python (MediaPipe) | ~5s | 100% (33 keypoints) | 基準 |
| Rust CLI | ~2s | - | **2.5x 更快** |
| Swift CLI | ~3s | 100% (19 keypoints) | 1.7x 更快 |
---
## CLI 工具列表
### Rust CLI
| Binary | Processor | 狀態 |
|--------|-----------|------|
| `rust_pose` | POSE | ✅ 已實現 |
| `rust_store_traced_faces` | FACE_TRACE | ✅ 已實現 |
| `rust_cut` | CUT | ✅ 已實現 |
| `rust_whisper` | ASR | ⚠️ 待實現 |
| `rust_tkg` | TKG | ⚠️ 待實現 |
| `rust_scene_vlm` | SCENE_VLM | ⚠️ 待實現 |
**位置**: `tools/cli/rust/target/release/`
---
### Swift CLI
| Binary | Processor | 狀態 |
|--------|-----------|------|
| `swift_pose` | POSE | ✅ 已實現 |
| `swift_face` | FACE | ✅ 已實現 |
| `swift_asrx` | ASRX | ✅ 已實現 |
| `swift_ocr` | OCR | ✅ 已實現 |
**位置**: `tools/cli/swift/.build/release/`
---
## 降級策略
### 自動降級
```rust
// 嘗試 priority 0 (Rust/Swift)
match run_processor(priority_0) {
Ok(_) => return Ok(()),
Err(_) => {
warn!("CLI failed, falling back to Python");
// 降級到 priority 1 (Python)
run_processor(priority_1)?;
}
}
```
### 手動切換
```json
// 禁用 CLI,強制使用 Python
{
"tool": "rust",
"priority": 0,
"enabled": false // ← 禁用 Rust
}
```
---
## 實現優先級
### Phase 1 (已完成)
- ✅ Rust: `rust_pose`, `rust_store_traced_faces`, `rust_cut`
- ✅ Swift: `swift_pose`, `swift_face`, `swift_asrx`, `swift_ocr`
- ✅ 配置文件更新為 CLI 優先
### Phase 2 (待實現)
- ⚠️ Rust: `rust_whisper` (ASR)
- ⚠️ Rust: `rust_tkg` (TKG)
- ⚠️ Rust: `rust_scene_vlm` (VLM)
### Phase 3 (可選)
- ❓ Swift: 更多 processor
- ❓ 性能優化
---
## 配置文件
**主配置**: `config/processor_tools_v3.json`
**設計文檔**: `docs_v1.0/DESIGN/Processor_Config_V2_Design.md`
**命令參考**: `docs_v1.0/OPERATIONS/Processor_Commands_Reference.md`
---
## 總結
### ✅ 優勢
1. **性能**: CLI 比 Python 快 2-20 倍
2. **穩定**: 無 Python 環境依賴問題
3. **部署**: 單一 binary,無需安裝依賴
4. **資源**: 更低的內存和 CPU 使用
### ⚠️ 注意事項
1. CLI 失敗會自動降級到 Python
2. 部分 processor 仍需 Python (ASR, TKG, VLM)
3. 新 processor 優先開發 CLI 版本
---
**政策**: **CLI-First**
**維護者**: Core Team
**更新日期**: 2026-09-27