M8:天工阁、叩心与辰正——受托任务后台并行、叩心四约束、时态感知投影

- 天工阁域 domains/tiangong:backstage_tasks(委托包+验收标准+结果证据);有限分解(parent 链)与受控并行(各自后台 Run);子任务全终态级联父任务进入待验收;按证据 accept/reject
- kernel.start_backstage_run(kind=background_task):loop 后台分支不占前台席位、与前台对话并行;断言放宽容纳无人物功能任务;结果只经回调回呈任务——无身份写入路径
- 叩心域 domains/kouxin:knocking_candidates(event/time_anchor/manual 触发 + 草稿 + 裁决快照);四约束裁决(总开关→静默窗口【本地时区判定】→24h 频率→预算),dispatch 未过 429 且快照留痕;候选默认不自动发送;expire_stale 过期推进不触碰缘契
- 辰正 domains/zhengchen:temporal_context() 复用 time_sense 计算核(快照/农历/季节),产出【时态感知】投影段接入镜树生成 prompt(客观时间语境,不附情绪臆测——守一纪律)
- 退役:modules/goal_orchestrator|planner|perception|big_cycle、application/planning、services/governance|goal_persist、candidates 表链(imports 候选抽取 API 面)、goals/plans/agent_roster/perception_channels/big_cycles/旧候选表(迁移 009);前端 admin goals/plans/agents/perception/world 页与六组件;governance 只留 GenerationPreferences;admin 治理面收敛为司命+百工两枢;pivots 健康以域表计数重建
- 验收(test_m8_tiangong 五用例):后台任务无身份写入(记忆/魂籍/缘契零新增);后台与前台并行;分解级联;叩心四约束逐项;不回应不降低关系(缘契维度/状态/版本零变化)
- 四套件:后端 345、前端 203、BFF 4、神识 5 包全绿(2 个预存环境失败不变);迁移 009 净库干净
This commit is contained in:
chenxin committed 2026-08-28 09:13:39 +08:00
1 parent b419e0afde
commit c63b75152a
68 files changed
+1205 -4750

No files matched your search

