refactor(api): Phase 17 P1 Tier 3 紅區服務 Protocol 定義
新增 5 個紅區核心服務的 Protocol 介面: - IDecisionManager: 決策狀態機 - ITrustScoreManager: 信任評分引擎 - IIncidentEngine: 事件處理引擎 - IMultiSigRedisService: 分散式鎖服務 - ITelegramSecurityInterceptor: 安全攔截器 符合 leWOOOgo 積木化規範: - 支援依賴注入 (DI) - 便於測試時 Mock - 型別約束確保實作一致性 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ Phase 3.2: Progressive Autonomy
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
from typing import Literal, Protocol, runtime_checkable
|
||||
|
||||
# Phase 16 R2 (2026-03-25): RiskLevel 統一改從 models/approval.py 導入
|
||||
# 原因: 消除重複定義,統一風險等級來源
|
||||
@@ -107,6 +107,57 @@ class TrustThresholds:
|
||||
DEFAULT_THRESHOLDS = TrustThresholds()
|
||||
|
||||
|
||||
# ==================== Protocol Interface (Phase 17 P1) ====================
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class ITrustScoreManager(Protocol):
|
||||
"""
|
||||
TrustScoreManager 介面定義
|
||||
|
||||
用途:
|
||||
- 依賴注入 (DI) 時的型別約束
|
||||
- 測試時 Mock 的型別檢查
|
||||
- 符合 leWOOOgo 積木化規範
|
||||
|
||||
Tier 3 紅區服務: 修改需首席架構師簽核
|
||||
|
||||
@see feedback_lewooogo_modular_enforcement.md
|
||||
@see docs/RED_ZONES.md
|
||||
"""
|
||||
|
||||
def record_approval(
|
||||
self,
|
||||
action_pattern: str,
|
||||
user_role: str,
|
||||
user_id: str | None = None,
|
||||
) -> TrustRecord:
|
||||
"""記錄人類批准"""
|
||||
...
|
||||
|
||||
def record_rejection(
|
||||
self,
|
||||
action_pattern: str,
|
||||
user_role: str,
|
||||
user_id: str | None = None,
|
||||
reason: str | None = None,
|
||||
) -> TrustRecord:
|
||||
"""記錄人類拒絕"""
|
||||
...
|
||||
|
||||
def evaluate_adjusted_risk(
|
||||
self,
|
||||
action_pattern: str,
|
||||
original_risk: str | RiskLevel,
|
||||
) -> RiskAdjustment:
|
||||
"""評估調整後的風險等級"""
|
||||
...
|
||||
|
||||
def get_trust_record(self, action_pattern: str) -> TrustRecord | None:
|
||||
"""取得信任記錄"""
|
||||
...
|
||||
|
||||
|
||||
# ==================== Trust Engine ====================
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user