🔒 限制 Agent OPFS 写操作至 workspace 并支持重命名与移动 - #1578
Merged
CodFrm merged 9 commits intoAug 27, 2026
Merged
Conversation
Collaborator
Author
|
已基于最新 修正 commit:
本地验证:
尚未验证:真实浏览器 OPFS 环境中的权限异常、进程崩溃或目标清理本身失败时的底层原子性;GitHub 远端 checks 以 PR 页面当前状态为准。 |
Collaborator
Author
|
@CodFrm 有空就测试一下。随便改 |
cyfung1031
marked this pull request as ready for review
August 22, 2026 02:58
评审 PR scriptscat#1578 时发现的四个问题,均在本 PR 范围内修掉: 1. moveEntry 的回滚会掩盖真正的失败原因。复制可能在创建目标之前就失败 (例如源文件 getFile() 抛错),此时目标条目根本不存在,cleanup 的 removeEntry 抛 NotFoundError,被包成 AggregateError("Failed to roll back a move") 抛出,UI 只取 error.message,用户看到的是"回滚失败"而不是 "read failure"。现在把 NotFoundError 视为"无需回滚",原始错误照常抛出。 2. 移动目标从自由文本框改为目录选择器。原实现要求用户手打完整路径,打 "workspace" 而不是 "agents/workspace" 就会撞上 read-only 报错。新增 listMoveDestinations() 递归列出 workspace 下的目录,并排除条目所在目录、 条目自身及其子目录,选项恒为合法目标;workspace 下无其他目录时直接提示, 不再打开一个没有可选项的对话框。 3. 重命名未修改名称时不再提示"重命名成功"。原实现走到 renameEntry 的早返回 分支后仍然弹成功提示。 4. 刷新时保留已加载列表,spinner 只在没有内容可显示时出现,避免每次刷新/每次 操作后列表整块闪烁。加载失败与真实空目录的区分保持不变。 另:copyEntry 递归时去掉 `handle.name || name` 的无谓兜底。 i18n:opfs_move_destination_placeholder(文本框占位符)已无对应控件,替换为 opfs_move_destination,并新增 opfs_move_no_destination,10 个语言包同步。 测试:补 opfs_fs 的"目标创建前失败保留原始错误"与 listMoveDestinations 排除 规则用例;补回 workspace 内上传按钮的桌面/移动端覆盖(此前被改成断言按钮不存在, 只剩系统目录一侧);新增重命名无改动、移动选择器、无可选目标、刷新保留列表四条 页面用例。
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.
Checklist / 检查清单
背景
Agent OPFS 浏览器此前从 OPFS 根目录开始浏览,并在任意目录提供上传和删除操作。这样会暴露 ScriptCat 的系统数据,用户也可能误修改或删除系统资源,导致扩展无法正常运行。
本次改动
agents/workspace/**设为唯一可修改范围;OPFS 根目录及其他系统目录保持只读。agents/workspace/**内都会拒绝。实现说明
UI 与底层文件系统操作共享同一套 workspace 路径判断。
writeFile、removeEntry、renameEntry和moveEntry都会在执行前验证可编辑路径和条目名称。重命名复用移动逻辑;移动通过递归复制后删除源条目实现,并在复制前检查目标是否已存在。源目录与目标目录都必须位于
agents/workspace/**,且不允许将目录移动到自身或其子目录中。验证
git diff --check通过。建议审查重点
agents/workspace/**。Closes #1572