Repository navigation
feat(plugin-api): 桌面端接通 API-11 保存与工作区文件变更 - #2358
Merged
Merged
Conversation
- documents/save|saveAs|close(documents.save):走文档自己的保存,冲突、硬链接、 未命名文档、组字返回错误码,不弹窗 - workspace/create|rename|copy|trash(workspace.files.write):磁盘变更由 Core 内核命令 workspace.createEntry|renameEntry|copyEntry|resolveEntry 完成,create 支持符号链接 - 固定 Core 升到 aadf63d(#184) - 权限说明文案、功能矩阵、计划表同步更新
1 task done
xiaoyumuxi
marked this pull request as ready for review
November 23, 2026 10:34
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.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
API-11 的契约和参数检查已经在 Core 里(#183、#184)。在此之前,插件拿到
documents.save或workspace.files.write授权后,调用这些方法在 Viva 桌面端没有处理函数。本 PR 把它们接到窗口上,让插件可以:磁盘变更全部交给 Core 的内核命令完成,桌面端只负责窗口上的事:先保存其下的文档、打开的文档跟着文件移动、本地历史、项目树和 Git 状态刷新、系统废纸篓。
改动 / Changes
插件服务(
desktop/internal/pluginservice/)新增
hostfilechanges.go,注册七个方法:documents/save|saveAs|close,权限documents.save;workspace/create|rename|copy|trash,权限workspace.files.write。decodeStrict),再确认工作区上下文,再检查每个resource/target都在插件拿到的根里,然后用相对路径交给窗口(FileChangeHost)。ChangeError把 Core 的错误码映射成插件错误码:entry_existsplugin.host.alreadyExistsentry_not_foundplugin.host.notFoundinvalid_request、permission_deniedinvalidParamsplugin.host.failed宿主错误、context 取消和 Core 的
cancelled原样传递。hostdocuments.go:窗口实现了FileChangeHost时才注册这组方法。Core 客户端(
desktop/internal/core/)file_changes.go,封装内核命令workspace.createEntry|renameEntry|copyEntry|resolveEntry,类型为WorkspaceEntry、WorkspaceEntryCreation。errors.go:新增CodeEntryNotFound、CodeEntryExists。窗口(
desktop/internal/workbench/)pluginfilechanges.go。documents/save:expectedVersion,版本过期返回versionConflict。documents/saveAs:alreadyExists),然后打开新文件。busy。documents/close:先保存,并确认磁盘内容与文档一致后再关标签;不一致返回diskChanged。虚拟文档直接关闭,未命名文档保留草稿。workspace/create:新建文件(可带text)、文件夹,或kind:"symlink"的符号链接(链接目标原样保存)。不覆盖,父目录不存在返回notFound。workspace/rename:workspace/copy:由 Core 复制,不覆盖。workspace/trash:先保存并关闭其下的文档,再把条目交给系统废纸篓,可以恢复;不提供永久删除。app.action.performed,action 为workspace.file.create|rename|copy|trash,surface 为plugin。被拒绝的记operationRejected,失败的记operationFailed。documents.go、document_autosave.go:saveDocumentMode的auto bool改成saveMode,取值为saveUser、saveAuto、savePlugin。saveWaiters,让插件的保存知道写入成功还是失败的原因。editor_essentials_test.go随之改成saveAuto。app.go:Kernel接口新增四个方法。设置窗口与文案
settingswindow/installed_view.go和shared/i18n/features/plugin-permissions.json:新增workspace.files.write、documents.save的权限说明(中英),并重新生成shared.generated.go。固定 Core 版本
scripts/desktop/build-desktop-core.sh:PINNED_CORE_REVISION升到 Core mainaadf63d([Feature] 添加对 JSON 格式 key value 结构的颜色显示区分,并且预留对颜色进行配置的窗口 #184)。文档与矩阵
docs/development/macos-plugin-api-plan.md:shared/platform-feature-matrix/features/plugin-host-editor-file-window-services.json:editor/registerProviders和documents/registerContentProvider已接通,读取、监视、搜索方法未接通。不在本 PR 范围内 / Out of scope
os.*和copyTreeEntry,改走 Core 见 [Feature] 项目树的新建、重命名、移动、粘贴、建副本改走 Core 的 workspace 内核命令,删除 Go 侧 os.Rename/copyTreeEntry #2356。workspace/readDirectory|stat|readFile|watch|findFiles|findText(API-06/07/08)在 Viva 桌面端未接通,见 [Feature] Viva 桌面端接通插件的工作区读取、监视和搜索方法(API-06/07/08) #2357。插件新建的符号链接,目前要靠这些方法才能读到它指向的文件。workspace/trash。类型专属:feat
多平台对齐
pending。范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/plugin-host-editor-file-window-services.json;没有做整机验收,验证状态保持pendingverify-platform-feature-matrix.sh和verify-platform-feature-matrix-change.sh origin/main HEAD,都通过.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
shared/i18n/;新增的两条是宿主自己的权限说明UI 验证 / UI evidence
N/A:除了“权限与程序”页里两条新权限的说明文字,没有界面布局或交互变化;说明文字由
TestEveryContractPermissionHasADescription覆盖中英两种语言。统一日志系统 / Structured logging
app.action.performed和operationRejected/operationFailed,没有新增事件,也没有手写事件 IDchangeFailed记录一次界面文案 / i18n
shared/i18n/features/plugin-permissions.json补齐中英,生成结果已提交verify-app-language-localization.mjs与generate-i18n.mjs --check都通过逻辑归属 / Logic placement
性能与内存 / Performance and memory
设置 / Settings
N/A:没有新增或修改设置项。
插件契约 / Plugin contract
PINNED_CORE_REVISION已升到aadf63d;桌面测试经desktop-go.sh读的就是这份契约lithe/host/documents/saveexpectedVersionlithe/host/documents/saveAslithe/host/documents/closelithe/host/workspace/createkind:"symlink"+linkTarget),不覆盖lithe/host/workspace/renamelithe/host/workspace/copylithe/host/workspace/trash发行包与资源 / Bundle and resources
verify-runtime-bundle-immutability.sh,通过无用代码与重构 / Dead code and refactoring
saveDocumentMode的布尔参数已整体换成saveMode)验证 / Verification
均在 macOS arm64 上运行,固定 Core
aadf63d:desktop-go.sh test -count=1 ./internal/workbench ./internal/pluginservice ./internal/core ./internal/settingswindow./internal/settingswindow ./internal/i18n通过TestFileChanges*、TestChangeErrorMapsCoreCodes、TestPlugin(Save|Create|Rename|Trash)*连跑-count=3desktop-go.sh vet ./...gofmt -lnode scripts/i18n/generate-i18n.mjs --check、verify-app-language-localization.mjsverify-platform-feature-matrix.sh、verify-platform-feature-matrix-change.sh origin/main HEADverify-runtime-bundle-immutability.shverify-test-stability.sh(工作区、--base origin/main)rg未能执行的检查和原因:
pending。提交前确认 / Final checks
main(d8f55a50c)创建,目标main