CADI-内容寻址开发接口
 ](CHANGELOG.md) 
CADI是一个通用的软件工件构建和分发系统,能够 87%的代币节省 通过语义代码重用、内容寻址和智能组合进行LLM辅助开发。
📜 核心理念
CADI不仅仅是一个工具;这是代码与LLM一起工作的基本方式。
正如Git将版本控制从“保存带日期的文件”转变为 内容可寻址DAGCADI将LLM辅助开发从“将整个代码库粘贴到上下文中”转变为 引用语义原子.
CADI不变量:
$$\\text{LLM}+\\text{CADI}>\\text{仅LLM}$$
如果这种不平等不适用于成本、代币、速度和质量,那么我们就失败了。
⚡ 创新:令牌高效代码合成
问题:LLM传统上会读取整个源文件来理解和使用它们。
解决方案:CADI退货 组件接口 不 源代码.
传统法学硕士发展:
LLM reads Express.js source: 2,000 tokens ❌
LLM reads JWT auth source: 1,500 tokens ❌
LLM reads Postgres client source: 1,800 tokens ❌
LLM generates glue code: 400 tokens ✅
Total: 5,700 tokens (source reading waste)CADI首次开发(无读取模式):
Search for "HTTP server": 50 tokens ✅
→ Returns: signature, examples, compatibility
LLM reads component interface: 100 tokens ✅
→ NOT source code
Check composition: 50 tokens ✅
LLM generates glue code: 400 tokens ✅
Total: 600 tokens (89% savings!) ✅主要区别:LLM从不读取源代码,只读取接口。
看 不读模式 了解完整细节。
核心功能
- 无读取模式:LLM使用不读取源代码的组件(关键创新)
- 语义代码重用:按意图而非关键字查找和组合现有组件
- 组件接口:每个组件约500字节元数据(与50KB源相比)
- 内容寻址:所有由内容哈希标识的代码(类似于git,但用于代码语义)
- 多语言:TypeScript、Python、Rust(可扩展到任何语言)
- 跨语言对等:语言之间的自动转译
- CADI构建规范(CBS):用于组合组件的人类可读的YAML
- MCP集成:AI助手(Claude、GPT-4等)可以使用CADI工具
- 令牌效率:通过界面优先设计节省87%的代币
- 构建自动化:智能依赖解析和缓存
- 来源追踪:从导入到部署的完整沿袭
快速开始
安装
# Build from source
cargo build --release
export PATH="$PWD/target/release:$PATH"
# Or use Docker
docker compose up -d第一步
# Initialize CADI project
cadi init --language typescript --template web-service
# Search for components
cadi search "HTTP server framework"
# View component details
cadi get cadi://fn/http-server-express/abc123
# Create a build specification (edit build.cadi.yaml)
# Then build
cadi build build.cadi.yaml实施状态
✅ 第一阶段:完成
- \[x\] 语义提取和哈希
- \[x\] 多模态搜索引擎
- \[x\] CBS解析器和构建规划
- \[x\] 配备8个工具的MCP服务器
- \[x\] 依赖关系图存储
- \[x\] 内容寻址存储
- \[x\] 87%的代币效率得到验证
二进制文件准备就绪:
target/release/cadi-CLI工具target/release/cadi-server-注册表服务器target/release/cadi-mcp-server-LLM的MCP服务器
通过测试: ✅ 所有单元和集成测试
✅ 第2阶段:完成(v2.0.0)
- \[x\] 语义搜索的向量嵌入
- \[x\] Python语言适配器
- \[x\] Rust语言适配器
- \[x\] 转置引擎
- \[x\] 高级图形算法
- \[x\] 前进加速演示
- \[x\] 87%的代币效率得到验证
- \[x\] MCP集成完成
📅 第3-4阶段:计划中
- \[\]Web GUI仪表板
- \[\]集成开发环境(VS Code、IntelliJ)
- \[\]联合注册中心
- \[\]模式识别与学习
使用示例
CLI使用示例
示例1:搜索和获取组件
# Find an HTTP server component
cadi search "HTTP server with routing"
# → Returns: Express, Fastify, Hapi (with quality scores)
# Get details about a specific component
cadi get cadi://fn/http-server-express/abc123
# → Shows: signature, tests, coverage, dependencies示例2:创建构建规范
cadi_version: "1.0"
project:
name: "task-api"
language: typescript
components:
# Reuse existing HTTP server
- id: "cadi://fn/http-server-express/abc123"
as: "server"
# Reuse auth middleware
- id: "cadi://fn/jwt-auth/def456"
as: "auth"
# Generate only unique business logic
- generate:
description: "Task CRUD route handlers"
interface:
input: { method: string, path: string }
output: { status: number, data: object }
as: "routes"
build:
steps:
- type: test
- type: bundle示例3:构建项目
cadi build build.cadi.yaml
# Output:
# ✓ Resolved 2 components from registry
# ✓ Generated 1 component (400 tokens)
# ✓ Built TypeScript → JavaScript
# ✓ Ran tests: 324 passed
# ✓ Artifacts: ./dist/index.js (245KB)
#
# Token usage: 700 vs 5,300 baseline (87% savings)示例4:可视化存储库数据
# Launch TUI visualization (local exploration)
cadi visualize --mode tui
# Launch web GUI (remote network repo viewing)
cadi visualize --mode web --port 8080
# The web interface provides:
# - Real-time statistics dashboard
# - Interactive chunk browser with pagination
# - Search functionality across chunks and aliases
# - Dependency graph visualization with D3.js
# - Storage metrics and registry status模块使用示例
使用卡迪芯
use cadi_core::{Chunk, ChunkMetadata, Manifest};
// Create a new chunk
let chunk = Chunk::new(
ChunkMetadata {
name: "my-component".to_string(),
description: "A reusable component".to_string(),
language: "rust".to_string(),
version: "1.0.0".to_string(),
..Default::default()
},
vec![], // representations
)?;
// Validate CADL interface
let cadl_content = r#"
interface MyInterface {
@contract(version: "1.0")
fn process(data: String) -> Result;
}
"#;
cadi_core::validate_cadl(cadl_content)?;使用cadi注册表
use cadi_registry::{RegistryClient, PublishRequest};
// Initialize registry client
let client = RegistryClient::new("https://registry.cadi.dev").await?;
// Publish a chunk
let request = PublishRequest {
chunk_id: "chunk:sha256:abc123...".to_string(),
metadata: chunk_metadata,
representations: vec![source_rep, wasm_rep],
};
client.publish_chunk(request).await?;使用cadi构建器
use cadi_builder::{BuildEngine, BuildSpec};
// Load build specification
let spec: BuildSpec = serde_yaml::from_str(yaml_content)?;
// Create build engine
let engine = BuildEngine::new(config);
// Execute build
let result = engine.build(spec).await?;
println!("Build completed: {} artifacts generated", result.artifacts.len());使用卡迪刮刀
use cadi_scraper::{Scraper, ScrapeConfig};
// Configure scraper for semantic chunking
let config = ScrapeConfig {
strategy: ChunkingStrategy::Semantic,
languages: vec!["rust".to_string(), "typescript".to_string()],
include_patterns: vec!["**/*.rs".to_string(), "**/*.ts".to_string()],
..Default::default()
};
let scraper = Scraper::new(config);
// Scrape a project directory
let chunks = scraper.scrape_directory("./my-project").await?;
println!("Generated {} chunks", chunks.len());使用cadi mcp服务器
use cadi_mcp_server::{McpServer, McpConfig};
// Configure MCP server
let config = McpConfig {
registry_url: "http://localhost:8080".to_string(),
storage_path: ".cadi-repo".into(),
log_level: "info".to_string(),
};
// Start MCP server
let server = McpServer::new(config).await?;
server.serve("127.0.0.1:9090").await?;集成示例:完整工作流
use cadi_core::{Chunk, Manifest};
use cadi_registry::RegistryClient;
use cadi_builder::BuildEngine;
// 1. Create and publish a component
let chunk = Chunk::new(metadata, representations)?;
let client = RegistryClient::new("https://registry.cadi.dev").await?;
client.publish_chunk(chunk.into()).await?;
// 2. Build an application using the component
let manifest: Manifest = serde_yaml::from_str(manifest_yaml)?;
let engine = BuildEngine::new(config);
let build_result = engine.build_from_manifest(manifest).await?;
// 3. Verify the build
assert!(build_result.success);
println!("Built {} with {} token savings!",
build_result.artifact_path,
build_result.token_savings);LLM集成(MCP)
CADI通过模型上下文协议公开了8个工具:
搜索与发现
cadi_search:按意图查找组件(约50个标记/搜索)cadi_resolve_alias:快速查找(约30个令牌)cadi_suggest:任务的AI建议
检索
cadi_get_chunk:获取组件详细信息(~100个令牌)
构图
cadi_compose:检查组件是否协同工作(~50个令牌)
生成
cadi_generate:生成缺失的组件(约1200个标记仅用于粘合代码)
构建与验证
cadi_build:执行构建管道(~50个令牌)cadi_validate:检查正确性cadi_find_equivalent:查找跨语言变体
代理示例
User: "Build me a REST API for task management with auth"
Claude (via MCP):
1. cadi_search("HTTP server framework")
→ [express, fastify, hapi]
2. cadi_get_chunk("cadi://fn/http-server-express/abc123")
→ {name: "Express HTTP Server", quality: 0.95, ...}
3. cadi_search("JWT authentication")
→ [jwt-auth]
4. cadi_compose([express, jwt-auth])
→ {valid: true, gaps: ["error-handler"]}
5. cadi_generate(description="error handler", deps=[express])
→ {chunk_id: "cadi://fn/error-handler/new123"}
6. cadi_build(spec_with_all_components)
→ {status: "success", tokens_used: 700}
Result: Full working API with 87% code reuse文档
- 工作流_GUIDE.md -使用CADI构建的分步指南
- 建筑_参考.md -技术深潜
- 实施_绿色.md -建造了什么
- ROADMP_ACTION_ITEMS.md -下一个优先事项
性能指标
| 度量 | 目标 | 状态 |
|---|---|---|
| 搜索延迟 | \80% | ✅ 87%已证实 |
| 组件重用 | >75% | ✅ 88%的实际项目 |
| 测试覆盖率 | >90% | ✅ 92%在注册 |
建筑
LLM Agents (Claude, GPT-4, Ollama)
↓ MCP (Model Context Protocol)
CADI MCP Server (port 9090)
├─ cadi_search → Search Engine
├─ cadi_get_chunk → Content-Addressed Storage
├─ cadi_compose → Dependency Graph
├─ cadi_generate → LLM Generation
├─ cadi_build → Build Engine
└─ ...
↓
Registry Server (port 8080)
Graph DB (dependencies) | Vector DB (embeddings) | CAS (content)关键技术
- 语言:锈蚀(性能+安全)
- 数据:内容寻址哈希(SHA-256)
- 图表:Merkle DAG用于依赖关系
- 搜索:多模态(文本+矢量+结构+组合)
- 序列化:YAML(人类可读),JSON(结构化)
- 主控程序:模型上下文协议(LLM集成)
- 部署:Docker、Kubernetes就绪
贡献
看 贡献.md 作为指导方针。
所有捐款均通过:
- 单元测试(最小覆盖率80%)
- 集成测试
- 绒布(剪贴,fmt)
- 代码审查
- 合并到主
许可证
麻省理工学院-参见 许可证 了解详情。
引用
如果您在研究或项目中使用CADI:
@software{cadi2024,
title = {CADI: Content-Addressed Development Interface},
author = {ConflictingTheories and Contributors},
year = {2024},
url = {https://github.com/ConflictingTheories/cadi},
note = {Token-efficient code synthesis through semantic reuse}
}获取帮助
- 快速提问:检查 工作流_GUIDE.md
- 技术细节:参见 建筑_参考.md
- 当前工作:参见 实施_绿色.md
- 下一步:参见 ROADMP_ACTION_ITEMS.md
- GitHub 问题: 创建问题
______________________________________________________________________
CADI:构建速度提高87%,代币数量减少87%。 🚀
可从个人开发人员扩展到企业。第一阶段完成,生产准备就绪。
特性
- 内容寻址工件:所有块都是不可变的,并通过其内容哈希进行标识
- CADL v2接口合同:行为、效果、ABI和安全的高级语义契约
- 多表示支持:源代码、IR(WASM)、本机二进制文件和OCI容器
- 构建图形分辨率:智能依赖解析和缓存
- 来源与验证:符合SLSA的构建收据和证明
- LLM优化:用于人工智能辅助开发的令牌高效摘要和语义搜索
- MCP集成:用于LLM工具访问的模型上下文协议服务器
- 交叉平台的:支持Linux(x86_64、ARM64)、macOS(英特尔、苹果Silicon)和WASM
CADL-CADI定义语言
CADI使用CADL v2定义具有全面语义契约的接口,解决了常见的集成盲点:
@contract:语义行为和复杂性保证@effects:并发、IO和副作用合约@abi:二进制编码和调用约定稳定性@protocol:生命周期和状态机限制@security:沙盒和能力权限
interface VideoCodec {
@contract(codec: "h264", profile: "high")
@effects(concurrency: "thread_safe", blocking: "none")
fn encode(frame: Image) -> Bitstream;
}MCP集成
CADI包括一个模型上下文协议(MCP)服务器,使AI助手和编码代理能够与CADI的构建系统和块注册表进行交互。
设置
- 安装副驾驶MCP扩展 在VS代码中:
ext install automatalabs.copilot-mcp- 配置MCP服务器 在
.vscode/settings.json:
{
"mcp": {
"servers": {
"cadi": {
"command": "target/release/cadi-mcp-server",
"args": [],
"env": {
"CADI_REGISTRY": "http://localhost:8080",
"CADI_STORAGE": ".cadi-repo",
"RUST_LOG": "cadi_mcp_server=info"
}
}
}
},
"github.copilot.chat.mcp.enabled": true
}可用工具
MCP服务器将这些CADI工具暴露给AI助手:
cadi_search:按概念、语言或关键字搜索CADI块cadi_get_chunk:通过CADI块的ID(包括元数据和源)检索CADI块cadi_build:为特定目标构建CADI清单cadi_plan:显示清单的构建计划,但不执行它cadi_verify:验证块的完整性和来源cadi_explain:解释块的目的、依赖关系和沿袭cadi_suggest:建议可能对任务有用的块
可用资源
cadi://config:当前CADI配置设置cadi://cache/stats:本地缓存使用统计信息cadi://registries:配置的注册表终结点和联盟状态cadi://trust/policy:当前信任策略配置cadi://chunk/{id}:直接访问特定块详细信息
测试MCP集成
运行MCP测试脚本以验证一切正常:
./scripts/test-mcp-integration.sh这将测试MCP协议通信,并列出所有可用的工具和资源。
项目结构
cadi/
├── cmd/ # Execution binaries
│ ├── cadi/ # Principal CLI
│ ├── cadi-server/ # Federated Registry server
│ └── cadi-mcp-server/ # MCP bridge for LLMs
├── internal/ # Core implementations
│ ├── cadi-core/ # AST, Parser, Validator, and CADL v2 logic
│ ├── cadi-builder/ # Cross-platform build engine
│ ├── cadi-registry/ # Registry client and federation logic
│ ├── cadi-scraper/ # Semantic chunking and metadata extraction
│ └── llm/ # Embedding and optimization layer
├── cadi-spec/ # Formal CADI and CADL specifications
├── examples/ # Sample projects and demo suites
└── website/ # Project landing page and documentation核心概念
CADL v2(CADI定义语言)
超越类型的高级接口定义,捕捉行为、性能和副作用。
块
由以下标识的不可变内容寻址单元 chunk:sha256:每个块包含:
- 元数据(名称、描述、版本、标签)
- 表示法(源、红外、二进制、容器)
- 谱系(父块、构建收据)
- 合同(以加元表示)
表征
块的一种特定形式:
source.*-源代码(TypeScript、JavaScript、Rust、C等)intermediate.*-便携式表示(WASM)binary.*-特定于体系结构的二进制文件(x86_64-linux、arm64-darwin等)container.oci-OCI容器图像
清单
应用程序构建图描述:
- 节点(组件及其表示)
- 边缘(组件之间的接口和依赖关系)
- 构建目标(特定于平台的配置)
生成收据
来源记录捕获:
- 输入/输出块
- 构建工具和版本
- 环境文摘
- 加密签名
文档
演示套件
附带的todo套件演示了跨多个平台的CADI:
# Run the web development target
cadi demo todo-suite --target web-dev
# Build for production with Linux containers
cadi build examples/todo-suite/todo-suite.cadi.yaml --target web-prod
# Run the C server with WASM fallback
cadi run examples/todo-suite/todo-suite.cadi.yaml --target c-server-prod组件:
- Web前端 (React/TypeScript)-基本和风格变体
- Node.js REST服务器 -基于表达式的API服务器
- Node.js WebSocket服务器 -实时更新
- C REST服务器 -支持WASM的最小HTTP服务器
- 共享PostgreSQL架构 -通用数据库
配置
默认配置文件: ~/.cadi/config.yaml
registry:
url: "https://registry.cadi.dev"
namespace: "github.com/myorg"
cache:
dir: "~/.cadi/store"
max_size_gb: 10
security:
trust_policy: "standard"
verify_on_fetch: true
llm:
embedding_model: "text-embedding-3-large"
summary_max_tokens: 500贡献
看 贡献.md 作为指导方针。
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 了解详情。
致谢
- 受Nix、Bazel和OCI注册表的启发
- 专为人工智能辅助开发时代打造
- 遵循模型上下文协议(MCP)规范
