diff --git a/app/server/engine.js b/app/server/engine.js index 3085e14..d10edde 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -820,7 +820,13 @@ async function runLoopInner(sessionId, run) { handoffDone = true; } } - if (handoffDone) enterExecuting(sessionId); + if (handoffDone) { + // 顾问标题已由 toolHandoff 直写 sessions.title:广播同 maybeGenerateTitle 的 title 事件, + // 已开窗口刷详情页标题 + 重拉会话列表(finalize 的自动标题见非空即跳过,不会覆盖)。 + const ht = db.prepare('SELECT title FROM sessions WHERE id = ?').get(sessionId); + if (ht && ht.title) bus.emit(sessionId, 'title', { title: ht.title }); + enterExecuting(sessionId); + } iter++; } if (iter >= maxIter && !run.cancelled) { diff --git a/app/server/templates/advising-system.txt b/app/server/templates/advising-system.txt index 5ad4670..97c3de9 100644 --- a/app/server/templates/advising-system.txt +++ b/app/server/templates/advising-system.txt @@ -50,8 +50,10 @@ When planning: When work should start — the requirement is clear, or the user explicitly asks to skip planning, or clarification has visibly stalled — call the `handoff` -tool with a `reason` and the full `brief`. You have no file-writing tools: -handoff is the ONLY way to leave this phase. The system stores your `brief` as +tool with a `reason`, the full `brief`, and a concise `title` for this +conversation (in the user's language; it becomes the session's display title). +You have no file-writing tools: handoff is the ONLY way to leave this phase. +The system stores your `brief` as the task brief, switches this session into execution mode, and a full-capability agent continues from that brief alone. Therefore: diff --git a/app/server/tools/definitions.json b/app/server/tools/definitions.json index efebb16..daae79a 100644 --- a/app/server/tools/definitions.json +++ b/app/server/tools/definitions.json @@ -114,7 +114,8 @@ "type": "object", "required": [ "reason", - "brief" + "brief", + "title" ], "properties": { "reason": { @@ -129,6 +130,10 @@ "brief": { "type": "string", "description": "The task brief content, in Markdown. Follow the structure described in your system prompt." + }, + "title": { + "type": "string", + "description": "A concise title for this conversation, in the user's language (3-7 words, or 6-14 Chinese characters). Straight to the title: no quotes, no prefix like \"Title:\"." } } } diff --git a/app/server/tools/executor.js b/app/server/tools/executor.js index e4d5b5e..a7a8da3 100644 --- a/app/server/tools/executor.js +++ b/app/server/tools/executor.js @@ -1119,6 +1119,8 @@ function runLabHelp(args) { } // handoff:顾问阶段唯一出口(advising 组合见 config.js)。brief 原样落盘任务目录根 task.md; +// title 直写 sessions.title(交接此刻顾问最懂这单任务,标题以此为准,finalize 的 +// maybeGenerateTitle 见非空即跳过);批尾由 engine 广播 title 事件同步已开窗口。 // 切换不在此发生——executeTool 只落盘与回执,runLoopInner 在工具批尾接成功回执触发 enterExecuting //(其读盘取快照作锚点,幂等防重切)。phase 守卫不可省:「名单外工具照跑」是全局策略, // 执行期幻觉调用不得覆写修订中的 task.md;reason 枚举与 brief 非空也在此兑底(checkToolArgs 只查必填键)。 @@ -1131,9 +1133,15 @@ async function toolHandoff(ctx, args) { } const brief = typeof args.brief === 'string' ? args.brief : ''; if (!brief.trim()) return 'Error: brief 不能为空,任务书需完整带上(user_skip/user_stuck 至少含用户原话与 Missing 清单)'; + // 标题清洗对齐 cleanTitle(engine 内函数,executor 反向引用会成环,此处同款口径): + // 压空白 + 截 60;引号剥除交给模型自觉(description 已明说),不做二次加工。 + const title = String(args.title || '').replace(/\s+/g, ' ').trim().slice(0, 60); + if (!title) return 'Error: title 不能为空,给出一个概括任务的简洁标题'; const abs = path.join(ctx.taskDir, 'task.md'); await fsp.writeFile(abs, brief, 'utf8'); recordFile(ctx, abs); // 同步 files 元数据表(与 write_file 同轨,任务目录列表/清理逻辑一致) + // task.md 落盘成功后才改标题:切换半途失败不留「有名无书」的残局 + ctx.db.prepare('UPDATE sessions SET title = ?, updated_at = ? WHERE id = ?').run(title, Date.now(), ctx.sessionId); // 同批多次 handoff:后写覆盖(last-wins),批尾的切换只发生一次(enterExecuting 幂等)。 return '任务书已写入 task.md(reason: ' + reason + '),本批工具跑完后系统将切换到执行模式。请在给用户的回复里带一句「已切换到执行阶段」。'; }