Files
hunjing/backend/app/models/evolution.py
T
2026-08-21 16:00:13 +08:00

51 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""大周天演化候选模型(契约字典 §12;self-evolution-design.md §11)。
演化候选是大周天(及未来镜界 / 反馈)产出的统一轻量演化增量载体;``type`` 区分
候选对象,``level``(L0-L4)决定半自动边界(见 [大周天演化候选落地设计]
../../docs/domain/core-domains.md §5)。``cycle_id`` 关联触发本次
的大周天循环,``resulting_target_id`` 记录派生后的下游资源 ID。
"""
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.ids import new_evolution_candidate_id
from app.core.time import utc_now
from app.db.base import Base
class EvolutionCandidate(Base):
"""演化候选(统一表)。"""
__tablename__ = "evolution_candidates"
id: Mapped[str] = mapped_column(
String(80), primary_key=True, default=new_evolution_candidate_id
)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
cycle_id: Mapped[str] = mapped_column(String(80), ForeignKey("big_cycles.id"), index=True)
type: Mapped[str] = mapped_column(String(60), nullable=False)
source: Mapped[str] = mapped_column(String(60), nullable=False, default="big_cycle")
level: Mapped[str] = mapped_column(String(8), nullable=False, default="L4")
scope: Mapped[str] = mapped_column(String(40), nullable=False, default="character_scope")
title: Mapped[str] = mapped_column(String(200), nullable=False)
proposal: Mapped[str] = mapped_column(Text, nullable=False)
delta_json: Mapped[str] = mapped_column(Text, nullable=False, default="{}")
evidence_ids_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
confidence: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
benefit_score: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
risk_score: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
drift_score: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
auto_apply_allowed: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
resulting_target_id: Mapped[str | None] = mapped_column(String(80))
error_message: Mapped[str | None] = mapped_column(Text)
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
reviewed_by: Mapped[str] = mapped_column(String(80), nullable=False, default="system")
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=utc_now, onupdate=utc_now
)