后台任务输出日志在打开的标签页内自动跟随磁盘变化刷新 - #775
Open
leehom0123 wants to merge 1 commit into
Open
leehom0123 wants to merge 1 commit into
leehom0123 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
聊天窗口顶部后台任务提醒条的"输出"按钮通过 openFilePreview 打开任务日志。日志位于系统临时目录,在所有已注册工作区根目录之外,后端文件监听覆盖不到这个文件,标签页打开后内容不再更新。已有的激活时新鲜度检查只在切换标签页的那一刻运行,用户停留在日志标签页期间看不到新内容。
改动
新增组件 LiveOutputFileWatcher,挂在 conversation-shell.tsx 的 AsyncTaskStrip 旁边,自身不渲染任何内容。以下三个条件同时满足时,它每 2 秒比对一次激活标签页的 etag 与磁盘:
etag 变化时走工作区存储的 applyExternalReload 写入新内容,复用它的代数检查、拒绝覆盖未保存内容、git 基线刷新。读取失败(最常见是日志被清理)时走 rejectFileTab 把错误显示在标签页上。任务结束、标签页关闭或用户开始编辑后,轮询定时器随之拆除。
组件是独立叶子节点:对高频 fileTabs 切片的订阅只触发这个空渲染组件重渲染,不影响会话外壳的渲染路径。
验证
取舍
没有改用文件系统监听:后端现有 notify 监听器有已知的事件丢失问题(src-tauri/src/workspace_state/mod.rs:1590 注释记载 macOS FSEvents 会丢事件),即使加监听也需要轮询兜底;现有 2 秒轮询已有任务存活、标签页激活、无未保存修改三重控制,空闲时成本接近零。