Commit Graph

105 Commits

Author SHA1 Message Date
OoO
c7d6db31f2 feat(p11): RAG 自主學習 + Promotion Gate 4 階段護欄(feature flag OFF)
Some checks are pending
CD Pipeline / deploy (push) Has started running
Operation Ollama-First v5.0 / Phase 11 / RAG 自主學習迴圈

services/rag_service.py (532 行)
- RAGService.query() — bge-m3 embed + cosine 0.85 threshold + top_k=5
- get_embedding_signature() — v5.0 護欄 #3 一致性檢查 (SHA1[:12])
- fire-and-forget rag_query_log INSERT (不阻塞主流程)
- feedback() — Telegram 👍/👎 寫回 feedback_score
- RAG_ENABLED 預設 OFF(戰前行為不變)

services/learning_pipeline.py (750 行)
- Distiller — 純 Hermes 規則引擎,零 LLM 成本
  Quality 規則:MCP >200 字 0.8 / LLM JSON ok 0.9 / TextRank 0.6 / 👍 1.0 / 👎 0.0
- PromotionGate — Owen v5.0 護欄 #1 鐵律
  Stage 1: quality_score >= 0.7
  Stage 2: 無幻覺檢測(規則引擎,零 LLM)
  Stage 3: 與既有 insight 相似度 < 0.95(Stage 3 在 episode embed 後啟用)
  Stage 4: weight >= 0.8 必經 Telegram 👍/👎
- expire_stale_reviews() — 24h 無回應自動降級 weight=0.5
- hash_human_approver — Telegram username SHA1[:8] PII 保護

services/hermes_analyst_service.py — 新增 analyze() RAG-first
- RAG hit → return synthesize(不燒 LLM)
- RAG miss → 既有 LLM 路徑 + enqueue learning_episodes

services/openclaw_strategist_service.py — Q&A 入口接 RAG-first
- 不動週/月/年報(敘事報告 RAG hit 機率低)

services/telegram_templates.py
- rag_feedback_keyboard() — 👍/👎 inline keyboard
- promotion_review_keyboard() — Stage 4 人工驗收按鈕

routes/openclaw_bot_routes.py — 3 組 callback handler
- rag_fb:{id}:{score} → rag_service.feedback()
- pg_ok:{episode_id} → PromotionGate.promote()
- pg_no:{episode_id} → PromotionGate.reject()

70 unit tests 全綠 + 全戰役 196 tests zero regression(4:17 跑完)

剩餘 limitations(Phase 12+ 補):
1. learning_episodes.embedding 寫入路徑(Stage 3 dedup 暫 skip)
2. PromotionGate worker cron 未掛
3. Telegram awaiting_review 推播未接(callback handler 已就位)

灰度開啟條件(建議 1 週後):
- ANTHROPIC_API_KEY 設定 + RAG_ENABLED=true + threshold=0.90 保守
- feedback_score >= 4 比率 > 70% → threshold 降至 0.85

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:56:12 +08:00
OoO
943de8466c feat(p7): Anthropic SDK + Claude Opus 4.7 接 Code Review (feature flag OFF)
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
Operation Ollama-First v5.0 / Phase 7 Frontier 升級

services/anthropic_service.py (新檔, 226 行)
- AnthropicService 包裝 + ClaudeResponse dataclass
- Ephemeral prompt cache 5 分鐘 TTL(重複 system_prompt 省 90% 成本)
- usage 解析 input/output/cache_creation/cache_read 四欄位
- ANTHROPIC_API_KEY 未設或 SDK 缺失時 is_available()=False 靜默退化

code_review_pipeline_service.py — _openclaw_assess 加 L1 Claude 分支
- CODE_REVIEW_USE_CLAUDE flag (預設 OFF,等 ANTHROPIC_API_KEY 設定後翻 ON)
- 路由:Claude Opus 4.7 (Arena code Elo 1548) → Gemini → ElephantAlpha 三層
- request_id 串鏈不變

