feat: 六爻算法修复 + prompt架构重构 + i18n输出规则

算法修复 (P0/P1):
- P0-1: 空亡判断改为仅从日柱计算(年月空亡标注但不断事)
- P0-2: 暗动判断重写为静爻+旺相+日冲三条件
- P1-1: 月破独立标注
- P1-2: 动不为空、旺不为空
- P1-3: 三合局判断
- P1-4: 反吟伏吟判断
- P1-5: 日辰十二长生
- P1-6: 回头生克判断

Prompt架构重构:
- 删除system_prompt中_build_env_section,不再泄露用户上下文到prompt
- 删除if is_chinese分支,_LANGUAGE_LABELS已覆盖全部语言映射
- 安全规则改为六爻专属约束,拒绝无关问题
- sign_level枚举值在所有语言版本中统一为简体中文(schema严格约束)
- _WORKER_ROLE_PLAYING始终为中文,不因ai_language切换
- _WORKER_OUTPUT_RULES按ai_language分zh-CN/zh-Hant/en三版本
- worker_rules.py独立文件管理多语言输出规则
- runner ai_language从user_context.settings.preferences提取传入prompt

清理死代码:
- 删除UserPreferences/RuntimePromptContext及辅助函数
- 删除runner中runtime_client_time参数链路
- 删除SystemAgentRuntimeConfig.extra_context
- 删除sections.py中env section marker
- 删除agent_prompt.py中AgentPromptRegistry死代码

安全规则:
- AGENTS.md添加Git Safety规则(禁止未经批准的破坏性git操作)
- opencode.json添加高危git命令审批配置

测试:
- 新增22个六爻算法单元测试(空亡/暗动/月破/三合局等)
- 重写7个prompt测试适配新签名
- 全部85个单元测试通过
This commit is contained in:
qzl
2026-04-15 16:45:57 +08:00
parent c74e3f688c
commit 9598d162dd
14 changed files with 1357 additions and 413 deletions
+7 -21
View File
@@ -3,7 +3,6 @@ from __future__ import annotations
import asyncio
import contextlib
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Any, Awaitable, Callable
from ag_ui.core.types import RunAgentInput
@@ -27,10 +26,8 @@ from models.llm import Llm
from models.llm_factory import LlmFactory
from models.system_agents import SystemAgents
from schemas.agent.forwarded_props import (
ClientTimeContext,
RuntimeMode,
parse_forwarded_props_divination_payload,
parse_forwarded_props_client_time,
parse_forwarded_props_runtime_mode,
)
from schemas.domain.divination import DerivedDivinationData
@@ -78,7 +75,6 @@ class AgentScopeRunner:
cancel_checker: Callable[[], Awaitable[bool]] | None = None,
) -> dict[str, Any]:
_ = runtime_config
runtime_client_time = self._resolve_runtime_client_time(run_input=run_input)
runtime_mode = self._resolve_runtime_mode(run_input=run_input)
stop_cancel_watch = asyncio.Event()
cancel_watch_task: asyncio.Task[None] | None = None
@@ -126,7 +122,6 @@ class AgentScopeRunner:
context_messages=context_messages,
toolkit=worker_toolkit,
stage_config=worker_config,
runtime_client_time=runtime_client_time,
runtime_mode=runtime_mode,
derived_divination=derived_divination,
)
@@ -196,7 +191,6 @@ class AgentScopeRunner:
api_base_url=factory.request_url,
api_key=self._resolve_provider_api_key(factory_name=factory.name),
llm_config=SystemAgentLLMConfig.model_validate(system_agent.config or {}),
extra_context=None,
)
async def _execute_worker_step(
@@ -208,7 +202,6 @@ class AgentScopeRunner:
context_messages: list[Msg],
toolkit: Any,
stage_config: SystemAgentRuntimeConfig,
runtime_client_time: ClientTimeContext | None,
runtime_mode: RuntimeMode,
derived_divination: DerivedDivinationData | None,
) -> WorkerAgentOutputLite | FollowUpOutput:
@@ -234,7 +227,6 @@ class AgentScopeRunner:
stage_config=stage_config,
worker_output_model=worker_output_model,
pipeline=pipeline,
runtime_client_time=runtime_client_time,
runtime_mode=runtime_mode,
derived_divination=derived_divination,
)
@@ -258,7 +250,6 @@ class AgentScopeRunner:
stage_config: SystemAgentRuntimeConfig,
worker_output_model: type[WorkerAgentOutputLite | FollowUpOutput],
pipeline: PipelineLike,
runtime_client_time: ClientTimeContext | None,
runtime_mode: RuntimeMode,
derived_divination: DerivedDivinationData | None,
) -> StageExecutionResult:
@@ -273,13 +264,16 @@ class AgentScopeRunner:
emit_text_events=True,
emit_tool_events=False,
)
ai_language = "zh-CN"
if user_context.settings is not None:
prefs = getattr(user_context.settings, "preferences", None)
if prefs is not None:
ai_language = getattr(prefs, "ai_language", "zh-CN") or "zh-CN"
system_prompt = build_system_prompt(
agent_type=stage_config.agent_type,
ai_language=ai_language,
llm_config=stage_config.llm_config,
user_context=user_context,
now_utc=datetime.now(timezone.utc),
runtime_client_time=runtime_client_time,
extra_context=stage_config.extra_context,
tools=None,
)
@@ -419,13 +413,6 @@ class AgentScopeRunner:
event=payload,
)
def _resolve_runtime_client_time(
self, *, run_input: RunAgentInput
) -> ClientTimeContext | None:
return parse_forwarded_props_client_time(
getattr(run_input, "forwarded_props", None)
)
@staticmethod
def _resolve_runtime_mode(*, run_input: RunAgentInput) -> RuntimeMode:
return parse_forwarded_props_runtime_mode(
@@ -470,7 +457,6 @@ class SystemAgentRuntimeConfig:
api_base_url: str
api_key: str
llm_config: SystemAgentLLMConfig
extra_context: str | None = None
AgentScopeReActRunner = AgentScopeRunner