Skip to main content
Glama

Alpha (0.1.x) — 可在真实项目上运行,作者每天使用。可能存在粗糙之处。

AI 助手每次只编辑一个文件。它们看不到依赖关系。它们 grep、阅读、猜测——然后弄坏三个文件之外的东西。

LensPR 为你的代码库构建依赖图,并在你的 AI 做出任何更改之前赋予它结构性的理解。

快速开始

需要 Python 3.11+macOS 或 Linux。对于 TypeScript/JS 项目,还需要 Node.js 18+

pip install 'lenspr[all]'
lenspr init .
lenspr setup .

重启你的 IDE。完成。你的 AI 现在拥有 lens_* 工具。

.lens/ 添加到你的 .gitignore — 依赖图是本地生成的,并从源码重建。


它能做什么

“什么依赖这个函数?”

一次调用即可返回源代码、谁调用了它、它调用了什么,以及相关测试:

> lens_context("auth.login_handler")

source: 42 lines
callers: auth_routes.create_routes, test_auth.test_login_success
callees: db.get_user, crypto.verify_password, jwt.create_token
tests: test_login_success, test_login_wrong_password

没有 LensPR,你的 AI 需要发出 5-7 次 grep/read 调用,仍然会漏掉东西。有了 LensPR — 一次调用,完整图景。

“如果我更改这个,会破坏什么?”

在任何修改之前,AI 就能看到影响范围:

> lens_check_impact("models.User")

severity: CRITICAL
direct_dependents: 15
indirect_dependents: 23
affected_modules: auth, payments, notifications
tests_covering: 3

AI 会提醒你、改变方案,或请求确认。不再有盲目的编辑。

“这个代码库的健康状况如何?”

> lens_vibecheck()

score: 86/100 (B)
  test_coverage:    17/25 — 67% functions tested
  dead_code:        20/20 — 0% dead code
  circular_imports: 15/15 — 0 cycles
  architecture:     12/15 — 1 violation
  documentation:     8/10 — 81% documented
  graph_confidence: 14/15 — 94% edges resolved

跟踪代码库随时间是在改进还是退化。

跨语言可见性

LensPR 将前端和后端连接成一个统一的图:

LoginModal.tsx → fetch("/api/auth/login")
                        ↓ CALLS_API
Backend:  @router.post("/login") → login_handler()
            → db.query(User)        [reads: users]
            → verify_password()
            → create_jwt_token()

同时还跟踪:数据库表、Docker 服务、环境变量、CI/CD 工作流、SQL 迁移。


兼容

IDE

设置

Claude Code

lenspr setup . — 自动

Cursor

.mcp.json 复制到 .cursor/mcp.json

任何 MCP 客户端

lenspr serve <path>

语言: Python(通过 Jedi/Pyright 解析率 95%+)和 TypeScript/JavaScript(通过 tree-sitter + TS Compiler API 解析率 85-95%)。

基础设施: .sql 文件、Dockerfile、docker-compose.yml、GitHub Actions 工作流、.env 文件 — 全部解析到同一个图中。

一切都在本地运行。你的代码永远不会离开你的机器。


主要特性

影响分析

任何更改前的严重性(低 → 严重)

单次调用上下文

一次请求中获取源码 + 调用者 + 被调用者 + 测试

跨语言

前端 HTTP → 后端路由、数据库表、Docker、环境变量、CI/CD

精准编辑

函数内的精准查找/替换 — 无需重写整个文件

死代码

查找不可达的函数(Django、FastAPI、Celery 入口)

架构规则

强制执行分层边界 — 违规会在更改生效前发出警告

函数级 Git

函数级别的 Blame、历史、提交范围

会话记忆

AI 在上下文重置后从上次中断的地方继续

自动同步

文件监视器在每次保存时更新图

健康评分

6 个维度的 0-100 分 — 跟踪随时间变化的质量

60+ 工具分为 12 组 — 通过 lenspr tools 只启用你需要的。

导航与搜索 (8): lens_context, lens_get_node, lens_search, lens_grep, lens_find_usages, lens_get_structure, lens_list_nodes, lens_get_connections

修改 (6): lens_update_node, lens_patch_node, lens_add_node, lens_delete_node, lens_rename, lens_batch

分析 (6): lens_check_impact, lens_validate_change, lens_health, lens_dead_code, lens_dependencies, lens_diff

质量 (7): lens_vibecheck, lens_nfr_check, lens_test_coverage, lens_security_scan, lens_dep_audit, lens_fix_plan, lens_generate_test_skeleton

架构 (9): lens_arch_rule_add, lens_arch_rule_list, lens_arch_rule_delete, lens_arch_check, lens_class_metrics, lens_project_metrics, lens_largest_classes, lens_compare_classes, lens_components

Git (4): lens_blame, lens_node_history, lens_commit_scope, lens_recent_changes

基础设施 (5): lens_api_map, lens_db_map, lens_env_map, lens_ffi_map, lens_infra_map

测试与追踪 (3): lens_run_tests, lens_trace, lens_trace_stats

注解 (5): lens_annotate, lens_save_annotation, lens_batch_save_annotations, lens_annotate_batch, lens_annotation_stats

会话 (4): lens_session_write, lens_session_read, lens_session_handoff, lens_resume

时序 (2): lens_hotspots, lens_node_timeline

解释 (1): lens_explain


已知限制

  • Windows — 不支持。仅支持 macOS 和 Linux。

  • self.method() 调用 — 静态解析器无法完全解析实例方法分派。解决办法:lens_trace(Python 3.12+)在运行时解析这些调用。

  • Go、Rust、Java — 尚不支持。解析器接口已为贡献者准备好。

  • 动态代码getattreval、动态导入无法被静态跟踪。


贡献

试试看。如果出问题,请告诉我。

  • Bug 报告 — 即使只是“这个不管用”也有帮助

  • 语言解析器 — Go、Rust、Java(BaseParser 接口已就绪)

  • 想法打开一个 issue

许可证

MIT


构建这个项目,是因为 AI 总在破坏我的代码。

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
0dRelease cycle
2Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Hosted MCP server for structured code review passes on human- and AI-written code. Free tier.

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

  • An MCP server that gives your AI access to the source code and docs of all public github repos

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kyrylopr/lenspr'

If you have feedback or need assistance with the MCP directory API, please join our Discord server