-50
View File
@@ -1,50 +0,0 @@
"""大周天运行记录数据访问。"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.big_cycle import BigCycle
async def add_cycle(session: AsyncSession, cycle: BigCycle) -> BigCycle:
session.add(cycle)
await session.flush()
return cycle
async def get_cycle(session: AsyncSession, cycle_id: str) -> BigCycle | None:
return await session.get(BigCycle, cycle_id)
async def get_last_completed(session: AsyncSession, character_id: str) -> BigCycle | None:
result = await session.execute(
select(BigCycle)
.where(
BigCycle.character_id == character_id,
BigCycle.completed_at.is_not(None),
)
.order_by(BigCycle.completed_at.desc())
.limit(1)
)
return result.scalar_one_or_none()
async def list_cycles(
session: AsyncSession,
character_id: str,
*,
page: int = 1,
page_size: int = 20,
) -> tuple[list[BigCycle], int]:
conditions = [BigCycle.character_id == character_id]
total = (
await session.execute(select(func.count()).select_from(BigCycle).where(*conditions))
).scalar_one()
items_result = await session.execute(
select(BigCycle)
.where(*conditions)
.order_by(BigCycle.created_at.desc())
.offset(max(page - 1, 0) * page_size)
.limit(page_size)
)
return list(items_result.scalars().all()), int(total or 0)
-70
View File
@@ -1,70 +0,0 @@
"""候选数据访问(api-spec §8;档案 / 记忆候选)。"""
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.candidates import MemoryCandidate, ProfileCandidate
async def add_profile_candidates(session: AsyncSession, candidates: list[ProfileCandidate]) -> None:
session.add_all(candidates)
await session.flush()
async def add_memory_candidates(session: AsyncSession, candidates: list[MemoryCandidate]) -> None:
session.add_all(candidates)
await session.flush()
async def list_profile_candidates(
session: AsyncSession,
character_id: str,
*,
import_job_id: str | None = None,
status: str | None = None,
) -> list[ProfileCandidate]:
conditions = [ProfileCandidate.character_id == character_id]
if import_job_id is not None:
conditions.append(ProfileCandidate.import_job_id == import_job_id)
if status is not None:
conditions.append(ProfileCandidate.status == status)
result = await session.execute(
select(ProfileCandidate).where(*conditions).order_by(ProfileCandidate.created_at.desc())
)
return list(result.scalars().all())
async def list_memory_candidates(
session: AsyncSession,
character_id: str,
*,
import_job_id: str | None = None,
cycle_id: str | None = None,
status: str | None = None,
source: str | None = None,
) -> list[MemoryCandidate]:
conditions = [MemoryCandidate.character_id == character_id]
if import_job_id is not None:
conditions.append(MemoryCandidate.import_job_id == import_job_id)
if cycle_id is not None:
conditions.append(MemoryCandidate.cycle_id == cycle_id)
if status is not None:
conditions.append(MemoryCandidate.status == status)
if source == "cycle":
conditions.append(MemoryCandidate.import_job_id.is_(None))
elif source == "import":
conditions.append(MemoryCandidate.import_job_id.is_not(None))
result = await session.execute(
select(MemoryCandidate).where(*conditions).order_by(MemoryCandidate.created_at.desc())
)
return list(result.scalars().all())
async def get_profile_candidate(
session: AsyncSession, candidate_id: str
) -> ProfileCandidate | None:
return await session.get(ProfileCandidate, candidate_id)
async def get_memory_candidate(session: AsyncSession, candidate_id: str) -> MemoryCandidate | None:
return await session.get(MemoryCandidate, candidate_id)
-150
View File
@@ -1,150 +0,0 @@
"""司命台治理对象数据访问(api-spec §19.4)。
目标 / 感知通道 / 世界实体 / 计划 / 天工阁角色的 CRUD 数据访问;
均为本地单用户全局对象,不挂 character_id。
"""
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.time import utc_now
from app.models.governance import (
AgentRosterEntry,
Goal,
PerceptionChannel,
Plan,
)
# —— 太一枢 · 目标 ——
async def list_goals(session: AsyncSession) -> list[Goal]:
result = await session.execute(
select(Goal).order_by(Goal.priority.desc(), Goal.updated_at.desc())
)
return list(result.scalars().all())
async def get_goal(session: AsyncSession, goal_id: str) -> Goal | None:
return await session.get(Goal, goal_id)
async def add_goal(session: AsyncSession, goal: Goal) -> Goal:
session.add(goal)
await session.flush()
return goal
async def list_goals_by_character(
session: AsyncSession,
character_id: str,
status_filter: str | None = None,
) -> list[Goal]:
"""按 character_id 获取目标列表;可选的 status 过滤。"""
stmt = select(Goal).where(Goal.character_id == character_id)
if status_filter:
stmt = stmt.where(Goal.status == status_filter)
stmt = stmt.order_by(Goal.priority.desc(), Goal.updated_at.desc())
result = await session.execute(stmt)
return list(result.scalars().all())
async def update_goal_progress(
session: AsyncSession,
goal_id: str,
progress: float,
) -> Goal | None:
"""更新目标的 progress 与 updated_at 字段。"""
goal = await session.get(Goal, goal_id)
if goal is None:
return None
goal.progress = progress
goal.updated_at = utc_now()
await session.flush()
return goal
async def list_active_session_goal(session: AsyncSession, character_id: str) -> Goal | None:
"""查找指定人物活跃的 session 级目标(各人物至多一个活跃 session 目标)。"""
result = await session.execute(
select(Goal)
.where(
Goal.character_id == character_id,
Goal.level == "session",
Goal.status == "active",
)
.limit(1)
)
return result.scalar_one_or_none()
# —— 烛照枢 · 感知通道 ——
async def list_perception_channels(session: AsyncSession) -> list[PerceptionChannel]:
result = await session.execute(select(PerceptionChannel).order_by(PerceptionChannel.channel))
return list(result.scalars().all())
async def get_perception_channel(session: AsyncSession, channel: str) -> PerceptionChannel | None:
return await session.get(PerceptionChannel, channel)
async def add_perception_channel(
session: AsyncSession, channel: PerceptionChannel
) -> PerceptionChannel:
session.add(channel)
await session.flush()
return channel
# —— 河图枢 · 世界实体 ——
async def list_plans(session: AsyncSession) -> list[Plan]:
result = await session.execute(select(Plan).order_by(Plan.updated_at.desc()))
return list(result.scalars().all())
async def get_plan(session: AsyncSession, plan_id: str) -> Plan | None:
return await session.get(Plan, plan_id)
async def add_plan(session: AsyncSession, plan: Plan) -> Plan:
session.add(plan)
await session.flush()
return plan
# —— 天工阁枢 · 角色在岗 ——
async def list_agent_roster(session: AsyncSession) -> list[AgentRosterEntry]:
result = await session.execute(select(AgentRosterEntry).order_by(AgentRosterEntry.role))
return list(result.scalars().all())
async def get_agent(session: AsyncSession, role: str) -> AgentRosterEntry | None:
return await session.get(AgentRosterEntry, role)
async def add_agent(session: AsyncSession, agent: AgentRosterEntry) -> AgentRosterEntry:
session.add(agent)
await session.flush()
return agent
# —— 百工枢 · 工具策略(§15/§16 共享)——
# —— 计数(供九枢健康度聚合)——
async def count(session: AsyncSession, model: type) -> int:
result = await session.execute(select(func.count()).select_from(model))
return int(result.scalar_one())