feat: Face JSON v2 schema - add schema_version, bbox x2/y2/center, keep embeddings, update clustering

This commit is contained in:
Accusys
2026-11-02 14:34:02 +08:00
parent 2fca49b120
commit 5d18183d82
566 changed files with 321788 additions and 1662 deletions
@@ -0,0 +1,88 @@
# Changelog
## 2026-11-01 — Initial Release
### New Documents
- `modules/000_Welcome.md` — Version overview and navigation
- `modules/001_Architecture_Reference.md` — Search architecture, JSON pipeline, VLM dual-track, Qdrant collections
- `modules/002_Language_Architecture.md` — Three language dimensions (UI/Search/Agent), 12 open questions
- `modules/003_Interface_Language_Ops.md` — Interface language definition, modification procedures
- `modules/004_Profile_Analysis.md` — Profile/Trace document review, issue list
- `modules/005_JSON_Config_Reference.md` — Complete JSON configuration reference
- `modules/006_JSON_Ecosystem_Design.md` — Full JSON ecosystem design, Producer/Consumer mapping, pipeline diagram
- `modules/101_MarkBase_API.md` — MarkBase Server API documentation
- `modules/102_MarkBaseEngine_API.md` — MarkBaseEngine LLM/VLM API documentation
- `modules/103A_File_Management.md` — Core API File Management
- `modules/103B_Pipeline.md` — Core API Pipeline
- `modules/103C_Search.md` — Core API Search
- `modules/103D_Identity.md` — Core API Identity
- `modules/103E_Trace.md` — Core API Trace Management
- `modules/103F_Admin.md` — Core API Admin
- `modules/103G_Media.md` — Core API Media
- `modules/104_Studio_Proxy_API.md` — Studio Proxy API (port 8888)
- `modules/105_Admin_Environment.md` — Admin Environment Management
- `modules/201_Cross_Project_Design.md` — Four-project collaboration architecture
- `modules/202_Workspace_Management.md` — Workspace management
- `modules/203_Shared_AGENTS.md` — Shared AGENTS.md mechanism
- `modules/204_Sandbox_Design.md` — Sandbox design
- `modules/205_Path_Registry.md` — Path registry management
- `modules/301_Gitea_Workflow.md` — Gitea workflow
- `modules/302_CICD_Design.md` — CI/CD design (M5Max48)
- `modules/303_Issue_Templates.md` — Issue/PR templates
- `modules/304_Test_Strategy.md` — Test strategy
- `modules/305_Cross_Project_Bug_Triage.md` — Cross-project bug triage
### Modified Documents (source)
- `API_WORKSPACE/modules/000_PeopleAPI_v1.0.0.md` — Added TEXT match clarification, Face 512D scope
- `API_WORKSPACE/modules/032_VLMSearch_v1.3.5.md` — Added dual VLM architecture, implementation files
- `API_WORKSPACE/modules/052_Profile_v1.3.5.md` — Updated terminology
- `DESIGN/FILE_PROCESSING_PIPELINE_V3.md` — Clarified `asr.json` → `asrx.json` pipeline
- `REFERENCE/Architecture_Reference.md` — Created comprehensive reference
### Key Findings
- `asr.json` is ONLY intermediate input for asrx tool, not used for search
- `asrx.json` is authoritative source for Keyword + Semantic search
- Face 512D vectors ONLY used for `rust_face_cluster`, not search
- VLM dual-source: Scene VLM → `_scenes`, Trace VLM → `_vlm`
- People Search uses TEXT match on `trace_profiles.name`, not vectors
- `vlm_output_language` default is `"ja"` but `preferred_language` default is `"zh-TW"` (conflict)
- Agent Search language fallback is hardcoded `"en"`, not from config
### Open Questions (12 total)
| ID | Priority | Area | Question |
|----|----------|------|----------|
| Q1 | P0 | UI | Single source of truth? |
| Q2 | P1 | UI | Empty string = fallback or error? |
| Q3 | P2 | UI | Browser language auto-detect? |
| Q4 | P0 | Search | Auto-select localized vs English? |
| Q5 | P1 | Search | Trace VLM localization? |
| Q6 | P1 | Search | Trace VLM language parameter? |
| Q7 | P2 | Search | Chinese synonym database? |
| Q8 | P0 | Search | `vlm_output_language` default? |
| Q9 | P0 | Agent | Fallback to preferred_language? |
| Q10 | P2 | Agent | Conversation history language? |
| Q11 | P1 | Agent | Localize base SYSTEM_PROMPT? |
| Q12 | P2 | Agent | Mixed language query handling? |
---
## 2026-11-01 — Gitea & CI/CD Setup
### New Documents
- `modules/401_MarkBase_Requirements.md` — MarkBase requirements for path registry, projects, workspaces
### Gitea Setup
- `.gitea/ISSUE_TEMPLATE/requirement.md` — Cross-project requirement template
- `.gitea/ISSUE_TEMPLATE/cross-bug.md` — Cross-project bug triage template
- `.gitea/ISSUE_TEMPLATE/feature.md` — Feature request template
### CI/CD Workflows
- `.gitea/workflows/core-test.yml` — Core Rust tests
- `.gitea/workflows/cross-project.yml` — Cross-project integration tests
- `.gitea/workflows/release.yml` — Release builds
### Sandbox Scripts
- `scripts/setup_sandbox.sh` — Create cross-project sandbox
- `scripts/start_services.sh` — Start all services in sandbox
- `scripts/run_integration_tests.sh` — Run integration tests
- `scripts/cleanup_sandbox.sh` — Cleanup sandbox
+62
View File
@@ -0,0 +1,62 @@
---
title: Language & Configuration Documentation
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Language & Configuration Documentation
獨立文件系統,記錄語言架構、配置管理、Profile 審查等分析結果。
---
## 文件索引
| 編號 | 文件 | 內容 |
|------|------|------|
| 000 | [Welcome](modules/000_Welcome.md) | 版本說明、目標、快速導覽 |
| 001 | [Architecture Reference](modules/001_Architecture_Reference.md) | 搜尋架構、JSON 管線、VLM 雙軌、Qdrant Collections |
| 002 | [Language Architecture](modules/002_Language_Architecture.md) | 三大語言層面、配置來源、12 個待澄清問題 |
| 003 | [Interface Language Operations](modules/003_Interface_Language_Ops.md) | 介面語言定義、修改流程、影響範圍 |
| 004 | [Profile Analysis](modules/004_Profile_Analysis.md) | Profile/Trace 文件審查、問題清單、修正建議 |
| 005 | [JSON Config Reference](modules/005_JSON_Config_Reference.md) | 所有 JSON 配置檔案結構、欄位說明、修改方式 |
| 006 | [JSON Ecosystem Design](modules/006_JSON_Ecosystem_Design.md) | JSON 生態系統完整設計、Producer/Consumer 映射、管線圖 |
| 101 | [MarkBase API](modules/101_MarkBase_API.md) | MarkBase Server API (port 11438) |
| 102 | [MarkBaseEngine API](modules/102_MarkBaseEngine_API.md) | MarkBaseEngine LLM/VLM 推理引擎 API |
| 103A | [Core API - File](modules/103A_File_Management.md) | 檔案管理 API |
| 103B | [Core API - Pipeline](modules/103B_Pipeline.md) | 處理管線 API |
| 103C | [Core API - Search](modules/103C_Search.md) | 搜尋 API |
| 103D | [Core API - Identity](modules/103D_Identity.md) | 身份與人物 API |
| 103E | [Core API - Trace](modules/103E_Trace.md) | Trace 管理 API |
| 103F | [Core API - Admin](modules/103F_Admin.md) | 系統管理 API |
| 103G | [Core API - Media](modules/103G_Media.md) | 媒體 API |
| 104 | [Studio Proxy API](modules/104_Studio_Proxy_API.md) | Studio Proxy API (port 8888) |
| 105 | [Admin Environment](modules/105_Admin_Environment.md) | 環境管理 |
| 201 | [Cross-Project Design](modules/201_Cross_Project_Design.md) | 四專案協同架構 |
| 202 | [Workspace Management](modules/202_Workspace_Management.md) | Workspace 管理 |
| 203 | [Shared AGENTS.md](modules/203_Shared_AGENTS.md) | 共享 AGENTS.md 機制 |
| 204 | [Sandbox Design](modules/204_Sandbox_Design.md) | Sandbox 設計 |
| 205 | [Path Registry](modules/205_Path_Registry.md) | 路徑註冊管理 |
| 301 | [Gitea Workflow](modules/301_Gitea_Workflow.md) | Gitea 工作流程 |
| 302 | [CI/CD Design](modules/302_CICD_Design.md) | CI/CD 設計 (M5Max48) |
| 303 | [Issue Templates](modules/303_Issue_Templates.md) | Issue/PR 模板 |
| 304 | [Test Strategy](modules/304_Test_Strategy.md) | 測試策略 |
| 305 | [Cross-Project Bug Triage](modules/305_Cross_Project_Bug_Triage.md) | 跨專案 Bug 會診 |
| 401 | [MarkBase Requirements](modules/401_MarkBase_Requirements.md) | MarkBase 需求文件 |
| 500 | [Gitea Unification](modules/500_Gitea_Unification.md) | Gitea 倉庫統一記錄 |
---
## 建立日期
**2026-11-01** — 語言架構分析會話產出
---
## 版本歷史
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial language & config documentation |
@@ -0,0 +1 @@
../../modules/105_Admin_Environment.md
@@ -0,0 +1,5 @@
# Admin 環境管理文件
| 文件 | 說明 |
|------|------|
| [105_Admin_Environment.md](../../modules/105_Admin_Environment.md) | 環境管理 |
@@ -0,0 +1 @@
../../modules/101_MarkBase_API.md
@@ -0,0 +1 @@
../../modules/205_Path_Registry.md
@@ -0,0 +1,6 @@
# MarkBase 專案文件
| 文件 | 說明 |
|------|------|
| [101_MarkBase_API.md](../../modules/101_MarkBase_API.md) | MarkBase Server API |
| [205_Path_Registry.md](../../modules/205_Path_Registry.md) | 路徑註冊管理 |
@@ -0,0 +1 @@
../../modules/102_MarkBaseEngine_API.md
@@ -0,0 +1,5 @@
# MarkBaseEngine 專案文件
| 文件 | 說明 |
|------|------|
| [102_MarkBaseEngine_API.md](../../modules/102_MarkBaseEngine_API.md) | MarkBaseEngine API |
@@ -0,0 +1 @@
../../modules/006_JSON_Ecosystem_Design.md
@@ -0,0 +1 @@
../../modules/103A_File_Management.md
@@ -0,0 +1 @@
../../modules/103B_Pipeline.md
@@ -0,0 +1 @@
../../modules/103C_Search.md
@@ -0,0 +1 @@
../../modules/103D_Identity.md
@@ -0,0 +1 @@
../../modules/103E_Trace.md
@@ -0,0 +1 @@
../../modules/103F_Admin.md
@@ -0,0 +1 @@
../../modules/103G_Media.md
@@ -0,0 +1,12 @@
# Momentry Core 專案文件
| 文件 | 說明 |
|------|------|
| [103A_File_Management.md](../../modules/103A_File_Management.md) | 檔案管理 API |
| [103B_Pipeline.md](../../modules/103B_Pipeline.md) | 處理管線 API |
| [103C_Search.md](../../modules/103C_Search.md) | 搜尋 API |
| [103D_Identity.md](../../modules/103D_Identity.md) | 身份與人物 API |
| [103E_Trace.md](../../modules/103E_Trace.md) | Trace 管理 API |
| [103F_Admin.md](../../modules/103F_Admin.md) | 系統管理 API |
| [103G_Media.md](../../modules/103G_Media.md) | 媒體 API |
| [006_JSON_Ecosystem_Design.md](../../modules/006_JSON_Ecosystem_Design.md) | JSON 生態系統 |
@@ -0,0 +1 @@
../../modules/104_Studio_Proxy_API.md
@@ -0,0 +1,5 @@
# Momentry Studio 專案文件
| 文件 | 說明 |
|------|------|
| [104_Studio_Proxy_API.md](../../modules/104_Studio_Proxy_API.md) | Studio Proxy API |
@@ -0,0 +1 @@
../../modules/001_Architecture_Reference.md
@@ -0,0 +1 @@
../../modules/201_Cross_Project_Design.md
@@ -0,0 +1 @@
../../modules/204_Sandbox_Design.md
@@ -0,0 +1,7 @@
# 架構設計文件
| 文件 | 說明 |
|------|------|
| [001_Architecture_Reference.md](../../modules/001_Architecture_Reference.md) | 搜尋架構、JSON 管線 |
| [201_Cross_Project_Design.md](../../modules/201_Cross_Project_Design.md) | 四專案協同架構 |
| [204_Sandbox_Design.md](../../modules/204_Sandbox_Design.md) | Sandbox 設計 |
@@ -0,0 +1 @@
../../modules/301_Gitea_Workflow.md
@@ -0,0 +1 @@
../../modules/302_CICD_Design.md
@@ -0,0 +1 @@
../../modules/303_Issue_Templates.md
@@ -0,0 +1 @@
../../modules/304_Test_Strategy.md
@@ -0,0 +1,8 @@
# CI/CD 文件
| 文件 | 說明 |
|------|------|
| [301_Gitea_Workflow.md](../../modules/301_Gitea_Workflow.md) | Gitea 工作流程 |
| [302_CICD_Design.md](../../modules/302_CICD_Design.md) | CI/CD 設計 |
| [303_Issue_Templates.md](../../modules/303_Issue_Templates.md) | Issue 模板 |
| [304_Test_Strategy.md](../../modules/304_Test_Strategy.md) | 測試策略 |
@@ -0,0 +1 @@
../../modules/202_Workspace_Management.md
@@ -0,0 +1 @@
../../modules/203_Shared_AGENTS.md
@@ -0,0 +1 @@
../../modules/305_Cross_Project_Bug_Triage.md
@@ -0,0 +1,7 @@
# 協同設計文件
| 文件 | 說明 |
|------|------|
| [202_Workspace_Management.md](../../modules/202_Workspace_Management.md) | Workspace 管理 |
| [203_Shared_AGENTS.md](../../modules/203_Shared_AGENTS.md) | 共享 AGENTS.md |
| [305_Cross_Project_Bug_Triage.md](../../modules/305_Cross_Project_Bug_Triage.md) | Bug 會診 |
@@ -0,0 +1 @@
../../modules/005_JSON_Config_Reference.md
@@ -0,0 +1 @@
../../modules/006_JSON_Ecosystem_Design.md
@@ -0,0 +1 @@
../../modules/205_Path_Registry.md
@@ -0,0 +1,7 @@
# 配置管理文件
| 文件 | 說明 |
|------|------|
| [005_JSON_Config_Reference.md](../../modules/005_JSON_Config_Reference.md) | JSON 配置參考 |
| [006_JSON_Ecosystem_Design.md](../../modules/006_JSON_Ecosystem_Design.md) | JSON 生態系統 |
| [205_Path_Registry.md](../../modules/205_Path_Registry.md) | 路徑註冊管理 |
@@ -0,0 +1 @@
../../modules/002_Language_Architecture.md
@@ -0,0 +1 @@
../../modules/003_Interface_Language_Ops.md
@@ -0,0 +1,6 @@
# 語言設計文件
| 文件 | 說明 |
|------|------|
| [002_Language_Architecture.md](../../modules/002_Language_Architecture.md) | 語言架構 |
| [003_Interface_Language_Ops.md](../../modules/003_Interface_Language_Ops.md) | 介面語言操作 |
@@ -0,0 +1,37 @@
---
title: Welcome
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Welcome — Language & Configuration Documentation
## 目標
本文件系統記錄 Momentry Core 的語言架構、配置管理、Profile 審查等分析結果,獨立於 API 文件之外。
## 範圍
| 主題 | 文件 |
|------|------|
| 系統架構參考 | [001_Architecture_Reference.md](/Users/accusys/momentry_core/docs_v1.0/doc_language_config/modules/001_Architecture_Reference.md) |
| 語言架構設計 | [002_Language_Architecture.md](/Users/accusys/momentry_core/docs_v1.0/doc_language_config/modules/002_Language_Architecture.md) |
| 介面語言操作 | [003_Interface_Language_Ops.md](/Users/accusys/momentry_core/docs_v1.0/doc_language_config/modules/003_Interface_Language_Ops.md) |
| Profile 文件審查 | [004_Profile_Analysis.md](/Users/accusys/momentry_core/docs_v1.0/doc_language_config/modules/004_Profile_Analysis.md) |
## 建立背景
2026-11-01 會話產出,涵蓋:
- 搜尋類型與資料來源修正
- JSON 管線澄清 (`asr.json` → `asrx.json`)
- VLM 雙軌架構 (Scene + Trace)
- 語言配置分析 (UI / Search / Agent)
- Profile/Trace 文件審查
## 版本歷史
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,105 @@
---
title: Architecture Reference
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Architecture Reference
## Search Types & Data Sources
| Search Type | Core Mechanism | Data Source | Storage |
|-------------|----------------|-------------|---------|
| **Keyword** | PostgreSQL `ts_rank` FTS | `asrx.json`, `ocr.json` | PostgreSQL `chunks` |
| **Semantic** | PostgreSQL FTS + Qdrant Vector | `asrx.json` only | PostgreSQL + Qdrant `_chunks` |
| **Visual** | Qdrant Vector Similarity | 10s scenes + face trace keyframes (VLM) | Qdrant `_scenes` + `_vlm` |
| **People** | **SQLite TEXT match** | `face_cluster.json` (group names) | SQLite `trace_profiles` |
## JSON Data Lineage
```
video.mp4
↓ (ASR processor)
{file_uuid}.asr.json → (ONLY intermediate input for asrx tool, NOT used for search)
↓ (ASRX processor)
{file_uuid}.asrx.json → (Authoritative source for Keyword + Semantic search)
```
**Key Clarification**:
- `asr.json`: Raw ASR output, used ONLY as input for the `asrx` processor
- `asrx.json`: Speaker-aware ASR output, feeds BOTH Keyword and Semantic search
- `face_cluster.json`: Face clustering output, feeds People Search (TEXT only)
## Face / Identity Data Flow
| Component | Purpose | Vector/Search |
|-----------|---------|---------------|
| **Face 512D** | ONLY for `rust_face_cluster` tool | **NOT used for search** |
| **Group Name** | People Search TEXT matching | SQLite TEXT (ILIKE) |
| **Identity** | Placeholder field | Currently unused |
| **Trace Profile** | Face trace metadata + VLM | PostgreSQL + SQLite |
## VLM & Qdrant Vector Search
| VLM Source | Analysis Target | Output | Qdrant Collection |
|------------|-----------------|--------|-------------------|
| **Scene VLM** (`scene_vlm.rs`) | 10s scene frames | Scene description vectors | `_scenes` |
| **Trace VLM** (`vlm_summary.rs`) | Face trace FS keyframes | Person description vectors | `_vlm` |
### VLM Dual-Source Flow
```
┌─────────────────────────────────────────────────────────────────┐
│ VLM Processing │
├──────────────────────────┬──────────────────────────────────────┤
│ Scene VLM │ Trace VLM │
│ - Analyzes 10s scenes │ - Analyzes face trace FS keyframes │
│ - Generates descriptions │ - Generates person descriptions │
│ - Embeds to Qdrant │ - Embeds to Qdrant │
│ `_scenes` collection │ `_vlm` collection │
└──────────────────────────┴──────────────────────────────────────┘
│ │
└──────────────┬───────────────────────┘
▼
Qdrant Vector Search
(Cosine similarity on 768D embeddings)
```
### Implementation Files
- Scene VLM: `/Users/accusys/momentry_core/src/core/processor/scene_vlm.rs`
- Trace VLM: `/Users/accusys/momentry_core/src/core/processor/vlm_summary.rs`
- Qdrant upsert: `/Users/accusys/momentry_core/src/core/db/qdrant_db.rs`
- `upsert_scene_embedding()` → `_scenes`
- `upsert_vlm_embedding()` → `_vlm`
- Search endpoints: `/Users/accusys/momentry_core/src/api/vlm_search.rs`
## Qdrant Collections Summary
| Collection | Content | Source | Dimension |
|------------|---------|--------|-----------|
| `_chunks` | Text chunk embeddings | `asrx.json` chunks | 768D |
| `_faces` | Face embeddings | Face detections | 512D |
| `_scenes` | Scene VLM embeddings | 10s scene frames | 768D |
| `_vlm` | Trace VLM embeddings | Face trace FS keyframes | 768D |
## API Endpoints
| Method | Endpoint | Type | Data Source |
|--------|----------|------|-------------|
| POST | `/api/v1/search/smart` | Semantic | Qdrant `_chunks` + PostgreSQL |
| POST | `/api/v1/search/universal` | Multi-type (BM25) | PostgreSQL FTS |
| POST | `/api/v1/search/frames` | Visual filter | YOLO/OCR/Face |
| GET | `/api/v1/search/people` | TEXT match | SQLite `trace_profiles` |
| POST | `/api/v1/search/vlm/scenes` | Vector | Qdrant `_scenes` |
| POST | `/api/v1/search/vlm/traces` | Vector | Qdrant `_vlm` |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial architecture reference |
@@ -0,0 +1,170 @@
---
title: Language Architecture
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Language Architecture
## Overview
Momentry Core handles language across three distinct dimensions:
| Dimension | Purpose | Current State |
|-----------|---------|---------------|
| **Interface (UI)** | Frontend display language | Single config, ambiguous defaults |
| **Search Results** | VLM descriptions, tags, localized text | Dual-language storage, no auto-selection |
| **Agent Conversation** | AI assistant responses | Request-param driven, no config fallback |
---
## 1. Interface (UI) Language
### Configuration Sources
| Layer | Source | Field | Default | ENV Fallback |
|-------|--------|-------|---------|--------------|
| **admin_config.json** | `admin_settings.preferred_language` | String | `""` (empty) | `MOMENTRY_PREFERRED_LANGUAGE` → `"zh-TW"` |
| **Runtime Static** | `config.rs::RUNTIME_PREFERRED_LANGUAGE` | `Lazy<RwLock<String>>` | `"zh-TW"` | `MOMENTRY_PREFERRED_LANGUAGE` |
### Current Flow
```
admin_config.json → admin_settings.preferred_language = "" (empty!)
└─▶ ENV: MOMENTRY_PREFERRED_LANGUAGE → "zh-TW" (if not set)
└─▶ RUNTIME_PREFERRED_LANGUAGE = "zh-TW"
```
### Open Questions
| # | Question | Priority |
|---|----------|----------|
| Q1 | Should `preferred_language` be the single source of truth? | P0 |
| Q2 | Should empty string `""` trigger fallback or be invalid? | P1 |
| Q3 | Should frontend auto-detect browser language? | P2 |
---
## 2. Search Results Language
### VLM Dual-Language Architecture
#### Scene VLM (`scene_vlm.rs`)
```
Input: image_frame + local_language (from search.vlm_output_language)
├─▶ VLM generates JSON (summary=EN, tags={en, local})
├─▶ Store in Qdrant `_scenes`
└─▶ If local_language != "en":
└─▶ Second LLM call → vlm_description_localized
```
#### Trace VLM (`vlm_summary.rs`)
```
Input: key_frame.jpg + prompt from admin_config
├─▶ VLM generates text (language depends on prompt)
│ ⚠️ Prompt says "same language as user" but NO param passed!
└─▶ Store in Qdrant + trace_profiles
- vlm_description = raw output (language unknown)
- vlm_description_localized = None (never populated)
```
### Supported Languages
| Code | Display Name |
|------|-------------|
| `zh-TW` | Traditional Chinese |
| `zh-CN` | Simplified Chinese |
| `ja` | Japanese |
| `ko` | Korean |
| `es` | Spanish |
| `fr` | French |
| `de` | German |
| other | English (fallback) |
### Chinese Text Processing
| Component | Handling |
|-----------|----------|
| **Tokenizer** | Auto-detect Chinese → Jieba segmentation |
| **Synonym (synonym.rs)** | OpenCC 簡→繁 conversion |
| **Online Synonym** | LLM fetch (disabled by default) |
| **Synonym Files** | English only (`data/english_synonyms.json`, `data/llm_synonyms.json`) |
### Open Questions
| # | Question | Priority |
|---|----------|----------|
| Q4 | Should Search API auto-select localized vs English? | P0 |
| Q5 | Should Trace VLM generate `vlm_description_localized`? | P1 |
| Q6 | Should Trace VLM prompt include language parameter? | P1 |
| Q7 | Should we build Chinese synonym database? | P2 |
| Q8 | Expected default for `vlm_output_language`? (currently `"ja"`) | P0 |
---
## 3. Agent Conversation Language
### Configuration Flow
```
AgentSearchRequest.output_language: Option<String>
├─▶ If provided → use it
└─▶ If None → fallback to "en" (hardcoded!)
└─▶ build_system_prompt(language)
├─▶ "zh-TW" → Chinese prompt
├─▶ "ja" → Japanese prompt
└─▶ other → English prompt
```
### Open Questions
| # | Question | Priority |
|---|----------|----------|
| Q9 | Should Agent fallback to `preferred_language`? | P0 |
| Q10 | Should Agent respect conversation history language? | P2 |
| Q11 | Should base SYSTEM_PROMPT be localized? | P1 |
| Q12 | Mixed language query handling? | P2 |
---
## 4. Current Configuration State
### admin_config.json
| Config | Current Value | Effective Value | Intended |
|--------|--------------|-----------------|----------|
| `admin_settings.preferred_language` | `""` | `"zh-TW"` (ENV) | `"zh-TW"` |
| `search.vlm_output_language` | `"ja"` | `"ja"` | `"zh-TW"`? |
| Agent fallback | - | `"en"` (hardcoded) | `preferred_language`? |
---
## 5. Proposed Architecture
```
┌─────────────────────────────────────────────────────────────────┐
│ admin_settings.preferred_language │
│ (Single Source of Truth) │
│ Default: "zh-TW" │
└──────────────┬──────────────────────────┬───────────────────────┘
│ │
▼ ▼
┌──────────────────────────┐ ┌──────────────────────────┐
│ Search VLM Language │ │ Agent Output Language │
│ (same as preferred) │ │ (same as preferred) │
│ Scene: EN + localized │ │ Override per-request OK │
│ Trace: EN + localized │ │ Fallback to preferred │
└──────────────────────────┘ └──────────────────────────┘
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial language architecture analysis |
@@ -0,0 +1,152 @@
---
title: Interface Language Operations
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Interface Language Operations Guide
## 1. Interface Language Definition
### Configuration Sources
| Layer | File/Variable | Field | Default | ENV Fallback |
|-------|--------------|-------|---------|--------------|
| **Config File** | `config/admin_config.json` | `admin_settings.preferred_language` | `""` (empty) | `MOMENTRY_PREFERRED_LANGUAGE` → `"zh-TW"` |
| **Runtime** | `config.rs::RUNTIME_PREFERRED_LANGUAGE` | `Lazy<RwLock<String>>` | `"zh-TW"` | `MOMENTRY_PREFERRED_LANGUAGE` |
### Supported Language Codes
| Code | Language | Note |
|------|----------|------|
| `zh-TW` | Traditional Chinese | **System default** |
| `zh-CN` | Simplified Chinese | |
| `ja` | Japanese | |
| `en` | English | |
| `ko` | Korean | Future |
| `es` | Spanish | Future |
| `fr` | French | Future |
| `de` | German | Future |
---
## 2. Language Change Operations
### Method 1: Via API (Recommended)
```bash
# 1. Check current config
curl -s "$API/api/v1/admin/config" -H "X-API-Key: $KEY" | jq '.admin_settings.preferred_language'
# 2. Update to Traditional Chinese
curl -X POST "$API/api/v1/admin/config" \
-H "Content-Type: application/json" \
-H "X-API-Key: $KEY" \
-d '{
"admin_settings": {
"preferred_language": "zh-TW"
}
}'
# 3. Verify
curl -s "$API/api/v1/admin/config" -H "X-API-Key: $KEY" | jq '.admin_settings.preferred_language'
```
### Method 2: Edit JSON File
```bash
# 1. Edit config
vim /Users/accusys/momentry_core/config/admin_config.json
# 2. Modify field
{
"admin_settings": {
"preferred_language": "zh-TW"
}
}
# 3. Reload (no restart needed)
curl -X POST "$API/api/v1/admin/config/reload" -H "X-API-Key: $KEY"
```
### Method 3: Via ENV Variable
```bash
# Set in .env or launchd plist
export MOMENTRY_PREFERRED_LANGUAGE=zh-TW
# Restart server
launchctl stop gui/$(id -u)/com.momentry.server
launchctl start gui/$(id -u)/com.momentry.server
```
---
## 3. Configuration Priority
```
admin_config.json → admin_settings.preferred_language
│
├─ Non-empty → use this value
│
└─ Empty "" → fallback
│
├─ ENV: MOMENTRY_PREFERRED_LANGUAGE
│ ├─ Set → use ENV value
│ └─ Not set → fallback to hardcoded "zh-TW"
│
└─ RUNTIME_PREFERRED_LANGUAGE (in memory)
```
---
## 4. Impact Scope
### Directly Affected
| Component | How Used | After Change |
|-----------|----------|-------------|
| **Frontend Studio** | Reads `/admin/config` → `admin_settings.preferred_language` | UI text language |
| **Worker (init)** | `config.search.vlm_output_language` → `set_preferred_language()` | VLM output language |
| **Scene VLM** | `search.vlm_output_language` | Scene description translation |
### Not Affected
| Component | Reason |
|-----------|--------|
| **Agent Search** | Uses request param `output_language`, not config |
| **BM25/Smart Search** | Returns raw chunk text, language determined by ASR |
| **Tokenizer** | Auto-detects Chinese, config-independent |
---
## 5. Best Practices
| Practice | Description |
|----------|-------------|
| **Explicit JSON values** | Don't leave empty strings; write `"zh-TW"` explicitly |
| **Single update entry** | Use API instead of editing files directly |
| **Verify after change** | Call `/admin/config` to confirm write |
| **Restart worker** | If VLM language changes, restart worker |
| **Version control** | `config/admin_config.json` should be in git |
---
## 6. Open Questions
| ID | Question | Impact |
|----|----------|--------|
| Q1 | Single source of truth for language? | Config simplification |
| Q2 | Empty string = fallback or error? | Config validation |
| Q3 | Browser language auto-detect? | UX improvement |
| Q8 | Merge `vlm_output_language` into `preferred_language`? | Config unification |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial interface language operations guide |
@@ -0,0 +1,107 @@
---
title: Profile Analysis
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Profile/Trace Document Analysis
## Documents Reviewed
| Document | Path | Status |
|----------|------|--------|
| Profile API | `API_WORKSPACE/modules/052_Profile_v1.3.5.md` | Modified |
| People API | `API_WORKSPACE/modules/000_PeopleAPI_v1.0.0.md` | Modified |
| VLM Search | `API_WORKSPACE/modules/032_VLMSearch_v1.3.5.md` | Modified |
| Trace Agent | `API_WORKSPACE/modules/064_TraceAgent_v1.3.5.md` | Needs update |
| Trace Thumbnail | `API_WORKSPACE/modules/054_TraceThumbnail_v1.3.5.md` | OK |
| Studio Bug | `API_WORKSPACE/modules/204_StudioTraceProfileBug_v1.3.5.md` | Status needs update |
| Trace Structure | `REFERENCE/Trace_Structure.md` | Outdated |
| Trace Face Binding | `REFERENCE/Trace_Face_Binding.md` | Outdated |
| Trace Inheritance | `DESIGN/Trace_Inheritance_Rules.md` | DEPRECATED, replacement missing |
---
## Key Findings
### 1. Profile API (052_Profile_v1.3.5.md)
| Item | Status | Note |
|------|--------|------|
| GET /trace-profile | ⚠️ Partial | Doc says `tkg_nodes.label` but code uses `COALESCE(tp.name, tn.label)` JOIN |
| PUT /trace-profile | ✅ OK | Uses `upsert_trace_profile()` |
| PUT /trace-profile/group | ✅ OK | Syncs both `trace_profiles.name` + `tkg_nodes.label` |
| Storage table | ⚠️ Needs update | Says `tkg_nodes` is source, but `trace_profiles` is authoritative |
### 2. People API (000_PeopleAPI_v1.0.0.md)
| Item | Status | Note |
|------|--------|------|
| TEXT match mechanism | ✅ Fixed | Documents `trace_profiles.name` ILIKE |
| Face 512D scope | ✅ Fixed | Documents not used for search |
| VLM fields | ✅ Complete | Lists all `vlm_*` fields |
| trace_profiles schema | ⚠️ Minor | Labeled PostgreSQL but People Search uses TEXT match |
### 3. VLM Search (032_VLMSearch_v1.3.5.md)
| Item | Status | Note |
|------|--------|------|
| Dual VLM architecture | ✅ Fixed | Scene VLM → `_scenes`, Trace VLM → `_vlm` |
| Implementation files | ✅ Correct | Points to correct source files |
| API endpoints | ✅ Complete | All three endpoints documented |
### 4. Trace Agent (064_TraceAgent_v1.3.5.md)
| Item | Status | Note |
|------|--------|------|
| Endpoints | ⚠️ Incomplete | Mostly stubs, missing request/response details |
| Data structures | ❌ Outdated | Lists `face_detections` table, migrated to Qdrant `_faces` |
| Database tables | ❌ Outdated | References old tables |
### 5. Trace Thumbnail (054_TraceThumbnail_v1.3.5.md)
| Item | Status | Note |
|------|--------|------|
| Root cause analysis | ✅ Complete | bbox overflow → ffmpeg silent clamp |
| Behavior | ✅ Correct | Only rewrites cache, no DB/Qdrant impact |
| Studio integration | ✅ Detailed | Cache refresh sequence documented |
### 6. Studio Bug Report (204_StudioTraceProfileBug_v1.3.5.md)
| Item | Status | Note |
|------|--------|------|
| Root cause | ✅ Complete | Write `trace_profiles.name`, read `tkg_nodes.label` |
| Fix | ✅ Implemented | `COALESCE` JOIN in code |
| Status | 🔴 Outdated | Still marked "待修復" but code is fixed |
### 7. Reference Documents
| Document | Status | Issue |
|----------|--------|-------|
| `REFERENCE/Trace_Structure.md` | ❌ Outdated | References `face_detections` table |
| `REFERENCE/Trace_Face_Binding.md` | ❌ Outdated | Heavy `face_detections` references |
| `DESIGN/Trace_Inheritance_Rules.md` | ⚠️ DEPRECATED | Replacement file doesn't exist |
---
## Required Fixes
| Priority | Document | Fix Direction |
|----------|----------|---------------|
| **P0** | `REFERENCE/Trace_Face_Binding.md` | Update to Qdrant `_faces` + `identity_bindings` |
| **P0** | `REFERENCE/Trace_Structure.md` | Update to Qdrant `_faces` + `trace_profiles` |
| **P0** | `DESIGN/Trace_Inheritance_Rules.md` | Create replacement or update |
| **P1** | `052_Profile_v1.3.5.md` | Update GET endpoint to `COALESCE` JOIN |
| **P1** | `064_TraceAgent_v1.3.5.md` | Update table references, complete endpoints |
| **P1** | `204_StudioTraceProfileBug_v1.3.5.md` | Update status to fixed |
| **P2** | `Architecture_Reference.md` | Add `trace_profiles` full field list |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial profile/trace document analysis |
@@ -0,0 +1,201 @@
---
title: JSON Configuration Reference
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# JSON Configuration Reference
## Active Configuration Files
### System Configuration
| File | Path | Purpose | Modified By |
|------|------|---------|-------------|
| **admin_config.json** | `config/admin_config.json` | 系統全域配置 (語言、VLM prompts、processor、路徑) | API + 手動編輯 |
| **processor_tools_v3.json** | `config/processor_tools_v3.json` | Processor 工具選擇與優先級 (V3) | 手動編輯 |
| **pipeline_flows.json** | `config/pipeline_flows.json` | Pipeline 流程定義 | 手動編輯 |
### Deprecated Configuration
| File | Path | Status | Replacement |
|------|------|--------|-------------|
| **processor_tools.json** | `config/processor_tools.json` | ❌ V1 已廢棄 | `processor_tools_v3.json` |
| **processor_tools_v2.json** | `config/processor_tools_v2.json` | ❌ V2 已廢棄 | `processor_tools_v3.json` |
---
## admin_config.json 完整結構
```json
{
"version": "1.0.0",
"updated_at": "ISO8601 timestamp",
"updated_by": "admin",
"vlm_prompts": {
"rust_vlm_summary": { "system_prompt": "...", "user_prompt": "...", "max_tokens": 300, "description": "..." },
"scene_vlm": { "system_prompt": "...", "user_prompt": "...", "max_tokens": 200, "description": "..." }
},
"llm_config": {
"chat": { "url": "http://localhost:8080/v1/chat/completions", "model": "gemma-4-12b-it", "timeout": 30 },
"summary": { "url": "http://localhost:8080/v1/chat/completions", "model": "gemma-4-12b-it", "timeout": 60 }
},
"processor_config": {
"FACE": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "swift" },
"FACE_TRACE": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "rust" },
"POSE": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "swift" },
"CUT": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "rust" },
"ASRX": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "swift" },
"OCR": { "timeout": 3600, "enabled": true, "tools": [...], "default_tool": "swift" }
},
"filter_config": {
"face": { "min_confidence": 0.5, "min_size": 30 }
},
"face_filter_defaults": {
"min_confidence": 50.0,
"min_size": 1,
"min_capture_quality": 0.25
},
"paths": {
"output_dir": "",
"backup_dir": "",
"scripts_dir": "",
"cli_dir": "",
"python_path": "",
"ffmpeg_path": ""
},
"concurrency": {
"max_concurrent_jobs": 0,
"poll_interval": 0,
"batch_size": 0,
"processor_timeout_secs": 0
},
"feature_flags": {
"cache_enabled": false,
"auto_pipeline_enabled": false,
"watcher_auto_register": false,
"summary_enabled": false
},
"server": {
"port": 0,
"media_base_url": "",
"serve_base_url": "",
"storage_root": "",
"timezone": ""
},
"admin_settings": {
"session_timeout": 0,
"max_login_attempts": 0,
"api_key_expiry_days": 0,
"system_stats_refresh_sec": 0,
"preferred_language": ""
},
"search": {
"vlm_min_score": 0.0,
"vlm_output_language": "ja"
},
"pipeline": {
"enabled": true,
"max_concurrent_stages": 5,
"default_timeout_secs": 7200,
"flows": {}
}
}
```
---
## 各區塊說明
### vlm_prompts
| 欄位 | 類型 | 用途 |
|------|------|------|
| `system_prompt` | String | VLM 系統提示詞 |
| `user_prompt` | String | VLM 用戶提示詞 |
| `max_tokens` | Integer | 最大輸出 token 數 |
| `description` | String | 提示詞用途說明 |
### processor_config
| 欄位 | 類型 | 用途 |
|------|------|------|
| `timeout` | Integer | Processor 超時秒數 |
| `enabled` | Boolean | 是否啟用 |
| `tools[]` | Array | 可用工具列表 (name, priority, enabled, parameters) |
| `default_tool` | String | 預設工具名稱 |
### admin_settings
| 欄位 | 類型 | 預設 | 用途 |
|------|------|------|------|
| `preferred_language` | String | `"zh-TW"` | 系統介面語言 |
| `session_timeout` | Integer | 3600 | Session 超時秒數 |
| `max_login_attempts` | Integer | 5 | 最大登入嘗試次數 |
| `api_key_expiry_days` | Integer | 365 | API Key 有效天數 |
### search
| 欄位 | 類型 | 預設 | 用途 |
|------|------|------|------|
| `vlm_min_score` | Float | 0.0 | VLM 搜尋最低分數 |
| `vlm_output_language` | String | `"ja"` | VLM 輸出語言 |
---
## 修改方式
### API 修改
```bash
# 修改語言設定
curl -X POST "$API/api/v1/admin/config" \
-H "Content-Type: application/json" \
-H "X-API-Key: $KEY" \
-d '{
"admin_settings": { "preferred_language": "zh-TW" }
}'
# 修改 VLM prompt
curl -X PUT "$API/api/v1/admin/config/vlm_prompts/rust_vlm_summary" \
-H "Content-Type: application/json" \
-H "X-API-Key: $KEY" \
-d '{
"system_prompt": "...",
"user_prompt": "...",
"max_tokens": 300,
"description": "..."
}'
# 重新載入配置
curl -X POST "$API/api/v1/admin/config/reload" -H "X-API-Key: $KEY"
```
### 直接編輯
```bash
vim /Users/accusys/momentry_core/config/admin_config.json
# 編輯後重啟 server 或呼叫 /admin/config/reload
```
---
## 版本歷史
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial JSON configuration reference |
@@ -0,0 +1,523 @@
---
title: JSON Ecosystem Design
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# JSON Ecosystem Design
## 1. JSON 分類總覽
| 類型 | 位置 | 數量 | 用途 |
|------|------|------|------|
| **管理配置** | `config/*.json` | 3 active + 2 deprecated | 系統行為定義、工具選擇 |
| **處理器產出** | `output/{file_uuid}/*.json` | 10+ | 每檔案處理結果 |
| **Trace 配置** | `output/{file_uuid}/trace_*/trace_profile.json` | N (每 trace 一個) | Trace 元資料、VLM 描述 |
| **語言資源** | `data/*.json` | 2 | 同義詞庫 |
---
## 2. 完整 JSON 管線圖
```
video.mp4
│
├─► probe ────────────────► {uuid}.probe.json ──────────────────────────────────┐
│ │
├─► asr ─────────────────► {uuid}.asr.json ─► asrx ─► {uuid}.asrx.json ──┐ │
│ │ │
├─► face ────────────────► {uuid}.face.json ─► trace ─► {uuid}.face_traced.json ─┤
│ │ │
├─► ocr ─────────────────► {uuid}.ocr.json ──────────┼──────────────────────────┤
│ │ │
├─► cut ─────────────────► {uuid}.cut.json ──────────┼──────────────────────────┤
│ │ │
├─► pose ────────────────► {uuid}.pose.json ─────────┼──────────────────────────┤
│ │ │
├─► yolo ────────────────► {uuid}.yolo.json ─────────┼──────────────────────────┤
│ │ │
└─► scenes ──────────────► {uuid}.scenes.json ─► VLM ─┼──► {uuid}.scene_vlm.json│
│ │
{uuid}.face_traced.json ─► cluster ─┼──► {uuid}.face_cluster.json
│
trace_*/trace_profile.json ◄── VLM Summary
│
{uuid}.tkg.json ◄── TKG Builder ────┘
```
---
## 3. 管理配置 JSON
### 3.1 admin_config.json
**路徑**: `config/admin_config.json`
**用途**: 系統全域配置
**修改方式**: API (`POST /api/v1/admin/config`) + 手動編輯
**載入時機**: Server 啟動時 + `/admin/config/reload`
| 區塊 | 欄位 | 類型 | 預設 | 用途 |
|------|------|------|------|------|
| `vlm_prompts` | `rust_vlm_summary` | Object | - | Trace VLM 提示詞 |
| | `scene_vlm` | Object | - | Scene VLM 提示詞 |
| `llm_config` | `chat` | Object | localhost:8080 | Chat LLM 配置 |
| | `summary` | Object | localhost:8080 | Summary LLM 配置 |
| `processor_config` | `FACE/POSE/CUT/...` | Object | - | Processor 工具選擇 |
| `filter_config` | `face` | Object | conf:0.5, size:30 | Face 過濾條件 |
| `face_filter_defaults` | - | Object | conf:50%, size:1 | 前端預設值 |
| `paths` | `output_dir/scripts_dir/...` | String | ENV fallback | 系統路徑 |
| `concurrency` | `max_concurrent_jobs/...` | Integer | 6/10/10/3600 | Worker 並發 |
| `feature_flags` | `cache_enabled/...` | Boolean | false | 功能開關 |
| `server` | `port/timezone/...` | String/Int | 3002/Asia/Taipei | 服務器配置 |
| `admin_settings` | `preferred_language/...` | String | zh-TW | 管理員設定 |
| `search` | `vlm_min_score/vlm_output_language` | Float/String | 0.0/ja | 搜尋配置 |
| `pipeline` | `enabled/max_concurrent_stages` | Bool/Int | true/5 | Pipeline 配置 |
**Consumer**: 所有模組讀取 (`AdminConfigManager`)
### 3.2 processor_tools_v3.json
**路徑**: `config/processor_tools_v3.json`
**用途**: Processor 工具選擇與優先級定義
**修改方式**: 手動編輯
**載入時機**: ToolSelector 初始化時
| Processor | 工具 | Priority | Output File | Timeout |
|-----------|------|----------|-------------|---------|
| `face` | swift_face | 0 | `{uuid}.face.json` | 3600s |
| `asr` | rust_whisper | 0 | `{uuid}.asr.json` | 3600s |
| `asrx` | rust_asrx | 0 | `{uuid}.asrx.json` | 1800s |
| `ocr` | swift_ocr | 0 | `{uuid}.ocr.json` | 3600s |
| `face_trace` | rust_store_traced_faces | 0 | `{uuid}.face_traced.json` | 600s |
| `scene_vlm_summary` | rust_scene_vlm | 0 | `{uuid}.scene_vlm.json` | 1800s |
| `tkg` | rust_tkg | 0 | `{uuid}.tkg.json` | 1800s |
| `cut` | rust_cut | 0 | `{uuid}.cut.json` | 1800s |
**Consumer**: `ToolSelector` (`src/core/processor/tool_selector.rs`)
### 3.3 pipeline_flows.json
**路徑**: `config/pipeline_flows.json`
**用途**: Pipeline 流程定義 (stages, dependencies)
**修改方式**: 手動編輯
**Consumer**: Pipeline 調度器
### 3.4 Deprecated Files
| File | Status | Replacement |
|------|--------|-------------|
| `config/processor_tools.json` | ❌ V1 已廢棄 | `processor_tools_v3.json` |
| `config/processor_tools_v2.json` | ❌ V2 已廢棄 | `processor_tools_v3.json` |
---
## 4. 處理器產出 JSON
### 4.1 產出對照表
| JSON 檔案 | Producer (生產工具) | Consumer (消費程序) | Downstream 影響 |
|-----------|-------------------|-------------------|----------------|
| `{uuid}.probe.json` | ffprobe | Registration, FileProfile | 檔案元資料 (duration/fps/resolution) |
| `{uuid}.asr.json` | ASR Processor (whisper) | ASRX Processor | 語音識別原始結果 → 說話人分段 |
| `{uuid}.asrx.json` | ASRX Processor | Chunk, Embedding, Search | 說話人分段 → 文本搜尋 |
| `{uuid}.face.json` | Face Processor (Swift/Rust) | Face Trace Processor | 人臉偵測 → 軌跡追蹤 |
| `{uuid}.face_traced.json` | Face Trace Processor | Clustering, TKG, Profile | 人臉軌跡 → 分群/知識圖譜 |
| `{uuid}.face_cluster.json` | Face Cluster Tool | People Search, Identity | 人臉分群 → 人物搜尋 |
| `{uuid}.ocr.json` | OCR Processor (Swift) | Keyword Search | 文字識別 → 關鍵字搜尋 |
| `{uuid}.cut.json` | Cut Processor (Rust) | Chunk, Scenes | 場景分割 → 文本分塊 |
| `{uuid}.scenes.json` | Scene Detector | Scene VLM | 場景資訊 → VLM 描述 |
| `{uuid}.scene_vlm.json` | Scene VLM (Gemma4) | VLM Search | 場景描述 → 向量搜尋 |
| `{uuid}.pose.json` | Pose Processor | Appearance, TKG | 姿態估計 → 外觀分析 |
| `{uuid}.yolo.json` | YOLO Processor | Frame Search | 物件偵測 → 畫面搜尋 |
| `{uuid}.tkg.json` | TKG Builder | Agent TKG Tools | 知識圖譜 → Agent 查詢 |
### 4.2 各 JSON 詳細結構
#### probe.json
```json
{
"file_uuid": "abc123...",
"duration": 120.5,
"width": 1920,
"height": 1080,
"fps": 29.97,
"codec": "h264",
"audio_codec": "aac",
"total_frames": 3612
}
```
**Producer**: ffprobe
**Consumer**: `FileProfile` (`src/core/file_profile.rs`)
#### asr.json
```json
{
"language": "en",
"language_probability": 0.95,
"text": "Hello world...",
"segments": [
{
"start": 0.0,
"end": 2.5,
"text": "Hello world",
"confidence": 0.9
}
]
}
```
**Producer**: ASR Processor (whisper)
**Consumer**: ASRX Processor (唯一消費者)
#### asrx.json
```json
{
"speakers": [
{
"speaker_id": "SPEAKER_0",
"segments": [
{
"start": 0.0,
"end": 5.2,
"text": "Hello, how are you?"
}
]
}
],
"language": "en"
}
```
**Producer**: ASRX Processor
**Consumer**: Chunk Processor → PostgreSQL `chunks` → Qdrant `_chunks`
#### face.json
```json
{
"status": "has_faces",
"frame_count": 150,
"frames": {
"92": {
"frame_number": 92,
"time_seconds": 3.07,
"faces": [
{
"x": 313, "y": 468, "width": 53, "height": 53,
"confidence": 0.6,
"captureQuality": 0.1
}
]
}
}
}
```
**Producer**: Face Processor (`swift_face` or Python)
**Consumer**: Face Trace Processor
#### face_traced.json
```json
{
"status": "has_faces",
"frame_count": 150,
"fps": 29.97,
"frames": {
"92": {
"frame_number": 92,
"time_seconds": 3.07,
"faces": [
{
"x": 313, "y": 468, "width": 53, "height": 53,
"confidence": 0.6,
"captureQuality": 0.1,
"trace_id": 1
}
]
}
},
"traces": [
{
"trace_id": 1,
"face_count": 50,
"frames": [92, 93, 94, ...]
}
]
}
```
**Producer**: Face Trace Processor (`rust_store_traced_faces`)
**Consumer**:
- Face Clustering → `face_cluster.json`
- TKG Builder → `tkg_nodes` (face_track)
- VLM Summary → `trace_profile.json`
#### face_cluster.json
```json
{
"status": "has_faces",
"file_uuid": "abc123...",
"clusters": [
{
"cluster_id": 0,
"face_count": 150,
"representative_frame": 100,
"frames": [92, 93, 94, ...],
"group_name": "Person_0"
}
]
}
```
**Producer**: Face Cluster Tool (`rust_face_cluster`)
**Consumer**:
- People Search (TEXT match on `group_name`)
- Identity binding
#### ocr.json
```json
{
"frames": {
"100": {
"frame_number": 100,
"texts": ["Hello", "World"]
}
}
}
```
**Producer**: OCR Processor (`swift_ocr`)
**Consumer**: Keyword Search (PostgreSQL FTS)
#### cut.json
```json
{
"cuts": [
{
"cut_number": 1,
"start_frame": 0,
"end_frame": 150,
"start_time": 0.0,
"end_time": 5.0
}
]
}
```
**Producer**: Cut Processor (`rust_cut`)
**Consumer**:
- Chunk Processor (scene-based chunking)
- Scene Detector
#### scenes.json
```json
{
"scenes": [
{
"scene_index": 1,
"start_time": 0.0,
"end_time": 10.5,
"key_frame": 150
}
]
}
```
**Producer**: Scene Detector
**Consumer**: Scene VLM → `scene_vlm.json`
#### scene_vlm.json
```json
{
"scenes": [
{
"scene_index": 1,
"vlm_description": "A man standing in a park",
"vlm_description_localized": "一名男子站在公園裡",
"vlm_objects": ["man", "park", "tree"],
"vlm_tags": [
{"en": "outdoor", "local": "戶外"}
]
}
]
}
```
**Producer**: Scene VLM (`rust_scene_vlm` + Gemma4)
**Consumer**: VLM Search → Qdrant `_scenes`
#### pose.json
```json
{
"frames": {
"100": {
"frame_number": 100,
"trace_id": 1,
"keypoints": [...]
}
}
}
```
**Producer**: Pose Processor (`swift_pose` or MediaPipe)
**Consumer**: Appearance expansion, TKG
#### yolo.json
```json
{
"frames": {
"100": {
"frame_number": 100,
"detections": [
{"class": "person", "confidence": 0.9, "bbox": [...]}
]
}
}
}
```
**Producer**: YOLO Processor (`swift_yolo`)
**Consumer**: Frame Search
#### tkg.json
```json
{
"nodes": [...],
"edges": [...]
}
```
**Producer**: TKG Builder (`rust_tkg`)
**Consumer**: Agent TKG Tools
---
## 5. Trace Profile JSON
### 位置
`output/{file_uuid}/trace_{id}/trace_profile.json`
### 結構
```json
{
"version": "1.0",
"file_uuid": "abc123...",
"trace_id": 1,
"label": "Person_0",
"frame_count": 50,
"start_frame": 92,
"end_frame": 242,
"best_frame": 150,
"avg_confidence": 0.75,
"best_confidence": 0.92,
"avg_capture_quality": 0.6,
"best_capture_quality": 0.85,
"avg_bbox": {"x": 300, "y": 400, "width": 80, "height": 80},
"key_frame": "key_frame.jpg",
"key_face": "key_face.jpg",
"status": "pending",
"vlm_summary": "A person wearing a blue shirt..."
}
```
### 生命週期
```
face_traced.json ─► Profile 建立 (new)
│
├─► VLM Summary ─► vlm_summary 填入
│
└─► User rename ─► label 更新
│
└─► PostgreSQL trace_profiles 同步
│
└─► People Search 可用
```
**Producer**: `FaceTraceProfile` (`src/core/file_profile.rs`)
**Consumer**:
- Profile API (`GET/PUT /api/v1/trace-profile`)
- People Search (TEXT match on `label`)
- VLM Search (enrichment)
---
## 6. 語言資源 JSON
### 6.1 english_synonyms.json
**路徑**: `data/english_synonyms.json`
**用途**: 英文同義詞擴展 (BM25 搜尋)
**格式**: `{word: [synonym1, synonym2, ...]}`
**Consumer**: `SynonymExpander` (`src/core/text/synonym_expander.rs`)
### 6.2 llm_synonyms.json
**路徑**: `data/llm_synonyms.json`
**用途**: LLM 生成的同義詞 (27 中文 + 135 英文)
**產生方式**: `scripts/generate_synonyms_llamacpp.py`
**格式**: `{word: [synonym1, synonym2, ...]}`
**Consumer**: `SynonymExpander` (合併載入)
---
## 7. JSON 依賴關係總結
```
admin_config.json ─────────────────────────────────────────────────┐
│ │
├─► vlm_prompts ──────► Scene VLM / Trace VLM │
├─► processor_config ─► ToolSelector ─► 所有 Processor │
├─► search ───────────► VLM Search / Agent Search │
└─► admin_settings ───► Worker / Preferred Language │
│
processor_tools_v3.json ──────────────────────────────────────────┤
│ │
├─► FACE ────► swift_face ─────────► face.json │
├─► ASR ─────► rust_whisper ───────► asr.json │
├─► ASRX ────► rust_asrx ─────────► asrx.json │
├─► OCR ─────► swift_ocr ─────────► ocr.json │
├─► FACE_TRACE► rust_store_traced_faces ► face_traced.json │
├─► CUT ─────► rust_cut ─────────► cut.json │
├─► SCENE_VLM► rust_scene_vlm ───► scene_vlm.json │
└─► TKG ─────► rust_tkg ─────────► tkg.json │
│
probe.json ───► FileProfile ───► videos table │
asr.json ───► ASRX ───► asrx.json ───► chunks ───► Qdrant _chunks │
face.json ──► Trace ───► face_traced.json ──┬─► Cluster ──► face_cluster.json
├─► TKG ──► tkg_nodes
└─► VLM ──► trace_profile.json
ocr.json ───► Keyword Search ───► PostgreSQL FTS │
cut.json ───► Chunk/Scenes │
scenes.json► Scene VLM ───► scene_vlm.json ───► Qdrant _scenes │
pose.json ─► Appearance/TKG │
yolo.json ► Frame Search │
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial JSON ecosystem design |
@@ -0,0 +1,149 @@
---
title: MarkBase Server API
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# MarkBase Server API
**路徑**: `~/markbase`
**Port**: 11438
**定位**: 檔案管理、路徑註冊、專案管理
---
## 現有 Endpoints
### `GET /api/v2/myfiles/:username/files`
列出用戶檔案。
**Response**:
```json
[
{
"file_uuid": "...",
"file_path": "...",
"name": "video.mp4",
"size": 1048576,
"modified": "2026-11-01T10:00:00Z",
"folder": "demo"
}
]
```
### `GET /api/v2/myfiles/:username/folders`
列出用戶資料夾。
---
## 需求 Endpoints
### `GET /api/v2/paths`
列出所有註冊路徑。
**Response**:
```json
[
{
"path_key": "output_dir",
"path_value": "/Users/accusys/momentry/output",
"category": "config"
}
]
```
### `POST /api/v2/paths`
註冊新路徑。
**Request**:
```json
{
"path_key": "output_dir",
"path_value": "/Users/accusys/momentry/output",
"category": "config",
"description": "Output directory"
}
```
### `GET /api/v2/paths/{key}`
查詢單一路徑。
### `PUT /api/v2/paths/{key}`
更新路徑。
### `GET /api/v2/paths/resolve/{template}`
解析路徑模板。
**Example**: `/api/v2/paths/resolve/{output_dir}/{file_uuid}.asr.json`
**Response**: `/Users/accusys/momentry/output/abc123.asr.json`
### `GET /api/v2/outputs/{file_uuid}`
查詢產出檔案。
### `POST /api/v2/outputs`
記錄產出檔案。
### `GET /api/v2/opencode/projects`
列出 OpenCode 專案。
### `POST /api/v2/opencode/projects`
註冊新專案。
### `GET /api/v2/opencode/workspaces`
列出 Workspace。
### `POST /api/v2/opencode/workspaces`
建立新 Workspace。
---
## 資料庫 Schema
```sql
CREATE TABLE path_registry (
id INTEGER PRIMARY KEY,
path_key TEXT UNIQUE,
path_value TEXT,
category TEXT,
is_template BOOLEAN DEFAULT FALSE
);
CREATE TABLE file_outputs (
id INTEGER PRIMARY KEY,
file_uuid TEXT,
output_type TEXT,
file_path TEXT,
status TEXT DEFAULT 'completed'
);
CREATE TABLE opencode_projects (
id INTEGER PRIMARY KEY,
project_key TEXT UNIQUE,
name TEXT,
git_path TEXT
);
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial API documentation |
@@ -0,0 +1,101 @@
---
title: MarkBaseEngine API
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# MarkBaseEngine API
**路徑**: `~/MarkBaseEngine`
**Port**: TBD (開發中)
**定位**: 高效 LLM/VLM 多模態運行引擎
---
## 功能概述
MarkBaseEngine 是 Momentry Suite 的 AI 推理引擎,提供:
| 功能 | 說明 |
|------|------|
| LLM Inference | 文字生成、對話 |
| VLM Inference | 視覺理解、圖像描述 |
| Embedding | 向量生成 |
| 多模態 | 圖文混合輸入 |
| 模型管理 | 載入、切換、健康檢查 |
---
## 需求 Endpoints
### `POST /api/v1/engine/llm`
LLM 文字推理。
**Request**:
```json
{
"model": "gemma-4-12b-it",
"prompt": "Hello",
"max_tokens": 300
}
```
### `POST /api/v1/engine/vlm`
VLM 視覺推理。
**Request**:
```json
{
"model": "gemma-4-12b-it",
"image": "base64...",
"prompt": "Describe this image",
"max_tokens": 500
}
```
### `POST /api/v1/engine/embedding`
Embedding 向量生成。
**Request**:
```json
{
"model": "embeddinggemma-300m",
"text": "Hello world"
}
```
### `GET /api/v1/engine/models`
列出可用模型。
### `POST /api/v1/engine/models/{name}/load`
載入模型。
### `GET /api/v1/engine/health`
健康檢查。
---
## 待確認事項
| 項目 | 狀態 |
|------|------|
| Port 號碼 | ⏳ 待定 |
| 現有 endpoints | ⏳ 待確認 |
| 模型清單 | ⏳ 待確認 |
| API 格式 (HTTP/gRPC) | ⏳ 待確認 |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial API documentation (draft) |
@@ -0,0 +1,74 @@
---
title: Core API - File Management
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 檔案管理
**Base URL**: `http://localhost:3002`
**分類**: A
---
## `GET /api/v1/files`
列出所有檔案。
## `GET /api/v1/file/:file_uuid`
取得檔案詳情。
## `POST /api/v1/file/:file_uuid/register`
註冊檔案。
## `DELETE /api/v1/file/:file_uuid`
登出檔案。
## `GET /api/v1/file/:file_uuid/video`
影片串流。
## `GET /api/v1/file/:file_uuid/thumbnail`
縮圖。
## `GET /api/v1/file/:file_uuid/face-thumbnail`
人臉縮圖。
## `GET /api/v1/file/:file_uuid/clip`
影片剪輯。
## `GET /api/v1/file/thumbnail`
路徑縮圖。
## `GET /api/v1/file/:file_uuid/scene/:scene_index/thumbnail`
場景縮圖。
## `GET /api/v1/file/:file_uuid/trace/:trace_id/thumbnail`
Trace 縮圖。
## `POST /api/v1/file/:file_uuid/scan`
掃描檔案。
## `GET /api/v1/file/:file_uuid/stats`
檔案統計。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,54 @@
---
title: Core API - Pipeline
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 處理管線
**Base URL**: `http://localhost:3002`
**分類**: B
---
## `POST /api/v1/file/:file_uuid/pipeline`
執行完整處理管線。
## `POST /api/v1/file/:file_uuid/store-asrx`
ASRX 儲存。
## `POST /api/v1/file/:file_uuid/rule1`
Rule1 處理。
## `POST /api/v1/file/:file_uuid/vectorize`
向量化處理。
## `POST /api/v1/file/:file_uuid/phase1`
Phase1 處理。
## `POST /api/v1/file/:file_uuid/complete`
完成處理。
## `GET /api/v1/pipeline/status/:command_id`
查詢管線狀態。
## `POST /api/v1/pipeline/progress/:command_id`
更新進度。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,54 @@
---
title: Core API - Search
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 搜尋
**Base URL**: `http://localhost:3002`
**分類**: C
---
## `POST /api/v1/search/smart`
智慧搜尋 (向量 + 關鍵字)。
## `POST /api/v1/search/keyword`
關鍵字搜尋 (BM25)。
## `POST /api/v1/search/semantic`
語意搜尋 (Embedding)。
## `POST /api/v1/search/vlm/scenes`
VLM 場景搜尋。
## `POST /api/v1/search/vlm/traces`
VLM 軌跡搜尋。
## `POST /api/v1/search/frames`
畫面搜尋 (YOLO/OCR/Face)。
## `GET /api/v1/search/people`
人物搜尋。
## `POST /api/v1/search/llm-smart`
LLM 重排搜尋。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,66 @@
---
title: Core API - Identity
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 身份與人物
**Base URL**: `http://localhost:3002`
**分類**: D
---
## `GET /api/v1/identities`
列出所有身份。
## `POST /api/v1/identities`
建立新身份。
## `GET /api/v1/identity/:identity_uuid`
取得身份詳情。
## `POST /api/v1/identity/:identity_uuid/bind`
綁定身份到 Trace。
## `POST /api/v1/identity/:identity_uuid/unbind`
解綁身份。
## `POST /api/v1/identity/:from_uuid/mergeinto`
合併身份。
## `POST /api/v1/identity/:identity_uuid/undo`
復原身份操作。
## `POST /api/v1/identity/:identity_uuid/redo`
重做身份操作。
## `POST /api/v1/identity/upload`
上傳身份資料。
## `GET /api/v1/search/identity_text`
身份文字搜尋。
## `GET /api/v1/identities/search`
身份文字搜尋 (替代)。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,82 @@
---
title: Core API - Trace
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — Trace 管理
**Base URL**: `http://localhost:3002`
**分類**: E
---
## `POST /api/v1/file/:file_uuid/traces`
列出 Trace 列表。
## `GET /api/v1/file/:file_uuid/trace/:trace_id/faces`
取得 Trace 人臉。
## `GET /api/v1/file/:file_uuid/trace/:trace_id/representative-face`
代表性人臉。
## `GET /api/v1/trace-profile`
取得 Trace 配置。
## `PUT /api/v1/trace-profile`
更新 Trace 配置。
## `PUT /api/v1/trace-profile/group`
批次更新 Trace 群組。
## `POST /api/v1/file/:file_uuid/groups/merge`
合併 Trace 群組。
## `POST /api/v1/file/:file_uuid/tkg/rebuild`
重建 TKG。
## `GET /api/v1/file/:file_uuid/tkg`
取得 TKG 操作。
## `DELETE /api/v1/file/:file_uuid/tkg`
刪除 TKG。
## `POST /api/v1/file/:file_uuid/rule2`
Rule2 處理。
## `POST /api/v1/file/:file_uuid/tkg/nodes`
查詢 TKG 節點。
## `POST /api/v1/file/:file_uuid/tkg/edges`
查詢 TKG 邊。
## `GET /api/v1/file/:file_uuid/representative-frame`
代表性幀。
## `POST /api/v1/file/:file_uuid/trace/:trace_id/regenerate-thumbnail`
重新產生縮圖。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,54 @@
---
title: Core API - Admin
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 系統管理
**Base URL**: `http://localhost:3002`
**分類**: F
---
## `GET /api/v1/admin/config`
取得完整系統配置。
## `POST /api/v1/admin/config`
更新系統配置。
## `GET /api/v1/admin/config/vlm_prompts`
取得所有 VLM prompts。
## `GET /api/v1/admin/config/vlm_prompts/:key`
取得單一 VLM prompt。
## `PUT /api/v1/admin/config/vlm_prompts/:key`
更新 VLM prompt。
## `POST /api/v1/admin/config/reload`
重新載入配置。
## `GET /api/v1/admin/settings`
取得系統設定 (前端相容)。
## `POST /api/v1/admin/sync-status`
同步所有檔案狀態。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,62 @@
---
title: Core API - Media
version: 1.0
date: 2026-11-01
author: Core Team
status: Active
---
# Core API — 媒體
**Base URL**: `http://localhost:3002`
**分類**: G
---
## `GET /api/v1/face-thumbnail`
人臉縮圖 (相容層)。
## `GET /api/v1/file/:file_uuid/video`
影片串流。
## `GET /api/v1/file/:file_uuid/thumbnail`
檔案縮圖。
## `GET /api/v1/file/thumbnail`
路徑縮圖。
## `GET /api/v1/file/:file_uuid/scene/:scene_index/thumbnail`
場景縮圖。
## `GET /api/v1/file/:file_uuid/trace/:trace_id/thumbnail`
Trace 縮圖。
## `GET /api/v1/file/:file_uuid/clip`
影片剪輯。
## `GET /api/v1/file/:file_uuid/pose`
姿態資料。
## `GET /api/v1/file/:file_uuid/appearance`
外觀資料。
## `GET /api/v1/media-proxy`
媒體代理。
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,64 @@
---
title: Momentry Studio Proxy API
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Momentry Studio Proxy API
**路徑**: `~/momentry_studio`
**Port**: 8888
**定位**: 前端 Proxy (App + Web)
---
## 功能概述
Studio Proxy 作為前端應用程式的 API 閘道,提供:
| 功能 | 說明 |
|------|------|
| App API Proxy | 行動端 API 轉發 |
| Web API Proxy | 網頁端 API 轉發 |
| 認證 | JWT/Session 管理 |
| 快取 | 前端資料快取 |
---
## Proxy 路由
| 前端路徑 | 後端目標 | 說明 |
|----------|---------|------|
| `/api/v1/*` | `http://localhost:3002/api/v1/*` | Core API Proxy |
| `/api/v2/*` | `http://localhost:11438/api/v2/*` | MarkBase API Proxy |
---
## 認證機制
| 機制 | 說明 |
|------|------|
| JWT | Token-based 認證 |
| Session | Cookie-based 會話 |
| API Key | 服務間認證 |
---
## 待確認事項
| 項目 | 狀態 |
|------|------|
| 現有 endpoints | ⏳ 待確認 |
| 認證方式 | ⏳ 待確認 |
| 快取策略 | ⏳ 待確認 |
| CORS 設定 | ⏳ 待確認 |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial API documentation (draft) |
@@ -0,0 +1,128 @@
---
title: Admin Environment Management
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Admin Environment Management
**路徑**: `~/admin`
**定位**: 環境管理、問題處理
---
## 目錄結構
```
~/admin/
├── config/
│ ├── servers.json # 伺服器清單
│ ├── services.json # 服務清單
│ └── environments/ # 環境設定
├── scripts/
│ ├── deploy.sh # 部署腳本
│ ├── rollback.sh # 回滾腳本
│ ├── health_check.sh # 健康檢查
│ └── backup.sh # 備份腳本
├── logs/
├── troubleshooting/
├── monitoring/
└── incidents/
```
---
## 伺服器清單
`config/servers.json`:
```json
[
{
"name": "m5max128",
"ip": "192.168.110.201",
"role": "primary",
"services": ["momentry_core", "markbase", "markbaseengine"]
},
{
"name": "m5max48",
"ip": "192.168.110.200",
"role": "ci_runner",
"services": ["gitea_actions"]
},
{
"name": "m4mini",
"ip": "192.168.110.210",
"role": "gitea",
"services": ["gitea"]
},
{
"name": "m4promini",
"ip": "192.168.110.203",
"role": "studio",
"services": ["momentry_studio"]
}
]
```
---
## 服務清單
`config/services.json`:
```json
[
{
"name": "momentry_core",
"port": 3002,
"server": "m5max128",
"manager": "launchd"
},
{
"name": "markbase",
"port": 11438,
"server": "m5max128",
"manager": "launchd"
},
{
"name": "markbaseengine",
"port": "TBD",
"server": "m5max128",
"manager": "launchd"
},
{
"name": "momentry_studio_proxy",
"port": 8888,
"server": "m4promini",
"manager": "pm2"
},
{
"name": "gitea",
"port": 3000,
"server": "m4mini",
"manager": "docker"
}
]
```
---
## 健康檢查腳本
`scripts/health_check.sh`:
```bash
#!/bin/bash
# Check all services
for service in momentry_core markbase markbaseengine; do
curl -sf http://localhost:$PORT/health && echo "$service: OK" || echo "$service: FAIL"
done
```
---
## 版本歷史
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,65 @@
---
title: Cross-Project Collaboration Design
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Cross-Project Collaboration Design
## 專案架構
| 專案 | 路徑 | Port | 定位 |
|------|------|------|------|
| markbase | `~/markbase` | 11438 | 檔案管理、路徑註冊 |
| MarkBaseEngine | `~/MarkBaseEngine` | TBD | LLM/VLM 推理引擎 |
| momentry_core | `~/momentry_core` | 3002 | 影片分析核心 |
| momentry_studio | `~/momentry_studio` | 8888 | 前端 Proxy |
| admin | `~/admin` | - | 環境管理 |
## 依賴關係
| 來源 | 目標 | 類型 | 說明 |
|------|------|------|------|
| momentry_core | markbase | API | 檔案列表、路徑查詢 |
| momentry_core | MarkBaseEngine | API | LLM/VLM 推理 |
| momentry_studio | momentry_core | API | 核心功能 |
| momentry_studio | markbase | API | 檔案瀏覽 |
| markbaseengine | markbase | API | 結果回報 |
## Workspace 定義
```sql
CREATE TABLE workspaces (
id INTEGER PRIMARY KEY,
workspace_key TEXT UNIQUE,
name TEXT,
description TEXT
);
CREATE TABLE workspace_projects (
workspace_id INTEGER,
project_key TEXT,
role TEXT DEFAULT 'member',
PRIMARY KEY (workspace_id, project_key)
);
```
## 共享 AGENTS.md
```
workspace/AGENTS.md (共享規則)
├─ momentry_core/AGENTS.md (extends workspace + local)
├─ momentry_studio/AGENTS.md (extends workspace + local)
├─ markbase/AGENTS.md (extends workspace + local)
└─ markbaseengine/AGENTS.md (extends workspace + local)
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,50 @@
---
title: Workspace Management
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Workspace Management
## Workspace 定義
**momentry_suite**: 包含 markbase, MarkBaseEngine, momentry_core, momentry_studio
## API 設計
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/workspaces` | GET | 列出 Workspace |
| `/api/v2/opencode/workspaces` | POST | 建立 Workspace |
| `/api/v2/opencode/workspaces/{key}` | GET | 查詢 Workspace |
| `/api/v2/opencode/workspaces/{key}/projects` | GET | 列出專案 |
| `/api/v2/opencode/workspaces/{key}/projects` | POST | 加入專案 |
## Schema
```sql
CREATE TABLE workspaces (
id INTEGER PRIMARY KEY AUTOINCREMENT,
workspace_key TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
description TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE workspace_projects (
workspace_id INTEGER NOT NULL REFERENCES workspaces(id),
project_key TEXT NOT NULL,
role TEXT DEFAULT 'member',
PRIMARY KEY (workspace_id, project_key)
);
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,56 @@
---
title: Shared AGENTS.md Mechanism
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Shared AGENTS.md Mechanism
## 層級結構
```
workspace/AGENTS.md (全域規則)
├─ momentry_core/AGENTS.md (extends workspace + Rust/Core rules)
├─ momentry_studio/AGENTS.md (extends workspace + Vue/Studio rules)
├─ markbase/AGENTS.md (extends workspace + MarkBase rules)
└─ markbaseengine/AGENTS.md (extends workspace + Engine rules)
```
## Workspace AGENTS.md 內容
```markdown
# Momentry Suite - Shared Rules
## Cross-Project Rules
- All API changes must include integration tests
- Breaking changes require milestone approval
- Sandbox testing required before merge
## Communication
- Use Gitea Issues for requirements
- Use PR for code review
- CI must pass before merge
```
## 繼承機制
專案 AGENTS.md 使用 `extends` 標記繼承 workspace 規則:
```markdown
<!-- extends: ../workspace/AGENTS.md -->
# Momentry Core - Local Rules
## Rust Conventions
...
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,75 @@
---
title: Sandbox Design
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Sandbox Design
## 架構
```
/sandboxes/{workspace}_{date}_{id}/
├── markbase/
│ ├── .git/
│ └── src/
├── markbaseengine/
│ ├── .git/
│ └── src/
├── momentry_core/
│ ├── .git/
│ ├── AGENTS.md
│ └── src/
├── momentry_studio/
│ ├── .git/
│ ├── AGENTS.md
│ └── src/
├── shared/
│ ├── AGENTS.md
│ └── test_config.json
└── scripts/
├── start_services.sh
└── run_tests.sh
```
## 生命週期
```
建立 → 就緒 → 測試中 → 完成 → 清理
```
## API
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/sandboxes` | POST | 建立 Sandbox |
| `/api/v2/opencode/sandboxes` | GET | 列出 Sandbox |
| `/api/v2/opencode/sandboxes/{id}` | GET | 查詢狀態 |
| `/api/v2/opencode/sandboxes/{id}/start` | POST | 啟動 |
| `/api/v2/opencode/sandboxes/{id}/stop` | POST | 停止 |
| `/api/v2/opencode/sandboxes/{id}/destroy` | POST | 銷毀 |
## Schema
```sql
CREATE TABLE sandboxes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
workspace_id INTEGER REFERENCES workspaces(id),
sandbox_id TEXT NOT NULL UNIQUE,
projects JSON NOT NULL,
base_path TEXT NOT NULL,
status TEXT DEFAULT 'creating',
purpose TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,65 @@
---
title: Path Registry Design
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Path Registry Design
## 路徑定義
| path_key | path_value | category |
|----------|-----------|----------|
| `output_dir` | `/Users/accusys/momentry/output` | config |
| `backup_dir` | `/Users/accusys/momentry/backup` | config |
| `scripts_dir` | `tools/script/` | config |
| `cli_dir` | `tools/cli/` | config |
| `markbase.port` | `11438` | config |
| `studio.proxy_port` | `8888` | config |
| `admin.base` | `/Users/accusys/admin` | config |
| `output_pattern.asr` | `{output_dir}/{file_uuid}.asr.json` | template |
| `output_pattern.face` | `{output_dir}/{file_uuid}.face.json` | template |
| `output_pattern.asrx` | `{output_dir}/{file_uuid}.asrx.json` | template |
## API
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/paths` | GET | 列出所有路徑 |
| `/api/v2/paths` | POST | 註冊新路徑 |
| `/api/v2/paths/{key}` | GET | 查詢單一路徑 |
| `/api/v2/paths/{key}` | PUT | 更新路徑 |
| `/api/v2/paths/resolve/{template}` | GET | 解析路徑模板 |
## Schema
```sql
CREATE TABLE path_registry (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path_key TEXT NOT NULL UNIQUE,
path_value TEXT NOT NULL,
category TEXT,
is_template BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```
## 模板語法
| 變數 | 說明 | 範例 |
|------|------|------|
| `{output_dir}` | 輸出目錄 | `/Users/.../output` |
| `{file_uuid}` | 檔案 UUID | `abc123...` |
| `{trace_id}` | Trace ID | `1` |
| `{scene_index}` | 場景索引 | `5` |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,53 @@
---
title: Gitea Workflow
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Gitea Workflow
## Gitea 設定
| 項目 | 值 |
|------|-----|
| 位置 | m4mini (192.168.110.210) |
| URL | http://192.168.110.210:3000 |
| 專案 | markbase, MarkBaseEngine, momentry_core, momentry_studio |
## 標籤體系
| Label | Color | 用途 |
|-------|-------|------|
| `project:markbase` | #1D76DB | MarkBase 相關 |
| `project:markbaseengine` | #5319E7 | MarkBaseEngine 相關 |
| `project:momentry_core` | #FF8C00 | Core 相關 |
| `project:momentry_studio` | #006B75 | Studio 相關 |
| `cross-project` | #8B4513 | 跨專案 |
| `type:feature` | #0E8A16 | 新功能 |
| `type:bug` | #D93F0B | 錯誤 |
| `type:requirement` | #1D76DB | 需求 |
| `priority:P0` | #D93F0B | 緊急 |
| `priority:P1` | #FBCA04 | 高 |
| `priority:P2` | #0E8A16 | 中 |
## Issue 模板
- `requirement.md` — 跨專案需求
- `cross-bug.md` — 跨專案 Bug 會診
- `feature.md` — 新功能
## PR 流程
```
PR Created → CI Test → Code Review → Merge → Release
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,60 @@
---
title: CI/CD Design
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# CI/CD Design
## Runner 設定
| 項目 | 值 |
|------|-----|
| 位置 | M5Max48 |
| 類型 | Self-hosted |
| 用途 | 整合測試、Sandbox |
## Workflow 矩陣
| Workflow | 觸發 | 範圍 | Runner |
|----------|------|------|--------|
| `core-test.yml` | momentry_core 變更 | Rust test | GitHub |
| `studio-test.yml` | momentry_studio 變更 | Vue test | GitHub |
| `markbase-test.yml` | markbase 變更 | MarkBase test | Self-hosted |
| `cross-project.yml` | 多專案變更 | 整合測試 | Self-hosted |
| `release.yml` | tag push | 完整測試 | Self-hosted |
## Cross-Project Workflow
```yaml
name: Cross-Project Integration
on:
push:
paths: ['momentry_core/**', 'momentry_studio/**', 'markbase/**']
jobs:
integration:
runs-on: self-hosted
steps:
- name: Setup Sandbox
run: ./scripts/setup_sandbox.sh
- name: Build All
run: ./scripts/build_all.sh
- name: Start Services
run: ./scripts/start_services.sh
- name: Run Tests
run: ./scripts/run_integration_tests.sh
- name: Cleanup
if: always()
run: ./scripts/cleanup_sandbox.sh
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,83 @@
---
title: Issue Templates
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Issue Templates
## Requirement Template
```markdown
---
name: Requirement
about: 跨專案需求
labels: type:requirement
---
## 需求名稱
## 影響專案
- [ ] markbase
- [ ] markbaseengine
- [ ] momentry_core
- [ ] momentry_studio
## 需求描述
## API 變更
## 驗收標準
- [ ] 標準 1
- [ ] 標準 2
```
## Cross-Bug Template
```markdown
---
name: Cross-Project Bug
about: 跨專案 Bug 會診
labels: type:bug, cross-project
---
## Bug 描述
## 影響專案
## 重現步驟
## 會診團隊
| 專案 | 負責人 |
|------|--------|
| markbase | @ |
| markbaseengine | @ |
| momentry_core | @ |
| momentry_studio | @ |
## 修復方案
```
## Feature Template
```markdown
---
name: Feature Request
about: 新功能需求
labels: type:feature
---
## 需求描述
## 驗收標準
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,46 @@
---
title: Test Strategy
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Test Strategy
## 測試矩陣
| 測試類型 | 觸發條件 | 環境 | 驗證內容 |
|----------|---------|------|---------|
| Unit Test | 每次 commit | GitHub Runner | cargo test, pytest |
| Integration Test | PR 建立 | Self-hosted | API + Frontend |
| Cross-Project Test | 多專案變更 | Self-hosted | 端到端測試 |
| MarkBase Compat | MarkBase 變更 | Self-hosted | API 相容性 |
| Performance Test | Release 前 | Self-hosted | 效能基準 |
## 測試覆蓋
| 專案 | Unit | Integration | E2E |
|------|------|-------------|-----|
| momentry_core | cargo test | API tests | Sandbox |
| momentry_studio | vitest | Component tests | Sandbox |
| markbase | Unit tests | API tests | Sandbox |
| markbaseengine | Unit tests | Model tests | Sandbox |
## Sandbox 測試流程
```
1. 建立 Sandbox (git clone all projects)
2. 啟動服務 (markbase, core, studio)
3. 執行測試套件
4. 收集結果
5. 清理 Sandbox
```
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,56 @@
---
title: Cross-Project Bug Triage
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# Cross-Project Bug Triage
## 會診流程
```
Bug 報告 → 影響分析 → 會診 → 根因分析 → 修復 → 驗證 → 合併
```
## 升級機制
| 等級 | 條件 | 回應 | 處理 |
|------|------|------|------|
| P0 | 服務中斷、資料損失 | 1 小時 | 24 小時 |
| P1 | 功能異常、多專案 | 4 小時 | 72 小時 |
| P2 | 單專案、非核心 | 24 小時 | 1 週 |
| P3 | UI 小問題 | 1 週 | 2 週 |
## Sandbox 會診
```
/sandboxes/bug_{issue_id}/
├── markbase/
├── markbaseengine/
├── momentry_core/
├── momentry_studio/
├── shared/
└── scripts/
├── reproduce_bug.sh
└── verify_fix.sh
```
## RCA 報告
| 欄位 | 說明 |
|------|------|
| Bug ID | Issue 編號 |
| 影響專案 | 受影響專案清單 |
| 根因 | 根本原因分析 |
| 修復方案 | 各專案修復內容 |
| 驗證結果 | 測試通過確認 |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |
@@ -0,0 +1,201 @@
---
title: MarkBase Requirements Document
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# MarkBase 需求文件
## 提交對象
MarkBase Team
## 需求概述
為支援 Momentry Suite 四專案協同作業,需要擴展 MarkBase Server 功能,包含:
1. 路徑註冊管理 (Path Registry)
2. 專案管理 (OpenCode Projects)
3. Workspace 管理
4. 檔案產出追蹤 (File Outputs)
5. Sandbox 管理
---
## 需求 1: Path Registry API
### 描述
集中管理所有系統路徑,取代分散在 JSON 和 ENV 的設定。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/paths` | GET | 列出所有路徑 |
| `/api/v2/paths` | POST | 註冊新路徑 |
| `/api/v2/paths/{key}` | GET | 查詢單一路徑 |
| `/api/v2/paths/{key}` | PUT | 更新路徑 |
| `/api/v2/paths/resolve/{template}` | GET | 解析路徑模板 |
### Schema
```sql
CREATE TABLE path_registry (
id INTEGER PRIMARY KEY AUTOINCREMENT,
path_key TEXT NOT NULL UNIQUE,
path_value TEXT NOT NULL,
category TEXT,
is_template BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```
### 優先級: P0
---
## 需求 2: OpenCode Project Manager
### 描述
管理 markbase, MarkBaseEngine, momentry_core, momentry_studio 四個專案。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/projects` | GET | 列出所有專案 |
| `/api/v2/opencode/projects` | POST | 註冊新專案 |
| `/api/v2/opencode/projects/{key}` | GET | 查詢專案 |
| `/api/v2/opencode/projects/{key}/git/status` | GET | Git 狀態 |
### Schema
```sql
CREATE TABLE opencode_projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_key TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
git_path TEXT NOT NULL,
agents_path TEXT,
status TEXT DEFAULT 'active',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```
### 優先級: P0
---
## 需求 3: Workspace Management
### 描述
管理專案群組,支援跨專案協同。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/workspaces` | GET | 列出 Workspace |
| `/api/v2/opencode/workspaces` | POST | 建立 Workspace |
| `/api/v2/opencode/workspaces/{key}/projects` | GET | 列出專案 |
### Schema
```sql
CREATE TABLE workspaces (
id INTEGER PRIMARY KEY AUTOINCREMENT,
workspace_key TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE workspace_projects (
workspace_id INTEGER NOT NULL,
project_key TEXT NOT NULL,
role TEXT DEFAULT 'member',
PRIMARY KEY (workspace_id, project_key)
);
```
### 優先級: P1
---
## 需求 4: File Output Tracking
### 描述
追蹤處理器產出檔案。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/outputs/{file_uuid}` | GET | 查詢產出 |
| `/api/v2/outputs` | POST | 記錄產出 |
### Schema
```sql
CREATE TABLE file_outputs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
file_uuid TEXT NOT NULL,
output_type TEXT NOT NULL,
file_path TEXT NOT NULL,
status TEXT DEFAULT 'completed',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```
### 優先級: P1
---
## 需求 5: Cross-Project Sandbox
### 描述
建立跨專案測試環境。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/sandboxes` | GET/POST | 列出/建立 Sandbox |
| `/api/v2/opencode/sandboxes/{id}` | GET | 查詢狀態 |
| `/api/v2/opencode/sandboxes/{id}/destroy` | POST | 銷毀 |
### 優先級: P1
---
## 需求 6: AGENTS.md 共享機制
### 描述
支援 Workspace 層級的 AGENTS.md 共享與繼承。
### API Endpoints
| Endpoint | Method | 用途 |
|----------|--------|------|
| `/api/v2/opencode/shared/agents/workspace/{key}` | GET | 取得共享 AGENTS.md |
| `/api/v2/opencode/shared/agents/workspace/{key}` | PUT | 更新 |
### 優先級: P2
---
## 時間軸建議
| 階段 | 內容 | 目標 |
|------|------|------|
| Phase 1 | Path Registry + Projects | 2 週 |
| Phase 2 | Workspace + Outputs | 2 週 |
| Phase 3 | Sandbox + AGENTS.md | 2 週 |
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial requirements document |
@@ -0,0 +1,34 @@
# Gitea 倉庫統一記錄
## 統一目標
所有專案 origin 指向 m4mini (192.168.110.210) warren 帳號。
## 已完成設定
| 專案 | Origin | 狀態 |
|------|--------|------|
| markbase | m4mini/warren/markbase.git | ✅ remote 已更新 |
| MarkBaseEngine | m4mini/warren/markbaseengine.git | ✅ remote 已新增 |
| momentry_core | m4mini/warren/momentry_core.git | ✅ remote 已更新 |
| momentry_studio | m4mini/warren/momentry_studio.git | ✅ remote 已更新 |
## 待執行
- [ ] Push markbase 到 m4mini
- [ ] Push MarkBaseEngine 到 m4mini
- [ ] Push momentry_core 到 m4mini
- [ ] Push momentry_studio 到 m4mini
## 推回指令
```bash
git -C ~/markbase push -u origin main
git -C ~/MarkBaseEngine push -u origin master
git -C ~/momentry_core push -u origin feature/dynamic-concurrency-v1.3.4
git -C ~/momentry_studio push -u origin main
```
## 注意
m4mini Gitea push 功能目前無法連線,需確認網路或服務狀態後再執行 push。
@@ -0,0 +1,27 @@
---
title: _TEMPLATE_
version: 1.0
date: 2026-11-01
author: Core Team
status: Draft
---
# _TITLE_
## Overview
_Description_
---
## Sections
_Content_
---
## Version History
| Version | Date | Changes |
|---------|------|---------|
| 1.0 | 2026-11-01 | Initial documentation |