flytohub/flyto-indexer

GitHub: flytohub/flyto-indexer

基于 AST 的代码智能索引 MCP 服务器,解决变更前的依赖影响与安全审计问题。

Stars: 4 | Forks: 0

Flyto Indexer

Know what breaks before you change it.

CI PyPI License Python 3.10+

MCP server that gives AI assistants impact analysis, cross-project reference tracking, and code health scoring.
Zero dependencies. Pure Python. 100% local.

flyto2.com · Documentation · YouTube

## 无需 Flyto 索引器 ``` You: "Rename validateOrder to validate_order" AI: *renames the function* *greps for "validateOrder"* *finds 3 matches in the same project* *misses 4 callers in the frontend repo* *misses the API endpoint that routes to it* *pushes broken code* ``` ## 使用 Flyto 索引器 ``` You: "Rename validateOrder to validate_order" AI: → impact(target="validateOrder", change_type="rename") ⚠️ 7 call sites across 3 projects: backend/checkout.py:42 — calls validateOrder() backend/api/orders.py:18 — imports validateOrder frontend/Cart.vue:55 — calls via useCheckout() frontend/QuickBuy.vue:23 — calls via useCheckout() mobile/OrderScreen.tsx:67 — API call to /api/validate tests/test_orders.py:12 — unit test tests/test_api.py:88 — integration test Risk: HIGH — 3 projects affected Test file: tests/test_orders.py Cross-project: 2 other repos affected *renames all 7 call sites, updates tests, pushes clean code* ``` **这就是区别。** grep 查找文本。这个查找依赖关系。
Flyto Indexer — impact analysis before renaming
## 安装 ``` pip install flyto-indexer flyto-index setup . ``` 仅此而已。一条命令完成所有操作: 1. **扫描** 项目并构建代码索引 2. **写入** `CLAUDE.md`,包含工具使用说明 3. **配置** Claude Code MCP 设置(`~/.claude/settings.json`) 重启 Claude Code 即可开始使用。适用于任何 MCP 客户端——Claude Code、Cursor、Windsurf 等。
手动设置(其他 MCP 客户端) 如果你的 MCP 客户端不使用 `~/.claude/settings.json`,请将以下内容添加到 MCP 配置中: ``` { "mcpServers": { "flyto-indexer": { "command": "python3", "args": ["-m", "flyto_indexer.mcp_server"] } } } ``` 然后单独扫描并设置 CLAUDE.md: ``` flyto-index scan . flyto-index setup-claude . ```
从源码运行 ``` git clone https://github.com/flytohub/flyto-indexer.git cd flyto-indexer && pip install -e . flyto-index setup . ```
卸载 ``` flyto-index setup . --remove pip uninstall flyto-indexer ```
## 功能 ### 影响分析——核心功能 AI 已具备的所有工具(grep、文件读取、通配符)只能查找**文本**。它们无法回答“**谁依赖于此?**”。 一次调用即可获取全部信息——引用、波及范围、跨项目影响以及测试文件: ``` → impact(target="useAuth") References: 12 across 4 projects flyto-cloud: LoginPage.vue, RegisterPage.vue, AuthGuard.ts, api.ts flyto-pro: vscode_agent/tools.py, middleware/auth.py flyto-vscode: ChatHandler.ts, AuthProvider.ts flyto-core: modules/auth/login.py Risk: HIGH — shared across 4 projects Cross-project: 3 other repos affected Test file: tests/test_auth.py ``` 即使在未提交的更改中也有效: ``` → impact(mode="unstaged") 3 symbols affected by your changes: validate_order — 5 callers, test: tests/test_orders.py OrderSchema — used in 2 API endpoints format_receipt — no callers (safe) ``` ### 跨语言 API 追踪 Python 后端端点会自动关联到 TypeScript/Vue 前端调用者: ``` → structure(focus="apis") POST /api/checkout Defined in: backend/routes/order.py (create_order) Called by: frontend/Cart.vue, frontend/api/orders.ts Call count: 4 ``` 可检测 FastAPI、Flask、Starlette 装饰器以及 `fetch()`、`axios`、`$http` 调用。 ### 代码健康与安全 一次调用即可审计整个项目——自动扩展薄弱维度并提供详细发现: ``` → audit() Health: 74/100 (C) ⚠️ Security (60/100) — auto-expanded: 2 critical: hardcoded API keys in config.py, settings.py 1 high: SQL string concatenation in query.py ⚠️ Complexity (65/100) — auto-expanded: process_data() — 87 lines, depth=6 → extract sub-functions ✓ Dead code (90/100) — passing ✓ Documentation (85/100) — passing Git hotspots: order.py (42 commits, complexity=8.5) Refactoring suggestions: [high] process_data() → extract sub-functions [medium] dead_fn() — unreferenced, 45 lines → safe to remove ``` ### 污点分析——追踪数据流,而不仅是模式 基于 AST 的引擎,可追踪未信任数据从源头到危险汇的流动。与正则表达式匹配不同,它能跟随变量在赋值、f 字符串和函数调用中的传播,并具备净化感知能力以消除误报。 - **Python**:完整 AST 分析——追踪赋值、f 字符串、连接、for 循环中的污点 - **跨函数**:检测当污点数据作为参数传递给具有危险汇的函数时的情况 - **JS/TS/Go**:对常见污点模式使用正则表达式作为后备 - **净化感知**:`int()`、`html.escape()`、`shlex.quote()`、参数化查询均可阻断污点链 - **自定义规则**:通过 `taint_rules.yaml` 添加项目特定的源、汇与净化器 ### 项目规则——AI 从你的修正中学习 `.flyto-rules.yaml`——结构化、可版本化的项目约定,由审计工具自动强制执行。 ``` # .flyto-rules.yaml architecture: - rule: "i18n files must be in flyto-i18n/" glob_deny: ["flyto-cloud/**/*.locale.json"] style: - rule: "Frontend does no data processing" grep_deny: [{ pattern: '\breduce\s*\(', glob: "*.vue" }] conventions: - rule: "Commit messages in English" ``` 当你修正 AI(“不要将 i18n 文件放在那里”)时,它会自动写入一条可验证的规则——这样错误就永远不会再次发生,无论对任何 AI 或任何工具: ``` User corrects AI → add_rule() writes .flyto-rules.yaml → audit checks compliance ``` - `glob_deny` —— 位于错误位置的文件 - `grep_deny` —— 特定文件类型中的禁止代码模式 - `conventions` —— 纯文本指导(不自动检查) - 规则会随时间累积——无需预先配置 ### 任务分析——编码前先规划 在 6 个维度上评估风险并生成执行计划: ``` → task(action="plan", description="Rename validateOrder to validate_order", intent="refactor") Dimensions: blast_radius: HIGH (8.0) — 7 callers across 3 projects breaking_risk: HIGH (7.0) — public API, used by external consumers test_risk: MEDIUM (5.0) — 2/7 callers have test coverage cross_coupling: HIGH (8.0) — referenced in 3 projects complexity: LOW (2.0) — straightforward rename rollback_difficulty: MEDIUM (5.0) — multi-project change Execution Plan: 1. scope_callers → find_references("validateOrder") 2. verify_test_coverage → find_test_file("checkout.py") 3. check_cross_project → cross_project_impact("validateOrder") 4. ⛔ gate_before_plan → task_gate_check(phase="plan") 5. preview_changes → edit_impact_preview("validateOrder", "rename") 6. ⛔ gate_before_apply → task_gate_check(phase="apply") ``` 每个步骤都包含预填充的参数——AI 遵循数据结构而非提示词。 服务端强制执行会阻止跳过关键步骤。 ## 工具 5 个智能工具。每个工具都会自动丰富结果相关数据——无需在数十个细粒度工具之间做选择。 | 工具 | 回答内容 | 自动丰富 | |------|----------|----------| | `search` | “按名称或描述查找代码” | 合并 BM25 与语义搜索,附加调用者和文件上下文 | | `impact` | “如果修改此内容会有什么影响?” | 引用 + 波及范围 + 跨项目 + 测试文件,一次调用完成 | | `audit` | “项目健康度如何?” | 健康评分(0-100),自动扩展薄弱维度,污点分析,规则合规性 | | `task` | “规划、门槛检查或验证变更” | 风险评分、执行计划、Linter + 测试 | | `structure` | “展示项目结构” | 项目、API、依赖、类型契约 |
每个工具替代了哪些功能 **`search`** 替代:`search_code`、`semantic_search`、`fulltext_search`、`get_file_info`、`get_file_symbols`、`get_symbol_content`、`get_file_context` **`impact`** 替代:`find_references`、`impact_analysis`、`batch_impact_analysis`、`edit_impact_preview`、`cross_project_impact`、`impact_from_diff` **`audit`** 替代:`code_health_score`、`security_scan`、`taint_analysis`、`rules_check`、`find_dead_code`、`find_complex_functions`、`find_duplicates`、`suggest_refactoring`、`find_stale_files`、`find_todos`、`coverage_gaps` **`task`** 替代:`analyze_task`、`task_gate_check`、`validate_changes` **`structure`** 替代:`list_projects`、`list_apis`、`list_categories`、`dependency_graph`、`check_api_contracts`、`contract_drift`、`extract_type_schema` 所有旧版工具在调度器中仍保留以保持向后兼容,并可用于执行计划步骤。
## 支持语言 | 语言 | 解析器 | 提取内容 | |------|--------|----------| | Python | AST | 函数、类、方法、装饰器、API 路由 | | TypeScript/JS | 自定义 | 函数、类、接口、类型、API 调用 | | Vue | SFC | 组件、组合式函数、事件、属性 | | Go | 自定义 | 函数、结构体、方法、接口、嵌入、类型别名、常量/变量、实现追踪 | | Rust | 自定义 | 函数、结构体、实现块、特征 | | Java | 自定义 | 类、方法、接口、注解 | ## 工作原理 ``` flyto-index scan . ``` 1. **解析**——AST(Python)或正则表达式(其他语言)提取每个函数、类和导入 2. **构建图**——建立依赖图与反向索引(调用者 → 被调用者) 3. **服务**——MCP 服务器在内存中回答图查询 4. **增量更新**——仅重新扫描变更文件,增量修补反向索引和 BM25(比全量重建快 10–50 倍) 5. **LSP**——通过 pyright/tsserver/gopls/rust-analyzer 提供可选类型感知引用(零依赖,优雅降级) ``` .flyto-index/ ├── index.json # Symbols + dependency graph + reverse index ├── content.jsonl # Source code (lazy-loaded) ├── bm25.json # BM25 keyword search index ├── semantic.json # TF-IDF + learned ConceptGraph (v2.2+) └── manifest.json # Change tracking ``` ## CI:阻止高风险变更 ``` # 如果更改影响太多调用点,则 PR 失败 - run: pip install flyto-indexer - run: flyto-index scan . - run: flyto-index check . --threshold medium --base main ``` ## CLI ``` flyto-index setup . # One command: scan + CLAUDE.md + MCP config flyto-index scan . # Index (or re-index) flyto-index impact useAuth --path . # Impact analysis flyto-index check . --threshold medium # CI gate flyto-index demo . # 30-second demo flyto-index install-hook . # Auto-reindex on commit flyto-index setup . --remove # Uninstall ``` ## 隐私 100% 本地化。不发送任何代码到外部。删除 `.flyto-index/` 可彻底清理。 ## 限制 - 仅静态分析——无法追踪动态导入与元编程 - 无类型推断——复杂的 TypeScript 泛型会被简化 - 跨项目追踪需要将所有项目一起建立索引 ## 许可证 [MIT](LICENSE)
标签:AI 编程助手, Claude Code, Cursor, JS文件枚举, MCP Server, PyPI, Python 3.10+, SEO: AI 编程助手, SEO: 代码智能分析, SEO: 依赖图谱, SEO: 影响分析, Windsurf, 代码健康评分, 代码导航, 代码智能, 代码重构, 依赖图, 可视化界面, 威胁情报, 开发者工具, 开源, 影响分析, 数据可视化, 日志审计, 本地分析, 纯Python, 语义搜索, 跨项目引用追踪, 逆向工具, 零依赖