cjdrift:基于 MCP 与 Cangjie 生态的 AI 开发工具项目

AI-native MCP toolchain for Cangjie 1.1.3 developers. Exposes cjpm / cjlint / cjfmt / std.api search / registry search / scaffolding / error explanation as 12 MCP tools.

分支1Tags0
文件最后提交记录最后更新时间
20 天前
29 天前
20 天前
19 天前
20 天前
29 天前
18 天前
29 天前
29 天前
29 天前
29 天前
29 天前
29 天前
29 天前
19 天前
29 天前
18 天前

cjdrift(仓颉漂移)

面向仓颉开发者的 AI 协作 MCP 工具集。

把仓颉 1.1.3 全工具链(cjpm / cjlint / cjfmt / stdlib API / 中心 仓 / 项目脚手架 / 错误诊断 / 受控文件系统)封装为 12 个生产 可用的 MCP 工具,让 Claude Desktop / Cursor / Windsurf / Continue 等所有支持 MCP 的 AI 编程助手都能"真正懂得"仓颉。


这个项目解决什么问题?

仓颉生态当前阶段的最大瓶颈不是"再多一个 HTTP 客户端库", 而是 AI 时代仓颉开发者与 LLM 之间的最后一公里

  • LLM 不知道仓颉 1.1.3 stdlib 的 API 名,常常生成 ArrayList 当成 Array 用的代码
  • LLM 不知道 cjpm 接受哪些子命令,常常写出 cjpm add cjpm-test 之类的错误
  • LLM 不知道中心仓有什么包,每次都要离开 IDE 去浏览器
  • LLM 读不懂 cjlint 报告,只能把一千条诊断贴回对话
  • LLM 写出来的代码风格不"仓颉",充斥 Python 的 elif、C 的 { } block

cjdrift 把这一公里接上。

12 个工具一览

方法 作用
cangjie_apis 模糊搜索仓颉 1.1.3 标准库 API
cangjie_doc 查一个 API 的完整文档
cangjie_patterns 查惯用代码片段(parse JSON、spawn future、mutex…)
cangjie_run 跑 cjpm / cjlint / cjfmt(白名单 10 个子命令)
cangjie_lint 跑 cjlint 并按规则聚合报告
cangjie_fmt 跑 cjfmt(dry-run 模式返回 unified diff)
cangjie_pkg_search 搜仓颉中心仓(带离线 fallback)
cangjie_scaffold 生成三种项目骨架(executable / library / mcp-server)
cangjie_explain 14 条规则解释 cjc / cjpm / cjlint 错误
cangjie_read_file 受控读文件(限在 root 之下)
cangjie_write_file 受控写文件(必须 confirm: true
cangjie_list_dir 受控列目录

安装

# 在你的仓颉项目根目录
cjpm add cjdrift

或者单独 clone:

git clone https://gitcode.com/jiangzeyu-2026/cjdrift
cd cjdrift
cjpm update && cjpm build
./target/release/cjdrift server   # 启动 MCP 服务器
./target/release/cjdrift search "ArrayList"
./target/release/cjdrift explain "cannot find symbol"

接入 Claude Desktop

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "cjdrift": {
      "command": "/abs/path/to/cjdrift",
      "args": ["server"]
    }
  }
}

重启 Claude Desktop 即可看到 12 个 cangjie_* 工具。

作为库使用

import cjdrift

main(): Int64 {
    return cjdrift.runDefaultServer()  // 启动默认 MCP 服务器
}

或自选工具:

import cjdrift.core.{Server, ServerConfig, ToolRegistry, Transport}
import cjdrift.tools.{CjapiTool, CjlintTool, ExplainTool}
import cjdrift.knowledge.{ApiIndexLoader, Explainer}
import std.io.{InputStream, OutputStream}

main(): Int64 {
    let registry = ToolRegistry()
    let idx = ApiIndexLoader().load()
    registry.register(CjapiTool(idx))
    registry.register(CjlintTool())
    registry.register(ExplainTool(Explainer()))

    let transport = Transport(InputStream.stdin(), OutputStream.stdout())
    return Server(ServerConfig(), registry, transport).run()
}

与官方工具的关系

工具 角色 cjdrift 是否依赖
cjc 编译器 是(间接)
cjpm 包管理 是(间接)
cjlint 静态检查 是(间接)
cjfmt 格式化 是(间接)
cjcov 覆盖率 否(0.1.0)
std.ast AST 库 否(保留给下游工具)
CangjieMagic Agent DSL 否(互补)
CangjieCorpus RAG 语料 否(互补)

cjdrift 不与它们竞争,而是把它们在 LLM 侧串起来。

三层安全

  1. cangjie_run 白名单 — 只允许 10 个 cjpm 子命令
  2. cangjie_write_file 必须 confirm: true — 模型 显式请求写入才会落盘
  3. cangjie_*_file 路径包含 — 所有路径在 root 下解 析,.. 段被拒绝

开发与测试

cjpm test            # 28 个单元 + 集成测试
cjpm run -- server   # 开发模式启动服务器
cjpm bundle          # 打包

兼容性

  • Cangjie SDK: 1.1.3 (STS)
  • MCP 协议: 2025-06-18
  • MCP 客户端: Claude Desktop 0.7+ / Cursor 0.40+ / Windsurf 1.5+ / Continue 0.9+ / OpenAI Agents SDK 0.3+
  • OS: Linux / macOS / Windows 一致

许可

Apache-2.0。详见 LICENSE

仓库

项目介绍

AI-native MCP toolchain for Cangjie 1.1.3 developers. Exposes cjpm / cjlint / cjfmt / std.api search / registry search / scaffolding / error explanation as 12 MCP tools.

定制我的领域