rhi-zone/normalize

GitHub: rhi-zone/normalize

一款基于 AST 分析的多语言结构化代码智能 CLI 工具,为人类和 AI 代理提供代码导航、质量分析、安全扫描、依赖审计和结构化编辑等统一能力。

Stars: 3 | Forks: 0

# 规范化 快速代码智能 CLI。通过基于 AST 的分析实现对代码库的结构感知。 ## 安装 ``` # 从源代码 cargo install --path crates/normalize # 或本地构建 cargo build --release ./target/release/normalize --help # 使用 Nix nix develop cargo build --release ``` ## 快速开始 ``` # 查看项目结构 normalize view # 查看特定文件的符号 normalize view src/main.rs # 查看特定符号 normalize view src/main.rs/main # 分析代码库健康状况 normalize analyze health # 搜索文本模式 normalize grep "TODO" # 运行 linters normalize tools lint ``` ## 命令 ### view - 导航代码结构 将目录、文件和符号作为统一的树状结构查看: ``` normalize view # Current directory tree normalize view src/ # Specific directory normalize view src/main.rs # File with symbols normalize view src/main.rs/MyClass # Specific symbol normalize view src/main.rs -d 2 # Depth 2 (show nested symbols) normalize view --full src/foo.rs/bar # Full source code of symbol normalize view --deps src/foo.rs # Show imports/exports normalize view --focus src/foo.rs # Resolve and show imported symbols ``` ### analyze - 代码库分析 带有子命令的统一分析: ``` normalize analyze health # Codebase metrics and health score normalize analyze complexity # Cyclomatic complexity report normalize analyze length # Function length analysis normalize analyze security # Security vulnerability scan normalize analyze hotspots # Git history analysis (churn + complexity) normalize analyze duplicates # Detect code clones normalize analyze duplicate-types # Detect duplicate type definitions normalize analyze graph # Dependency graph analysis normalize analyze docs # Documentation coverage ``` ### tools - Linter 和测试运行器 统一的 linter、格式化工具和类型检查器接口: ``` normalize tools lint # Auto-detect and run relevant tools normalize tools lint --fix # Auto-fix where possible normalize tools lint --sarif # Output in SARIF format normalize tools lint --category type # Only type checkers normalize tools lint --tools ruff,clippy # Specific tools normalize tools lint --list # List available tools normalize tools test # Run native test runners ``` 支持的工具:ruff、clippy、rustfmt、oxlint、biome、prettier、tsc、mypy、pyright、eslint、gofmt、go-vet、deno-check 等。 ### grep - 搜索代码 基于 ripgrep 的快速搜索: ``` normalize grep "pattern" # Search all files normalize grep "TODO" --only "*.rs" # Filter by extension normalize grep "fn main" -i # Case insensitive normalize grep "error" --limit 50 # Limit results ``` ### package - 包管理 查询包注册表并分析依赖项: ``` normalize package info tokio # Package info from registry normalize package list # List project dependencies normalize package tree # Dependency tree normalize package outdated # Check for updates normalize package why tokio # Why is this dependency included? normalize package audit # Security vulnerability scan ``` 支持:Cargo、npm、pip、Go modules、Bundler、Composer、Hex、Maven、NuGet、Nix、Conan。 ### serve - 服务器模式 将 Normalize 作为服务器运行以进行集成: ``` normalize serve mcp # MCP server for LLM tools (stdio) normalize serve http --port 8080 # REST API server normalize serve lsp # LSP server for IDEs ``` ### edit - 结构化代码修改 通过定位符号来结构化地编辑代码: ``` normalize edit src/main.rs/old_fn delete # Delete a symbol normalize edit src/main.rs/Foo replace < new.rs # Replace symbol content normalize edit src/main.rs/bar insert --after # Insert after symbol normalize edit undo # Undo last edit normalize edit delete --dry-run src/main.rs/Foo # Preview without applying ``` ### edit history - Shadow Git 编辑历史 查看结构化编辑的历史记录: ``` normalize edit history # Recent edit history normalize edit undo # Undo last edit normalize edit redo # Redo last undone edit normalize edit goto # Jump to a shadow commit ``` ### context - 目录上下文 显示分层的 `.context.md` 文件: ``` normalize context # Context for current directory normalize context src/ # Context for specific path normalize context --list # Show file paths only ``` ### rules - 分析规则 管理和运行语法+事实规则: ``` normalize rules list # List all rules normalize rules run # Run all rules normalize rules setup # Interactive rule configuration normalize rules add # Add a rule from URL normalize rules enable # Enable a rule normalize rules tags # List rule tags ``` ### translate - 代码翻译 在编程语言之间翻译代码: ``` normalize translate src/main.ts --to python # TypeScript to Python normalize translate src/lib.py --to lua # Python to Lua normalize translate - --from ts --to lua # Stdin with explicit langs ``` ### structure - 结构索引 管理结构索引(符号、导入、调用): ``` normalize structure stats # Index stats normalize structure rebuild # Rebuild the index normalize structure files # List indexed files normalize structure query "SELECT name, kind FROM symbols WHERE kind = 'function' LIMIT 10" # SQL query ``` ### sessions - 会话分析 分析 Claude Code 和其他代理的会话日志: ``` normalize sessions list # List recent sessions normalize sessions show # Show session details normalize sessions stats # Aggregate statistics normalize sessions patterns # Tool call sequence analysis (Markov chains) normalize sessions plans # View agent plans ``` ## 命令别名 其他工具的熟悉名称可以透明地工作: | 您输入的命令 | 实际运行的命令 | |----------|------| | `normalize search` | `normalize grep` | | `normalize find` | `normalize grep` | | `normalize lint` | `normalize rules run` | | `normalize check` | `normalize ci` | | `normalize index` | `normalize structure rebuild` | | `normalize refactor` | `normalize edit` | ## CI 集成 使用单个命令运行所有已配置的检查: ``` normalize ci # run all engines, exit 1 on errors normalize ci --strict # treat warnings as errors normalize ci --no-native # skip native checks (ratchet, budget, stale-summary) normalize ci --sarif # SARIF output for GitHub Actions annotations ``` 有关完整的 CI 设置指南(GitHub Actions、GitLab CI、ratchet 引导工作流和版本固定),请参阅 [docs/ci.md](docs/ci.md)。 ## 配置 创建 `.normalize/config.toml`: ``` [structure] # enabled = true [view] depth = 1 line_numbers = false [filter.aliases] tests = ["**/test_*.py", "**/*_test.go"] [walk] ignore_files = [".gitignore"] # gitignore-format files to respect (default) exclude = [".git", "node_modules"] # directory names to always skip ``` ### 自定义 Lint 工具 在 `.normalize/tools.toml` 中添加自定义工具: ``` [[tools]] name = "my-linter" command = ["my-linter", "--format", "json"] category = "linter" languages = ["python"] output_format = "sarif" ``` ## 输出格式 大多数命令支持 `--json` 进行结构化输出: ``` normalize view src/main.rs --json normalize analyze health --json normalize tools lint --json ``` ## 语言支持 Normalize 通过 tree-sitter 语法支持 98 种语言,包括: Python、Rust、TypeScript、JavaScript、Go、Java、C、C++、Ruby、PHP、Swift、Kotlin、Scala 等等。 ## 开发 ``` # 构建 cargo build # 测试 cargo test # 构建 grammars(测试必需) cargo xtask build-grammars # 本地安装 cargo install --path crates/normalize ``` ### 前置条件 - Rust 工具链 (1.75+) - `bun` 或 `npm` - 构建 sessions web viewer SPA 所需 如果使用 Nix:`nix develop` 可提供所有依赖项。 ## 许可证 MIT
标签:AI编程助手, Cargo, CLI, Nix, Rust, WiFi技术, 代码健康度, 代码分析器, 代码复杂度分析, 代码审查, 代码度量, 代码搜索引擎, 代码智能, 代码结构可视化, 代码重复检测, 依赖图分析, 可视化界面, 圈复杂度, 多线程, 威胁情报, 开发者工具, 数据管道, 网络流量审计, 软件工程, 通知系统, 错误基检测, 静态代码分析, 静态分析工具, 静态安全扫描