feat(observability): 重塑 AI 觀測台戰情室 UI
Some checks failed
CD Pipeline / deploy (push) Has been cancelled

This commit is contained in:
OoO
2026-05-05 13:17:42 +08:00
parent 2bb2e16442
commit 054685826a
18 changed files with 1579 additions and 2608 deletions

View File

@@ -17,6 +17,7 @@
| `credentials_passbook.md` | 伺服器、帳密、埠位對照 | 需要維運、部署、憑證核對時 |
| `feedback_db_metadata_import.md` | SQLAlchemy metadata / `create_all()` 漏表鐵律 | 新增 model、修 schema、排查 fresh env 漏表時 |
| `db_connection_pool_singleton_20260430.md` | PostgreSQL `too many clients` 連線池放大事故與 DatabaseManager singleton 修正 | 排查 DB 連線數暴增、route 內反覆初始化 DatabaseManager、SQLAlchemy engine/pool 行為時 |
| `project_phase38_56_observability_war_room.md` | Phase 38→56 AI 觀測台戰役落地盤點、已知缺口與後續拆分方向 | 接續觀測台頁面、Telegram 指令、scheduler probe、AutoHeal/CodeReview L2 入口、Chart.js polish 或 deploy_doctor 時 |
| `project_phase3f_cleanup_roadmap.md` | ADR-017 執行矩陣與階段紅線 | 正在做 3f 模組化收尾時 |
| `code_modularization_inventory_20260430.md` | Python 大檔盤點、分層規範與拆分工作項目 | 新增功能、拆大檔、審查是否違反模組化治理時 |
| `schema_inventory_baseline.md` | DB 表分類與 drift 基線 | 要收斂 migration / ORM / raw SQL 真相時 |

View File

@@ -7,7 +7,8 @@
- Python 總量:約 66,997 行。
- 最大壓力區:`routes/` 約 21,095 行、`services/` 約 26,023 行。
- `app.py` 目前約 1,209 行,功能定位應固定為 bootstrap / Blueprint registration / startup guard不再承接新 route。
- 目前工作樹仍有 16 個 Python 檔案超過 800 行;這些不是禁止修 bug而是禁止繼續塞新功能。
- 目前工作樹仍有 18 個 Python 檔案超過 800 行;這些不是禁止修 bug而是禁止繼續塞新功能。
- 2026-05-05 追記Phase 38→56 觀測台戰役讓 `routes/admin_observability_routes.py``run_scheduler.py` 進入大檔治理清單;後續觀測台功能應先抽 query/action service不再把新 SQL 與 L2 mutation 直接塞回 route。
## 超過 800 行檔案清單
@@ -16,6 +17,7 @@
| 5240 | `routes/openclaw_bot_routes.py` | P0 巨型 Blueprint | route / bot command service / report service / scheduler hook |
| 2707 | `scheduler.py` | P0 排程總管 | task registry / crawler jobs / report jobs / notification jobs |
| 2653 | `routes/sales_routes.py` | P0 巨型 Blueprint | page routes / API routes / chart query service / calendar service |
| 2550 | `routes/admin_observability_routes.py` | P0 觀測台巨型 Blueprint | `services/observability_query_service.py` / `services/observability_action_service.py` / route glue |
| 1743 | `routes/ai_routes.py` | P1 AI Blueprint | route glue / AI orchestration service / prompt builders |
| 1485 | `routes/vendor_routes.py` | P1 Vendor Blueprint | route glue / stockout mutation/emailV2 page query、stockout list/batches API query、vendor list/detail query 已抽到 `services/vendor_stockout_query_service.py` |
| 1345 | `services/ppt_generator.py` | P1 報表生成 service | deck orchestration / slide builders / chart builders |
@@ -27,6 +29,7 @@
| 986 | `services/telegram_bot_service.py` | P2 Telegram service | command handlers / message formatters / bot client |
| 966 | `services/trend_crawler.py` | P2 crawler service | source adapters / parser / persistence |
| 946 | `services/elephant_alpha_autonomous_engine.py` | P2 ElephantAlpha engine | HITL / executor / planning policy |
| 868 | `run_scheduler.py` | P2 scheduler entrypoint | observability jobs / token report jobs / task registration 分離 |
| 829 | `routes/export_routes.py` | P2 Export flow | export command/router glue / file path / download orchestration |
| 818 | `services/import_service.py` | P2 import service | validators / import writers / report builders |
| 805 | `routes/bot_api_routes.py` | P2 Bot API Blueprint | route glue / bot action service |
@@ -37,9 +40,10 @@
1. P0持續拆 `routes/openclaw_bot_routes.py`Telegram API helper 已搬到 `services/openclaw_bot/telegram_api.py`Inline Keyboard builders 已搬到 `services/openclaw_bot/menu_keyboards.py`,下一步拆 report formatting 或 command dispatcher。
2. P0`routes/sales_routes.py`,先把 chart/query/calendar 計算搬到 `services/sales/`
3. P0`scheduler.py`,建立 `jobs/``services/scheduler/` task registry。
4. P1 `routes/ai_routes.py``routes/vendor_routes.py` 的資料處理移出 routeVendor V2 page query、stockout API list/batches、vendor list/detail 已完成,下一步可抽 email grouping 或 vendor mutation service。
5. P1PPT / NemoTron / OpenClaw 大 service 拆成 client、parser、composer、policy
6. P2對 800-1100 行檔案採「碰到就順手抽」策略,但不可讓淨行數繼續增加
4. P0 `routes/admin_observability_routes.py`,先搬純查詢函式到 `services/observability_query_service.py`,再搬 AutoHeal / Code Review / AiderHeal / throttle mutation 到 `services/observability_action_service.py`
5. P1`routes/ai_routes.py``routes/vendor_routes.py` 的資料處理移出 routeVendor V2 page query、stockout API list/batches、vendor list/detail 已完成,下一步可抽 email grouping 或 vendor mutation service
6. P1把 PPT / NemoTron / OpenClaw 大 service 拆成 client、parser、composer、policy
7. P2對 800-1100 行檔案採「碰到就順手抽」策略,但不可讓淨行數繼續增加。
## 守門

