fix(tui-v3): /continue 恢复后镜像源日志,避免续聊丢失旧历史 (#612)

v3 的 _do_restore 此前只把历史载入内存 backend.history,不碰当前进程日志。native 后端逐轮只把新增消息 append 到 model_responses_{pid}.txt,恢复出的旧历史从不写入当前日志——续聊只追加增量,下次 /continue 扫到的本进程文件就只剩续聊部分,旧历史丢失。

对齐 v2 _do_continue_restore:恢复前 reset_conversation(快照+清空当前日志),恢复后 copyfile(源日志 → 当前日志),续聊便接在完整历史之后。
This commit is contained in:
nianyucatfish authored and GitHub committed 2026-06-15 08:59:37 +08:00
1 parent 80d900514d
commit b4356c7262
1 file changed
+9
+9
View File
@@ -4483,7 +4483,16 @@ class SB:
self.commit([_DIM + _t('msg.no_history') + _RST]); return
def _do_restore(path: str) -> None:
continue_cmd.reset_conversation(ag, message=None) # 快照+清空当前进程日志
msg, _ = continue_cmd.restore(ag, path)
# 镜像源日志进当前进程日志,否则续聊只 append 增量,下次 /continue 丢旧历史。
# 对齐 v2 _do_continue_restore(tuiapp_v2.py:5285)。
current_log = getattr(ag, 'log_path', '') or ''
if current_log and path != current_log:
try:
shutil.copyfile(path, current_log)
except Exception:
pass
self.commit([_DIM + '┄┄ ' + _t('msg.continue_loading', name=os.path.basename(path)) + ' ┄┄' + _RST])
for mm in continue_cmd.extract_ui_messages(path):
c = (mm.get('content') or '').strip()