Turn any codebase into searchable knowledge for AI-powered workflows.
主要特点
核心(Rust驱动-零依赖)
- 🚀 快速燃烧 -基于Rust的AI代理文件系统操作
- 📖 智能文件读取 -读取具有行范围(包括负索引)的文件
- 📁 目录列表 -递归和非递归目录遍历
- 🔍 模式搜索 -与上下文行快速模式匹配
- 🔄 批量操作 -并行处理多个操作
- 🌐 JSON输出 -用于代理集成的机器可读输出
- 💡 零依赖 -核心功能不需要外部依赖
可选RAG功能(安装时 pip install contextinator[rag])
- AST供电分块 -从23种以上的编程语言中提取函数、类和方法
- 亲子关系 -维护分层块上下文以实现完全理解
- 语义搜索 -使用自然语言查询查找相关代码
- 多种搜索模式 -语义、基于符号、模式匹配和混合搜索
- TOON格式导出 -LLM提示的令牌高效输出格式(节省40-60%的令牌)
- Docker就绪 -附带ChromaDB服务器
用例
| AI代理文件系统工具(v2核心) | RAG应用程序(可选) | 代码智能 |
|---|---|---|
| AI代理的快速文件读取 | 具有嵌入功能的高精度代码检索 | 跨存储库代码搜索和发现 |
| 目录遍历和探索 | 代码解释和文档的上下文注入 | 重复和相似代码检测 |
| 代码库中的模式匹配 | 跨存储库的语义代码搜索 | 遗留代码库分析和理解 |
| 批处理文件系统操作 | 完整上下文的父子关系跟踪 | 符合MCP的异步架构 |
______________________________________________________________________
入门指南
先决条件
- Python 3.10或更高版本
- 可选:Docker(用于ChromaDB的RAG功能)
- 可选:OpenAI API密钥(用于RAG嵌入)
安装
核心(仅限Rust驱动的工具):
pip install contextinator具有RAG功能:
pip install contextinator[rag]验证安装:
contextinator --help有关详细的设置和配置,请参阅 USAGE.md
______________________________________________________________________
快速入门-v2.0(Rust驱动)
1.读取具有行范围的文件
# Read specific line range
contextinator read --path myfile.py --mode Line --start-line 10 --end-line 50
# Read last 10 lines (negative indexing)
contextinator read --path myfile.py --mode Line --start-line -10 --end-line -1
# Read entire file
contextinator read --path myfile.py --mode Line2.列出目录内容
# Non-recursive listing
contextinator read --path src/ --mode Directory --depth 0
# Recursive listing (depth 2)
contextinator read --path src/ --mode Directory --depth 2
# JSON output for agents
contextinator read --path src/ --mode Directory --format json3.寻找模式
# Find TODOs with context
contextinator read --path . --mode Search --pattern "TODO" --context-lines 2
# Find function definitions
contextinator read --path src/ --mode Search --pattern "def " --context-lines 5
# JSON output
contextinator read --path . --mode Search --pattern "FIXME" --format json4.Python API
from contextinator import fs_read
# Read file lines
result = fs_read("file.py", mode="Line", start_line=10, end_line=50)
# List directory
result = fs_read("src/", mode="Directory", depth=2)
# Search patterns
result = fs_read(".", mode="Search", pattern="TODO", context_lines=2)______________________________________________________________________
可选:RAG功能
对于语义代码搜索和高级代码智能,请安装RAG extra:
pip install contextinator[rag]为存储库建立索引:
contextinator --rag chunk --path ./myrepo --save
contextinator --rag embed --path ./myrepo --save
contextinator --rag store-embeddings --path ./myrepo --collection-name MyRepo语义理解搜索:
# Natural language semantic search
contextinator --rag search "authentication logic" --collection MyRepo
# Find specific functions
contextinator --rag symbol authenticate_user --collection MyRepo
# Export results in TOON format for LLM consumption
contextinator --rag search "error handling" --collection MyRepo --toon results.json有关全面的CLI和RAG文档,请参阅 USAGE.md
致谢
基于令人惊叹的开源项目构建并受到其启发:
核心技术
- 锈 -用于快速性能的系统编程语言
- PyO3 -Python的Rust绑定
- 树保姆 -AST生成的增量解析系统(RAG功能)
- ChromaDB -AI原生嵌入数据库(RAG功能)
- 开放人工智能 -嵌入式生成API(RAG功能)
受启发于
- AWS Q开发人员 -具有本地文件系统操作的AI编码助手(启发了我们的fs_read方法)
- 塞雷娜 -代码智能和语义搜索
- 继续 -AI驱动的代码助手
- 虎斑猫 -自托管AI编码助手
- 语义代码搜索 -代码搜索和检索
- 帮助 -终端中的AI配对编程
- VS代码复制聊天 -用于代码的对话式人工智能
许可证
根据Apache许可证2.0版授权。看 许可证 了解详情。
TL;DR
上下文生成器是 Rust驱动的文件系统工具包 专为AI代理设计,以极快的性能高效读取文件、探索目录和搜索代码库。它提供了受AWS Q Developer方法启发的本地文件系统操作,将速度和简单性置于基于嵌入的解决方案之上。此外,它还提供了可选的RAG功能,使用抽象语法树(AST)解析来提取语义代码块,生成嵌入,并启用高级代码智能以实现更深入的代码库理解。
星迹

