Commit Graph

29 Commits

Author SHA1 Message Date
OG T
8ef8347f2c chore: debug endpoint 更詳細的錯誤追蹤 2026-03-23 22:23:24 +08:00
OG T
58f3339561 chore(api): 新增 debug endpoint 測試 incident resolve
臨時測試端點,用於驗證 resolve_incident_after_approval 邏輯

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 22:15:16 +08:00
OG T
03ca124967 fix(api): _persist_incident 新增顯式 commit + 追蹤日誌
根因: DB 變更未被 commit,導致 Incident 狀態更新不持久化

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 22:02:00 +08:00
OG T
65fa1168b8 feat(api): ApprovalRequestResponse 新增 metadata 欄位
讓前端/API 可見 incident_id,用於除錯和關聯追蹤

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 21:51:05 +08:00
OG T
ac3bf97920 fix(api): 簽核後更新 Incident 狀態為 RESOLVED
根因: 簽核成功後 Incident.status 未更新,導致刷新頁面後 Y/n 按鈕重現

修復:
- proposal_service.py: 新增 resolve_incident_after_approval() 方法
- approvals.py: sign_approval 成功後呼叫更新 Incident 狀態
- 使用 metadata.incident_id 反查關聯的 Incident

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 21:37:50 +08:00
OG T
e23493741a fix(telegram): respect C-Suite decision - OpenClaw is sole brain
架構修正 2026-03-23 (遵循 C-Suite 決議):
- 鐵律: .188 為唯一大腦,禁止腦分裂
- OpenClaw (192.168.0.188) = 唯一 Telegram Gateway
- AWOOOI API (K8s) = Web API + Sensor,不做 Polling
- TELEGRAM_ENABLE_POLLING 預設 False

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 19:25:08 +08:00
OG T
7478dc0254 feat(phase6-9): Complete modular architecture and Agent Teams
Phase 6.4 - Modular Architecture:
- Add lewooogo-brain adapters for LLM providers
- Add lewooogo-data dual memory (Redis + PostgreSQL)
- Implement consensus engine for multi-agent decisions
- Add incident memory service for historical context

Phase 9 - Agent Teams (Claude Agent SDK):
- Add base agent class with Claude Sonnet 4 integration
- Implement action planner, blast radius, and security agents
- Add agent API endpoints and proposal workflow
- Integrate ADR-009 OpenClaw Agent Teams architecture

DevOps & CI/CD:
- Add GitHub Actions CI/CD workflows (ci.yaml, cd.yaml)
- Add pre-commit hooks and secrets baseline
- Add docker-compose for local development
- Update Kubernetes network policies

Frontend Improvements:
- Add auto-healing error boundary component
- Update i18n messages for agent features
- Enhance dual-state incident card with execution feedback

Documentation:
- Add 7 ADRs covering MCP, design system, architecture decisions
- Update ARCHITECTURE_MEMORY.md with modular design
- Add GLOBAL_RULES.md and SOUL.md for project identity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 18:40:36 +08:00
OG T
6eccb45757 fix(api): Use in-cluster K8s config for executor in K8s pods
- Try load_incluster_config() first (for pods running in K8s)
- Fallback to kubeconfig file (for local development)
- Fixes "K8s connection not available" error in production

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 14:45:58 +08:00
OG T
d1fb3aa010 fix(api): Expand Chinese action parsing for K8s executor
- Add 擴展...副本數 pattern (scale variant)
- Add 重新啟動 without 服務 suffix
- Auto-detect StatefulSet Pod names (xxx-N) for DELETE_POD
- Strip -deployment suffix from resource names

Fixes Y button execution failure when LLM generates Chinese actions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 14:15:49 +08:00
OG T
962b1e75a5 refactor: Rename ClawBot → OpenClaw across documentation
- Update .awoooi-agent-rules.md (4 occurrences)
- Update docs/api/openapi.yaml (all schema references)
- Update apps/web/tailwind.config.ts (comment)
- Update apps/api/src/core/config.py (comment)

Legacy CLAWBOT_URL field kept for backward compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 14:05:53 +08:00
OG T
0aaf6a276b feat(api,web): Phase 6.5 DecisionManager with dual-engine fallback
Backend:
- Add DecisionManager with state machine (INIT→ANALYZING→READY→EXECUTING)
- Implement Expert System rules engine (100% local, never fails)
- Dual-engine: LLM (primary) + Expert System (fallback)
- Auto-generate decision_token for each incident
- 30-second timeout guarantee

