io.github.kyrylopr/lenspr

编码与调试

by kyrylopr

用代码图谱看清项目结构,帮助 AI 理解代码库,减少跨模块修改时误伤其他功能。

什么是 io.github.kyrylopr/lenspr

用代码图谱看清项目结构,帮助 AI 理解代码库,减少跨模块修改时误伤其他功能。

README

<p align="center"> <img src="assets/LensPR.png" alt="LensPR" width="200"> </p> <p align="center"><strong>Code intelligence for AI coding agents. Your AI sees dependencies before making changes.</strong></p>

Alpha (0.1.x) — works on real projects, used daily by the author. Expect rough edges.

AI assistants edit your code one file at a time. They don't see dependencies. They grep, read, guess — and break things three files away.

LensPR builds a dependency graph of your codebase and gives your AI structural understanding before it changes anything.

<!-- TODO: Add demo GIF here --> <!-- ![Demo](assets/demo.gif) -->

Quick Start

Requires Python 3.11+, macOS or Linux. For TypeScript/JS projects, also Node.js 18+.

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

Restart your IDE. Done. Your AI now has lens_* tools.

Add .lens/ to your .gitignore — the graph is local and rebuilt from source.


What It Does

"What depends on this function?"

One call returns source code, who calls it, what it calls, and related tests:

code
> 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

Without LensPR your AI makes 5-7 grep/read calls and still misses things. With LensPR — one call, full picture.

"What breaks if I change this?"

Before any modification, the AI sees the blast radius:

code
> lens_check_impact("models.User")

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

The AI warns you, changes its approach, or asks for confirmation. No more blind edits.

"How healthy is this codebase?"

code
> 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

Track whether the codebase is improving or degrading over time.

Cross-language visibility

LensPR connects frontend and backend into a single graph:

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

Also tracks: database tables, Docker services, env vars, CI/CD workflows, SQL migrations.


Works With

IDESetup
Claude Codelenspr setup . — automatic
CursorCopy .mcp.json to .cursor/mcp.json
Any MCP clientlenspr serve <path>

Languages: Python (95%+ resolution via Jedi/Pyright) and TypeScript/JavaScript (85-95% via tree-sitter + TS Compiler API).

Infrastructure: .sql files, Dockerfiles, docker-compose.yml, GitHub Actions workflows, .env files — all parsed into the same graph.

Everything runs locally. Your code never leaves your machine.


Key Features

Impact AnalysisSeverity (LOW → CRITICAL) before any change
One-Call ContextSource + callers + callees + tests in one request
Cross-LanguageFrontend HTTP → backend routes, DB tables, Docker, env vars, CI/CD
Surgical EditsTargeted find/replace within a function — no full file rewrites
Dead CodeFind unreachable functions (Django, FastAPI, Celery entry points)
Architecture RulesEnforce layer boundaries — violations warn before changes apply
Git per FunctionBlame, history, commit scope at function level
Session MemoryAI picks up where it left off across context resets
Auto-SyncFile watcher updates graph on every save
Health Score0-100 score across 6 dimensions — track quality over time

60+ tools organized in 12 groups — enable only what you need with lenspr tools.

<details> <summary>All tools by category</summary>

Navigation & Search (8): lens_context, lens_get_node, lens_search, lens_grep, lens_find_usages, lens_get_structure, lens_list_nodes, lens_get_connections

Modification (6): lens_update_node, lens_patch_node, lens_add_node, lens_delete_node, lens_rename, lens_batch

Analysis (6): lens_check_impact, lens_validate_change, lens_health, lens_dead_code, lens_dependencies, lens_diff

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

Architecture (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

Infrastructure (5): lens_api_map, lens_db_map, lens_env_map, lens_ffi_map, lens_infra_map

Testing & Tracing (3): lens_run_tests, lens_trace, lens_trace_stats

Annotations (5): lens_annotate, lens_save_annotation, lens_batch_save_annotations, lens_annotate_batch, lens_annotation_stats

Session (4): lens_session_write, lens_session_read, lens_session_handoff, lens_resume

Temporal (2): lens_hotspots, lens_node_timeline

Explanation (1): lens_explain

</details>

Known Limitations

  • Windows — not supported. macOS and Linux only.
  • self.method() calls — static parser can't fully resolve instance method dispatch. Workaround: lens_trace (Python 3.12+) resolves these at runtime.
  • Go, Rust, Java — not yet supported. Parser interface is ready for contributors.
  • Dynamic codegetattr, eval, dynamic imports can't be tracked statically.

Contributing

Try it. If it breaks, tell me.

  • Bug reports — even "this doesn't work" is helpful
  • Language parsers — Go, Rust, Java (BaseParser interface is ready)
  • Ideasopen an issue

License

MIT


Built because AI kept breaking my code.

<!-- mcp-name: io.github.kyrylopr/lenspr -->

常见问题

io.github.kyrylopr/lenspr 是什么?

用代码图谱看清项目结构,帮助 AI 理解代码库,减少跨模块修改时误伤其他功能。

相关 Skills

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描123.0k

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描123.0k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描123.0k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
84.2k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
53.3k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
46.4k

评论