From 76781ecc9e120da0bd0f56a61f13fc5cda7fe557 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Tue, 19 May 2026 23:08:39 +0800 Subject: [PATCH] auto-sync: 2026-05-19 23:08:39 --- src/daemon/spawner.py | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 824b75c..68868f8 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -124,6 +124,7 @@ class AgentSpawner: dry_run: bool = False, api_host: str = "127.0.0.1", api_port: int = 8083, + bootstrap_builder: Optional[Any] = None, ): """ Args: @@ -138,6 +139,7 @@ class AgentSpawner: self.dry_run = dry_run self.api_host = api_host self.api_port = api_port + self.bootstrap_builder = bootstrap_builder # session 注册表 {session_id: {...}} self._sessions: Dict[str, Dict[str, Any]] = {} @@ -160,13 +162,33 @@ class AgentSpawner: agent_id: str = "", current_status: str = "claimed", retry_context: str = "", + task: Optional[Any] = None, + project_config: Optional[Dict[str, Any]] = None, ) -> str: - """构建 Agent spawn 的消息(使用 prompt 模板) + """构建 Agent spawn 的消息(优先用 BootstrapBuilder,fallback 用模板) Args: current_status: 任务当前状态(动态生成状态机提示) retry_context: 重试上下文(前轮产出摘要 + 审查意见) + task: Task 对象(BootstrapBuilder 用) + project_config: 项目配置(BootstrapBuilder 用) """ + # 尝试 BootstrapBuilder + if self.bootstrap_builder and task is not None: + try: + bootstrap_prompt = self.bootstrap_builder.build_for_task( + task=task, + role="executor", + project_config=project_config, + ) + # 在 bootstrap 后追加操作指令(状态机 + API 回写) + api_section = self._build_api_section( + project_id, task_id, agent_id) + return bootstrap_prompt + "\n\n---\n\n" + api_section + except Exception: + logger.exception("BootstrapBuilder failed, falling back to template") + + # Fallback: 使用硬编码模板 return SPAWN_PROMPT_TEMPLATE.format( project_id=project_id, task_id=task_id, @@ -182,6 +204,30 @@ class AgentSpawner: retry_context=retry_context or "", ) + def _build_api_section(self, project_id: str, task_id: str, + agent_id: str) -> str: + """构建 API 回写操作指令(BootstrapBuilder 模式下补充)""" + return f"""## 操作指令 + +### 状态回写 +开始工作: +```bash +curl -X POST http://{self.api_host}:{self.api_port}/api/projects/{project_id}/tasks/{task_id}/status \ + -H 'Content-Type: application/json' \ + -d '{{"status": "working", "agent": "{agent_id}"}}' +``` + +### 写入产出 +```bash +curl -X POST http://{self.api_host}:{self.api_port}/api/projects/{project_id}/tasks/{task_id}/outputs \ + -H 'Content-Type: application/json' \ + -d '{{"agent": "{agent_id}", "type": "<类型>", "title": "<标题>", "content": "<内容>", "summary": "<摘要>"}}' +``` + +### 完成后 +成功:status → "review" | 失败:status → "failed" +""" + async def spawn_full_agent( self, agent_id: str,