Frontend:
- Use decision.state to unlock [Y/n] buttons
- Display AI action suggestion in card
- Show source indicator [AI] or [EXP]
- Generate proposal on-demand if needed

Fixes: UI locked with hourglass when LLM times out

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 13:19:55 +08:00
OG T
eee4ab9b36 feat(api): Phase 6.6 implement k8s execution engine with subprocess
ActionExecutor enhancements:
- Add execute_kubectl_command() using asyncio.create_subprocess_shell
- Security: Only kubectl commands allowed, forbidden patterns blocked
- Shadow Mode: Simulate execution without actual kubectl calls
- Capture stdout/stderr with PIPE, handle timeout gracefully

New execute_approved_proposal() function:
- Background task entry point for approved proposals
- Read approval from Redis/DB, verify status='approved'
- Extract kubectl_command from metadata
- Execute via execute_kubectl_command()
- Update status to 'executed' or 'failed' with execution_log

Security guardrails:
- Forbid delete namespace/ns, rm -rf, drop database
- Forbid batch deletion patterns
- 60 second default timeout

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 12:46:47 +08:00
OG T
a769738499 feat(api): Phase 6.4h replace mock DI with real ProposalService
- Remove MockEngine and embedded Proposal/Guardrails classes
- Import real ProposalService with OpenClaw LLM integration
- Use get_real_proposal_service() for dependency injection
- ProposalService integrates:
  - OpenClaw LLM (Ollama → Gemini → Claude fallback)
  - Redis Working Memory
  - PostgreSQL Episodic Memory
  - TrustEngine risk assessment
- Add llm_provider, llm_confidence, kubectl_command to response
- Map ApprovalRiskLevel to Tier (LOW=1, MEDIUM=2, CRITICAL=3)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 12:25:39 +08:00
OG T
0aa80c1d32 fix(docker): embed mock types for Docker build compatibility
Remove lewooogo-brain local dependency that breaks Docker context.
Inline Proposal/Guardrails definitions in proposals.py mock.

Phase 6.4i will address proper monorepo Docker packaging.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 12:01:20 +08:00
OG T
cb5d0ecfe4 feat(phase-6.4g-6.5b): API Synaptic Integration + Dual-State WarRoom UI
Phase 6.4g (API 突觸對接):
- lewooogo-brain dependency binding in apps/api/pyproject.toml
- POST /api/v1/incidents/{id}/propose route (proposals.py)
- Guardrails integration (8/8 tests passed)

Phase 6.5a (視覺皮層建置):
- DualStateIncidentCard.tsx with Nothing.tech visual compliance
- Ping radar animation for alert state
- Tier-based decision layer UI (AI 執行中 / 等待親核)

Phase 6.5b (神經網路串接):
- Main warroom page integration (page.tsx)
- IncidentResponse → DualState mapper function
- Empty state: "系統穩定。0 活躍異常。"

Tests:
- test_guardrails.py (8/8)
- test_incident_engine.py (6/6)
- test_skill_loader.py (6/6)
- Frontend build: 0 errors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 11:58:28 +08:00
OG T
1576f2ab20 fix(db): eliminate SQLite brain-split, force PostgreSQL
Root cause: Worker used SQLITE_DATABASE_URL causing "no such table: incidents"
because each Pod had isolated SQLite file, not shared PostgreSQL.

Fixes:
- db/base.py: Use DATABASE_URL (PostgreSQL) instead of SQLITE_DATABASE_URL
- Added SQLite prohibition guard with logging
- Added pool_size and pool_pre_ping for production stability

New: packages/lewooogo-data PgMemoryProvider (Phase 6.4d)
- Episodic Memory implementation for PostgreSQL
- init_pg_engine() with auto table creation
- SQLite forbidden by Commander's decree

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 10:02:43 +08:00
OG T
9f353343c9 fix(worker): dedicated Redis pool with unlimited timeout for XREADGROUP
Root cause: Worker shared Redis pool with API (socket_timeout=5s),
but XREADGROUP blocks for 5s causing timeout errors every cycle.

Fix:
- Add init_worker_redis_pool() with socket_timeout=None
- Worker now uses get_worker_redis() for XREADGROUP operations
- API continues using get_redis() with short timeout

Also destroyed 50 zombie consumers via:
  XGROUP DESTROY stream:awoooi_signals awoooi_workers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 09:42:11 +08:00
