文档 chevron_right AI 智能体

AI 智能体

在你的编码智能体写出另一个副本之前,Deslop 会告诉它相似代码已经存在。 智能体发问,Deslop 依据它正在工作的这个仓库的实时分析作答。没有定时任务,没有批处理,也不需要谁记得去跑一次扫描。

本页是写给你 —— 正在做配置的人类。 它说明 MCP 服务器提供了什么,以及如何把各个客户端连接上去。

写给智能体本身的说明 —— 它在写代码前遵循的规则、相似度阈值、MCP 不可用时的 CLI 回退,以及如何解析报告 —— 都在 面向 AI。那一页以第二人称写成,直接写给机器。请把你的智能体指向那个 URL。

可直接粘贴到你项目 AGENTS.md / CLAUDE.md 的规则块参见智能体配方。它适用于 Claude Code、Cursor、Copilot、Continue 与 Codex。

Connect a coding agent to the Deslop MCP server · 1:03 · English narration and captions
英文文字稿

Ask the agent before writing

Before asking my coding agent to write another helper, I ask it to check the project first. Here I am using pi with the Deslop connection enabled. I give it the existing file so the request is about the code I actually have.

Let the agent check Deslop

The agent reads the file and calls Deslop to look for similar code. This is a real tool call against the open project. I can see the request and the returned result in the conversation, instead of relying on the agent to guess.

Review the returned files

Deslop returns two matching files, and pi points me to them. That gives me an existing implementation to review before I create another copy. I read the file names and the reported locations, then check the source rather than stopping at the agent's summary.

Check the source yourself

I open the matching files side by side in Deslop. Now I can check the code and its differences myself. The agent helped me find a possible reuse; I still decide whether that implementation fits the change I want to make.

MCP 工具,全部实时

只有 find-similar 属于编写代码的内循环。其余的全是只读报告查询,或按需取用的配置工具,因此智能体的工作上下文保持精简,而不必背负一整面墙的工具输出。

工具 何时调用
find-similar 在编写新代码之前——是否已存在等价实现?这就是预防工具。
duplicates 从小型概览页开始,按路径、语言或 kinds 缩小范围。省略种类时继承配置,默认完全相同和几乎相同。
cluster-by-id 选定簇的完整成员列表;配对证据由 compare-pair 提供。
compare-pair 为什么这两处具体的出现被判定为彼此的重复。
merge-plan 动手编辑之前,为某个簇生成只读的机械合并方案。
rescan 在大规模外部变更后强制刷新。
session 会话元数据;列出提供方公布的语义模型,或切换到你选定的模型。
schema-doc 每个响应的权威 JSON schema。每个会话调用一次,而非每次响应都调用。

每一个响应都针对实时工作区状态计算。编辑器服务器在内存中持有实时报告,并在每次变更时刷新(防抖,并设有硬上限);MCP 服务器则在下一次工具调用时通过本地 IPC 端点读取该实时状态。macOS 与 Linux 使用 .deslop/cache/deslop.sock;Windows 使用通过 .deslop/cache/deslop.port 发现、由令牌保护的 TCP 回环端点。没有批处理步骤。

将 deslop-mcp 接入你的客户端——指向 VSIX 捆绑的二进制文件

deslop-mcp 随 VS Code 扩展 VSIX 一同发布。安装扩展后,每个外部 MCP 客户端(Claude Code、Claude Desktop、Codex、Cursor、Continue)都应通过绝对路径引用解包后的 VSIX 二进制文件,这样智能体运行的就是扩展所发布的那个确切二进制文件——与 VSIX 版本锁定,不会发生 PATH 漂移。

从 Marketplace 安装扩展后,二进制文件位于:

~/.vscode/extensions/nimblesite.deslop-live-<VERSION>-<platform>/bin/<platform>/deslop-mcp

<platform> 为 darwin-arm64、darwin-x64、linux-x64、linux-arm64 或 win32-x64。<VERSION> 为已安装的扩展版本——每次更新 VSIX 后,都要把它改为新安装的版本号。

Claude Code

claude mcp add deslop -s user -- \
  ~/.vscode/extensions/nimblesite.deslop-live-<VERSION>-darwin-arm64/bin/darwin-arm64/deslop-mcp \
  --root .

Codex (~/.codex/config.toml)

