Skip to content

后台任务输出日志在打开的标签页内自动跟随磁盘变化刷新 - #775

Open
leehom0123 wants to merge 1 commit into
xintaofei:mainfrom
leehom0123:feat/live-output-auto-reload
Open

leehom0123 wants to merge 1 commit into
xintaofei:mainfrom
leehom0123:feat/live-output-auto-reload

Conversation

@leehom0123

Copy link
Copy Markdown
Contributor

背景

聊天窗口顶部后台任务提醒条的"输出"按钮通过 openFilePreview 打开任务日志。日志位于系统临时目录,在所有已注册工作区根目录之外,后端文件监听覆盖不到这个文件,标签页打开后内容不再更新。已有的激活时新鲜度检查只在切换标签页的那一刻运行,用户停留在日志标签页期间看不到新内容。

改动

新增组件 LiveOutputFileWatcher,挂在 conversation-shell.tsx 的 AsyncTaskStrip 旁边,自身不渲染任何内容。以下三个条件同时满足时,它每 2 秒比对一次激活标签页的 etag 与磁盘:

  • 任务未结束(任务在 liveAsyncTasks 名单内);
  • 该日志正是当前激活的文件标签页;
  • 标签页无未保存修改、不在保存中,且不是图片、Office 预览。

etag 变化时走工作区存储的 applyExternalReload 写入新内容,复用它的代数检查、拒绝覆盖未保存内容、git 基线刷新。读取失败(最常见是日志被清理)时走 rejectFileTab 把错误显示在标签页上。任务结束、标签页关闭或用户开始编辑后,轮询定时器随之拆除。

组件是独立叶子节点:对高频 fileTabs 切片的订阅只触发这个空渲染组件重渲染,不影响会话外壳的渲染路径。

验证

  • 新增 live-output-file-watcher.test.tsx,7 个测试:任务存活时磁盘变化写入、etag 相同不写入、未保存修改的标签页不轮询、任务结束后停止轮询、忽略非日志标签页、日志消失显示错误、读取期间切换标签页丢弃结果。7 个通过。
  • pnpm test 全量运行:455 个测试文件、6623 个测试通过。
  • pnpm eslint、prettier --check、tsc --noEmit 全部干净。

取舍

没有改用文件系统监听:后端现有 notify 监听器有已知的事件丢失问题(src-tauri/src/workspace_state/mod.rs:1590 注释记载 macOS FSEvents 会丢事件),即使加监听也需要轮询兜底;现有 2 秒轮询已有任务存活、标签页激活、无未保存修改三重控制,空闲时成本接近零。

The task strip's "Output" button opens the task log through
openFilePreview, but the log lives under the OS temp root, outside every
notify-watched workspace root, so the open-tab watcher never sees it
change. A null-rendering leaf component now polls the active, clean
output tab every 2 s while its task is live and routes changes through
applyExternalReload; the interval stops as soon as the task settles,
the tab closes, or the buffer turns dirty.
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