|
|
@@ -28,6 +28,7 @@ from pathlib import Path
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
+
|
|
|
load_dotenv()
|
|
|
|
|
|
from agent.llm.prompts import SimplePrompt
|
|
|
@@ -43,12 +44,11 @@ from agent.tools import get_tool_registry
|
|
|
|
|
|
DEFAULT_MODEL = "anthropic/claude-sonnet-4.5"
|
|
|
|
|
|
-
|
|
|
-
|
|
|
# ===== 非阻塞 stdin 检测 =====
|
|
|
if sys.platform == 'win32':
|
|
|
import msvcrt
|
|
|
|
|
|
+
|
|
|
def check_stdin() -> str | None:
|
|
|
"""
|
|
|
跨平台非阻塞检查 stdin 输入。
|
|
|
@@ -95,7 +95,7 @@ def _read_multiline() -> str:
|
|
|
blank_count += 1
|
|
|
if blank_count >= 2:
|
|
|
break
|
|
|
- lines.append("") # 保留单个空行
|
|
|
+ lines.append("") # 保留单个空行
|
|
|
else:
|
|
|
blank_count = 0
|
|
|
lines.append(line)
|
|
|
@@ -107,10 +107,10 @@ def _read_multiline() -> str:
|
|
|
|
|
|
|
|
|
async def show_interactive_menu(
|
|
|
- runner: AgentRunner,
|
|
|
- trace_id: str,
|
|
|
- current_sequence: int,
|
|
|
- store: FileSystemTraceStore,
|
|
|
+ runner: AgentRunner,
|
|
|
+ trace_id: str,
|
|
|
+ current_sequence: int,
|
|
|
+ store: FileSystemTraceStore,
|
|
|
):
|
|
|
"""
|
|
|
显示交互式菜单,让用户选择操作。
|
|
|
@@ -261,7 +261,7 @@ async def main():
|
|
|
output_dir = base_dir / "output_1"
|
|
|
output_dir.mkdir(exist_ok=True)
|
|
|
|
|
|
- # 加载项目级 presets(examples/how/presets.json)
|
|
|
+ # 加载项目级 presets(examples/create/presets.json)
|
|
|
presets_path = base_dir / "presets.json"
|
|
|
if presets_path.exists():
|
|
|
import json
|
|
|
@@ -289,6 +289,53 @@ async def main():
|
|
|
print("1. 加载 prompt 配置...")
|
|
|
prompt = SimplePrompt(prompt_path)
|
|
|
|
|
|
+ # 读取 system.md 并替换 {system} 占位符
|
|
|
+ system_md_path = base_dir / "PRD" / "system.md"
|
|
|
+ if system_md_path.exists():
|
|
|
+ system_content = system_md_path.read_text(encoding='utf-8')
|
|
|
+ if 'system' in prompt._messages and '{system}' in prompt._messages['system']:
|
|
|
+ prompt._messages['system'] = prompt._messages['system'].replace('{system}', system_content)
|
|
|
+ else:
|
|
|
+ print(f" - 警告: system.md 文件不存在: {system_md_path}")
|
|
|
+
|
|
|
+ # 读取 create_process.md 并替换 {create_process} 占位符
|
|
|
+ create_process_md_path = base_dir / "PRD" / "create_process.md"
|
|
|
+ if create_process_md_path.exists():
|
|
|
+ create_process_content = create_process_md_path.read_text(encoding='utf-8')
|
|
|
+ if 'system' in prompt._messages and '{create_process}' in prompt._messages['system']:
|
|
|
+ prompt._messages['system'] = prompt._messages['system'].replace('{create_process}', create_process_content)
|
|
|
+ print(f" - 已替换 create_process.md 内容到 prompt")
|
|
|
+ else:
|
|
|
+ print(f" - 警告: prompt 中未找到 {{create_process}} 占位符")
|
|
|
+ else:
|
|
|
+ print(f" - 警告: create_process.md 文件不存在: {create_process_md_path}")
|
|
|
+
|
|
|
+ # 读取 user.md 并替换 {user} 占位符
|
|
|
+ user_md_path = base_dir / "PRD" / "user.md"
|
|
|
+ if user_md_path.exists():
|
|
|
+ user_content = user_md_path.read_text(encoding='utf-8')
|
|
|
+ if 'user' in prompt._messages and '{user}' in prompt._messages['user']:
|
|
|
+ prompt._messages['user'] = prompt._messages['user'].replace('{user}', user_content)
|
|
|
+ print(f" - 已替换 user.md 内容到 prompt")
|
|
|
+ else:
|
|
|
+ print(f" - 警告: prompt 中未找到 {{user}} 占位符")
|
|
|
+ else:
|
|
|
+ print(f" - 警告: user.md 文件不存在: {user_md_path}")
|
|
|
+
|
|
|
+ print("\n替换后的prompt:")
|
|
|
+ print("=" * 60)
|
|
|
+ print("System:")
|
|
|
+ print("-" * 60)
|
|
|
+ print(prompt._messages.get('system', ''))
|
|
|
+ print("=" * 60)
|
|
|
+ if 'user' in prompt._messages:
|
|
|
+ print("\nUser:")
|
|
|
+ print("-" * 60)
|
|
|
+ print(prompt._messages['user'])
|
|
|
+ print("=" * 60)
|
|
|
+ print()
|
|
|
+
|
|
|
+
|
|
|
# 2. 构建消息(仅新建时使用,恢复时消息已在 trace 中)
|
|
|
print("2. 构建任务消息...")
|
|
|
messages = prompt.build_messages()
|
|
|
@@ -299,8 +346,6 @@ async def main():
|
|
|
print(f" - 模型: {prompt.config.get('model', 'sonnet-4.5')}")
|
|
|
|
|
|
# 加载自定义工具
|
|
|
- print(" - 加载自定义工具: nanobanana")
|
|
|
- import examples.how.tool # 导入自定义工具模块,触发 @tool 装饰器注册
|
|
|
print(" - 加载自定义工具: topic_search")
|
|
|
import examples.create.tool # 选题检索工具,用于在数据库中匹配已有帖子选题
|
|
|
|
|
|
@@ -309,7 +354,7 @@ async def main():
|
|
|
trace_store=store,
|
|
|
llm_call=create_openrouter_llm_call(model=DEFAULT_MODEL),
|
|
|
skills_dir=skills_dir,
|
|
|
- experiences_path="./.cache/experiences_how.md",
|
|
|
+ experiences_path="./.cache/experiences.md",
|
|
|
debug=True
|
|
|
)
|
|
|
|