handoff 新增必填 title 参数:交接时刻的标题回写会话标题
顾问在 handoff 此刻最懂这单任务,其起的标题比首交互后自动生成(maybeGenerateTitle) 的更有价值。落地: - definitions.json:handoff 参数加 title(必填),描述对齐 title-prompt 口径 (3-7 词/中文 6-14 字,无引号无前缀);工具字母序复查未破坏; - executor.toolHandoff:清洗(压空白+截 60,同 cleanTitle 口径;executor 反引用 engine 会成环故就地实现),task.md 落盘成功后才 UPDATE sessions.title (切换半途失败不留「有名无书」残局);空 title 拒回执; - engine 批尾 handoffDone:enterExecuting 前广播 title 事件,已开窗口刷详情页 标题+重拉列表(与自动生成同链路);finalize 的 maybeGenerateTitle 见非空即跳过, getSession 现读 DB 无覆盖竞态; - advising-system.txt:handoff 调用说明同步带 title(提示词与必填参数对齐)。 存量被画像污染的旧标题可被下次 handoff 直接顶掉。
This commit is contained in:
@@ -820,7 +820,13 @@ async function runLoopInner(sessionId, run) {
|
|||||||
handoffDone = true;
|
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++;
|
iter++;
|
||||||
}
|
}
|
||||||
if (iter >= maxIter && !run.cancelled) {
|
if (iter >= maxIter && !run.cancelled) {
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ When planning:
|
|||||||
|
|
||||||
When work should start — the requirement is clear, or the user explicitly asks
|
When work should start — the requirement is clear, or the user explicitly asks
|
||||||
to skip planning, or clarification has visibly stalled — call the `handoff`
|
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:
|
tool with a `reason`, the full `brief`, and a concise `title` for this
|
||||||
handoff is the ONLY way to leave this phase. The system stores your `brief` as
|
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
|
the task brief, switches this session into execution mode, and a full-capability
|
||||||
agent continues from that brief alone.
|
agent continues from that brief alone.
|
||||||
Therefore:
|
Therefore:
|
||||||
|
|||||||
@@ -114,7 +114,8 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"reason",
|
"reason",
|
||||||
"brief"
|
"brief",
|
||||||
|
"title"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"reason": {
|
"reason": {
|
||||||
@@ -129,6 +130,10 @@
|
|||||||
"brief": {
|
"brief": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The task brief content, in Markdown. Follow the structure described in your system prompt."
|
"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:\"."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1119,6 +1119,8 @@ function runLabHelp(args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handoff:顾问阶段唯一出口(advising 组合见 config.js)。brief 原样落盘任务目录根 task.md;
|
// handoff:顾问阶段唯一出口(advising 组合见 config.js)。brief 原样落盘任务目录根 task.md;
|
||||||
|
// title 直写 sessions.title(交接此刻顾问最懂这单任务,标题以此为准,finalize 的
|
||||||
|
// maybeGenerateTitle 见非空即跳过);批尾由 engine 广播 title 事件同步已开窗口。
|
||||||
// 切换不在此发生——executeTool 只落盘与回执,runLoopInner 在工具批尾接成功回执触发 enterExecuting
|
// 切换不在此发生——executeTool 只落盘与回执,runLoopInner 在工具批尾接成功回执触发 enterExecuting
|
||||||
//(其读盘取快照作锚点,幂等防重切)。phase 守卫不可省:「名单外工具照跑」是全局策略,
|
//(其读盘取快照作锚点,幂等防重切)。phase 守卫不可省:「名单外工具照跑」是全局策略,
|
||||||
// 执行期幻觉调用不得覆写修订中的 task.md;reason 枚举与 brief 非空也在此兑底(checkToolArgs 只查必填键)。
|
// 执行期幻觉调用不得覆写修订中的 task.md;reason 枚举与 brief 非空也在此兑底(checkToolArgs 只查必填键)。
|
||||||
@@ -1131,9 +1133,15 @@ async function toolHandoff(ctx, args) {
|
|||||||
}
|
}
|
||||||
const brief = typeof args.brief === 'string' ? args.brief : '';
|
const brief = typeof args.brief === 'string' ? args.brief : '';
|
||||||
if (!brief.trim()) return 'Error: brief 不能为空,任务书需完整带上(user_skip/user_stuck 至少含用户原话与 Missing 清单)';
|
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');
|
const abs = path.join(ctx.taskDir, 'task.md');
|
||||||
await fsp.writeFile(abs, brief, 'utf8');
|
await fsp.writeFile(abs, brief, 'utf8');
|
||||||
recordFile(ctx, abs); // 同步 files 元数据表(与 write_file 同轨,任务目录列表/清理逻辑一致)
|
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 幂等)。
|
// 同批多次 handoff:后写覆盖(last-wins),批尾的切换只发生一次(enterExecuting 幂等)。
|
||||||
return '任务书已写入 task.md(reason: ' + reason + '),本批工具跑完后系统将切换到执行模式。请在给用户的回复里带一句「已切换到执行阶段」。';
|
return '任务书已写入 task.md(reason: ' + reason + '),本批工具跑完后系统将切换到执行模式。请在给用户的回复里带一句「已切换到执行阶段」。';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user