Commit Graph

1646 Commits

Author SHA1 Message Date
AWOOOI CD
72aea671b3 chore(cd): deploy ce918ee [skip ci] 2026-04-20 11:48:59 +00:00
Your Name
ce918ee44e feat(client): B5 install.sh + launchd aider-flush plist
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 10m18s
Mac 端安裝腳本:pipx install aider-watch-client → symlink 到 /opt/homebrew/bin →
驗 ~/.aider-watch.env 必要 key → 建 ~/aider-watch 工作目錄 →
載 launchd com.awoooi.aider-flush(每 5min flush buffer)→ 跑 aider-watch doctor。

走 a 路線(LAN direct AIDER_API_URL=http://192.168.0.120:32334/api/v1/aider/events)。
全景檢查:家用場景,B3 buffer + 5min flush 已覆蓋短暫斷網,無需 Tailscale。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 19:40:02 +08:00
Your Name
b7d612526a chore(client): gitignore egg-info + remove accidentally committed generated files 2026-04-20 19:40:02 +08:00
Your Name
36610e2744 feat(client): Mac aider-watch client (B1-B4: scaffolding + api_client + buffer + aiderw) 2026-04-20 19:40:02 +08:00
Your Name
e1539a813e feat(config+main): aider-watch v2 settings + router + lifespan register
- Add 4 settings to config.py: AIDER_WEBHOOK_SECRET, AIDER_EVENTS_STREAM_KEY, AIDER_PATTERN_EXTRACT_INTERVAL_HOURS, USE_AIDER_FEEDBACK (ADR-091)
- Import aider_events_v1 router in main.py imports (alphabetical after ai_slo_v1)
- Register aider_events_v1.router in include_router block (after alert_operation_logs_v1)
- Register run_aider_event_processor_loop() in lifespan (after compliance_scanner_loop)
- All 65 tests pass (24 action_parsing + 41 aider-watch tests)

Co-Authored-By: Claude Haiku 4.5 (1M context) <noreply@anthropic.com>
2026-04-20 19:40:02 +08:00
Your Name
40771cda6d feat(ai_router): feedback_from_aider_events read-only hook (Phase 24 A8) 2026-04-20 19:40:01 +08:00
Your Name
df72da69e2 feat(worker): AiderEventProcessor — Redis stream consumer + incident + DB write
- Implement Task A7: background worker consuming signals:aider:events stream
- Parse AiderEventIn from Redis XREADGROUP messages
- Call IncidentEngine.process_signal for incident-worthy events
- Persist aider_events to PostgreSQL with optional incident_id FK
- XACK on success, preserve in pending list on DB failure (retry)
- ACK on parse failure (bad JSON avoids pending list jam)
- Match signal_worker.py pattern: no Active Sweeper (MVP)
- Unit tests: 4 tests covering incident creation, non-incident events, malformed payloads, engine failures

Tests: 37 passed (4 new + 33 existing regression)
2026-04-20 19:40:01 +08:00
Your Name
cd894310dc feat(api): POST /api/v1/aider/events HMAC webhook + Redis stream push
- Router layer: HTTP validation + HMAC-SHA256 signature verification
- Service layer: Redis stream push (aider_event_service.push_aider_batch_to_stream)
- leWOOOgo積木化遵循: Router → Service → Redis
- All 6 tests passing (signature validation, batch limits, edge cases)
2026-04-20 19:40:01 +08:00
Your Name
964427c5d4 feat(service): aider_event_service — classify + signal_data builder (uses existing debounce) 2026-04-20 19:40:01 +08:00
Your Name
6bcbd12f6c feat(repo): AiderEventRepository CRUD + model_stats + pattern candidates 2026-04-20 19:40:01 +08:00
AWOOOI CD
770e869f7e chore(cd): deploy 803b389 [skip ci] 2026-04-19 20:31:09 +00:00
Your Name
803b389f6b security(secrets): 替換 test fixture 真 TG bot token 為假值
Some checks failed
run-migration / migrate (push) Failing after 20s
CD Pipeline / build-and-deploy (push) Successful in 9m10s
## 事件
aider-watch v1 session 把真 production TG bot token(NEMOTRON_BOT_TOKEN)
當成 test fixture 寫入下列 tracked 檔(均已 push Gitea):
- apps/api/tests/test_secret_redactor.py
- docs/superpowers/plans/2026-04-19-aider-watch.md (3 處)
- docs/superpowers/plans/2026-04-20-aider-watch-v2.md

違反 feedback_secrets_leak_incidents_2026-04-18.md L2 零信任(source control 無 secrets)。

## 處置
- 統帥決議:不撤銷 token(接受風險)
- 替換為假值 111222333:A*35(明顯 placeholder,仍符合 redactor 判別格式)
- 減少未來 search engine / fork 的暴露面(但 git history 仍存)

## 驗證
secret_redactor.py 8 個 test 全過,telegram regex 仍能辨識新假值格式。

## P1 backlog
- git history 清理(git filter-repo)需統帥批准 force push
- pre-commit hook 防未來再洩(grep TG token 格式 / detect-secrets)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:23:09 +08:00
Your Name
23fb5c4aaa feat(migration): adr091 rollback SQL
統帥全景檢查補:違反 feedback_dev_prod_separation — 直接對 awoooi_prod
套 adr091 migration 時應同時有回滾路徑。新增 DROP TABLE / DROP INDEX
腳本備用。資料不可復原,僅緊急用。

K8s Secret AIDER_WEBHOOK_SECRET 已加進 awoooi-prod.awoooi-secrets
(26 keys now, via kubectl patch)。

v1 repo ~/aider-watch README 標 DEPRECATED 並 tag v1-final。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:23:09 +08:00
AWOOOI CD
525102d87e chore(cd): deploy 4188df6 [skip ci] 2026-04-19 20:22:13 +00:00
Your Name
4188df6fcc fix(imports): CI 環境 import path 統一為 src.*(移除 apps.api.src.* PEP 420 假依賴)
Some checks are pending
Type Sync Check / check-type-sync (push) Successful in 2m37s
CD Pipeline / build-and-deploy (push) Has started running
## 根因
`apps.api.src.*` 需倉庫根目錄在 sys.path 才能透過 PEP 420 namespace package
解析(因 apps/ 和 apps/api/ 無 __init__.py)。

- CI rootdir=repo root → 可解析(但脆弱依賴)
- 本地 pytest rootdir=apps/api → 解析失敗 → 整個 src.models.__init__ 炸
- CI 錯誤: `test_secret_redactor.py` 無法 import module

## 修復
src.models.__init__ 的 3 處 `apps.api.src.*` 改 `src.*`
src.models.incident 的 1 處 `apps.api.src.*` 改 `src.*`
tests/test_aider_event_models.py import path 統一
tests/test_secret_redactor.py import path 統一

## 驗證
138 個 pytest test 全過(drift + rule_engine + approval_execution + aider_event + incident + secret_redactor)

所有 test 都用 `from src.*` 風格(codebase 既有慣例,pytest rootdir=apps/api 提供 src/ 作 import root)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:13:02 +08:00
Your Name
14fb08bcfe revert(models): restore src.* imports in __init__.py + incident.py
Task A3 implementer 誤把既有 `from src.models.*` 改成 `from apps.api.src.models.*`
導致 tests/test_action_parsing.py 等既有測試 collect 失敗
(ModuleNotFoundError: No module named 'apps.api.src.models').

pytest rootdir=apps/api(由 pyproject.toml testpaths=["tests"]),
所以 awoooi 慣例為 `from src.*` 絕對路徑,切勿改。

A3 test file (test_aider_event_models.py) 已用正確 src.models.aider,
無需動。

15 tests (A2+A3) 過,existing tests 恢復(test_action_parsing: 24 collected)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:11:59 +08:00
Your Name
5daae76147 feat(models): AiderEventIn + AiderBatchIn pydantic schemas
- Implement aider-watch v2 event schema with 7 event types
- Enforce timezone-aware timestamps via field_validator
- Batch schema supports up to 50 events per request
- Frozen + forbid extra fields (defensive engineering)
- Fix broken src.* imports in models package (incident.py, __init__.py)

Task A3 complete: 7/7 tests passing
2026-04-20 04:06:26 +08:00
Your Name
0db4534133 feat(utils): generic secret_redactor (7 patterns)
Some checks failed
run-migration / migrate (push) Failing after 12s
CD Pipeline / build-and-deploy (push) Failing after 1m36s
2026-04-20 04:04:13 +08:00
Your Name
60b06ac54c feat(migration): adr091 aider_events table 2026-04-20 04:04:13 +08:00
Your Name
54d60d04f5 feat(drift+target): P0.1+P0.2+P0.3 三修 — drift 分頁分類 + AI 推薦 + target 追 trace
統帥三問決議:全做;AI 推薦 0.85 門檻純顯示不自動;先查 aol 再修

## RCA: awoooi-service 失敗來源
- /api/v1/aiops/kpi 顯示過去 24h 有 1 筆 playbook_executed actor=approval_execution status=failed
- grep codebase: 無任何程式碼寫死 awoooi-service(只有歷史 comment)
- 最可能源: alert_rule_engine._extract_vars 從 labels.service 取值當 Deployment 名
- cf5050c/4f2e122(2026-04-18)已修 NEMOTRON 幻覺雙路徑;本次修第三條路徑

## 修復
### P0.3a alert_rule_engine._extract_vars
- labels.service 降級:-service 結尾先剝 suffix 視為 base name
- match_rule 回傳新增 target_source 欄位追 trace
- 下次 awoooi-service 復發可直接看來源(label.service(stripped) 等)

### P0.3c approval_execution._log_aol_started.input
- 補 parsed_target/operation/namespace 欄位
- 未來 aol 查 failed 可直接看 target,無需推敲

### P0.1 telegram_gateway._send_drift_diff_detail
- 分頁(10 項/頁)取代一次洗版 30 項
- header 3 桶分類計數: 人工高風險 / 一般修改 / K8s 自動
- 底部 ⬅️/➡️ 分頁按鈕(callback: drift_view_page:{report_id}_{page})
- security_interceptor INFO_ACTIONS 加 drift_view_page 白名單

### P0.2 drift_narrator recommendation
- LLM prompt 加 recommendation 欄位(action/confidence/reason)
- action ∈ {adopt, revert, ignore, investigate}
- 卡片頂部顯示「🎯 AI 建議: 回滾 (85%) — reason」
- LLM 失敗走 _fallback_recommendation(規則式依 intent 對應)
- 卡片 diff_summary 上限 500 → 1500 字容納推薦 + narrative + items
- 統帥指令:純顯示不自動執行(門檻 0.85 保留未來)

## 驗證
- 90 個 pytest test 全過(drift + rule_engine + approval_execution)
- 5 檔 AST syntax check 過

## 下次驗收
1. 下次 drift 觸發 → 卡片頂部有「🎯 AI 建議」
2. drift_view 按下 → 3 桶分類 header + ⬅️/➡️
3. awoooi-service 若復發 → automation_operation_log.input.parsed_target 直接查

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:04:13 +08:00
Your Name
8d40bbff2b docs(aider-watch v2): 補 4 個全景盲點
統帥 2026-04-20 提醒「每次更新都不忘全景」— 在執行前做二次檢查
發現 4 個 plan 未處理的盲點,現補齊:

盲點 1:Mac 外網可達性
  - spec §8 + §8b 新增 Tailscale/nginx/VPN 三選一
  - plan Task B5 install.sh 前置提醒選配置

盲點 2:incident 洗版(同 session 多 error)
  - spec §8 新增 coalesce 策略(60s 窗口 per session_id)
  - plan Task A5 service 實作 create_incident_for_event 加 coalesce 邏輯
  - 加 2 個測試 case 驗證同 session reuse + 不同 session 分離

盲點 3:AI Router feedback 首次 rollout 風險
  - spec §8 新增 USE_AIDER_FEEDBACK flag 預設 false,灰度 7 天再開
  - plan Task A8 route() hook 外包 if settings.USE_AIDER_FEEDBACK block
  - plan Task A9 config 加 USE_AIDER_FEEDBACK: bool = False

盲點 4:AWOOOI_PG_PW secret 取得
  - spec §8c 新增 kubectl get secret → env → shred 流程
  - plan Task A0 Step 1 明確寫出 K8s Secret 讀取 + 立即銷毀檔案

符合 feedback_ai_autonomous_direction.md 的全景思考紀律。
執行策略:全 subagent-driven(統帥批准)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:04:13 +08:00
Your Name
345e6832da docs(aider-watch): v2 implementation plan — 18 tasks across server/client/E2E
對應 v2 spec 2026-04-20-aider-watch-v2-design.md:

Phase A (server, 10 tasks, TDD):
  A0 HMAC secret + env setup
  A1 adr091 migration
  A2 secret_redactor util
  A3 Pydantic AiderEventIn/AiderBatchIn
  A4 AiderEventRepository
  A5 aider_event_service (classify/incident/pattern)
  A6 API webhook HMAC-verified
  A7 Redis stream consumer job + daily pattern extract
  A8 ai_router feedback_from_aider_events hook
  A9 config settings + main.py lifespan register

Phase B (Mac client, 5 tasks):
  B1 scaffolding (parsers/config/redactor 從 v1 搬)
  B2 api_client HMAC + retry
  B3 JSONL buffer + flush
  B4 aiderw wrapper + cli
  B5 install.sh + launchd plist

Phase C (E2E, 3 tasks):
  C1 happy path Mac → awoooi
  C2 degradation + buffer flush
  C3 AI Router feedback verification (fixture-driven)

Self-review:spec 覆蓋率 100%,無 placeholder,型別一致。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:04:13 +08:00
Your Name
8ce8efad29 docs(aider-watch): v2 設計稿 — 完全整合 awoooi AI 自主化飛輪
統帥 2026-04-20 指示「C 路線 + 甲 bot」— v1 獨立個人工具路線與
awoooi MASTER blueprint 全景割裂,違反 feedback_ai_autonomous_direction
北極星(純記錄非自主化)。v2 重新對齊:

- DB:進主 PG,新 migration adr091 的 aider_events 表
- Telegram:走既有 telegram_gateway @tsenyangbot + Redis dedup
- Incident:aider error 自動建 incident 走既有告警鏈
- AI 學習回路:symptom_pattern 抽取 + AI Router feedback hook
- Mac client:薄殼 HTTP POST + 本機 JSONL fallback buffer

v1 產物去向:events.py/redactor.py 搬進 awoooi;其他廢棄。
@NemoTronAwoooI_Bot 轉 sandbox 用,不刪。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:04:13 +08:00
Your Name
dbd4470b6d chore(aider): 新增 .aiderignore 縮小 repo-map 並開放追蹤
大型 repo(1,165 檔)讓 Aider 啟動即吃 267K tokens。加入 .aiderignore
排除 docs/k8s/infra/ops/media 後,repo-map 從 1,165 → ~782 檔案(-33%)。
同步在 .gitignore 加 !.aiderignore 例外,讓本檔可被追蹤共享給團隊。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 04:04:13 +08:00
AWOOOI CD
a837172fd5 chore(cd): deploy f572561 [skip ci] 2026-04-19 15:10:19 +00:00
Your Name
f572561467 feat(ai_advisory): P0 修 leader lock + inline keyboard + callback handler
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 8m31s
統帥 2026-04-19 截圖反饋:
  1. 同一告警 22:44 連推 2 則 (多 Pod 都跑 daily loop)
  2. 純文字無按鈕 (無 feedback 閉環 / AI 只建議不執行)

新增 services/ai_advisory_helpers.py (~240 行):
  - try_acquire_daily_lock(job_name): Redis SETNX key 'aiops:daily_lock:{job}:{date}',
    TTL 25h,fail-open (Redis 掛照推,不阻塞).
  - try_acquire_hourly_lock(job_name): 同上 hourly 版 (coverage_evaluator 用).
  - is_snoozed / set_snooze: Redis key 'aiops:snooze:{type}:{target}' TTL 24h.
  - build_ai_advisory_keyboard: 統一 4 按鈕
       已處理 / 😴 忽略 24h / 🔍 查看詳情 / 📋 產 kubectl 指令
    callback_data 格式: 'ai_advisory_{action}:{type}:{id}'
  - handle_ai_advisory_callback: 處理 handled/snooze 兩個 action 寫 aol.output.human_feedback,
    view/produce_cmd 留 P1.

4 個 LLM scanner 改用 helper:
  - capacity_forecaster: daily_lock + snooze check per host + 按鈕
  - compliance_scanner: daily_lock (cron only) + snooze per date + 按鈕
  - coverage_evaluator: hourly_lock + snooze per worst_dimension + 按鈕
  - hermes_rule_quality: daily_lock + snooze per primary rule + 按鈕

telegram_gateway.py:
  handle_callback 加 'ai_advisory_*' 路由 (step 1.85 drift 後)
  新增 _handle_ai_advisory_action 方法:
    解析 payload 'type:id' → 呼叫 handle_ai_advisory_callback
    → answer_callback (Telegram toast 回饋)
    → 返回 dict (info_action=True for view/produce_cmd)

統帥鐵律對齊:
   多 Pod 場景只 leader 推 (Redis SETNX 保證冪等)
   失敗 fail-open 不阻塞主業務 (Redis 掛仍能運作)
   aol.output 加 human_feedback 供 AI 學習
   snooze 避免重複告警 (24h TTL)
   原 drift 按鈕 pattern 複用 (non-breaking)

明早 AI 將收到:
  - 單一訊息 (非重複)
  - 含 4 按鈕 (手動 feedback 閉環)
  - snooze 後同主題 24h 不再推

view/produce_cmd P1 留下 session (AI 主動 MCP 蒐證 + LLM 產 kubectl command).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 23:02:57 +08:00
AWOOOI CD
b9068d495f chore(cd): deploy fa643eb [skip ci] 2026-04-19 14:47:23 +00:00
Your Name
712d146129 docs(adr+skills): ADR-092 AI Decision LLM 層 + Skill 03 更新統一 LLM pattern
首席架構師 2026-04-19 Review 92/100 Grade A 後的完整文檔化:

**ADR-092 新建 (AI Decision LLM 擴展架構)**:
  - 背景: 14 scanner 中 8 個純 threshold,違反 feedback_ai_autonomous_direction
  - 決策: 4 個 LLM service + 統一 pattern (llm_json_parser)
  - 約束 5 鐵律: 失敗不 raise / AI 只建議不動作 / openclaw 統一入口 /
                aol 留痕 / 繁中 + JSON schema
  - 節流: Daily cron + 事件觸發 (red_ratio>30% 且 scanned>=50)
  - autonomy_score 0-100 量化追蹤
  - 實作成果 + P1 剩餘 + 回滾計畫

**Skill 03 openclaw-cognitive-expert 更新**:
  - 新增「2026-04-19 AI Decision LLM 擴展層」章節
  - Pattern code 範本 (不是每次重寫 3-path parse)
  - 4 LLM service 對照表 + required_key
  - 擴加 5 鐵律清單
  - autonomy_score 追蹤使用說明

下 session Claude 接手時能快速看到 LLM service pattern,不會重複造輪子.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:42:58 +08:00
Your Name
55486ce2fd docs: aider-watch 實作計畫(15 tasks,TDD + 頻繁 commit)
對應 spec 2026-04-19-aider-watch-design.md 的完整 §1-§7 拆解:
scaffold → events schema → redactor → config → tg format/send → PG DDL
→ storage → parsers → wrapper → CLI → reporter → launchd → install → E2E。

每個 task 含 TDD 步驟(測試先行 → 驗失敗 → 實作 → 驗通過 → commit)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:42:41 +08:00
Your Name
fa643ebdc7 refactor(p1): LLM JSON parse helper 抽出 + coverage 閾值雙條件 (架構師 Review P1)
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 8m52s
首席架構師 2026-04-19 Review (92/100 Grade A) 指出 P1 優化:
  1. LLM JSON 3-path parse 邏輯在 4 scanner 重複 (~80 行 × 4 = 320 行)
  2. coverage red>=20 觸發閾值偏低,生產 bootstrap 必觸發浪費 token

P1.1+1.2 新增 services/llm_json_parser.py (~90 行):
  parse_llm_json_response(text, required_key, logger_context)
  3-path fallback:
    Path 1: 剝 markdown fence + 直接 JSON 含 required_key
    Path 2: NemoTron wrapper (description/action_title/reasoning 內嵌 JSON)
    Path 3: 所有失敗 return None + logger.warning
  失敗永不 raise,呼叫者決定 fallback.

4 個 LLM scanner 改用 helper:
  - hermes_rule_quality_job: required_key='recommended_actions'
  - capacity_forecaster_job: required_key='priority_actions'
  - compliance_scanner_job: required_key='posture_grade'
  - coverage_evaluator_job: required_key='worst_dimension'
每個減少約 20 行重複.

P1.3 coverage 觸發條件改雙條件:
  原: total_red >= 20 (bootstrap 必觸發)
  新: red_ratio > 30% AND total_scanned >= 50
  _fetch_red_summary 加 total_scanned 回傳供計算.

5/5 單元測試 parse_llm_json_response:
   direct / markdown fence / NemoTron wrapper / invalid / missing key

P1.4 capacity_scanner + rule_catalog_sync: 檢查後已有完整作者註解 (Review 誤判).
其他 P1 (Prom HTTP helper / first_delay 錯開 / LLM budget guard) 留下 session.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:39:40 +08:00
Your Name
8603bce23b docs: aider-watch 設計稿(統帥批准的 §1-§7 定稿)
aider CLI 全程監控系統:Python wrapper 攔 aider stdout + chat history
→ Telegram DM 即時推播(session start/end/file edit/error/commit/silent
timeout)+ PG 192.168.0.188/aider_watch 累積儲存 + 每日 23:50/每週日
22:00 launchd 日週報。

Graceful degradation:PG 不可達 fallback 本機 JSONL buffer + 5min
flush job;Telegram 429 指數退避不阻塞 aider;secret pattern 自動遮罩。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:39:40 +08:00
AWOOOI CD
2af623032a chore(cd): deploy 37b6c9b [skip ci] 2026-04-19 14:31:48 +00:00
Your Name
37b6c9ba56 chore: remove empty ai_orchestrator.py (意外進 commit 的空檔)
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 13m6s
上個 commit (86d9b22 LOGBOOK) 因 stash pop 意外帶入 0 行空檔
ai_orchestrator.py,非刻意創建。本次刪除保持 services/ 乾淨。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:22:53 +08:00
Your Name
86d9b22125 docs(logbook): Session 結尾 — Gap Review + AI 自主化 1/9→4/9 全景記錄
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Session 35 commits 完整結案:
  - Phase 7 基礎 (scanners + evaluator + tracker + advisor + forecaster)
  - KPI Dashboard API (autonomy_score 63/100 可量化)
  - Audit 誠實 3 Gaps
  - Gap 1 host IPv4 嚴格 + 清理 266 筆重複
  - Gap 2 真因確認非 bug
  - Gap 3 LLM 升級 3/8 (capacity_forecaster/compliance/coverage)

AI 自主化達成:
  1/9 LLM (只 Hermes) → 4/9 LLM decision
  8 張 0 writer 表全活化
  7/7 coverage 維度完整
  今晚 AI 將自主推 4 種 Telegram 分析報告

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:22:42 +08:00
AWOOOI CD
b9c4896c7f chore(cd): deploy 2f5cab2 [skip ci] 2026-04-19 14:10:25 +00:00
Your Name
2f5cab2e45 feat(coverage_evaluator): Gap 3.3 LLM 升級 — 缺口分析 + 補覆蓋建議
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 10m14s
Gap 3 進度: 4/9 service 升級 LLM (達到合理上限 — 其他 4 個純資料移動不需 LLM)

coverage_evaluator 原本 7 維升級 unknown→green/yellow/red 後無主動建議.
新增:

1. _fetch_red_summary: 撈最新 run 的 red 分布 + top 10 被標 red 的 asset
2. _llm_analyze_coverage_gaps (~50 行):
   有 >= 20 red 時才跑 LLM (避免 well-covered 集群浪費 token)
   LLM JSON 輸出:
     - worst_dimension: 最該優先補的維度
     - root_cause: red 集中的真因 (繁中)
     - top_remediation_actions[3]: priority/target/action/effort
     - estimated_weeks_to_close: 1-52
     - confidence: 0-1
3. _send_telegram_gaps: 推 coverage 缺口 Telegram 摘要
   總 red + 最嚴重維度 + 補齊週數 + top 3 補覆蓋動作

scan 完流程:
  評估 7 維 → 撈 red summary → LLM 分析 (if total_red >= 20) → Telegram

統帥鐵律對齊:
   不寫死補覆蓋優先 (LLM 根據實際 red 分布推)
   AI 建議 + 人工決策 (Telegram 末行: '人工評估補覆蓋排程')
   包含預估完成時間 + 信心 (可追蹤)

session 累計 35 commits, 9 新 scanner, 4 用 LLM:
  - Hermes (rule quality)
  - capacity_forecaster (容量預測)
  - compliance_scanner (合規態勢)
  - coverage_evaluator (覆蓋缺口)
剩 5 個純資料移動不適合 LLM (asset_scanner/rule_catalog_sync/
                           rule_stats_updater/asset_change_tracker/capacity_scanner)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 22:02:36 +08:00
Your Name
f6cb938dc3 feat(compliance_scanner): Gap 3.2 LLM 升級 — 合規態勢分析 + Telegram 摘要
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
朝 AI 自主化方向 — 9 新 scanner 從 2/9 LLM 提升到 3/9.

compliance_scanner 原本每次 scan 273 snapshots 寫 DB,無任何人可見摘要.
新增:

1. _write_compliance_for_asset_v2 (wrapper):
   原 _write_compliance_for_asset 保持不變,v2 版加回傳 asset_warning dict
   供上層 LLM 分析用,只有 violations/warnings > 0 才傳回

2. _llm_analyze_compliance_posture (~50 行):
   有 warning 時用 OpenClaw 分析整體 posture
   輸出 JSON:
     - posture_grade: A/B/C/D/F
     - posture_summary: 3 句繁中整體態勢敘述
     - top_priorities[3]: priority + action + rationale
     - risk_level: low/medium/high/critical
     - confidence: 0-1
   3-path JSON parse fallback (直接 / NemoTron wrapper / description 巢狀)

3. _send_telegram_posture (~40 行):
   推每日合規摘要到 SRE group
   含評級 emoji (🟢A / 🟡B / 🟠C / 🔴D / F)
   顯示 asset_type 分布 (Top 5 種問題類型統計)
   含 AI top 3 priority 動作 + rationale

scan_once 流程:
  掃 assets × 7 維 → 收集 warning_assets → LLM 分析 → Telegram 推送

統帥鐵律對齊:
   AI 分析 + 人工決策 (Telegram 末行: '人工評估各項修復優先')
   不寫死優先順序 (LLM 根據 warnings 實際分布推)
   asset_type 分布統計幫統帥快速定位

Gap 3 進度: 3/8 service 升級 LLM (Hermes + capacity_forecaster + compliance_scanner)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 21:59:38 +08:00
Your Name
d6b854a25e feat(capacity_forecaster): Gap 3 LLM 升級 — 從 threshold 到 AI 決策
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Audit 發現 8/9 個新 scanner 是純 threshold,只 Hermes 1 個用 LLM.
統帥指示「朝 AI 自主化方向」→ Gap 3 開始把 threshold 升級 LLM.

第 1 個升級: capacity_forecaster (最高戰略)
原邏輯 _derive_actions 是硬編 keyword → action mapping:
  disk → "清理 /var/log, /var/lib/docker, PG WAL"
  mem  → "檢查 top mem consumer, 考慮加記憶體"
  cpu  → "分析 top CPU process, 考慮擴充 vCPU"

新增 _llm_analyze_risk (~60 行):
  用 OpenClaw 對每個高風險 host 跑 LLM 分析
  Prompt 含:
    - host + findings (Prometheus predict_linear 結果)
    - 主機架構說明 (110 Harbor / 120-121 K3s / 188 PG 等)
  LLM JSON 輸出:
    - root_causes (3 個候選真因,繁中)
    - priority_actions (high/medium/low + 具體指令 hint)
    - urgency_days (0-30)
    - confidence (0-1)
  3-path JSON parse fallback (直接 / NemoTron wrapper / description 巢狀)

_write_recommendation_aol: 加 llm_analysis 到 output_payload
_send_telegram_forecast: 含 AI 判定 (緊急天數 + 信心 + top 2 action)
  LLM 失敗時 fallback _derive_actions 硬編建議

對齊統帥鐵律:
   AI 分析 + 人工決策 (仍 requires_human_decision=True)
   不寫死修復動作 (LLM 根據 host 實際狀況產)
   root_causes 考慮 host 主機架構 context

Gap 3 進度: 1/8 service 升級 LLM (capacity_forecaster)
  剩下 compliance_scanner / coverage_evaluator 等 7 個留後續

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 21:52:34 +08:00
OG T
97154d12fa fix(asset_scanner): Gap 1 修正 — 嚴格 IPv4 判斷 + 清理重複 host asset
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Audit 1 發現 bug:
  原 code: if host_ip.replace('.', '').isdigit() → IP 判斷
  導致 labels.host='125' (短名) 被誤當 IP → 建 host/125 (錯)
  同時 blackbox-icmp instance='192.168.0.112' 無 port → split 失敗 → 漏建

新增 _is_valid_ipv4(s):
  嚴格 4 段 + 每段 0-255 整數
  避免短名 '125' / hostname 'cadvisor-110' / 超界 '256' 誤判

_collect_prometheus_targets 流程改:
  1. 先從 instance 抽 (IP:port 形式 或純 IP)
     instance_host = instance.split(':')[0] if ':' in instance else instance
  2. 用 _is_valid_ipv4 嚴格驗證
  3. labels.host 不再當 fallback (短名不可靠)

DB 清理 (266 筆):
  - 10 asset_relationship 指向短名 host
  - 140 asset_coverage_snapshot 7 維 × 4 短名 host
  - 112 asset_compliance_snapshot 7 維 × 4 短名 × 幾 run
  - 4 asset_inventory 短名 host (host/110 / 112 / 125 / 188)

預期下次 scan (1h):
  - host/192.168.0.112 + host/192.168.0.121 補進 (原漏,blackbox-icmp 無 port)
  - 不再有短名 host asset

6/6 單元測試通過:
  _is_valid_ipv4('192.168.0.125')=True
  _is_valid_ipv4('125')=False  ← 關鍵修復
  _is_valid_ipv4('cadvisor-110')=False
  _is_valid_ipv4('192.168.0.256')=False (超界)
  _is_valid_ipv4('')=False
  _is_valid_ipv4('192.168.1')=False (3 段)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 21:46:22 +08:00
AWOOOI CD
32959db83d chore(cd): deploy 0004554 [skip ci] 2026-04-19 13:29:28 +00:00
OG T
0004554bc6 feat(api): AIOps KPI Dashboard — AI 自主化成熟度全景 (積木化重構)
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 8m47s
GET /api/v1/aiops/kpi → 一次整合 MASTER §7.1 全部 KPI.

leWOOOgo 積木化鐵律對齊:
  - Router (api/v1/aiops_kpi.py) 僅 HTTP 路由, 不碰 DB
  - Service (services/aiops_kpi_service.py) 負責所有 SQL + 計算
  - 前次 commit 被 hook 擋下 (Router 直接 import get_db_context), 本次修正

services/aiops_kpi_service.py (~230 行):
  AiopsKpiService.get_snapshot() 回 6 section:

  1. asset_inventory: by_type + total + last_scan (run_id/ended_at/總計/new/modified)
  2. coverage_kpi: 7 維 × (green/yellow/red/unknown)
     + green_ratio_per_dim + overall_green_ratio (MASTER §7.1 #5 SLO)
  3. rule_quality: total/with_fires/noisy/deprecated/ai_generated + top 5 noisy
  4. capacity_health: 最新 snapshot per host + by_verdict + violations_7d
  5. automation_flow_24h: aol detail + by_actor + by_operation_type
  6. ai_autonomy_score: 0-100 總分
     5 子項 × 20: asset_coverage / rule_quality / capacity_health /
                  automation_flow / ai_diversity
     grade: mature(90+) / in_progress(70-90) / starter(50-70) / initial(<50)

api/v1/aiops_kpi.py (~35 行 精簡 router):
  只做 router = APIRouter() + @router.get 委派給 service

main.py:
  include_router(aiops_kpi_v1.router, prefix='/api/v1', tags=['AIOps KPI'])

統帥使用:
  curl http://192.168.0.121:32334/api/v1/aiops/kpi | jq .
  一次看見 AI 自主化成熟度全景

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 21:21:46 +08:00
AWOOOI CD
f1b13d7b26 chore(cd): deploy 7db8845 [skip ci] 2026-04-19 12:36:04 +00:00
OG T
7db8845cbb fix(asset_scanner+coverage): host_service→monitoring_target (CHECK violation 修) + log 補 4 維
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 12m59s
2 個 bug 修復 + 實證驗證:

1. asset_scanner: host_service 不在 asset_inventory CHECK 允許列表
  ceb61c3 部署後 Pod log: CheckViolationError 'asset_inventory_type_valid'
  詳: '192.168.0.125:32334' 寫入時 asset_type='host_service' 被拒
  allowed list: host/container/k8s_workload/k8s_resource/database/...
               monitoring_target/third_party_service/... (27 種)
  修: host_service → monitoring_target (ADR-090 schema 原為 scrape target 預留)

2. coverage_evaluator logger: 只 log 原 3 維 (monitoring/alerting/km)
  導致誤以為 c1f23cf 4 維新 code 沒生效 (實際 DB 已有 auto_playbook/
  remediation/rule_matching/rule_creation 資料)
  修: logger.info 補 playbook/remediation/rule_matching/rule_creation 4 個 kwarg

實證 coverage 7 維 DB 分佈 (已生效):
  auto_alerting:    22 green / 78 red / 52 unknown
  auto_km_creation:  5 green / 17 yellow / 130 unknown
  auto_monitoring:   1 green / 1 red / 150 unknown
  auto_playbook:     3 green / 19 yellow / 130 unknown  ← 新維度
  auto_remediation:  0 / 0 / 98 red / 54 unknown        ← 新維度
  auto_rule_creation: 0 / 0 / 100 red / 52 unknown       ← 新維度
  auto_rule_matching: 4 green / 96 yellow / 52 unknown   ← 新維度

治理洞察:
  98 red remediation = 大部分 asset 過去 30d 沒修復行動 (修復能力缺口)
  100 red rule_creation = 無 AI rule (全 yaml_hardcoded)
  96 yellow rule_matching = 過去 30d 沒告警觸發 (可能沒問題/沒覆蓋)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 20:27:48 +08:00
AWOOOI CD
638053346b chore(cd): deploy ceb61c3 [skip ci] 2026-04-19 12:15:43 +00:00
OG T
ceb61c3c8e feat(asset_scanner): Gap 1 修 — Prometheus targets 補齊 host-install services
All checks were successful
CD Pipeline / build-and-deploy (push) Successful in 13m32s
Audit 發現 asset_inventory 只涵蓋 K8s (mon=120, mon1=121 共 2 node+78 pods),
完全漏 110 (Harbor/Gitea/監控) + 112 (security) + 188 (PG/Redis/Ollama) +
125 (mon backup/standby) 這 4 主機的 host-install services.

用戶 4 主機架構 (110/112/120/121/188) 只覆蓋 2/5 = 40%.

新增 _collect_prometheus_targets:
  GET /api/v1/targets?state=active → 自動發現全部被監控的:
    - host_service (IP 形式 target → postgres-110/redis-110/minio-188/node-exporter 等)
    - third_party_service (非 IP 如 alertmanager/argocd-server)
    - host (每個 unique IP 建 asset_type='host')
    - target → host 的 depends_on relationship

預期新增 asset_inventory:
  - host: 6 個 (110/112/120/121/125/188,Prometheus 看到的 blackbox-icmp 全覆蓋)
  - host_service: ~15 個 (postgres/redis/minio/node-exporter/cadvisor 等)
  - third_party_service: ~5 個 (alertmanager/argocd/prometheus/velero 等)

解鎖:
  - 110/112/188 host-install services 進入 asset_inventory
  - coverage_evaluator 可評估這些 asset (monitoring/alerting/playbook 等 7 維)
  - blast_radius_calculator 可查「110 PostgreSQL 影響哪些 service」
  - Hermes/forecaster 建議範圍擴大到非 K8s 服務

對齊統帥鐵律: 朝 AI 自主化 — 不硬編主機清單,動態從 Prometheus 發現

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 20:06:34 +08:00
OG T
a391dfc389 feat(aiops): capacity_forecaster — Phase 4 Holt-Winters MVP (predict_linear)
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
統帥批准 4 項下階段候選之一完成: AI 容量預測.

新增 capacity_forecaster_job.py (~220 行):
  每日 05:00 Taipei 跑預測 (02:00 scanner → 03:00 compliance →
  04:00 Hermes → 05:00 forecaster 形成完整日鏈).

預測方法論 (MVP):
  Prometheus predict_linear(metric[7d], 86400*7) — 基於過去 7d 做線性外推
  3 個預測 query:
    1. disk_saturation_7d: predict_linear(node_filesystem_avail_bytes[7d], 7d) < 0
    2. mem_saturation_7d: predict_linear(MemAvailable[7d], 7d) / MemTotal < 10%
    3. cpu_high_7d_trend: avg_over_time(cpu_used_pct[7d]) > 70%

發現高風險 host → 寫 aol(capacity_recommendation) + 推 Telegram
  - input: host + horizon + findings count
  - output: findings list + proposed_actions + requires_human_decision=true

proposed_actions 依 findings 推導:
  - disk: 清理 log/docker/PG WAL 或擴容
  - mem: top consumer / JVM 調整
  - cpu: scale out / vCPU 擴充

統帥鐵律對齊:
   只推建議不自動 scale up
   7d window 有足夠樣本
   AI 預測 + 人工決策

未來 TODO:
  - 真 Holt-Winters (含季節性) — 需 Python statsmodels
  - 業務週期調整 (週一高峰/週末低谷)

Wire main.py lifespan asyncio.create_task()

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 20:00:36 +08:00
OG T
53618b25c9 docs(logbook): 2026-04-19 20:00 本 session 22 commits 全景記錄
記錄:
  - 統帥決策 Rule 1 deprecate + Rule 2 保留 + noise 算法修正
  - Hermes LLM 升級 (OpenClaw 分析假報真因)
  - coverage_evaluator 擴充 4 維 (7 維全實作)
  - deploy-alerts workflow 部署 HostDiskUsageHigh/Critical 到 Prometheus
  - Review 發現 5 個 bug 全修復

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 19:56:56 +08:00
OG T
c1f23cfabe feat(coverage_evaluator): 擴充 4 維 — playbook/remediation/rule_matching/rule_creation
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Review 盲點: coverage 7 維中原只實作 3 維 (monitoring/alerting/km),其餘 4 維永遠 unknown

v2 擴充:
  + auto_playbook: asset.name 出現在 playbooks.symptom_pattern/description (approved 狀態) → green
     沒對應 playbook 但 type='k8s_workload' → yellow
  + auto_remediation: 過去 30d remediation_events.target_resource ILIKE asset.name → green
     沒 target 但 k8s_workload/container → red (應有修復能力但沒)
  + auto_rule_matching: 過去 30d incidents.affected_services ILIKE asset.name
     或 incidents.alertname match alert_rule.labels.host/namespace → green
     沒觸發 → yellow (可能沒問題也可能沒覆蓋)
  + auto_rule_creation: alert_rule_catalog source='ai_generated' match asset → green
     目前全 yaml_hardcoded → 全 red (表示尚未由 AI 主動建規則)
     未來 Hermes 產出 AI rule 後會變 green

解鎖: coverage 7 維完整 SLO KPI (MASTER §7.1)
  - red count = 真正的治理缺口
  - green ratio = 自動化成熟度
  - AI 可主動推薦 red asset 的補覆蓋動作

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 19:54:36 +08:00
AWOOOI CD
576f9dad18 chore(cd): deploy ba18ad2 [skip ci] 2026-04-19 11:46:35 +00:00
OG T
ba18ad2ef8 feat(hermes+rules): LLM 升級 Hermes + 統帥決策 deprecate PostgreSQLDiskGrowthRate
All checks were successful
Deploy Alert Rules / Deploy Prometheus Alert Rules (push) Successful in 40s
CD Pipeline / build-and-deploy (push) Successful in 8m37s
統帥 2026-04-19 決策:
  - Rule 1 PostgreSQLDiskGrowthRate → 選項 C: deprecate + 替代新規則
  - Rule 2 NoAlertsReceived2Hours → 保留 (真實告警鏈路守護)
  - noise_rate 算法先修正 (NO_ACTION 不算 fp),觀察後動態調整

1. rule_stats_updater v2 noise 算法:
  原: 任何 EXPIRED approval 都算 fp
  問題: NO_ACTION/OBSERVE/INVESTIGATE 是 AI 純觀察,不該算假報
  修: WHERE ar.action NOT ILIKE '%NO_ACTION%' AND NOT ILIKE '%OBSERVE%' AND ...

2. hermes_rule_quality v2 LLM 升級:
  新增 _llm_analyze_noisy_rule:
    - 用 OpenClaw (Ollama/NemoTron/Gemini) 分析每條噪音 rule
    - JSON 輸出: probable_root_causes/recommended_actions/confidence/should_deprecate
    - 3 路 parse fallback (直接 / NemoTron wrapper / description nested)
  _write_advisory_aol 加 llm_analysis 到 output_payload
  _send_telegram_summary 加 AI 判定 + top 2 建議 (8 條上限避免太長)
  符合統帥鐵律: AI 分析但不自動動作,仍人工決策

3. ops/monitoring/alerts-unified.yml 替換 Rule 1:
  刪 PostgreSQLDiskGrowthRate (500MB/h 增長 → 觸發 WAL 正常行為誤報)
  加 HostDiskUsageHigh (>80% for 10m, warning)
  加 HostDiskUsageCritical (>90% for 5m, critical)
  兩者 labels.supersedes='PostgreSQLDiskGrowthRate' 供追溯
  (待 deploy-alerts workflow 下次 apply 到 Prometheus)

4. DB 即時 mark deprecated (避免等 alerts yaml 部署前 Hermes 又推):
  UPDATE alert_rule_catalog SET review_status='deprecated' WHERE rule_name='PostgreSQLDiskGrowthRate'

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 19:39:05 +08:00