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

+5 -16
View File
@@ -1,19 +1,13 @@
"""SQLAlchemy 模型导出。"""
from app.models.big_cycle import BigCycle
from app.models.candidates import MemoryCandidate, ProfileCandidate
from app.models.character import Character
from app.models.governance import (
AgentRosterEntry,
GenerationPreferences,
Goal,
PerceptionChannel,
Plan,
)
from app.models.governance import GenerationPreferences
from app.models.idempotency import IdempotencyKey
from app.models.imports import CharacterImportJob, ImportItem
from app.domains.baigong.models import Capability, Mandate, ToolCall
from app.domains.hetu.models import PersistentWorld, WorldEntity, WorldRelation
from app.domains.kouxin.models import KnockingCandidate
from app.domains.tiangong.models import BackstageTask
from app.domains.xingyi.models import Form, FormAnchor, VoiceProfile
from app.domains.yuanqi.models import Covenant, CovenantEvent
from app.models.jingsheng import Custodianship, EmbryoDraft, IdentityRecord, RuntimeSeat, SoulForging
@@ -33,7 +27,9 @@ from app.models.safety import AuditEvent, PendingConfirmationRecord
from app.models.user import User
__all__ = [
"BackstageTask",
"Capability",
"KnockingCandidate",
"Form",
"FormAnchor",
"VoiceProfile",
@@ -45,25 +41,18 @@ __all__ = [
"Mandate",
"ToolCall",
"AgentRosterEntry",
"AuditEvent",
"BigCycle",
"Character",
"CharacterImportJob",
"Event",
"GenerationPreferences",
"Goal",
"IdempotencyKey",
"ImportItem",
"Lorebook",
"LorebookEntry",
"McpServer",
"MemoryCandidate",
"PendingConfirmationRecord",
"PerceptionChannel",
"Permission",
"Plan",
"ProfileCandidate",
"Role",
"RolePermission",
"Run",
-38
View File
@@ -1,38 +0,0 @@
"""大周天运行记录(architecture §3.2;v1-scope §3.3)。
大周天是长期演化循环:记忆积累 → 自我评估 → 演化策略 → 候选生成。
本表记录每次循环的触发、阶段与终态;演化候选 / 内驱力 / 自动抽取由后续
子阶段写入各自表,循环本身只承载编排与留痕。
"""
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.ids import new_cycle_id
from app.core.time import utc_now
from app.db.base import Base
class BigCycle(Base):
"""大周天循环运行记录。"""
__tablename__ = "big_cycles"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_cycle_id)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
trigger: Mapped[str] = mapped_column(String(40), nullable=False)
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
phase: Mapped[str | None] = mapped_column(String(40))
memory_count_at_trigger: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
evaluation_snapshot_json: Mapped[str | None] = mapped_column(Text)
summary: Mapped[str | None] = mapped_column(Text)
error_code: Mapped[str | None] = mapped_column(String(80))
error_message: Mapped[str | None] = mapped_column(Text)
started_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), index=True)
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
)
-67
View File
@@ -1,67 +0,0 @@
"""资料导入候选模型(api-spec §8;契约字典 §10.6 candidate.status)。
导入资料经模型抽取产生档案 / 记忆候选,待用户审核后应用;人格建议复用
``personality_proposals``(005)。``evidence_ids`` 指向 ``import_items.id``
(EvidenceRef source_type = ``import_item``)。
"""
from datetime import datetime
from sqlalchemy import DateTime, Float, ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.ids import new_memory_candidate_id, new_profile_candidate_id
from app.core.time import utc_now
from app.db.base import Base
class ProfileCandidate(Base):
"""人物档案候选(契约字典 §10.6)。"""
__tablename__ = "character_profile_candidates"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_profile_candidate_id)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
import_job_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("character_import_jobs.id"), index=True
)
field: Mapped[str] = mapped_column(String(60), nullable=False)
value: Mapped[str] = mapped_column(Text, nullable=False)
confidence: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
evidence_ids_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
reason: Mapped[str | None] = mapped_column(Text)
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
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
)
class MemoryCandidate(Base):
"""记忆候选(契约字典 §10.6)。"""
__tablename__ = "memory_candidates"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_memory_candidate_id)
character_id: Mapped[str] = mapped_column(String(80), ForeignKey("characters.id"), index=True)
import_job_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("character_import_jobs.id"), index=True
)
cycle_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("big_cycles.id"), index=True
)
type: Mapped[str] = mapped_column(String(60), nullable=False)
title: Mapped[str] = mapped_column(String(200), nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
confidence: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
importance: Mapped[float] = mapped_column(Float, nullable=False, default=0.5)
sensitivity: Mapped[str] = mapped_column(String(40), nullable=False, default="low")
evidence_ids_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
reason: Mapped[str | None] = mapped_column(Text)
reviewed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
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
)
+4 -106
View File
@@ -1,118 +1,16 @@
"""司命台治理对象模型(九枢治理视图,api-spec §19.4)。
目标(太一)/ 感知通道(烛照)/ 世界实体(河图)/ 计划(洛书)/ 天工阁角色
为可增长的开放集合;生成偏好(模型网关 §4.3)为本地单用户单行配置。
这些对象当前由司命台治理视图维护,对应枢的自动运行时暂未启用(见
docs/operations/capability-matrix.md §8)。
"""
"""治理域模型:生成偏好(其余旧枢治理表随 M8 退役)。"""
from datetime import datetime
from sqlalchemy import (
Boolean,
DateTime,
Float,
ForeignKey,
Integer,
String,
Text,
)
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import Boolean, DateTime, Float, Integer, String
from app.core.config import settings
from app.core.ids import new_goal_id, new_plan_id, new_world_entity_id
from sqlalchemy.orm import Mapped, mapped_column
from app.core.time import utc_now
from app.db.base import Base
class Goal(Base):
"""太一枢目标节点(契约字典 §5.11 / §5.12)。"""
__tablename__ = "goals"
def __init__(self, **kwargs: object) -> None:
# Python 端默认值:mapped_column(default=...) 仅在 ORM flush 时生效,
# __init__ 覆盖使测试在不侵入 session 时就能验证默认值。
kwargs.setdefault("type", "session")
kwargs.setdefault("progress", 0.0)
super().__init__(**kwargs)
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_goal_id)
character_id: Mapped[str | None] = mapped_column(
String(80), ForeignKey("characters.id"), nullable=True, index=True
)
title: Mapped[str] = mapped_column(String(300), nullable=False)
description: Mapped[str] = mapped_column(Text, nullable=False, default="")
level: Mapped[str] = mapped_column(String(40), nullable=False, default="task", index=True)
type: Mapped[str] = mapped_column(String(40), nullable=False, default="session")
status: Mapped[str] = mapped_column(String(40), nullable=False, default="pending", index=True)
priority: Mapped[int] = mapped_column(Integer, nullable=False, default=50)
progress: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
constraints_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
parent_id: Mapped[str | None] = mapped_column(String(80), ForeignKey("goals.id"), nullable=True)
success_criteria_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
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
)
class PerceptionChannel(Base):
"""烛照枢感知通道授权(契约字典 §5.7 频道级)。channel 为主键,默认六类可自定义。"""
__tablename__ = "perception_channels"
channel: Mapped[str] = mapped_column(String(80), primary_key=True)
name: Mapped[str] = mapped_column(String(120), nullable=False)
description: Mapped[str] = mapped_column(Text, nullable=False, default="")
enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
consent_status: Mapped[str] = mapped_column(String(40), nullable=False, default="unknown")
privacy_level: Mapped[str] = mapped_column(String(40), nullable=False, default="normal")
risk_level: Mapped[str] = mapped_column(String(20), nullable=False, default="L2")
last_active_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
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
)
class Plan(Base):
"""洛书枢计划(契约字典 §5.13)。goal_id 关联太一枢目标,可空。"""
__tablename__ = "plans"
id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_plan_id)
goal_id: Mapped[str | None] = mapped_column(String(80), ForeignKey("goals.id"), index=True)
title: Mapped[str] = mapped_column(String(300), nullable=False)
status: Mapped[str] = mapped_column(String(40), nullable=False, default="draft", index=True)
assumptions_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
risks_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
required_tools_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
success_criteria_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]")
step_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
completed_steps: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
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
)
class AgentRosterEntry(Base):
"""天工阁枢九角色在岗(契约字典 §5.14)。role 为主键,默认九角色可自定义。"""
__tablename__ = "agent_roster"
role: Mapped[str] = mapped_column(String(80), primary_key=True)
name: Mapped[str] = mapped_column(String(120), nullable=False)
responsibility: Mapped[str] = mapped_column(Text, nullable=False, default="")
enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
last_active_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
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
)
class GenerationPreferences(Base):
"""生成参数偏好(模型网关 §4.3)。本地单用户单行,按 owner_scope 固定。"""