M6:缘契、人格与世界——契约版本链、铸魂分灵、河图境界与三界分流

- 缘契域 domains/yuanqi:covenants(当前版)+ covenant_events(不可变历史);提议—问心—铭契—撤回全链;边界变更立即生效;多维关系并存,服务层拒绝 affinity/好感度单一键;浪漫维度成人资格标记位
- 道体铸魂与分灵 domains/jingsheng/soul.py:soul_forgings 确认流(锚点变更 pending→confirmed 应用并签发新魂籍版本,确认前人物锚点不变);分灵创建新人物(继承资料与谱系 lineage 链、不继承原身份,魂籍从 v1 起)
- 河图域 domains/hetu:persistent_worlds 境界 + world_entities/world_relations 境界作用域重建 + 世谱挂接;境界正史视图(scope=persistent_world 归真集合);canonize 后置推进正史计数
- 三界分流:reality→息壤提取(不变);persistent_world→境界实录+正史推进;simulation→只记试演实录;factual_records 增 scope 列——境界/幻境实录与真界本相隔离
- 正影打通:引文 target_type=memory 时被引记忆 superseded → 返回 successor_memory_id 提示,不静默替换
- 前端:人物详情页缘契面板(提议维度选择/铭契/撤回/事件史)+ 世界页重建(境界目录/实体/正史概览)+ covenants/worlds api 库
- 退役:旧 personality/drive/evolution/world 模块、服务、端点、仓储、schema、前端五页与组件样式;迁移 007 退役九张旧表与 characters.current_personality_version_id
- 验收(test_m6_domains 六用例):多维无单一好感度/铭契版本链/事件不可抹除/撤回立即生效/边界即时/铸魂确认流+魂籍版本/分灵谱系/境界正史不进真界(实录 scope 隔离+真界候选=0)/引文正影后继
- 四套件:后端 379、前端 199、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 007 净库+±1 干净
This commit is contained in:
chenxin committed 2026-08-27 20:10:11 +08:00
1 parent 684261f4b4
commit 7e23d6fa84
108 files changed
+2600 -9732

No files matched your search

-97
View File
@@ -1,97 +0,0 @@
"""内驱力数据访问(好奇问题 + 探索性次生目标)。"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.drive import CuriosityQuestion, ExploratorySubgoal
async def add_curiosities(session: AsyncSession, curiosities: list[CuriosityQuestion]) -> None:
session.add_all(curiosities)
await session.flush()
async def get_curiosity(session: AsyncSession, curiosity_id: str) -> CuriosityQuestion | None:
return await session.get(CuriosityQuestion, curiosity_id)
async def list_curiosities(
session: AsyncSession,
character_id: str,
*,
source: str | None = None,
page: int = 1,
page_size: int = 20,
) -> tuple[list[CuriosityQuestion], int]:
conditions = [CuriosityQuestion.character_id == character_id]
if source is not None:
conditions.append(CuriosityQuestion.source == source)
total = (
await session.execute(
select(func.count()).select_from(CuriosityQuestion).where(*conditions)
)
).scalar_one()
items = await session.execute(
select(CuriosityQuestion)
.where(*conditions)
.order_by(CuriosityQuestion.created_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items.scalars().all()), int(total or 0)
async def add_subgoals(session: AsyncSession, subgoals: list[ExploratorySubgoal]) -> None:
session.add_all(subgoals)
await session.flush()
async def get_subgoal(session: AsyncSession, subgoal_id: str) -> ExploratorySubgoal | None:
return await session.get(ExploratorySubgoal, subgoal_id)
async def list_subgoals(
session: AsyncSession,
character_id: str,
*,
status: str | None = None,
page: int = 1,
page_size: int = 20,
) -> tuple[list[ExploratorySubgoal], int]:
conditions = [ExploratorySubgoal.character_id == character_id]
if status is not None:
conditions.append(ExploratorySubgoal.status == status)
total = (
await session.execute(
select(func.count()).select_from(ExploratorySubgoal).where(*conditions)
)
).scalar_one()
items = await session.execute(
select(ExploratorySubgoal)
.where(*conditions)
.order_by(ExploratorySubgoal.created_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items.scalars().all()), int(total or 0)
async def list_approved_subgoals(
session: AsyncSession,
character_id: str,
limit: int = 5,
) -> list[ExploratorySubgoal]:
"""列出已批准(approved)的次生目标,按 created_at 升序排列。
供大周天自主探索执行阶段拾取。
"""
result = await session.execute(
select(ExploratorySubgoal)
.where(
ExploratorySubgoal.character_id == character_id,
ExploratorySubgoal.status == "approved",
)
.order_by(ExploratorySubgoal.created_at.asc())
.limit(limit)
)
return list(result.scalars().all())
-44
View File
@@ -1,44 +0,0 @@
"""演化候选数据访问。"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.evolution import EvolutionCandidate
async def add_candidates(session: AsyncSession, candidates: list[EvolutionCandidate]) -> None:
session.add_all(candidates)
await session.flush()
async def get_candidate(session: AsyncSession, candidate_id: str) -> EvolutionCandidate | None:
return await session.get(EvolutionCandidate, candidate_id)
async def list_candidates(
session: AsyncSession,
character_id: str,
*,
status: str | None = None,
candidate_type: str | None = None,
page: int = 1,
page_size: int = 20,
) -> tuple[list[EvolutionCandidate], int]:
conditions = [EvolutionCandidate.character_id == character_id]
if status is not None:
conditions.append(EvolutionCandidate.status == status)
if candidate_type is not None:
conditions.append(EvolutionCandidate.type == candidate_type)
total = (
await session.execute(
select(func.count()).select_from(EvolutionCandidate).where(*conditions)
)
).scalar_one()
items_result = await session.execute(
select(EvolutionCandidate)
.where(*conditions)
.order_by(EvolutionCandidate.created_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items_result.scalars().all()), int(total or 0)
-16
View File
@@ -13,7 +13,6 @@ from app.models.governance import (
Goal,
PerceptionChannel,
Plan,
WorldEntity,
)
# —— 太一枢 · 目标 ——
@@ -102,23 +101,8 @@ async def add_perception_channel(
# —— 河图枢 · 世界实体 ——
async def list_world_entities(session: AsyncSession) -> list[WorldEntity]:
result = await session.execute(select(WorldEntity).order_by(WorldEntity.updated_at.desc()))
return list(result.scalars().all())
async def get_world_entity(session: AsyncSession, entity_id: str) -> WorldEntity | None:
return await session.get(WorldEntity, entity_id)
async def add_world_entity(session: AsyncSession, entity: WorldEntity) -> WorldEntity:
session.add(entity)
await session.flush()
return entity
# —— 洛书枢 · 计划 ——
async def list_plans(session: AsyncSession) -> list[Plan]:
result = await session.execute(select(Plan).order_by(Plan.updated_at.desc()))
-84
View File
@@ -1,84 +0,0 @@
"""人格数据访问。"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.personality import PersonalityProposal, PersonalityVersion
async def get_personality(session: AsyncSession, personality_id: str) -> PersonalityVersion | None:
return await session.get(PersonalityVersion, personality_id)
async def get_latest_personality(
session: AsyncSession, character_id: str
) -> PersonalityVersion | None:
result = await session.execute(
select(PersonalityVersion)
.where(PersonalityVersion.character_id == character_id)
.order_by(PersonalityVersion.version.desc())
.limit(1)
)
return result.scalar_one_or_none()
async def list_personality_versions(
session: AsyncSession,
character_id: str,
*,
page: int = 1,
page_size: int = 20,
) -> tuple[list[PersonalityVersion], int]:
"""按版本号倒序分页返回某人物的人格版本历史,返回 (条目, 总数)。"""
cond = PersonalityVersion.character_id == character_id
total = int(
(
await session.execute(select(func.count()).select_from(PersonalityVersion).where(cond))
).scalar_one()
)
result = await session.execute(
select(PersonalityVersion)
.where(cond)
.order_by(PersonalityVersion.version.desc())
.offset((page - 1) * page_size)
.limit(page_size)
)
return list(result.scalars().all()), total
async def add_proposal(session: AsyncSession, proposal: PersonalityProposal) -> PersonalityProposal:
session.add(proposal)
await session.flush()
return proposal
async def get_proposal(session: AsyncSession, proposal_id: str) -> PersonalityProposal | None:
return await session.get(PersonalityProposal, proposal_id)
async def list_proposals(
session: AsyncSession,
*,
character_id: str | None = None,
status: str | None = None,
page: int = 1,
page_size: int = 20,
) -> tuple[list[PersonalityProposal], int]:
"""按创建时间倒序分页返回人格修改建议;可选按人物/状态过滤,返回 (条目, 总数)。"""
conds = []
if character_id is not None:
conds.append(PersonalityProposal.character_id == character_id)
if status is not None:
conds.append(PersonalityProposal.status == status)
count_stmt = select(func.count()).select_from(PersonalityProposal)
list_stmt = select(PersonalityProposal)
if conds:
count_stmt = count_stmt.where(*conds)
list_stmt = list_stmt.where(*conds)
total = int((await session.execute(count_stmt)).scalar_one())
result = await session.execute(
list_stmt.order_by(PersonalityProposal.created_at.desc())
.offset((page - 1) * page_size)
.limit(page_size)
)
return list(result.scalars().all()), total
-104
View File
@@ -1,104 +0,0 @@
"""世界模型运行时数据访问(api-spec §12,按人物隔离)。"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.world import CharacterWorldEntity, WorldRelation
async def list_entities(
session: AsyncSession,
character_id: str,
*,
entity_type: str | None = None,
status: str | None = None,
page: int = 1,
page_size: int = 20,
) -> tuple[list[CharacterWorldEntity], int]:
conditions = [CharacterWorldEntity.character_id == character_id]
if entity_type is not None:
conditions.append(CharacterWorldEntity.type == entity_type)
if status is not None:
conditions.append(CharacterWorldEntity.status == status)
total = (
await session.execute(
select(func.count()).select_from(CharacterWorldEntity).where(*conditions)
)
).scalar_one()
items_result = await session.execute(
select(CharacterWorldEntity)
.where(*conditions)
.order_by(CharacterWorldEntity.updated_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items_result.scalars().all()), int(total or 0)
async def get_entity(session: AsyncSession, entity_id: str) -> CharacterWorldEntity | None:
return await session.get(CharacterWorldEntity, entity_id)
async def add_entity(session: AsyncSession, entity: CharacterWorldEntity) -> CharacterWorldEntity:
session.add(entity)
await session.flush()
return entity
async def list_relations(
session: AsyncSession,
character_id: str,
*,
page: int = 1,
page_size: int = 20,
) -> tuple[list[WorldRelation], int]:
conditions = [WorldRelation.character_id == character_id]
total = (
await session.execute(select(func.count()).select_from(WorldRelation).where(*conditions))
).scalar_one()
items_result = await session.execute(
select(WorldRelation)
.where(*conditions)
.order_by(WorldRelation.updated_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items_result.scalars().all()), int(total or 0)
async def get_relation(session: AsyncSession, relation_id: str) -> WorldRelation | None:
return await session.get(WorldRelation, relation_id)
async def add_relation(session: AsyncSession, relation: WorldRelation) -> WorldRelation:
session.add(relation)
await session.flush()
return relation
async def delete_relation(session: AsyncSession, relation_id: str) -> None:
"""删除世界关系。"""
relation = await session.get(WorldRelation, relation_id)
if relation:
await session.delete(relation)
await session.flush()
async def list_all_entities(session: AsyncSession, character_id: str) -> list[CharacterWorldEntity]:
"""获取人物的所有世界实体(无分页)。"""
result = await session.execute(
select(CharacterWorldEntity)
.where(CharacterWorldEntity.character_id == character_id)
.order_by(CharacterWorldEntity.updated_at.desc())
)
return list(result.scalars().all())
async def list_all_relations(session: AsyncSession, character_id: str) -> list[WorldRelation]:
"""获取人物的所有关系(无分页)。"""
result = await session.execute(
select(WorldRelation)
.where(WorldRelation.character_id == character_id)
.order_by(WorldRelation.updated_at.desc())
)
return list(result.scalars().all())