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:
1 parent
b419e0afde
commit
c63b75152a
68 files changed
+1205
-4750
No files matched your search
@@ -12,19 +12,12 @@ from app.core.config import settings
|
||||
from app.core.security import redact_text
|
||||
from app.core.time import to_iso, utc_now
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.governance import (
|
||||
AgentRosterEntry,
|
||||
Goal,
|
||||
PerceptionChannel,
|
||||
Plan,
|
||||
)
|
||||
from app.models.idempotency import IdempotencyKey
|
||||
from app.models.xirang import Memory
|
||||
from app.models.runtime import Event, Run
|
||||
from app.models.safety import AuditEvent, PendingConfirmationRecord
|
||||
from app.repositories import audit as audit_repo
|
||||
from app.repositories import characters as character_repo
|
||||
from app.repositories import governance as governance_repo
|
||||
from app.repositories import idempotency as idempotency_repo
|
||||
from app.repositories import runtime as runtime_repo
|
||||
from app.schemas.admin import (
|
||||
@@ -41,16 +34,14 @@ from app.schemas.common import Page
|
||||
from app.services.serializers import audit_to_response
|
||||
|
||||
# 九枢全集(契约字典 §5.9):枢标识、中文名、工程模块名。
|
||||
_PIVOT_REGISTRY: list[tuple[str, str, str]] = [
|
||||
_PIVOT_REGISTRY = [
|
||||
("personality_core", "灵核枢", "Personality Core"),
|
||||
("goal_orchestrator", "太一枢", "Goal Orchestrator"),
|
||||
("capability_registry", "百工枢", "Capability Registry"),
|
||||
("safety_governor", "司命枢", "Safety Governor"),
|
||||
("perception", "烛照枢", "Perception Layer"),
|
||||
("world_model", "河图枢", "World Model"),
|
||||
("planner", "洛书枢", "Planner"),
|
||||
("memory", "息壤枢", "Memory System"),
|
||||
("tool_runtime", "百工枢", "Tool Runtime"),
|
||||
("agent_society", "天工阁枢", "Agent Society"),
|
||||
("hetu", "河图枢", "Hetu World"),
|
||||
("tiangong", "天工阁", "Tiangong Backstage"),
|
||||
("kouxin", "叩心枢", "Kouxin Proactive"),
|
||||
("memory", "息壤枢", "Xirang Memory"),
|
||||
]
|
||||
|
||||
|
||||
@@ -64,7 +55,15 @@ def _summarize_input(value: dict | None) -> str:
|
||||
async def get_pivots_health(
|
||||
*,
|
||||
owner_scope: str = settings.default_owner_scope,
|
||||
) -> PivotHealthReport:
|
||||
):
|
||||
"""九枢健康度:以事件流与域表计数呈现(旧枢治理表随 M8 退役)。"""
|
||||
from app.domains.baigong.models import Capability
|
||||
from app.domains.hetu.models import PersistentWorld
|
||||
from app.domains.kouxin.models import KnockingCandidate
|
||||
from app.domains.tiangong.models import BackstageTask
|
||||
from app.models.safety import PendingConfirmationRecord
|
||||
from app.models.xirang import Memory
|
||||
|
||||
async with AsyncSessionLocal() as session:
|
||||
pending_count = len(
|
||||
list(
|
||||
@@ -79,64 +78,47 @@ async def get_pivots_health(
|
||||
.all()
|
||||
)
|
||||
)
|
||||
goals_n = await governance_repo.count(session, Goal)
|
||||
from app.domains.hetu.models import PersistentWorld
|
||||
|
||||
world_n = await governance_repo.count(session, PersistentWorld)
|
||||
plans_n = await governance_repo.count(session, Plan)
|
||||
perception_n = await governance_repo.count(session, PerceptionChannel)
|
||||
agents_n = await governance_repo.count(session, AgentRosterEntry)
|
||||
memories_n = await governance_repo.count(session, Memory, Memory.status != "tombstoned")
|
||||
caps_n = await _count(session, Capability)
|
||||
world_n = await _count(session, PersistentWorld)
|
||||
tasks_n = await _count(session, BackstageTask)
|
||||
knocks_n = await _count(session, KnockingCandidate)
|
||||
memories_n = await _count(session, Memory, Memory.status != "tombstoned")
|
||||
character = await character_repo.get_active_character(session, owner_scope)
|
||||
has_personality = bool(character and character.identity_baseline_json not in ("", "{}"))
|
||||
tool_enabled = True # 百工域常驻(乾坤可用性按端点区分)
|
||||
now = to_iso(utc_now())
|
||||
|
||||
raw: list[tuple[str, str, str, bool, str]] = [
|
||||
(
|
||||
"personality_core",
|
||||
"steady" if has_personality else "void",
|
||||
"人格版本已就绪" if has_personality else "人格未初始化",
|
||||
),
|
||||
("goal_orchestrator", "steady" if goals_n else "void", f"目标 {goals_n} 项"),
|
||||
(
|
||||
"safety_governor",
|
||||
"cracked" if pending_count else "steady",
|
||||
f"{pending_count} 项工具调用待裁定" if pending_count else "无待裁定",
|
||||
),
|
||||
("perception", "steady" if perception_n else "void", f"感知通道 {perception_n} 项"),
|
||||
("world_model", "steady" if world_n else "void", f"世界实体 {world_n} 项"),
|
||||
("planner", "steady" if plans_n else "void", f"计划 {plans_n} 项"),
|
||||
raw: list[tuple[str, str, str]] = [
|
||||
("personality_core", "steady" if has_personality else "void", "道体锚点已就绪" if has_personality else "锚点未初始化"),
|
||||
("capability_registry", "steady" if caps_n else "void", f"能力 {caps_n} 项"),
|
||||
("safety_governor", "cracked" if pending_count else "steady", f"{pending_count} 项待裁决" if pending_count else "无待裁决"),
|
||||
("hetu", "steady" if world_n else "void", f"境界 {world_n} 个"),
|
||||
("tiangong", "steady" if tasks_n else "void", f"受托任务 {tasks_n} 项"),
|
||||
("kouxin", "breathing" if knocks_n else "void", f"叩心候选 {knocks_n} 条"),
|
||||
("memory", "steady" if memories_n else "void", f"记忆 {memories_n} 条"),
|
||||
(
|
||||
"tool_runtime",
|
||||
"breathing" if tool_enabled else "void",
|
||||
"沙箱运行时在线" if tool_enabled else "工具运行时未启用",
|
||||
),
|
||||
("agent_society", "steady" if agents_n else "void", f"在岗角色 {agents_n} 位"),
|
||||
]
|
||||
|
||||
name_map = {pivot: (name, module) for pivot, name, module in _PIVOT_REGISTRY}
|
||||
pivots: list[PivotHealthSummary] = []
|
||||
for pivot, health, summary in raw:
|
||||
name, module = name_map[pivot]
|
||||
pivots.append(
|
||||
PivotHealthSummary(
|
||||
pivot=pivot,
|
||||
name=name,
|
||||
module=module,
|
||||
health=health,
|
||||
summary=summary,
|
||||
updated_at=now,
|
||||
)
|
||||
pivots = [
|
||||
PivotHealthSummary(
|
||||
pivot=pivot, name=name_map[pivot][0], module=name_map[pivot][1],
|
||||
health=health, summary=summary, updated_at=now,
|
||||
)
|
||||
|
||||
for pivot, health, summary in raw
|
||||
]
|
||||
alerts = sum(1 for item in pivots if item.health == "cracked")
|
||||
return PivotHealthReport(
|
||||
overall="cracked" if alerts else "steady", alerts=alerts, pivots=pivots
|
||||
)
|
||||
|
||||
|
||||
async def _count(session, model, *criteria) -> int:
|
||||
from sqlalchemy import func as _func
|
||||
|
||||
stmt = select(_func.count()).select_from(model)
|
||||
for c in criteria:
|
||||
stmt = stmt.where(c)
|
||||
return int((await session.execute(stmt)).scalar_one())
|
||||
|
||||
async def get_pending_approvals() -> list[PendingApproval]:
|
||||
async with AsyncSessionLocal() as session:
|
||||
records = (
|
||||
|
||||
Reference in new issue
Block a user