feat(api): 統一使用台北時區 UTC+8 (禁止 UTC)

- 新增 src/utils/timezone.py 時區工具函式
- 修改 11 個後端檔案,全部改用 now_taipei()
- 更新 HARD_RULES.md 加入時區鐵律章節
- 更新 Skills 02/04 加入時區禁令

🔴 HARD RULE: 禁止 datetime.utcnow() / datetime.now(UTC)
 正確做法: from src.utils.timezone import now_taipei

Memory: feedback_timezone_taipei.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-25 09:08:34 +08:00
parent 5f3271174f
commit 2a2dac865a
14 changed files with 276 additions and 49 deletions

View File

@@ -17,6 +17,9 @@
| **測試** | **Mock 測試** | **真實 DB/服務** | [→ No Mock Testing](#no-mock-testing) |
| **API** | **單獨改路徑** | **前後端同步** | [→ API Path Naming](#api-path-naming) |
| **部署** | **假設已部署** | **驗證 Pod 版本** | [→ Deployment Verification](#deployment-verification) |
| **Alertmanager** | **指向 OpenClaw** | **指向 AWOOOI API** | [→ Alertmanager Routing](#alertmanager-routing) |
| **簽核 UI** | **清空內容** | **保留原始內容** | [→ Approval Preserve Content](#approval-preserve-content) |
| **時區** | **UTC/utcnow** | **台北時區 +8** | [→ Timezone Taipei](#timezone-taipei) |
---
@@ -224,6 +227,75 @@ curl -f https://api.awoooi.wooo.work/api/v1/health
---
## Alertmanager Routing
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_alertmanager_awoooi_flow.md`
```yaml
# ❌ 禁止 - 指向 OpenClaw (會使用舊 AIOPS 格式)
receivers:
- name: openclaw
webhook_configs:
- url: 'http://192.168.0.188:8088/api/v1/webhook/alertmanager'
# ✅ 正確 - 指向 AWOOOI API (K3s)
receivers:
- name: awoooi
webhook_configs:
- url: 'http://192.168.0.120:32334/api/v1/webhooks/alertmanager'
```
**職責分工:**
| 系統 | 職責 | Telegram 權限 |
|------|------|--------------|
| AWOOOI API (K3s 32334) | 告警處理 + 格式化 + 發送 | ✅ |
| OpenClaw (188:8088) | AI 大腦、LLM 分析 | ❌ |
**原因:** 2026-03-25 災難Claude 錯誤將 Alertmanager 指向 OpenClaw導致 Telegram 發送舊 AIOPS 格式(🤝 [協同警報]),而非 AWOOOI 格式(═══ 🚨 CRITICAL ═══)。
---
## Approval Preserve Content
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_approval_preserve_content.md`
```tsx
// ❌ 禁止 - 簽核後清空內容
if (approval.status === 'approved') {
return <div></div> // 原始內容不見了!
}
// ✅ 正確 - 保留原始內容
<Badge></Badge>
<OriginalAlertContent alert={approval} /> {/* 保留! */}
<ExecutionResult result={approval.result} />
```
**原因:** 2026-03-25 統帥指示:簽核後必須保留原始告警內容,用戶需要回顧已處理的告警。
---
## Timezone Taipei
**Memory:** `~/.claude/projects/-Users-ogt-awoooi/memory/feedback_timezone_taipei.md`
```python
# ❌ 禁止 - UTC 時區
from datetime import UTC
datetime.now(UTC)
datetime.utcnow()
# ✅ 正確 - 台北時區
from src.utils.timezone import now_taipei, now_taipei_iso
now_taipei() # datetime with +08:00
now_taipei_iso() # '2026-03-25T02:08:04+08:00'
```
**原因:** 統帥在台灣,日誌和 Telegram 告警必須顯示台北時間 (UTC+8),方便閱讀無需心算。
---
## 如何新增規則
1. 在此文件新增章節