title_locked:用户手动重命名的标题不许被 handoff 自动标题冲掉
三个标题触发点里,maybeGenerateTitle 见非空即跳过,天然尊重手动改名; 唯独 handoff 的 title 是无条件覆写——用户改名后再一次交接,名字静默蒸发。 - db.js:sessions 加 title_locked 列(迁移,默认 0); - engine.renameSession:手动改名即置 1(唯一上锁入口); - toolHandoff:SELECT 带出 title_locked,task.md 落盘成功后见锁跳过写标题 (其余动作照常,静默处理,不打扰交接回执); - clearSessionMessages:title 置 null 的同时复位锁——旧名字已文不对题, 新一轮自动标题不该被上一世代的改名挡住。 engine 批尾的 title 广播逻辑不动:见锁未写时广播的是原样标题,前端刷新无害。
This commit is contained in:
@@ -162,6 +162,9 @@ function initDb(dbPath) {
|
||||
// 迁移:profile_snapshot 存会话创建/清空时冻结的用户画像注入文本(buildMessages 每轮首条 user 注入,
|
||||
// 字节恒定不破坏前缀缓存;不入 messages 表,阶段切换/压缩动不到它,见 user-profile.js)。
|
||||
if (!cols.some(c => c.name === 'profile_snapshot')) db.exec("ALTER TABLE sessions ADD COLUMN profile_snapshot TEXT DEFAULT ''");
|
||||
// 迁移:title_locked 用户手动重命名过标题(renameSession 置 1):handoff 的自动标题见锁即跳过,
|
||||
// 不得静默冲掉用户给会话起的名字;清空会话时随标题一并复位(旧名字已文不对题)。
|
||||
if (!cols.some(c => c.name === 'title_locked')) db.exec("ALTER TABLE sessions ADD COLUMN title_locked INTEGER NOT NULL DEFAULT 0");
|
||||
// 迁移:phase 语义重定义为 advising(顾问:澄清需求/规划)/ executing(执行)。
|
||||
// 存量会话(旧值 planning/NULL)统一回填 executing——它们都有历史,行为与改造前一致、零打扰;
|
||||
// 只有新建会话进 advising(createSession 显式写入)。幂等,每次启动一条廉价 UPDATE。
|
||||
|
||||
@@ -1092,7 +1092,9 @@ function renameSession(sessionId, title) {
|
||||
const t = String(title || '').trim();
|
||||
if (!t) throw Object.assign(new Error('名称不能为空'), { status_code: 400 });
|
||||
if (t.length > 100) throw Object.assign(new Error('名称不能超过 100 字'), { status_code: 400 });
|
||||
touch(sessionId, { title: t });
|
||||
// 手动改名即上锁:后续 handoff 的自动标题见 title_locked 即跳过,不许冲掉用户起的名字
|
||||
//(maybeGenerateTitle 本就见非空即跳,无需看锁)。
|
||||
touch(sessionId, { title: t, title_locked: 1 });
|
||||
log.info('task', sessionId + ' 重命名为「' + t + '」');
|
||||
return { ok: true, title: t };
|
||||
}
|
||||
@@ -1235,7 +1237,7 @@ function clearSessionMessages(sessionId) {
|
||||
autoCompressProposed.delete(sessionId); // 历史清零,恢复自动压缩提议额度
|
||||
// 标题随历史一并清零:旧标题描述的是已删除的对话,留着会让新对话文不对题;
|
||||
// 新一轮交互结束后 maybeGenerateTitle 见 title 为空会自动重新生成。
|
||||
touch(sessionId, { status: 'completed', completed_at: now(), cancelled_at: null, held_at: null, title: null, phase: 'advising' });
|
||||
touch(sessionId, { status: 'completed', completed_at: now(), cancelled_at: null, held_at: null, title: null, title_locked: 0, phase: 'advising' });
|
||||
profile.freezeSnapshot(db, sessionId); // 回 advising 重新规划:画像快照随新一轮重新冻结
|
||||
bus.emit(sessionId, 'done', { status: 'completed' });
|
||||
bus.emit(sessionId, 'title', { title: null }); // 供其他打开同一会话的窗口同步清掉旧标题
|
||||
|
||||
@@ -1125,7 +1125,7 @@ function runLabHelp(args) {
|
||||
//(其读盘取快照作锚点,幂等防重切)。phase 守卫不可省:「名单外工具照跑」是全局策略,
|
||||
// 执行期幻觉调用不得覆写修订中的 task.md;reason 枚举与 brief 非空也在此兑底(checkToolArgs 只查必填键)。
|
||||
async function toolHandoff(ctx, args) {
|
||||
const sess = ctx.db.prepare('SELECT phase FROM sessions WHERE id = ?').get(ctx.sessionId);
|
||||
const sess = ctx.db.prepare('SELECT phase, title_locked FROM sessions WHERE id = ?').get(ctx.sessionId);
|
||||
if (!sess || sess.phase !== 'advising') return 'Error: 当前不在顾问阶段,handoff 仅在 advising 可用';
|
||||
const reason = String((args && args.reason) || '');
|
||||
if (['ready', 'user_skip', 'user_stuck'].indexOf(reason) < 0) {
|
||||
@@ -1140,8 +1140,11 @@ async function toolHandoff(ctx, args) {
|
||||
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);
|
||||
// task.md 落盘成功后才改标题:切换半途失败不留「有名无书」的残局;
|
||||
// 用户手动重命名过(title_locked,见 engine.renameSession)则尊重用户的名字,静默跳过。
|
||||
if (!sess.title_locked) {
|
||||
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 + '),本批工具跑完后系统将切换到执行模式。请在给用户的回复里带一句「已切换到执行阶段」。';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user