Cursor客户端解剖(二)整体架构鸟瞰

系列:Cursor客户端解剖系列学习笔记
上一篇:(一)为什么是-VS-Code-Fork

先看分层总览

Cursor 分层架构

从上到下可以记成五层:Glass/Workbench UI → Workbench Services → Extension Host 集群 → Monaco/Platform → Electron 进程模型。细节见学习材料中的分层说明。

为什么这样分层

VS Code 的经典理念没有被推翻:

  • UI 与扩展隔离:扩展跑在 Extension Host,崩溃不拖死编辑器
  • 服务可替换platform / workbench/services 用 DI 组装
  • 贡献点:命令、视图、配置用 package.json 声明

Cursor 在这上面加了三刀:

  1. 把 AI 相关能力拆成多个内置扩展(Agent Exec / Host / Worker / Retrieval / MCP…)
  2. 在 workbench 里加 composer / ai / agentData 等核心服务与 UI
  3. Glass 做 Agent-first 的另一套入口壳

学习启示很直接:

UI 可以花,执行链必须硬。
先画「哪些必须和 UI 同命运、哪些必须可崩溃可重启」,再决定模块边界。

内置扩展集群:按能力域看

extension-catalog.json / 各扩展 package.json 归纳:

能力域 扩展 设计意图
Agent 编排与执行 cursor-agent-host / cursor-agent-exec / cursor-agent-worker 控制面 / 执行面 / 工人面拆开
本地私有推理 cursor-local-agent-runtime Private Inference 放在普通 workspace extension host 之外
代码检索 cursor-retrieval(及清单型 cursor-file-service 索引检索与编辑器进程解耦
工具协议 cursor-mcp / cursor-browser-automation MCP 一等公民;浏览器自动化也走 MCP 形态
隔离写代码 cursor-shadow-workspace / cursor-worktree-textmate Shadow/Worktree;TextMate-only 避免误启 LSP
后台/云端通道 cursor-resolver* / cursor-socket / cursor-always-local 自定义 remote authority:background-composer
产品化杂项 cursor-deeplink / cursor-commits / cursor-checkout / cursor-ndjson-ingest 深链、指标、分支迁移、调试日志摄入

激活策略:基础设施不能懒加载碰运气

很多 Cursor 扩展是 activationEvents: ["*"]onStartupFinished

含义很硬:Agent 基础设施必须尽早、确定地起来。
Host / Exec / Local Runtime 常见 *;MCP / Retrieval / Shadow / Worker 常见启动完成后激活。

另外还有 extensionKind

  • workspace:跟着工作区走(retrieval、mcp、shadow)
  • ui:必须在本地 UI 机(socket、resolver、local-agent-runtime、browser)

这是在回答:「这段代码该死在哪台机器、哪个进程」。

Utility 进程:重活出局

out/vs/code/electron-utility/ 下能看到诸如 mcpProcessconversationSearchalwaysLocalSingleton 等目录名。

长连接、重 IO 不进 UI 进程——和 VS Code 自己的 shared/utility 思路一脉相承。

一条能力流公式

学习材料给的精髓公式:

Intent UI → Context Service → Orchestrator → Sandboxed Executor → Protocol Tools → Isolated Apply

对应到扩展:

Agent 能力流

缺任何一段都会疼:只有 UI 没有隔离执行 → 不安全;只有执行没有检索 → 胡编;只有硬编码工具没有协议 → 扩展不动。

小结

鸟瞰之后记住三句话:

  1. Cursor = 编辑器平台 + Agent 运行时,不是侧边栏 Chat
  2. 能力按故障域拆成内置扩展,而不是一个超级扩展包打天下
  3. 后台任务按 Remote Authority 建模,而不是 renderer 里随便 fetch

下一篇进入上下文引擎:cursor-retrieval 如何把「模型能看什么」产品化。