feat(maf): Phase 5 - action coordinator, approval flow, frontend MAF roundtable pages
- Backend: action_coordinator, capability_snapshot, event_normalizer, tool_executor updates - Backend: approved_tool_executor with write guard, action leases, migration script - Frontend: maf-roundtable module (API client, event timeline, approval cards, fact flow panel) - Frontend: MafRoutes, MafSessionsPage, MafRunDetailPage - Tests: action_leases, migration_phase5, phase5_entry_e2e, real_write_e2e/http_e2e - Docs: update implementation plan Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
21c4c898e7
commit
f82363d81f
55 files changed
+6304
-167
No files matched your search
+88
-1
@@ -17,15 +17,74 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
# ── shared enums (config + API schemas) ───────────────────────────────────
|
||||
|
||||
MafMode = Literal["structured", "group_chat"]
|
||||
MafWritePolicy = Literal["auto", "confirm_high_risk", "confirm_all_writes"]
|
||||
MafParticipantRole = Literal["manager", "seat"]
|
||||
MafToolSideEffect = Literal["read", "skill", "write"]
|
||||
MafRiskLevel = Literal["R0", "R1", "R2", "R3", "R4"]
|
||||
|
||||
|
||||
class MafToolMetadata(BaseModel):
|
||||
"""Deployment-owned side-effect classification for one actual tool name.
|
||||
|
||||
This lives in the MAF configuration rather than in the browser request or
|
||||
model output. The key in ``MafRoundtableConfig.tool_metadata`` must be the
|
||||
exact runtime tool name (including the MCP server prefix when applicable).
|
||||
"""
|
||||
|
||||
side_effect: MafToolSideEffect = Field(
|
||||
description="Tool side effect class used by the MAF WriteGuard",
|
||||
)
|
||||
risk_level: MafRiskLevel = Field(
|
||||
description="External action risk level used by MAF approval policy",
|
||||
)
|
||||
target_key_fields: list[str] = Field(
|
||||
default_factory=list,
|
||||
description=(
|
||||
"仅服务端配置的、用于派生目标租约键的顶层参数字段。"
|
||||
"参数值只参与稳定哈希,绝不直接写入 target_key。"
|
||||
),
|
||||
)
|
||||
target_key_namespace: str = Field(
|
||||
default="default",
|
||||
min_length=1,
|
||||
max_length=96,
|
||||
description="服务端目标键命名空间;用于隔离不同租户/业务域。",
|
||||
)
|
||||
|
||||
@field_validator("target_key_fields")
|
||||
@classmethod
|
||||
def _validate_target_key_fields(cls, fields: list[str]) -> list[str]:
|
||||
"""Only allow explicit top-level server-owned argument names.
|
||||
|
||||
In particular, a model/client supplied ``target_key`` is never a
|
||||
valid input. Nested paths are deliberately unsupported: a production
|
||||
adapter must register the exact stable business-id fields it owns.
|
||||
"""
|
||||
valid = re.compile(r"^[A-Za-z_][A-Za-z0-9_]{0,63}$")
|
||||
normalized: list[str] = []
|
||||
for field in fields:
|
||||
if not isinstance(field, str) or not valid.fullmatch(field):
|
||||
raise ValueError("target_key_fields must be simple top-level argument names")
|
||||
if field == "target_key":
|
||||
raise ValueError("target_key must not be supplied as a target key input")
|
||||
if field not in normalized:
|
||||
normalized.append(field)
|
||||
return normalized
|
||||
|
||||
@field_validator("target_key_namespace")
|
||||
@classmethod
|
||||
def _validate_target_key_namespace(cls, namespace: str) -> str:
|
||||
if not re.fullmatch(r"[A-Za-z0-9_.:-]{1,96}", namespace):
|
||||
raise ValueError("target_key_namespace contains unsupported characters")
|
||||
return namespace
|
||||
|
||||
|
||||
class MafRoundtableConfig(BaseModel):
|
||||
@@ -74,11 +133,39 @@ class MafRoundtableConfig(BaseModel):
|
||||
default=True,
|
||||
description="席位输出未通过 SeatTurnOutput 校验时是否允许一次定向格式修复",
|
||||
)
|
||||
# Server-trusted metadata keyed by the exact runtime tool name. Do not
|
||||
# infer this from MCP server names or prefixes: the actual discovered name
|
||||
# is what the capability snapshot and runtime WriteGuard see.
|
||||
tool_metadata: dict[str, MafToolMetadata] = Field(
|
||||
default_factory=dict,
|
||||
description="MAF 专用工具副作用/风险元数据,键必须是实际运行时 tool name",
|
||||
)
|
||||
approval_timeout_seconds: int = Field(
|
||||
default=3600,
|
||||
ge=60,
|
||||
le=604800,
|
||||
description="外部写入审批有效期(秒);到期后自动拒绝,绝不执行。",
|
||||
)
|
||||
approval_scan_interval_seconds: int = Field(
|
||||
default=10,
|
||||
ge=1,
|
||||
le=3600,
|
||||
description="MAF approval expiry scan interval in seconds",
|
||||
)
|
||||
target_lease_seconds: int = Field(
|
||||
default=900,
|
||||
ge=30,
|
||||
le=7200,
|
||||
description="外部业务目标写入租约有效期(秒);过期运行中的动作转 unknown。",
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"MafMode",
|
||||
"MafParticipantRole",
|
||||
"MafRiskLevel",
|
||||
"MafRoundtableConfig",
|
||||
"MafToolMetadata",
|
||||
"MafToolSideEffect",
|
||||
"MafWritePolicy",
|
||||
]
|
||||
Reference in new issue
Block a user