Skip to content

feat(history): 全部会话导出成一个文件,导入时不重复(#7) - #38

Merged
WhiteNightShadow merged 2 commits into
mainfrom
feat/export-all-conversations
Nov 4, 2026
Merged

WhiteNightShadow merged 2 commits into
mainfrom
feat/export-all-conversations

Conversation

@WhiteNightShadow

Copy link
Copy Markdown
Owner

背景

#7第一条:办公电脑上有很多会话,希望回家后在另一台电脑上也能看到。v0.23.0做了单会话导出导入,但会话一多就得一个一个导,而且同一个会话导两次会变成两份。

改动(按提交)

  • feat(history) 全部会话导出成一个文件,导入两种文件都认(f92f8e7):
    • 导出:ConversationStore.exportAllThreads/exportAllThreadsToFile把有消息的会话按最近更新排序,写成一个.frx-chats.json:
      • 格式名firefox-reverse-conversations,schemaVersion 1;
      • 每个会话的结构和单会话文件里的conversation相同,同样不带工作目录、环境绑定、运行状态、投影和Usage;
      • 空会话不导出;个别会话导不出时跳过并在结果里记下,不让整个文件失败;
      • 总量超过200MB时停下,提示先删会话或逐个导出。
    • 导入:importConversations/importFromFile认单会话文件和全部会话文件:
      • 先校验全部条目,有一条不合格就整个文件都不导入,报错时指出是第几个会话;
      • 来源会话id和导出时的更新时间都相同的,视为已导入过,跳过。导回原来的profile也一样;导入后在本机接着聊过的,也认得出来;
      • 在来源电脑上又更新过的,作为新会话导入,不覆盖本地的;
      • 导入后保持原来的先后顺序;写盘失败时内存里也撤掉。
    • 界面:历史抽屉新增“全部导出”;“导入”两种文件都认,提示导入了几个、几个之前已导入过;侧栏窄时抽屉头部自动换行。
    • 兼容:原来的importThread、importThreadFromFile、exportThreadToFile行为不变。
  • docs(readme)(6dc041d):开头的历史抽屉介绍,以及“main(尚未发布)”里的一条。

验证

  • 全量自测:bash scripts/selftest-agent-tools.sh通过,共46步。
    • selftest-conversations新增存储层用例,覆盖:
      • 打包和排序,空会话跳过;
      • 不带本机资源;
      • 两种文件导入、各种重复情况;
      • 来源更新后作为新会话导入;
      • 坏条目整包拒绝并指出位置;
      • 数量上限;
      • 写盘失败回滚。
    • 新增selftest-history-transfer:用jsdom渲染真实的AgentPanel,配真的ConversationStore和一个假文件选择器,点按钮走完整流程,覆盖:
      • 全部导出(保存对话框、默认文件名、过滤器、提示);
      • 在新profile里一次导回、顺序不变、列表刷新;
      • 再导一次不重复;
      • 单会话文件导入过的、来源更新过的;
      • 坏文件报错且不导入;
      • 全是空会话时提示没有可导出的。
  • 真实引擎:在v0.27.0最终arm64包的临时副本里换上新的ConversationStore,临时profile、无头启动,经marionette用真实落盘的存储做了一遍:
    • 导出2个会话,跳过1个空会话,没有残留.tmp;
    • 在另一个存储里导入2个,重新打开后两个会话和消息数都在;
    • 再导一次是0个新会话、2个重复;单会话文件也认出是重复;
    • 坏文件报“不是有效JSON”。

没验证的

  • 真实浏览器里的文件选择对话框没有点过。无头模式开不了系统对话框,选择器的调用方式和原来的单会话导入导出相同。
  • 没有出新包。

已知问题(本pr未处理)

  • 导出时不区分会话是否正在运行。和单会话导出一样,当前会话在跑时按钮不可用;后台别的窗口里正在跑的会话,会按已经存下的内容导出。

🤖 Generated with Claude Code

WhiteNightShadow and others added 2 commits November 2, 2026 07:38
… kind

Issue #7 asked for moving many conversations from one computer to
another; only one conversation at a time could be exported and imported.

- ConversationStore.exportAllThreads/exportAllThreadsToFile write every
  conversation with messages into one .frx-chats.json bundle (format
  firefox-reverse-conversations, schemaVersion 1, newest first), with the
  same per-conversation shape as the single-conversation file. Empty
  conversations are left out; one that cannot be exported is skipped and
  reported instead of failing the whole bundle.
- importConversations/importFromFile accept a single-conversation file or
  a bundle. Every entry is validated before anything is written, so one
  bad entry rejects the file and the error names its position. Entries
  whose source conversation and source updatedAt match a thread already
  here (the original, or an earlier import, even if it was continued
  locally) are skipped; a conversation updated at the source comes in as
  a new one. The original order is kept, and a failed save rolls back.
- History drawer: a new "全部导出" button, and "导入" now takes both kinds
  of file and reports how many were imported or already there. The header
  wraps on narrow sidebars.
- selftest-conversations covers the store; selftest-history-transfer
  drives both buttons in jsdom with the real store and a fake file picker.

Refs #7

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@WhiteNightShadow
WhiteNightShadow merged commit 127dd62 into main Nov 4, 2026
2 checks passed
@WhiteNightShadow
WhiteNightShadow deleted the feat/export-all-conversations branch November 4, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant