BearWisdom
Structural code intelligence that's un-bear-ably fast.
31 languages. Cross-framework graph. Hybrid search. One index.
Features · Quick Start · Web Explorer · CLI Reference · Architecture · MCP Server · Benchmarks
______________________________________________________________________
这是什么?
熊智慧是 代码智能引擎 它构建了对整个代码库的结构理解——符号、边、调用层次结构、概念和跨语言流——并使其在毫秒内可搜索。
它通过以下方式解析您的代码 树保姆,将所有内容存储在本地SQLite图形数据库中,并通过CLI、MCP服务器、web UI和Claude Code代理公开结果。把它想象成一只熊,它和你的代码库一起冬眠,醒来时知道一切都在哪里。
为什么是“熊智慧”? 因为理解代码不需要 *灰熊* 努力让熊来抬重物。
特性
熊的必需品
- 31种语言 --C#、TypeScript、JavaScript、Python、Rust、Go、Java、C/C++、Ruby、PHP、Kotlin、Swift、Scala、Haskell、Elixir、Dart、Lua、R、HTML、CSS、JSON、YAML、Bash、SQL、Markdown、XML、Dockerfile等
- 结构图 --存储在SQLite中的符号、边(调用、继承、实现、type_ref、实例化)、概念和注释
- 5优先级分解器 --命名空间导入、范围分析、限定名匹配、文件路径关联和基于类型的推理
- 跨框架连接器 --Spring Boot,Django。NET DI、EF Core、gRPC、GraphQL、Electron IPC、Tauri IPC、React/Zustand和HTTP API路由
- 智能上下文 --用自然语言描述任务,并获取与之最相关的排名符号和文件,为LLM上下文窗口做好准备
- 完整跟踪 --端到端执行流跟踪,从任何符号或自动检测的入口点遍历调用图和跨框架流边缘(DI、HTTP、事件)
- 流动可视化 --web资源管理器中的Sankey图显示了具有点击到引脚突出显示、深度控制和特定符号跟踪的架构流
难以置信的搜索
- FTS5符号搜索 --BM25对所有符号名称和限定名称的全文搜索进行了排名
- 模糊查找器 --文件(Ctrl+P)和符号(Ctrl+T)的核动力模糊匹配
- 内容搜索 --FTS5三元组索引,用于跨文件内容的子字符串搜索
- grep --具有范围过滤的gitignore感知正则表达式/文字搜索
- 混合搜索 --通过互易秩融合融合FTS5+ONNX矢量嵌入
- 语义搜索 --通过CodeRankEmbed嵌入进行自然语言查询
极化分析
- 架构概述 --语言分解、热点检测、入口点发现
- 爆炸半径 --“如果我更改X,什么会中断?”通过递归CTE图遍历
- 调用层次结构 --具有边缘来源的呼入和呼出呼叫链
- 完整跟踪 --从入口点到调用链和跨框架流边缘(DI、HTTP、事件、IPC)的端到端执行跟踪
- 智能上下文 --LLM上下文窗口的排序符号的自然语言任务描述(多策略种子:FTS5原始、按关键字、LIKE回退)
- 概念发现 --带成员分配的自动命名空间分组
- 子图导出 --D3/Cytoscape可视化的过滤图导出
互动方式
| 接口 | 说明 |
|---|---|
bw 命令行界面 | 30多个用于脚本和代理的JSON输出命令 |
| Web资源管理器 | 基于Sankey流程图的React+D3力导向知识图 |
| MCP 服务器 | Claude和其他LLM的模型上下文协议服务器 |
| 克劳德代码代理 | 包装CLI的会话子代理 |
快速开始
先决条件
- 锈 1.75+(2021年版)
- Node.js 18+(适用于网络浏览器,可选)
- ONNX 运行时 (AI搜索/语义嵌入所需)
- 通过Python安装: pip install onnxruntime 并设置 ORT_DYLIB_PATH 到 onnxruntime 该软件包内的共享库,或从下载独立版本 和点 ORT_DYLIB_PATH 在 onnxruntime.dll / libonnxruntime.so / libonnxruntime.dylib - 没有 ORT_DYLIB_PATH 发动机正常启动,但 bw hybrid, bw embed,web UI中的AI搜索将返回错误
构建
# Clone the repo
git clone https://github.com/MariusAlbu/BearWisdom.git
cd BearWisdom
# Build all crates
cargo build --release
# The CLI binary is at:
./target/release/bw --help为项目建立索引
# Full index with concept discovery + automatic embedding (if ORT_DYLIB_PATH is set)
bw open /path/to/your/project
# Check index stats
bw status /path/to/your/project索引存储在 /.bearwisdom/index.db --一个SQLite文件。添加 .bearwisdom/ 到你的项目 .gitignore.
对于AI搜索, bw open 在索引后自动计算CodeRankEmbed嵌入 ORT_DYLIB_PATH 已设置。您还可以独立运行嵌入:
# Download the CodeRankEmbed model first (one time)
# Place it at
/models/CodeRankEmbed OR ~/.bearwisdom/models/CodeRankEmbed
# Compute embeddings independently
bw embed /path/to/your/project搜索
# Find symbols by name
bw search-symbols /path/to/project "ProductService"
# Fuzzy find files (like Ctrl+P)
bw fuzzy-files /path/to/project "ProdServ"
# Fuzzy find symbols (like Ctrl+T) — yes, it's *fuzzy*, like a bear
bw fuzzy-symbols /path/to/project "GetById"
# Grep across files
bw grep /path/to/project "TODO" --case-insensitive
# Content search (trigram, min 3 chars)
bw search-content /path/to/project "repository"
# Hybrid search (FTS + embeddings when model is available)
bw hybrid /path/to/project "authentication middleware"导航
# Go to definition
bw definition /path/to/project "ProductService"
# Find all references
bw references /path/to/project "IProductRepository"
# List symbols in a file
bw file-symbols /path/to/project "Services/ProductService.cs"
# Full symbol detail
bw symbol-info /path/to/project "ProductService"分析
# Architecture overview
bw architecture /path/to/project
# Blast radius — what breaks if I change this?
bw blast-radius /path/to/project "Product" --depth 3
# Who calls this?
bw calls-in /path/to/project "GetById"
# What does this call?
bw calls-out /path/to/project "PlaceOrder"
# Cross-language flow trace
bw trace-flow /path/to/project "Controllers/OrderController.cs" 45概念
# Discover namespace concepts automatically
bw discover-concepts /path/to/project
# List concepts
bw concepts /path/to/project
# Show concept members
bw concept-members /path/to/project "MyApp.Services"
# Export graph filtered by concept
bw export-graph /path/to/project --filter "@MyApp.Services"Web资源管理器
BearWisdom包括一个基于网络的知识图谱浏览器。这是一个React+D3应用程序,可以让你直观地探索结构图。
跑
# Build the frontend (one time)
cd web && npm install && npm run build && cd ..
# Start the server
cargo run -p bearwisdom-web --release -- --static-dir web/dist
# Open http://localhost:3030你能做什么
- 浏览 您的文件系统,并选择一个项目进行索引
- 探索 力导向知识图——拖动、缩放、平移、悬停以突出显示连接
- 按概念筛选 --单击侧边栏中的概念以隔离该子图
- 搜索6种方式 --符号、模糊、文件、内容、Grep和AI搜索选项卡
- 启用AI搜索 --web UI有一个“启用AI搜索”按钮,可按需触发嵌入计算(需要
ORT_DYLIB_PATH在服务器环境中设置) - 检查符号 --单击节点以查看其签名、文档、传入/传出呼叫
- 查看源代码 --file/content/grep结果打开一个带有行突出显示的完整代码查看器
- 调整细节面板的大小 --拖动左边缘为代码审查腾出空间
- “流”选项卡 --Sankey图显示了跨代码库的端到端执行流。从特定符号或自动检测的入口点进行跟踪。单击节点以固定路径,悬停以探索连接。深度滑块控制轨迹深度。节点颜色表示符号类型(类、方法、接口)
发展
# Backend (auto-rebuilds on change)
cargo run -p bearwisdom-web -- --port 3030
# Frontend dev server (hot reload, proxies /api to :3030)
cd web && npm run dev
# Open http://localhost:5173CLI参考
所有命令都将JSON输出到stdout。信封: {"ok": true, "data": {...}} 或 {"ok": false, "error": "..."}.
全球标志: --full 恢复详细输出(签名、文档注释、子项)。
| 命令 | 描述 |
|---|---|
| `bw open | |
| ` | 全索引+概念发现+后索引嵌入 |
| `bw status | |
| ` | 索引统计数据(只读) |
| `bw embed | |
| ` | 独立计算CodeRankEmbed嵌入 |
| `bw architecture | |
| ` | 语言统计、热点、入口点 |
| `bw search-symbols | |
| ` | FTS5符号搜索 |
| `bw fuzzy-files |
|模糊文件查找器| | bw fuzzy-symbols
|模糊符号查找器| | bw search-content |FTS5三元组内容搜索| | bw grep
|正则表达式/文字grep| | bw hybrid |混合FTS+矢量搜索| | bw definition |转到定义| | bw references |查找所有参考文献| | bw file-symbols |文件中的符号| | bw symbol-info |完整的符号细节| | bw blast-radius |影响分析| | bw calls-in |来电层次结构| | bw calls-out |呼出层次结构| | bw trace-flow
|跨语言流| | bw full-trace [symbol] |端到端执行跟踪(调用图+流边)| | bw smart-context |LLM提示的智能上下文选择| | bw investigate |组合深潜(符号信息+呼叫者+被呼叫者+爆炸半径)| | bw complete-at
|范围感知符号完成| | bw diagnostics |文件诊断(未解析的引用、低置信度边)| | bw quality-check --baseline |根据质量基线进行回归测试| | bw import-scip --scip |导入SCIP指数以获得高置信度边缘| | bw concepts |列出概念| | bw discover-concepts |自动发现概念| | bw concept-members |概念成员| | bw export-graph ` |图形导出(JSON)|
建筑
看 架构图 以获得视觉概述。
bearwisdom/ Core library — parser, indexer, query, search, bridge
src/
parser/ Tree-sitter extractors (31 languages)
indexer/ Full + incremental indexing
query/ Architecture, blast radius, call hierarchy, full trace,
smart context, investigate, diagnostics, completion,
concepts, search, subgraph, definitions
search/ Grep, FTS5, fuzzy, hybrid, embeddings, vector store
bridge/ SCIP import, background enrichment
connectors/ Cross-framework edge detection (Spring, Django, EF Core, etc.)
db/ SQLite schema, database management
bearwisdom-cli/ CLI binary (bw) — 30+ JSON commands
bearwisdom-mcp/ MCP server (bw-mcp) — tool registration
bearwisdom-web/ Web server (bw-web) — Axum HTTP + static files + Sankey flows
bearwisdom-profile/ Language detection, project scanning
bearwisdom-bench/ Benchmark harness
benchmarks/ LLM benchmark runner (bw-bench) — API-based task evaluation
web/ React + D3 frontend (Vite + TypeScript)
tests/ Integration test suite
agents/ Claude Code agent definitions捆绑依赖关系
sqlite-vc 静态链接到BearWisdom二进制文件中。不 SQLITE_VEC_PATH 环境变量或外部 .dll/.so 需要——矢量搜索开箱即用。
ONNX 运行时 在运行时通过以下方式动态加载 load-dynamic 功能。集 ORT_DYLIB_PATH 在运行任何嵌入命令之前,请先访问共享库的路径。sqlite-vc处理存储;ONNX运行时处理推理。
数据库模式
SQLite数据库存储:
| 表 | 目的 |
|---|---|
files | 带有路径、语言、内容哈希和时间戳的索引文件 |
symbols | 提取的符号(名称、限定名、种类、线条、签名、文件注释) |
edges | 有信心的定向关系(调用、继承、实现、type_ref、实例化) |
unresolved_refs | 待LSP/SCIP决议的参考文献 |
imports | 每个文件导入/使用指令,由5优先级解析器使用 |
routes | 框架连接器提取的HTTP路由端点 |
db_mappings | EF核心实体到表的映射 |
symbols_fts | 用于BM25排名符号搜索的FTS5虚拟表 |
annotations | 符号上附有自由形式的标记注释 |
concepts | 使用auto_pattern进行成员资格匹配的命名空间分组 |
concept_members | 符号到概念的分配(手动和自动) |
lsp_edge_meta | LSP解析边缘来源 |
fts_content | 用于文件内容搜索的FTS5三元组虚拟表 |
code_chunks | AST感知块与符号边界对齐,用于嵌入 |
flow_edges | 跨语言流边缘(TS→C#、gRPC客户端→服务器等) |
search_history | 最近和已保存的搜索,包括查询类型和范围 |
MCP 服务器
BearWisdom提供了一个MCP(模型上下文协议)服务器,该服务器将所有功能作为Claude Code和其他LLM代理的工具公开。服务器在启动时在后台对项目进行索引,并使所有查询工具立即可用。
设置
# Build the MCP server (release recommended — it runs as a long-lived process)
cargo build --release -p bearwisdom-mcp
# Register it for a specific project
./target/release/bw-mcp register --project /path/to/your/project这写了一个 bearwisdom 进入 /.mcp.json下次在该项目目录中打开Claude Code时,MCP服务器会自动启动。
手动使用
# Run standalone (indexes current directory by default)
./target/release/bw-mcp
# Run for a specific project
./target/release/bw-mcp --project /path/to/your/project
# Unregister from a project
./target/release/bw-mcp unregister --project /path/to/your/project服务器使用JSON-RPC(MCP协议)通过stdio进行通信。启动时,它会在后台运行一个完整的索引——索引期间的工具调用会短暂阻塞,直到当前批处理完成。
克劳德代码代理
这 agents/bearwisdom.md agent允许您通过对话方式查询任何代码库:
> /bearwisdom
You: What's the architecture of this project?
Bear: Running bw architecture... [shows language stats, hotspots, entry points]
You: Who calls ProductService?
Bear: Running bw calls-in ProductService... [shows call hierarchy]
You: What would break if I change the Order model?
Bear: Running bw blast-radius Order --depth 3... [shows impact analysis]项目结构
| 板条箱 | 类型 | 描述 |
|---|---|---|
bearwisdom | lib | 核心引擎——31语言解析器、图形数据库、混合搜索 |
bearwisdom-cli | 垃圾箱(bw) | 具有30多个JSON命令的CLI |
bearwisdom-mcp | 垃圾箱(bw-mcp) | LLM代理的MCP服务器 |
bearwisdom-web | 垃圾箱(bw-web) | Axum HTTP服务器+React UI |
bearwisdom-profile | lib | 语言检测、项目扫描 |
bearwisdom-bench | bin | 指数基准 |
bw-bench | bin | LLM基准运行器(in benchmarks/) |
基准测试
BearWisdom包括一个基准线束(bw-bench)其比较了三种条件下的代码智能质量:
- 主控程序:通过MCP协议的BearWisdom工具
- 命令行界面:BearWisdom工具通过
bwCLI命令 - 本土的:仅限标准读取/Grep/Glob工具
在4个项目(eShop、SimplCommerce、go-gitea、react-calcom)中进行了测试,每个项目有10个任务,涵盖6个类别:符号查找、跨文件引用、调用层次结构、影响分析、架构概述和代码导航。
# Generate tasks from a test project
bw-bench generate --project /path/to/project --output bench-results/tasks.json
# Run benchmarks (all conditions)
bw-bench run --tasks bench-results/tasks.json --model claude-sonnet-4-6 --output bench-results/
# Generate report
bw-bench report --results bench-results/
# Full pipeline (generate + run + report)
bw-bench full --project /path/to/project --model claude-sonnet-4-6 --output bench-results/度量:精确度、召回率、F1、效率(惩罚工具调用计数)、令牌使用。需要 ANTHROPIC_API_KEY.
许可证
MIT许可证。看 许可证-麻省理工学院 了解详情。
______________________________________________________________________
Built with the patience of a bear and the precision of tree-sitter.
May your searches always be fuzzy in the right way. 🐻