[mcp_servers.deslop]
command = "/Users/you/.vscode/extensions/nimblesite.deslop-live-<VERSION>-darwin-arm64/bin/darwin-arm64/deslop-mcp"
args    = ["--root", "."]

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "deslop": {
      "command": "/Users/you/.vscode/extensions/nimblesite.deslop-live-<VERSION>-darwin-arm64/bin/darwin-arm64/deslop-mcp",
      "args": ["--root", "/absolute/path/to/your/repo"]
    }
  }
}

不要让 MCP 客户端指向 cargo install 或 target/release 构建产物。 从源码构建 Deslop 是为了测试你刚做的改动;它不是分发渠道。本仓库刻意不提供 make install-binary 目标。

Homebrew / Scoop CLI 用户——指向 $PATH 上的裸 deslop-mcp

如果你通过 brew install nimblesite/tap/deslop 或 scoop install deslop 安装了 CLI,该包还会把 deslop-mcp 和 deslop-lsp 一并放到你的 $PATH 上,与 deslop 并列——Homebrew tap 配方和 Scoop 清单会安装全部三个二进制文件,并与发布版本锁定。无需 VSIX、无需扩展目录、无需绝对路径。直接使用裸命令:

claude mcp add deslop -s user -- deslop-mcp --root .
{
  "mcpServers": {
    "deslop": {
      "command": "deslop-mcp",
      "args": ["--root", "."]
    }
  }
}

同样的 "command": "deslop-mcp" 形式适用于 Codex(~/.codex/config.toml)、Cursor 和 Continue,前提是该机器上的 Deslop 通过 Homebrew 或 Scoop 安装。不要把它写进签入的 .mcp.json 或团队共享配置:使用 VS Code 扩展的队友在 $PATH 上没有任何 Deslop 程序,而扩展的绝对路径又随版本和平台而变。请让每个人自行注册服务器:使用 claude mcp add … -s user,或各自客户端的用户级配置。

需要知道的两点:

  • 不存在 deslop mcp 子命令。 deslop CLI 只用于一次性运行和 CI 审计;MCP 由独立的 deslop-mcp 二进制文件提供。
  • 从源码构建不会把任何东西放到 $PATH 上。 只有锁定发布版本的安装方式会这么做:brew、scoop,以及官方发布的 curl 安装脚本(它固定一个发布版本并校验其校验和)。cargo build 不固定任何版本。

智能体循环

主打的工作流是响应式的,而非批处理:

  1. 智能体提出一个改动。在它写出新代码之前,它通过 MCP 对候选片段调用 find-similar。
  2. 如果 find-similar 返回一个高于所配置相似度下限的簇,智能体就复用规范实现,或重写该调用点。
  3. 当智能体编辑文件时,文件监视器会触发,分析随之刷新。下一次工具调用时,MCP 服务器会提供新状态。
  4. 智能体重新查询 duplicates,确认该簇已消失。无需重新运行、无需标志、无需批处理 CLI 调用。

当 MCP 不可用时 —— CI、冷缓存审计,或没有 MCP 客户端的智能体 —— 循环会降级到 deslop CLI,它运行完全相同的流水线,产出完全相同的 JSON。增量缓存默认开启,因此编辑后的重新运行只会重新解析发生变化的文件。逐步的回退方案见面向 AI。

Find similar code before writing with an AI coding agent · 1:02 · English narration and captions
英文文字稿

Ask what is repeated

I ask pi to check the repeated code in this project before making a change. It calls Deslop and brings the result into the conversation. I start with one finding so the review stays small enough to understand and act on.

Read the files behind the result

I ask the agent for the files behind that finding. The reply shows where the repeated code lives and how many copies were found. I use those locations to guide the next step, rather than asking for a broad rewrite of the project.

Check before adding a helper

Before adding another helper, I ask pi to read the existing file and search for similar code. Deslop returns the matching files. This is the useful moment to spot something I can reuse, while there is still time to avoid writing another copy.

Review before accepting a change

I finish by opening the source comparison in the editor. I check that the proposed reuse preserves the behavior I need. After a focused change, I run the project's tests and review Deslop again instead of assuming the agent's first answer is enough.

Deslop 刻意不做的事

  • 它不会重写你的代码。Deslop 负责发现、排名、比较与预防重复;提取由你决定。
  • 它不会让 CI 失败,除非你自己设置阈值。
  • 它不会假定"近似命中 = bug"。有些重复是有意为之的(测试夹具、引导代码)。Deslop 负责报告;由你来决定。
  • 它不会访问网络,除非你显式选择一个远程嵌入模型。