Skip to content

feat: add plugin mode - #382

Merged
leookun merged 10 commits into
mainfrom
feat/plugin
Aug 30, 2026
Merged

leookun merged 10 commits into
mainfrom
feat/plugin

Conversation

@leookun

@leookun leookun commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Summary

将订阅类 Provider 能力(PR #360 的目标)重构为通用插件系统:插件实现核心定义的能力接口,核心负责状态持久化与 UI 绘制。

插件契约(TypeScript SDK,server/src/plugin/sdk/)

  • Provider:invoke() 接收完整 LlmRequest(指令/消息/工具/思考配置/会话缓存键),自行完成协议适配与 SSE 解析,边流式 emit() 标准化 ModelEvent(与核心 provider/event.rs 一一对应,含工具参数增量与加密推理回放),返回 completed 或类型化错误(resource-error 携带资源补丁)
  • Model:models.list() 枚举上游模型,核心持久化目录;每个模型独立进入 Cursor(plugin:<plugin>/<provider>/<model>),支持 Context/Effort/Fast 变体
  • Resource:账号等凭证资源;OAuth 2.0 设备码流程(begin/poll,核心驱动轮询/超时/退避)、批量导入(兼容 cliproxyapi 格式)/导出、present() 投影、额度刷新;插件零持久状态,数据全部由核心以 0600 原子 JSON 持有
  • LocalizedText 全链路 i18n;协议帮助库 cursor-byok:protocol/openai-responses(与 Rust 内置 Provider 行为对齐,replay kind 互通)

核心(Rust)

  • 插件模型对路由完全等同内置 Provider:统一 Recorder/调用记录(ProviderType::Plugin)、规范化管道、流空闲超时看门狗;资源选择内聚在插件 Provider 内,为负载均衡预留
  • Deno 沙箱 Worker:NDJSON 多路复用、事件流、拉取式 network.stream、精确 HTTPS 主机白名单、取消传播;Windows 下 CREATE_NO_WINDOW 与原子替换重试
  • 内置插件按 manifest version 预装进 plugins/installed/(版本一致零写盘,变化时整目录同步),minAppVersion 门控由桌面壳注入应用版本
  • 迁移 0007:去除 llm_calls.model_hash 外键,插件稳定模型 ID 直接参与调用统计与筛选

内置 Codex 插件(server/plugins/build-in/codex-auth)

ChatGPT 设备码登录、凭证导入导出、周/5 小时额度、官方模型同步、fast→service_tier: priorityprompt_cache_key + session-id/thread-id 缓存亲和(与 codex-rs 契约一致)。

桌面端

插件配置页(卡片:图标/开发者/版本/状态,添加账号/账号管理/更多菜单)、OAuth 与资源管理面板、模型页可折叠分组列表、截断按钮 Tooltip、自绘斑马纹进度条、菜单重组(模型配置/设置)、中英文案。

Test plan

  • cargo test -p cursor-server --lib(39 通过,含 wire/state/manifest/builtin/migration 用例)
  • cargo clippy -- -D warningscargo fmt --check
  • Codex 插件 Deno 测试 9/9(OAuth、导入、额度、模型解析、invoke 全链路 SSE mock)
  • desktop / docs npm run check
  • 真实链路:ChatGPT 设备码登录 → 模型同步 → Cursor 对话流式输出,前缀缓存命中约 95%+
  • Windows 复测(拒绝访问重试与无 cmd 窗口)

… PluginManagementPage

- Updated the UI components in CursorModelCards and PluginManagementPage to use TruncatedButton for better text handling and display.
- Adjusted styles in CursorSettings and PluginManagementPage to ensure proper button layout and responsiveness.
- Added new ActionMenu component for handling additional actions in PluginManagementPage.
- Enhanced localization files to include new strings for the ActionMenu and TruncatedButton components.
- Replaced the native progress element with a custom-styled progress bar for improved visual feedback during downloads.
- Added new styles for progress bar and fill animations to enhance user experience.
- Updated the component to use ARIA roles for better accessibility.
@leookun
leookun marked this pull request as ready for review August 30, 2026 13:00
…rvices

- Added detailed error messages for plugin data read/write failures, including file paths for better debugging.
- Updated logging levels for upstream request rejections in account services to debug for less critical issues.
- Enhanced error handling in the plugin worker to provide clearer context when starting the plugin worker fails.
- Introduced new functions for merging extra parameters and applying body allowlists in provider services, improving request validation.
- Implemented a new button to copy the user code in the OAuthMethodCard, enhancing user experience.
- Added styles for the copy button to match the UI design.
- Updated localization files to include new strings for the copy action in both English and Chinese.
- Replaced asynchronous file operations with a synchronous approach to ensure file handles are properly closed before replacement.
- Introduced a new `write_once` function for atomic file writing, including directory creation, temporary file writing, and target file replacement.
- Enhanced error handling to retry on transient errors specific to Windows, improving robustness during file operations.
- Updated the `clear` method in `PluginRegistry` to ensure OAuth sessions are only removed after successful persistence of resources.
@leookun
leookun merged commit fc79adb into main Aug 30, 2026
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