get_document_count に改名し、SELECT COUNT(*) FROM documents で返す。HTTP /doc_count と UI も同様に documents 件数に統一した。mcp_messages_handler 内で tools/call 受信時に state.tx.send("mcp:call:<actual_method>") を送信するようにした。train_lsa_and_sync_hnsw を実行する schedule_retrain_if_needed を実装し、add_item_text・update_item・delete_item・delete_document の成功後に呼び出すようにした。AppState に indexing_status を追加し、/indexing_status API と SSE の indexing:training / indexing:syncing / indexing:idle でヘッダーに表示するようにした。AIエージェントは、次の変更を実施した。
get_item_count を get_document_count に変更し、SELECT COUNT(*) FROM documents で件数を返す。tools/list・dispatch・handle_get_document_count を追加・改名。handlers.rs の doc_count_handler を documents に変更。04_mcp_api_specification.md に get_document_count を追記。mcp/mod.rs の mcp_messages_handler で、tools/call および該当ツール実行直後に state.tx.send(format!("mcp:call:{}", actual_method)) を実行。lib.rs の on_tray_icon_event で左クリック時に AtomicU64 で前回クリック時刻を記録し、400ms 以内のクリックを無視。それ以外で表示/非表示をトグル。AppState に changes_since_train(AtomicU64)と retrain_scheduled(AtomicBool)を追加。system.rs に schedule_retrain_if_needed を実装(閾値 max(1, min(ceil(doc_count*0.2), 5))、90秒デバウンス、spawn で train_lsa_and_sync_hnsw)。add_item_text・update_item・delete_item・delete_document の成功後に呼び出し。AppState に indexing_status(RwLock)を追加。train_lsa_and_sync_hnsw の開始・sync 前・完了・失敗・件数0 で indexing_status と SSE を更新。GET /indexing_status を追加。フロントのヘッダーにバッジを追加し、3秒ポーリングと SSE の indexing:* で更新。list_documents の SQL に chunk0 の先頭15文字のサブクエリを追加し、返却に chunk0_preview を含める。main-panel の文書管理テーブルに「先頭(chunk0)」列を追加。.docs-cell-preview でスタイルを指定。app-sidebar.js から sidebar-bottom(TelosDB アコーディオン・著作権表示)を削除。flowchart LR
A[get_document_count / doc_count] --> B[documents 統一]
C[MCP tools/call] --> D[SSE mcp:call]
E[変更検知] --> F[schedule_retrain_if_needed]
F --> G[90s デバウンス]
G --> H[train_lsa_and_sync_hnsw]
H --> I[indexing_status / SSE]
I --> J[ヘッダー表示]
MCP と UI の「X docs」がドキュメント数で一致し、MCP ACTIVITY にツール呼び出しが表示されるようになった。トレイクリックでウィンドウの表示・非表示が安定して切り替わる。変更が閾値を超えたタイミングで 90 秒後に LSA が自動再学習され、ヘッダーで training / syncing / idle が確認できる。文書一覧でチャンク0の冒頭が把握でき、サイドバーはナビのみに整理された。