OG T
6d7486634b fix(worker): correct redis function names causing CrashLoopBackOff
signal_worker.py was importing non-existent init_redis/close_redis
Correct names are init_redis_pool/close_redis_pool

Root cause of:
- No Telegram alerts for 7+ hours
- No new approval cards
- No incident processing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 09:19:01 +08:00
OG T
de5796522f fix(api): fix optimization_suggestions dict access in proposal generation
The optimization_suggestions field is list[dict], not list[object].
Use .get() to access dict keys instead of attribute access.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 01:40:00 +08:00
OG T
141df533cc feat(api): Phase 6.4 LLM-based proposal generation with cache
- Add _call_with_cache wrapper in OpenClaw (Redis-based LLM cache)
- Add generate_incident_proposal method for incident analysis
- Integrate ProposalService with OpenClaw LLM
- Fallback to template-based proposals if LLM fails
- Include LLM metadata (provider, confidence, cache status) in proposals

憲法條款: 必須使用快取保護算力資源,嚴禁無快取裸奔調用

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 01:33:46 +08:00
OG T
e4bd030882 fix(api): use INTERVAL syntax to avoid ClickHouse Decimal overflow
The toDateTime64(nanoseconds, 9) caused Decimal overflow.
Switched to simpler `now() - INTERVAL X MINUTE` syntax.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 00:57:45 +08:00
OG T
7f2adab78b fix(api): query correct SigNoz traces table (v3 not v2)
The SignOz trace data is stored in distributed_signoz_index_v3,
not v2. This fixes GlobalPulse showing all zeros.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 00:50:15 +08:00
OG T
b00f318450 fix(api): correct OTEL gRPC endpoint format and SignOz query table
Root cause analysis:
1. OTEL gRPC endpoint had http:// prefix which is invalid for gRPC
2. SignOz query was targeting wrong table (signoz_metrics.distributed_samples_v4)
3. Should query signoz_traces.distributed_signoz_index_v2 for trace data

Fixes:
- Remove http:// prefix from OTEL_EXPORTER_OTLP_ENDPOINT (gRPC needs host:port)
- Update SignOz client to query traces table instead of metrics table
- Fix timestamp format (nanoseconds for DateTime64(9))
- statusCode: 0=Unset, 1=Ok, 2=Error

This should enable OTEL traces to reach SigNoz and GlobalPulse to show real metrics.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 00:41:51 +08:00
OG T
21ce7056fa fix(otel): correct OTEL endpoint to port 24317 and fix NetworkPolicy
- SigNoz OTEL Collector maps container:4317 to host:24317
- Updated NetworkPolicy egress to allow 24317/24318
- Updated ConfigMap with correct OTEL_EXPORTER_OTLP_ENDPOINT
- Fixed OpenClaw port from 8089 to 8088

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-23 00:06:07 +08:00
OG T
551a305fcf fix(config): rename _OPENCLAW_TG_USER_WHITELIST_RAW to comply with pydantic v2
Pydantic v2 does not allow field names with leading underscores.
Changed from @property pattern to method pattern.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-22 23:40:09 +08:00
OG T
c2b33a99a3 fix(config): 避免 pydantic-settings 自動 JSON 解析 WHITELIST
使用 str + property 取代 list[int] + validator
解決 K8s Secret 注入時的解析錯誤

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-22 23:18:50 +08:00
OG T
0c80f6a996 fix(worker): add standalone entry point for K8s deployment
- 新增 __main__ 入口點
- 寫入 health files for K8s probes
- Graceful shutdown 處理

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-22 19:56:15 +08:00
OG T
196d269b92 feat: add all application source code
- apps/api: FastAPI backend with Dockerfile
- apps/web: Next.js frontend with Dockerfile
- apps/sensor: Signal collection agent
- packages: shared packages

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-22 18:57:44 +08:00
OG T
ccdf757edd chore: initial commit for AWOOOI project
Phase 0 Day 1 - Project initialization:
- Independent repository (Option A)
- .awoooi-agent-rules.md (AI development contract)
- Project skeleton (apps/web, apps/api, packages, docs)
- ADR template for architecture decisions
- LOGBOOK for progress tracking

Strategic decision: 2026-03-19 Operation Cyber-Shell
Reference: /wooo-aiops/docs/meetings/2026-03-19_FRONTEND_RESTRUCTURE_STRATEGY.md

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-03-19 19:16:12 +08:00