Commit Graph

8 Commits

Author SHA1 Message Date
OoO
f4149d4c05 fix(db): 補全 metadata model import 與 realtime sales ORM
ADR-017 Phase 3f-0
2026-04-29 21:00:46 +08:00
ogt
4a648ea6bf refactor: fix reverse dependencies — logger_manager→utils, dashboard_service extraction
- Move SystemLogger implementation to utils/logger_manager.py (pure utility, no deps)
- services/logger_manager.py becomes a backward-compat re-export shim
- database/manager.py and database/vendor_manager.py now import from utils layer
- Extract get_dashboard_stats() to services/dashboard_service.py
- services/task_runner.py no longer imports from routes layer
- routes/dashboard_routes.py get_dashboard_stats() delegates to service layer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 21:28:23 +08:00
ogt
e611702bb9 refactor: unify 4 isolated SQLAlchemy Base instances to database.models.Base
- database/import_models.py: 移除 ext.declarative.declarative_base,改用 from database.models import Base
- database/notification_models.py: 同上
- database/ppt_reports.py: 移除 orm.declarative_base,改用共用 Base
- database/vendor_models.py: 同上
- database/manager.py: 加入 4 個模型的 noqa import,確保 Base.metadata 完整管理所有資料表

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 21:27:20 +08:00
ogt
f59b23f969 security: P0 修復 S1-S5 — 移除所有硬編碼密碼與 SQL Injection 漏洞
S1: config.py — LOGIN_PASSWORD 移除硬編碼預設值 0936223270,改 fail-fast
S2: config.py — SECRET_KEY 移除弱預設值,無值或預設值時 sys.exit(1)
S3: services/user_service.py — create_initial_admin 改讀 INITIAL_ADMIN_PASSWORD env
S4: app.py — 匯入流程 table_name 正規表達式白名單驗證,date_list 格式驗證
S5: database/manager.py — ALLOWED_SALES_TABLES frozenset 白名單,日期改參數化查詢

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 20:34:15 +08:00
ogt
266af27fd6 fix: correct broken ai_models imports in database/manager.py
Some checks failed
CD Pipeline / deploy (push) Failing after 2m10s
AIGenerationHistory/AIInsight/AIUsageTracking/AIPromptTemplate never existed;
actual classes are AgentContext/ActionPlan/ActionOutcome/AgentStrategyWeights.
This caused momo-scheduler to crash on every restart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 04:30:47 +08:00
ogt
e6642d5e17 fix(ai-ops): 修正 _init_autoheal_tables 建表順序 (Playbook 先於 Incident FK)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m23s
incidents.playbook_id → FK → playbooks.id
建表必須先 Playbook 再 Incident,否則 psycopg2 報 UndefinedTable

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 16:09:47 +08:00
ogt
77d3a1da48 feat(ai-ops): ADR-013 AIOps 自動修復閉環完整實作
Some checks failed
CD Pipeline / deploy (push) Failing after 3m24s
架構(Exception → Incident → PlayBook → Heal → KM → Telegram):

新增元件:
- database/autoheal_models.py: Incident/Playbook/HealLog 三張表 + 7 條種子 PlayBook
- migrations/013_autoheal.sql: 建表 DDL + 種子資料(冪等 INSERT)
- services/auto_heal_service.py: 核心引擎 7 步閉環
  - _classify_error: 8 類錯誤自動分類 (DNS_FAIL/DB_UNREACHABLE/OOM/...)
  - _match_playbook: error_type + keyword + 冷卻 + max_retries 保護
  - _execute_playbook: DOCKER_RESTART/SSH_CMD/ALERT_ONLY/WAIT_RETRY
  - _sink_to_km: 修復知識寫入 ai_insights (auto_heal_playbook)
  - SSH 白名單:僅允許 docker restart / compose restart / docker start

修改元件:
- database/manager.py: _init_autoheal_tables() 啟動時建表+種子 PlayBook
- scheduler.py: 3 個核心任務植入 handle_exception
  (run_auto_import_task / run_icaim_analysis_task / run_weekly_strategy_task)
- requirements.txt: paramiko(SSH 跳板;不可用時降級 subprocess+CLI ssh)

安全設計: CMD 白名單 + cooldown + max_retries escalation + DB 冪等 migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 16:03:49 +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