View File

@@ -0,0 +1,32 @@
# Phase 38→56 AI 觀測台戰役盤點
> 日期2026-05-05
> 用途接續觀測台、Telegram、scheduler probe、L2 自動化與 deploy_doctor 時的低成本入口。
## 已確認落地
- Commit 19f1340→df2311d 覆蓋 Phase 38→55HEAD 另有 Phase 56 deploy_doctor 擴充。
- Web 觀測台已形成 10 頁overview、agent_orchestration、business_intel、host_health、ai_calls、budget、promotion_review、rag_queries、quality_trend、ppt_audit_history。
- `templates/components/_ewoooc_shell.html` 已加入 AI 觀測 sidebar group`templates/ewoooc_base.html` 已加入 topbar health indicator。
- Telegram 已加入 `obs_*` 指令與 `cmd:obs_heal:*``cmd:obs_force_throttle``cmd:obs_trigger_review` inline action。
- `run_scheduler.py` 已加入 host probe、cleanup、AI error spike、observability daily summary。
- `migrations/029_create_host_health_probes.sql``migrations/030_create_ppt_audit_results.sql` 已補 host health / PPT audit 持久化。
## 2026-05-05 修補
- AutoHeal Web / Telegram 入口不再只看 `_is_unhealthy()` 30 秒記憶體 TTL也接受 `host_health_probes` 30 分鐘內最新探針為 unhealthy。
- AI 呼叫錯誤突增告警補上 1 小時 in-process dedup避免每 30 分鐘重複推送。
- 補回 memory 索引與模組化治理清單,避免 Phase 38→56 戰役只存在於聊天戰報。
## 已知治理債
- `routes/admin_observability_routes.py` 約 2550 行,已是 P0 巨型 Blueprint。後續不可再直接塞新頁面或 SQL應抽 `observability_query_service``observability_action_service`
- `routes/openclaw_bot_routes.py` 約 9104 行Telegram 指令應繼續拆到 `services/openclaw_bot/`
- 觀測台 template 仍大量使用 Bootstrap `card` / `btn-*`,尚未完全改成 `--momo-*` design token這是 cosmetic不是 P0。
- 現有 smoke test 多數 mock DB/Ollama/MCP只能證明 route 不 500不能證明 SQL schema、真實資料或 L2 side effect 正確。
## 下一步建議
- 優先抽 `routes/admin_observability_routes.py` 的查詢層,保留 route 只做 request parsing 與 render。
- 補一個整合級 smoke用測試 DB 建 `host_health_probes`,驗證 Web/TG AutoHeal 在 DB 最新 unhealthy 時不會被 `_is_unhealthy()` TTL 擋下。
- 若要做視覺 polish再集中處理 Bootstrap → MOMO V2 token不要混進功能 patch。