ai_call_logger.py COST_TABLE 補 3 個 Claude 模型:
- claude-opus-4-7:    $15/$75 per M tokens (程式碼 #1)
- claude-sonnet-4-6:  $3/$15  per M tokens (agentic 平衡)
- claude-haiku-4-5:   $0.8/$4 per M tokens (輕量快速)

requirements.txt: 加 anthropic>=0.40.0
.env.example: 加 ANTHROPIC_API_KEY / CODE_REVIEW_USE_CLAUDE / CLAUDE_MODEL

52 unit tests 全綠(22 logger + 18 anthropic + 5 routing + 7 security)

啟用步驟(待統帥手動):
  1. .env 加 ANTHROPIC_API_KEY=sk-ant-...
  2. CODE_REVIEW_USE_CLAUDE=true + restart momo-app
  3. 觀察 ai_calls.cache_read_tokens > 0 確認 cache 生效

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:31:30 +08:00
OoO
bc4332d53f test(p3): 配合 OPENCLAW_DAILY_HERMES_TEMPLATE 預設翻 ON 更新 assertion 2026-05-03 23:30:47 +08:00
OoO
838267c293 feat(p1+p3): logger 接 13 caller + Q&A/Nemotron/日報 feature flag 灰度
Phase 1 A4 — 13 個呼叫點接 ai_call_logger(覆蓋率 11.8% → 預估 50%+)
- TOP-1 nemoton_dispatcher: nemotron_dispatch caller (NIM 配額追蹤)
- TOP-2 openclaw_strategist: 4 reports (daily/weekly/monthly/meta) + qa caller
- TOP-3 hermes_analyst: hermes_analyst + hermes_intent (順修 commit 00591c5 殘留 bug)
- TOP-4 code_review_pipeline: code_review_hermes/openclaw/elephant 三鏈 (request_id 串)
- TOP-5 openclaw_bot_routes: openclaw_bot_main/gemini/nim 三層 fallback

Phase 3 A7 — OpenClaw Q&A → qwen3:14b(feature flag OFF)
- OPENCLAW_QA_OLLAMA_FIRST 灰度開關
- 繁中強制 system prompt + Gemini fallback chain
- _is_low_quality_response 品質守門(簡體字檢測 + 拒答訊號 + 結構分數)
- 黃金集 A/B 對照測試框架(10 樣本去 PII)

Phase 3 A8 — OpenClaw 日報 → Hermes 模板(feature flag OFF)
- OPENCLAW_DAILY_HERMES_TEMPLATE 灰度開關
- _compute_daily_kpi 純 SQL + Hermes 規則引擎
- _compute_gemini_insight 精簡 200 字洞察 prompt
- templates/daily_report_v2.j2 + _SafeUndefined 缺欄位優雅降級
- scripts/compare_daily_report_versions.py 雙版本盲測

Phase 3 A9 — Nemotron NIM → qwen3:14b(feature flag OFF)
- NEMOTRON_OLLAMA_FIRST 灰度開關(A2 紅燈:deepseek-r1 假支援,改 qwen3)
- _call_qwen3_dispatch + 既有 NIM tool_calls 解析共用
- 保留 ADR-004「🟡 [降級模式]」Hermes 規則引擎兜底

H6 PII fix — chat_id 進 ai_calls.meta 改 SHA1[:8](4 處 Bot Q&A)

Code Review pipeline — N3 動態 provider tag(gcp/secondary/111)+ A4 logger 三鏈

37 unit tests 全綠(routing 15 + golden 5 + qwen3 8 + daily template 8 + nemotron 1)

Operation Ollama-First v5.0 / Phase 1 A4 + Phase 3 A7+A8+A9

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:05:38 +08:00
OoO
078bf2683c fix(adr-027): Phase 2 — ADR-027 4 破洞修補 + 移除寫死 111
config.py — B1+B2 lazy resolve
- get_ollama_host() 取代 import-time freeze 的 OLLAMA_HOST
- get_embedding_host() 取代 EMBEDDING_HOST
- 主機切換時不需重啟 Python 進程

services/ollama_service.py — B3+B4 三主機級聯
- resolve_ollama_host(primary, secondary, fallback) 三主機級聯
  - Primary:   34.143.170.20 (SSD) — GCP 主主機
  - Secondary: 34.21.145.224 (SSD) — 同等效能備援
  - Fallback:  192.168.0.111 (HDD) — 最後一道防線
- _is_reachable: HTTP /api/version probe 取代 TCP socket(防 process 卡死假活)
- mark_unhealthy(host) 即時失效 cache,30s 內跳過該主機
- 14 unit tests 全綠

services/aider_heal_executor.py — N2
- 移除寫死 192.168.0.111,改用 get_ollama_host()
- AiderHeal 終於遵循 ADR-027 GCP 優先策略

Operation Ollama-First v5.0 / Phase 2 A6

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:05:11 +08:00
OoO
bb891f1a6e feat(observability): ai_call_logger + 23:55 Telegram token 日報
services/ai_call_logger.py(300 行)— 統一 LLM 遙測層
- context manager log_ai_call() / decorator logged_ai_call()
- async fire-and-forget 寫 ai_calls,DB 失敗永不影響主流程
- kill-switch:連續 10 次失敗自動降級為 logger.info
- env AI_CALL_LOGGING_ENABLED=false 一鍵關閉
- COST_TABLE 集中 13 個模型計費(gemini/claude/nim/ollama)
- PII 保護:meta 只存 prompt_hash[:12],不存原文
- 22 unit tests 全綠

services/token_report_service.py(580 行)— 6 段落每日 23:55 日報
- Section 1-6: 總覽 / 供應商分布 / TOP10 caller / 成本預算 / 趨勢 / 告警建議
- 7 條告警規則 + Hermes 規則引擎智能建議
- HTML escape + 4096 字元雙保險
- Telegram 失敗 fallback 訊息
- ai_insights 寫入 PII safe(無 chat_id/username 落地)
- 30 unit tests 全綠

A11 critic 護欄:H6 chat_id PII fix(services/openclaw_bot_routes 4 處 → SHA1[:8])

Operation Ollama-First v5.0 / Phase 1 A4+A5

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:04:58 +08:00
OoO
6cad59f83e feat(code-review): ADR-020 全自動修復政策 — 拆掉 CRITICAL/HIGH HITL 閘門
All checks were successful
CD Pipeline / deploy (push) Successful in 2m23s
post-deploy code review pipeline 改為「任何 finding 一律觸發 AiderHeal」,
局部覆寫 ADR-012 L3 HITL(不影響 schema migration / 流量切換 /
customer-facing 廣播 / AIOps prod SSH 等其他 L3 場景)。安全網改為
Git revert + Gitea CI/CD 健康檢查 + 主開關 CODE_REVIEW_AUTO_FIX_ENABLED。

實作:
  • _ea_orchestrate / _guard_ea_decision / rule fallback 三條路徑統一為
    has_findings AND AUTO_FIX_ENABLED → auto_fix=true
  • _guard 強制 LLM 即使回 auto_fix=False 也升級為 true(核心保證)
  • CODE_REVIEW_AUTO_FIX_ENABLED 預設 false → true
  • Telegram 文案移除「需人工審查」,改顯示主開關狀態
  • action_plan status pending_review → auto_disabled(語意對齊)
  • aider_heal_executor 標頭 ADR-014 → ADR-020、補「直推 main」分支策略

文件:
  • 新增 docs/adr/ADR-020-code-review-full-autoheal.md
  • ADR-012 加 Note 行反向引用 ADR-020
  • README 索引收錄

測試:tests/test_code_review_pipeline_security.py 反轉 HITL 期望,
新增 5 case(含 LLM 降級被 guard 拒絕、LLM human_review_needed=true 被改 false)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 23:44:01 +08:00
OoO
0232dbb902 test(openclaw): assert /menu returns full main menu keyboard 2026-05-02 16:13:43 +08:00
OoO
3f40089d8c fix(openclaw): show full main menu for wakeup phrases
All checks were successful
CD Pipeline / deploy (push) Successful in 2m44s
2026-05-02 16:12:30 +08:00
OoO
7b6423fa67 fix(openclaw): route wakeup phrases back to menu
All checks were successful
CD Pipeline / deploy (push) Successful in 2m55s
2026-05-02 16:03:49 +08:00
OoO
673982d83b Fix OpenClaw callback command path from NL dispatch regression
All checks were successful
CD Pipeline / deploy (push) Successful in 4m17s
2026-05-02 15:59:54 +08:00
OoO
4c6e4ca5fb style(ppt): align PPT palette perfectly with MOMO Pro v2 design tokens (Beige, Warm Ink, Caramel Orange) as per frontend upgrade roadmap 2026-05-02 15:01:55 +08:00
OoO
1a886d962b fix(telegram): dedupe webhook+polling updates via shared DB guard
All checks were successful
CD Pipeline / deploy (push) Successful in 8m50s
Webhook (Flask) and polling (momo-telegram-bot) consumed the same
Telegram update_id, causing /menu callbacks to fire twice. Add a
shared dedup module backed by telegram_update_dedup table (300s TTL,
60s cleanup) with in-memory fallback, wired into both paths.

Polling launcher now skips startup when webhook is configured to
prevent dual-consumption at the source.

38 tests across webhook, menu keyboards, telegram_api, dedup guard,
and trend bot service.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 12:01:04 +08:00
OoO
75de76ac12 fix(momo): block EC404 auto-open with end-to-end URL guard
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
- normalize URLs at write time (scheduler crawlers, routes) to drop
  javascript:/EC404/placeholder i_code (momo_/manual_/pchome_)
- add global click+auxclick guard in base.html and ewoooc_base.html
  that intercepts blocked MOMO URLs and redirects to safe i_code URL
- per-page dashboards reuse the same isLikelyMomoIcode validation
- /api/track_momo_link records blocked events for diagnosis
- ship sanitize_momo_urls.py to clean existing polluted DB rows

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 12:00:34 +08:00
OoO
026d0e7539 feat(reports): move monthly analysis to v2 shell
All checks were successful
CD Pipeline / deploy (push) Successful in 2m14s
2026-05-01 21:13:18 +08:00
OoO
d6782ee710 feat(ai): move recommendation page to v2 shell
All checks were successful
CD Pipeline / deploy (push) Successful in 2m13s
2026-05-01 21:08:44 +08:00
OoO
9b3e0a4565 feat(ai): move history page to v2 shell
All checks were successful
CD Pipeline / deploy (push) Successful in 2m19s
2026-05-01 21:06:17 +08:00
OoO
939ed5eef5 feat(ai): move intelligence page to v2 shell
All checks were successful
CD Pipeline / deploy (push) Successful in 2m18s
2026-05-01 21:03:19 +08:00
OoO
7d46ff9ba5 feat(competitor): persist match attempts
All checks were successful
CD Pipeline / deploy (push) Successful in 2m9s
2026-05-01 20:56:17 +08:00
OoO
c1f43b0ae4 fix(campaign): persist full crawl snapshots
All checks were successful
CD Pipeline / deploy (push) Successful in 2m22s
2026-05-01 20:48:28 +08:00
OoO
bb99dfeab6 feat(campaign): restore operations table signals
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-05-01 20:43:46 +08:00
OoO
4e853a233f perf(dashboard): speed up competitor overview
All checks were successful
CD Pipeline / deploy (push) Successful in 2m12s
2026-05-01 20:36:25 +08:00
OoO
b9d6186d68 feat(frontend): sync latest MOMO Pro prototype styling
All checks were successful
CD Pipeline / deploy (push) Successful in 2m18s
2026-05-01 20:32:23 +08:00
OoO
066cf1846f feat(dashboard): show AI pick evidence gaps
All checks were successful
CD Pipeline / deploy (push) Successful in 2m18s
2026-05-01 17:17:03 +08:00
OoO
e86075d59d fix(dashboard): avoid redundant prewarm rebuilds
All checks were successful
CD Pipeline / deploy (push) Successful in 2m15s
2026-05-01 16:36:58 +08:00
OoO
2ac7410d40 fix(dashboard): prewarm cache and expose pick evidence
All checks were successful
CD Pipeline / deploy (push) Successful in 2m20s
2026-05-01 16:34:13 +08:00
OoO
9e2337764b fix(ai): supersede old product picks
All checks were successful
CD Pipeline / deploy (push) Successful in 2m48s
2026-05-01 16:24:15 +08:00
OoO
b3d00a011c fix(dashboard): warm cache after AI pick refresh
All checks were successful
CD Pipeline / deploy (push) Successful in 3m37s
2026-05-01 16:16:39 +08:00
OoO
b447aefcfb fix(ai): clear dashboard cache after pick regeneration
All checks were successful
CD Pipeline / deploy (push) Successful in 2m27s
2026-05-01 16:10:51 +08:00
OoO
3920701e1a feat(dashboard): optimize cache and AI pick confidence
All checks were successful
CD Pipeline / deploy (push) Successful in 2m46s
2026-05-01 16:01:52 +08:00
OoO
0334051aa7 feat(dashboard): 匯出 AI 挑品操作清單
All checks were successful
CD Pipeline / deploy (push) Successful in 2m39s
2026-05-01 15:43:57 +08:00
OoO
1d1a7f6e94 feat(dashboard): 強化 AI 挑品清單決策資訊
All checks were successful
CD Pipeline / deploy (push) Successful in 2m22s
2026-05-01 15:22:21 +08:00
OoO
a5de082437 feat(dashboard): 顯示 50 品 AI 挑品清單
All checks were successful
CD Pipeline / deploy (push) Successful in 3m12s
2026-05-01 15:08:41 +08:00
OoO
6bce46bbc7 fix(runtime): 強化健康檢查監控韌性
All checks were successful
CD Pipeline / deploy (push) Successful in 2m29s
2026-05-01 14:46:49 +08:00
OoO
ea15aa6437 refactor(vendor): 抽出廠商管理查詢服務
Some checks failed
CD Pipeline / deploy (push) Failing after 8m57s
2026-05-01 14:20:09 +08:00
OoO
1012d609d4 feat(dashboard): 顯示 PChome 比價決策總覽
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-05-01 14:19:18 +08:00
OoO
fbc85fcedc refactor(vendor): 抽出缺貨 API 查詢服務
All checks were successful
CD Pipeline / deploy (push) Successful in 2m11s
2026-05-01 14:12:56 +08:00
OoO
b5de8d5d61 fix(ai): 價格調整轉人工覆核
All checks were successful
CD Pipeline / deploy (push) Successful in 2m16s
2026-05-01 14:09:54 +08:00
OoO
62f8f1d52d refactor(vendor): 抽出缺貨 V2 查詢服務
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-05-01 14:07:10 +08:00
OoO
8a3d50933b feat(ai): 自動補抓並重算 PChome 挑品
All checks were successful
CD Pipeline / deploy (push) Successful in 2m18s
2026-05-01 14:02:37 +08:00
OoO
043a7dc915 feat(ai): 補抓 PChome 待比對商品
All checks were successful
CD Pipeline / deploy (push) Successful in 2m20s
2026-05-01 13:40:37 +08:00
OoO
9f9e0727e7 fix(ai): 自動偵測挑品銷售欄位
All checks were successful
CD Pipeline / deploy (push) Successful in 1m50s
2026-05-01 10:18:07 +08:00
OoO
70de91f1f6 fix(ai): 修正挑品清單銷售日期查詢
All checks were successful
CD Pipeline / deploy (push) Successful in 2m14s
2026-05-01 10:12:32 +08:00
OoO
82d759d3b1 feat(ai): 建立 PChome 銷售挑品清單
All checks were successful
CD Pipeline / deploy (push) Successful in 2m24s
2026-05-01 10:05:16 +08:00
OoO
55855ef508 feat(frontend): 保存 PChome 競品價格歷史
All checks were successful
CD Pipeline / deploy (push) Successful in 1m39s
2026-05-01 00:53:37 +08:00
OoO
6b8e511246 feat(frontend): 補齊活動看板篩選與價格歷史區間
All checks were successful
CD Pipeline / deploy (push) Successful in 1m44s
2026-05-01 00:43:38 +08:00
OoO
22b27d19df fix(frontend): 讓價格圖表按鈕直接開啟歷史走勢
All checks were successful
CD Pipeline / deploy (push) Successful in 1m44s
2026-05-01 00:38:32 +08:00
OoO
4945aeed3b fix(frontend): 還原商品看板價格歷史圖表
All checks were successful
CD Pipeline / deploy (push) Successful in 1m45s
2026-05-01 00:35:04 +08:00
OoO
8e9fb3dd17 feat(frontend): 將 V2 設為正式預設介面
All checks were successful
CD Pipeline / deploy (push) Successful in 1m46s
2026-05-01 00:28:56 +08:00
OoO
15b3bae9cb feat(frontend): 新增廠商缺貨匯入 V2
All checks were successful
CD Pipeline / deploy (push) Successful in 1m42s
2026-05-01 00:21:26 +08:00