muin-company/roast

GitHub: muin-company/roast

基于 Anthropic Claude 的 AI 代码审查 CLI 工具,支持幽默吐槽和专业严肃两种模式,为开发者提供即时、有趣的代码质量反馈。

Stars: 0 | Forks: 0

# roast AI 代码审查工具,用幽默和诚实的方式吐槽你的代码。
## 🚀 即将登陆 Product Hunt — 2026 年 4 月 9 日 **[👉 在 Product Hunt 上支持我们](https://www.producthunt.com/posts/roast-cli)** | 上线时获取通知!
[![npm version](https://badge.fury.io/js/@muin%2Froast.svg)](https://www.npmjs.com/package/@muin/roast) [![npm downloads](https://img.shields.io/npm/dm/@muin/roast.svg)](https://www.npmjs.com/package/@muin/roast) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js Version](https://img.shields.io/node/v/@muin/roast.svg)](https://nodejs.org) [![GitHub stars](https://img.shields.io/github/stars/muinmomin/roast.svg?style=social)](https://github.com/muinmomin/roast) [![GitHub issues](https://img.shields.io/github/issues/muinmomin/roast.svg)](https://github.com/muinmomin/roast/issues) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/muinmomin/roast/pulls) ## 这是什么? `roast` 是一个 CLI 工具,它使用 Claude 来审查你的代码,并提供准确、有趣且有用的反馈。想象一下 Gordon Ramsay 遇上了你的资深开发工程师。 ## 为什么要用这个? **使用前:** ``` You: "Is this code good?" Brain: "Probably fine..." *ships to production* *everything breaks* ``` **使用后:** ``` $ roast bubble-sort.js ``` ``` 🔥 Oh boy, bubble sort in 2026? What's next, a floppy disk driver? 🔥 This function mutates the input array. That's like borrowing someone's car and returning it as a motorcycle. 💡 Use Array.prototype.toSorted() if you're on Node 20+ ``` **真实痛点:** - 代码审查需要好几天 - 队友太客气了,不愿直说 - 你在单打独斗,没人给反馈 - CI 在你提交后才捕捉 bug - 写测试并不能发现设计问题 `roast` 在你提交前给你即时、极其诚实的反馈。用自己的代码时开启吐槽模式,团队审查时用严肃模式。 ## roast-cli 有什么不同? | 功能 | roast-cli | ESLint | SonarQube | GitHub Copilot | |---------|-----------|--------|-----------|----------------| | **设置时间** | 0 秒 (npx) | 几分钟 | 几小时 | GitHub 账号 | | **个性** | Gordon Ramsay 🔥 | 干巴巴/技术流 | 企业化 | 乐于助人的 AI | | **娱乐性** | ✅ 很高 | ❌ 无 | ❌ 无 | 🤷 看情况 | | **代码质量** | ✅ 真实反馈 | ✅ 严格规则 | ✅ 深度分析 | ✅ 建议 | | **使用场景** | 快乐一笑 + 洞察 | 执行标准 | 团队质量 | 代码辅助 | | **费用** | 免费 | 免费 | 付费层级 | $10/月 | **核心差异:** 我们是唯一让代码审查变得*有趣*的工具。请配合你的 linter 使用,而不是替代它。 ## 安装 ``` npm install -g @muin/roast ``` 或者不安装直接运行: ``` npx @muin/roast your-file.js ``` ## 设置 在 [console.anthropic.com](https://console.anthropic.com/settings/keys) 获取你的 Anthropic API key ``` export ANTHROPIC_API_KEY="your-key-here" ``` 添加到 `~/.bashrc` 或 `~/.zshrc` 使其永久生效。 ## 用法 ### 吐槽模式(默认) ``` roast src/app.js ``` 输出: ``` 🔥 CODE ROAST 🔥 Victim: bubble-sort.js (JavaScript) ────────────────────────────────────────────────── 🔥 Oh boy, bubble sort in 2026? What's next, a floppy disk driver? 🔥 This function mutates the input array. That's like borrowing someone's car and returning it as a motorcycle. 💡 Use Array.prototype.toSorted() if you're on Node 20+, or at least clone the array first: const sorted = [...arr] 🔥 No input validation. Passing a string? Enjoy your runtime error. ✨ At least you got the algorithm right. It's bad, but it's correctly bad. ────────────────────────────────────────────────── Roasted with ❤️ by Claude ``` ### 严肃模式 ``` roast --serious src/app.js ``` 输出: ``` 📋 Professional Code Review File: api-handler.js (JavaScript) ────────────────────────────────────────────────── 🚨 No input sanitization on user data - SQL injection risk ⚠️ Synchronous file operations will block the event loop 💡 Consider using async/await with fs.promises ✅ Good error handling structure ────────────────────────────────────────────────── ``` ### 自定义模型 ``` roast --model claude-opus-4 src/app.js ``` ## 支持的语言 JavaScript, TypeScript, Python, Go, Rust, Java, C, C++, Ruby, PHP, Swift, Kotlin, Shell, SQL, HTML, CSS 等等。 ## 选项 ``` -s, --serious Professional review mode (no humor) --severity Roast severity: mild, medium, harsh (default: medium) -m, --model AI model to use (default: claude-sonnet-4-5) --no-color Disable colors -V, --version Output version -h, --help Display help ``` ### 严厉程度等级 **温和** (😊 友好模式):友好、鼓励性的反馈。非常适合初学者,或者当你想要支持性语气的建设性批评时。 ``` roast --severity mild src/app.js ``` **中等** (🔥 默认):幽默与批评的平衡组合。讽刺但有用,就像代码审查时的资深开发者。 ``` roast src/app.js # 或显式执行: roast --severity medium src/app.js ``` **严厉** (💀 毫不留情):极其诚实、凶狠的吐槽。只有当你能承受真相时才使用。Gordon Ramsay 模式。 ``` roast --severity harsh src/app.js ``` ## 示例 ### 示例 1:快速审查单个文件 ``` $ roast src/utils/array-helpers.js 🔥 CODE ROAST 🔥 Victim: array-helpers.js (JavaScript) ────────────────────────────────────────────────── 🔥 You wrote a custom array flatten function? Array.flat() has been in JavaScript since 2019. ES2019 is not "too new." 🔥 uniqueArray uses indexOf in a loop - O(n²) complexity. Set([...arr]) is O(n) and already built in. 💡 Half these functions are one-liners with modern JS: flatten: arr.flat() unique: [...new Set(arr)] last: arr.at(-1) ✨ At least they work correctly. But you've essentially reinvented lodash, poorly. ────────────────────────────────────────────────── ``` ### 示例 2:用于团队 PR 审查的严肃模式 ``` $ roast --serious src/api/auth.ts 📋 Professional Code Review File: auth.ts (TypeScript) ────────────────────────────────────────────────── 🚨 Password comparison using === instead of timing-safe compare Risk: Timing attacks could leak password information ⚠️ JWT secret loaded from process.env without fallback check Will crash on startup if JWT_SECRET is not set 💡 Consider using express-validator for input sanitization ✅ Good: Proper async/await usage throughout ✅ Good: TypeScript types are well-defined ⚠️ Token expiration set to 30 days - consider shorter duration for sensitive operations ────────────────────────────────────────────────── ``` ### 示例 3:从 stdin 审查(管道或粘贴) ``` $ cat suspicious-code.py | roast 🔥 CODE ROAST 🔥 Victim: stdin (Python) ────────────────────────────────────────────────── 🔥 eval() on user input? That's not a security vulnerability, that's a welcome mat for hackers. 🔥 Bare except: catches everything including KeyboardInterrupt. You can't even Ctrl+C out of this disaster. 🔥 Global variables modified inside functions with no documentation. Reading this code is like a mystery novel where the butler did it, but also the gardener, and maybe the protagonist. 💡 Use ast.literal_eval() for safe evaluation, or better yet, json.loads() if you're parsing data. ────────────────────────────────────────────────── ``` ### 示例 4:提交前的 Git diff 审查 ``` $ git diff src/payment-processor.js | roast --serious 📋 Professional Code Review ────────────────────────────────────────────────── 🚨 Changed error handling to swallow exceptions silently Original code logged errors, new code hides them ⚠️ Removed input validation for transaction amount Could now process negative or NaN values 🚨 API timeout increased from 5s to 60s May cause cascading failures under load Recommendation: These changes reduce system reliability. Suggest reverting the exception handling changes. ────────────────────────────────────────────────── ``` ### 示例 5:复杂代码使用自定义模型 ``` $ roast --model claude-opus-4 src/distributed-lock.go 🔥 CODE ROAST 🔥 Victim: distributed-lock.go (Go) ────────────────────────────────────────────────── 🔥 Your distributed lock implementation has a race condition between checking and acquiring. Classic "check-then-act" bug. 🔥 Lock timeout is hardcoded to 10 seconds. Production load spikes will turn this into a deadlock factory. 💡 Redis SETNX is atomic - use it directly instead of GET + SET. Or better yet, use Redlock algorithm for multi-node safety. 🔥 Panic on Redis connection error. In distributed systems, network failures are features, not exceptions. ✨ Good use of context for cancellation. That's the one part that won't cause a 3 AM page. ────────────────────────────────────────────────── ``` ### 示例 6:用于学习的温和模式 ``` $ roast --severity mild beginner-script.py 😊 Friendly Code Review Victim: beginner-script.py (Python) ────────────────────────────────────────────────── 💡 Great start! Your code works, which is the most important part. 💛 Small improvement: Instead of opening files without 'with', try using context managers: with open('file.txt', 'r') as f: data = f.read() This automatically closes the file for you! 💡 You're using global variables. As your program grows, consider passing data as function parameters instead. ✨ Your variable names are clear and descriptive. Keep that up! ────────────────────────────────────────────────── ``` ### 示例 7:认清现实的严厉模式 ``` $ roast --severity harsh legacy-spaghetti.php 💀 BRUTAL CODE ROAST 💀 Victim: legacy-spaghetti.php (PHP) ────────────────────────────────────────────────── 💀 This code is a war crime. The Geneva Convention should cover this. 💀 mysql_* functions were deprecated 11 years ago. This isn't legacy code, it's a fossil. 💀 SQL injection vulnerabilities everywhere. You're concatenating user input into queries like it's 1999. It was bad in 1999 too. 💀 Password stored in plaintext. Just... why? WHY?! 💀 4 levels of nested if statements with no clear logic. This is a crime scene where the detective gave up and went home. 💀 Variable names like $a, $tmp, $data2. Were descriptive names too expensive? Reality check: This needs a complete rewrite. I'm not even sure where to start. Maybe with fire. ────────────────────────────────────────────────── Roasted with absolute honesty by Claude ``` ### 示例 8:TypeScript React 组件 ``` $ roast src/components/UserDashboard.tsx 🔥 CODE ROAST 🔥 Victim: UserDashboard.tsx (TypeScript/React) ────────────────────────────────────────────────── 🔥 850 lines in one component. This isn't a component, it's a monolith. Break it down before it breaks you. 🔥 useEffect with 12 dependencies? That's not reactive programming, that's chaos with extra steps. 💡 Extract at least 4 sub-components: - UserHeader - ActivityFeed - SettingsPanel - NotificationCenter 🔥 Inline styles everywhere instead of styled-components or CSS modules. Your future self will hate present you. ✨ Props are properly typed. That's good! Now use that discipline everywhere else. ────────────────────────────────────────────────── ``` ### 示例 9:Shell 脚本审查 ``` $ roast deploy.sh 🔥 CODE ROAST 🔥 Victim: deploy.sh (Shell) ────────────────────────────────────────────────── 🔥 No 'set -e' at the top. If step 1 fails, steps 2-10 will still run and cause chaos. 🔥 rm -rf without any confirmation? Living dangerously, I see. 💡 Add error handling: set -euo pipefail This will: - Exit on error (e) - Fail on undefined variables (u) - Catch errors in pipes (pipefail) 🔥 Hardcoded paths and credentials. Use environment variables: ${DB_HOST:-localhost} ✨ At least you have comments. That's rare for shell scripts. ────────────────────────────────────────────────── ``` ### 示例 10:SQL 查询审查 ``` $ roast db/queries.sql 🔥 CODE ROAST 🔥 Victim: queries.sql (SQL) ────────────────────────────────────────────────── 🔥 SELECT * in production queries. Your DBA is crying somewhere. List the exact columns you need. 🔥 No indexes on the WHERE clause columns. This will be fast now with 100 rows. With 1,000,000 rows? Enjoy your 30-second queries. 💡 Add indexes: CREATE INDEX idx_users_email ON users(email); CREATE INDEX idx_orders_user_created ON orders(user_id, created_at); 🔥 LEFT JOIN without understanding why. If you need all rows from both tables, that's a FULL JOIN (or you don't actually need all rows). ✨ Query is at least readable and properly formatted. ────────────────────────────────────────────────── ``` ### 示例 11:Rust 代码审查 ``` $ roast src/main.rs 🔥 CODE ROAST 🔥 Victim: main.rs (Rust) ────────────────────────────────────────────────── 🔥 .unwrap() everywhere. You learned Rust yesterday, didn't you? 💡 Use proper error handling: // Instead of: let file = File::open("data.txt").unwrap(); // Use: let file = File::open("data.txt")?; // or let file = File::open("data.txt") .expect("Failed to open data.txt"); 🔥 Cloning everything to avoid fighting the borrow checker. That's like buying a sports car and only driving in first gear. ✨ You're using match instead of if-let. Good! Pattern matching is the way. 💡 Learn lifetimes. They're scary at first, but they'll save you from these clones. ────────────────────────────────────────────────── ``` ## 真实场景 ### 提交前的健全性检查 ``` # 准备提交你一直在做的 refactor $ git diff HEAD src/auth.js | roast 🔥 You're exporting the private key in plaintext? Bold strategy. 🔥 This regex will match "admin@evil.com" as a valid admin email. Better tighten that up unless you're running a very open company. 💡 hash.compare() is async but you're not awaiting it. This will always return true. Always. Every time. 100% authentication success rate! # ……好吧也许我应该先测试一下 ``` ### 审查凌晨 2 点写的那个“快速修复” ``` $ roast src/hotfix-do-not-touch.js 🔥 File name is literally "do-not-touch.js" - that's a red flag wrapped in another red flag 🔥 You're catching errors and logging "it broke lol". When production is on fire, your logs will just say "it broke lol" repeated 50,000 times. 🔥 This setTimeout is set to 86400000ms. That's 24 hours. Hope nobody's waiting for this response. ✨ The actual logic is... fine? But please, for the love of debugging, add better error messages. ``` ### 复制粘贴教程代码前先检查一下 ``` $ curl -s https://example.com/tutorial.js | roast 🔥 This tutorial is using var in 2026. It was written during the Mesozoic Era and hasn't been updated since. ⚠️ jQuery is loaded from an HTTP URL. That's a mixed content warning waiting to happen. 💡 Modern replacement using fetch() would be 10 lines and zero dependencies. Just saying. ``` ### “我昨天刚学这个”的审查 ``` # 刚学了 Rust,写了第一个程序 $ roast hello.rs --serious 📋 Professional Code Review ────────────────────────────────────────────────── ✅ Proper error handling with Result type ⚠️ .unwrap() on line 8 will panic on error. Consider using expect() with a meaningful message, or propagate with ? 💡 String ownership is correct, but you're cloning unnecessarily on line 12. Use a reference: &user_name ✅ Good use of match for control flow Overall: Solid first program. Remove the unwrap() and you're good to go. ``` ### 遗留代码考古 ``` $ roast legacy/customer-import-final-v3-NEW-USE-THIS.php 🔥 Based on the filename, this has been "final" at least 3 times. That's not a good sign. 🔥 mysql_connect() was deprecated in PHP 5.5 (2013) and removed in PHP 7 (2015). This code is old enough to vote. 🔥 SQL query is concatenating user input directly. This is how Little Bobby Tables drops your database. 🔥 No password hashing - passwords stored in plaintext. In the event of a breach, this is "directly to jail, do not pass go" territory. 💡 Complete rewrite recommended. Start fresh with PDO and password_hash(). This is beyond roasting, this needs a Viking funeral. ``` ### 团队代码风格检查 ``` # 检查新来的 junior 的代码是否符合你的风格 $ roast --serious src/components/UserCard.jsx 📋 Professional Code Review ────────────────────────────────────────────────── ⚠️ Component is 450 lines long. Consider splitting into smaller pieces. ⚠️ Inline styles instead of CSS modules/styled-components 💡 Three useState hooks could be combined into useReducer ✅ Proper PropTypes definitions ✅ Good accessibility attributes (aria-labels, roles) ⚠️ useEffect missing dependency 'userId' - will cause stale closures Recommendation: Works, but needs refactoring before it grows larger. ``` ## 使用案例 ### 1. **独立开发者 —— 做自己的代码审查者** 独自工作?没有团队审查你的代码?`roast` 来填补这个空白。 ``` $ roast src/new-feature.js ``` **好处:** 在 bug、安全问题和不良模式进入生产环境之前就发现它们。让 AI 成为你的第二双眼睛。 **何时使用:** - 提交新功能之前 - 重构之后 - 学习新语言/框架时 - 部署到生产环境之前 ### 2. **学习与技能提升** 刚学了一门新语言?`roast` 通过批评来教学。 ``` # 第一个 Python 脚本 $ roast my_first_app.py # 第一个 Rust 程序 $ roast --serious main.rs ``` **好处:** 通过在自己的代码中看到问题,学习最佳实践、惯用语和常见陷阱。学习时使用 `--severity mild` 获得更多鼓励。 ### 3. **提交前的质量关卡** 将 `roast` 添加到你的 git hooks,在提交前强制执行质量检查。 ``` # .git/hooks/pre-commit #!/bin/bash git diff --cached --name-only --diff-filter=ACM | \ grep -E '\.(js|ts|py|go)$' | \ xargs -I {} roast --serious {} || exit 1 ``` **好处:** 自动化代码质量检查。在 CI 之前、代码审查之前、在团队看到之前就发现问题。 ### 4. **快速上手新代码库** 刚加入一个拥有大型代码库的团队?使用 `roast` 来理解模式。 ``` $ roast src/core/auth-handler.js --serious ``` AI 会解释代码的作用,突出问题,并建议改进。就像让一位资深开发者带你过一遍代码。 **好处:** 更快上手。理解现有的模式和反模式。 ### 5. **遗留代码评估** 接手了一个遗留项目?获得对你所面临情况的诚实评估。 ``` $ roast legacy/modules/payment-v1.php --severity harsh ``` **好处:** 优先安排重构。知道什么是可挽救的,什么需要重写。 ### 6. **教学与指导** 教别人写代码?展示好的代码和坏的代码是什么样的。 ``` # 学生的代码 $ roast student-assignment.py --severity mild # 同时向他们展示 roast 和 serious 模式 $ roast --serious student-assignment.py ``` **好处:** 一致、耐心的反馈。不带评判地传授最佳实践。 ### 7. **代码审查准备(在人工审查之前)** 在请求队友进行 PR 审查之前,运行 `roast` 来发现明显的问题。 ``` $ git diff main...feature-branch | roast --serious ``` 修复 `roast` 发现的问题,*然后*再请求人工审查。 **好处:** 不要在琐碎问题上浪费队友的时间。提交更干净的 PR。建立高质量的声誉。 ## 性能技巧 ### 1. **为常用工作流设置 Shell 别名** 为频繁使用的吐槽场景创建快捷方式: ``` # 添加到 ~/.bashrc 或 ~/.zshrc alias roast-js='roast --serious' alias roast-diff='git diff | roast --serious' alias roast-mild='roast --severity mild' alias roast-harsh='roast --severity harsh' ``` 现在只需输入: ``` $ roast-diff # Review uncommitted changes $ roast-js src/app.js # Serious review ``` ### 2. **批量审查多个文件** 使用 shell 循环进行批量审查: ``` # 审查 src/ 下的所有 JavaScript 文件 for file in src/**/*.js; do echo "=== $file ===" roast --serious "$file" done # 或者使用 find find src -name "*.py" -exec roast --serious {} \; ``` **保存结果:** ``` for file in src/**/*.js; do roast --serious "$file" > "reviews/$(basename $file).review.txt" done ``` ### 3. **优化 API 成本** 吐槽功能使用 Anthropic 的 API。为了降低成本: **a) 只审查修改过的文件:** ``` git diff --name-only | grep -E '\.(js|ts|py)$' | xargs -I {} roast {} ``` **b) 简单审查使用 haiku 模型**(修改源代码): ``` // In lib/roast.js, change: model: 'claude-haiku-4-5' // Faster, cheaper, less detailed ``` **c) 审查较小的代码片段:** ``` # 而不是整个 1000 行的文件 $ head -100 large-file.js | roast ``` ### 4. **本地缓存审查结果(手动)** 对于你反复审查的文件: ``` # 保存审查以供后续参考 $ roast src/utils.js > reviews/utils-2026-02-08.txt # 与之前的审查进行比较 $ diff reviews/utils-2026-02-01.txt reviews/utils-2026-02-08.txt ``` ### 5. **结合 Git Hooks 实现自动化** **Pre-commit hook**(提交前审查): ``` #!/bin/bash # .git/hooks/pre-commit git diff --cached --name-only | \ grep -E '\.(js|ts)$' | \ xargs -I {} roast --serious {} read -p "Proceed with commit? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi ``` **Pre-push hook**(推送前最后检查): ``` #!/bin/bash # .git/hooks/pre-push git diff origin/main...HEAD --name-only | \ grep -E '\.(py|js|go)$' | \ xargs -I {} roast --serious {} > /tmp/pre-push-review.txt cat /tmp/pre-push-review.txt ``` ### 6. **大型项目的并行处理** 使用 GNU parallel 加速: ``` # 安装:brew install parallel (macOS) 或 apt-get install parallel (Linux) # 并行审查所有文件(一次 4 个) find src -name "*.js" | parallel -j 4 roast --serious {} > reviews.txt ``` ### 7. **智能文件选择** 不要审查所有东西。重点关注: **新建/修改的文件:** ``` git diff --name-only main | xargs -I {} roast {} ``` **复杂文件(高行数):** ``` find src -name "*.js" -exec wc -l {} \; | \ sort -rn | head -10 | \ awk '{print $2}' | xargs -I {} roast {} ``` **最近出过 bug 的文件(从 git 历史中查找):** ``` git log --format=format: --name-only | \ sort | uniq -c | sort -rn | \ head -10 | awk '{print $2}' | \ xargs -I {} roast --serious {} ``` ## 故障排除 ### 1. **"ANTHROPIC_API_KEY not set" 错误** **问题:** ``` $ roast src/app.js 💥 Error: ANTHROPIC_API_KEY environment variable is required ``` **解决方案:** a) 为当前会话设置: ``` export ANTHROPIC_API_KEY="sk-ant-your-key-here" ``` b) 永久设置(添加到 shell 配置): ``` # 针对 bash echo 'export ANTHROPIC_API_KEY="sk-ant-your-key"' >> ~/.bashrc source ~/.bashrc # 针对 zsh echo 'export ANTHROPIC_API_KEY="sk-ant-your-key"' >> ~/.zshrc source ~/.zshrc ``` c) 获取你的 API key: 访问 [console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys) ### 2. **"Cannot find file" 错误** **问题:** ``` $ roast src/app.js 💥 Error: ENOENT: no such file or directory ``` **解决方案:** a) 检查文件路径: ``` $ ls -la src/app.js # Verify file exists ``` b) 使用绝对路径: ``` $ roast /full/path/to/src/app.js ``` c) 检查当前目录: ``` $ pwd $ roast ./src/app.js ``` ### 3. **输出为空或通用** **问题:** ``` $ roast my-code.js 🔥 CODE ROAST 🔥 ────────────────────────────────────────────────── This code looks fine. ────────────────────────────────────────────────── ``` **解决方案:** a) 文件可能太小/太简单: ``` # 代码可能确实没问题! $ wc -l my-code.js # Check line count ``` b) 语言未检测到。使用正确的扩展名重命名文件: ``` $ mv script script.py # Add .py extension $ roast script.py ``` c) 使用详细模式(如果有)或尝试严肃模式: ``` $ roast --serious my-code.js ``` ### 4. **"Invalid severity level" 错误** **问题:** ``` $ roast --severity extreme src/app.js 💥 Error: Invalid severity level: extreme Valid options: mild, medium, harsh ``` **解决方案:** a) 使用有效的严厉程度: ``` $ roast --severity harsh src/app.js ``` b) 检查可用选项: ``` $ roast --help ``` ### 5. **Command not found: roast** **问题:** ``` $ npm install -g @muin/roast $ roast src/app.js zsh: command not found: roast ``` **解决方案:** a) 检查 npm 全局 bin 目录是否在 PATH 中: ``` $ npm config get prefix # 应该显示类似 /usr/local 或 ~/.npm-global $ echo $PATH # 应该包含上面的 bin 目录 ``` b) 修复 PATH(添加到 ~/.bashrc 或 ~/.zshrc): ``` export PATH="$PATH:$(npm config get prefix)/bin" source ~/.bashrc # or ~/.zshrc ``` c) 改用 npx(不需要全局安装): ``` $ npx @muin/roast src/app.js ``` ### 6. **API 速率限制错误** **问题:** ``` $ roast src/app.js 💥 Error: rate_limit_error: You have exceeded your API rate limit ``` **解决方案:** a) 等待一分钟再重试(Anthropic 有每分钟限制) b) 检查你的速率限制: 访问 [console.anthropic.com/settings/limits](https://console.anthropic.com/settings/limits) c) 批量处理时添加延迟: ``` for file in src/*.js; do roast "$file" sleep 3 # Wait 3 seconds between calls done ``` d) 如果经常达到限制,考虑升级到更高级别 ### 7. **彩色输出乱码 / 出现奇怪字符** **问题:** ``` $ roast src/app.js [31m🔥[0m [1mCODE ROAST[0m... ``` **解决方案:** a) 禁用颜色: ``` $ roast --no-color src/app.js ``` b) 检查终端颜色支持: ``` $ echo $TERM # 应该是 xterm-256color 或类似的 # 如果是 'dumb',请设置: export TERM=xterm-256color ``` c) 重定向到文件(自动禁用颜色): ``` $ roast src/app.js > review.txt ``` ### 8. **响应非常慢(>30 秒)** **问题:** ``` $ roast very-large-file.js # ……永远等待中…… ``` **解决方案:** a) 文件可能太大。Claude 有 token 限制(~100k tokens ≈ 75k 单词)。 检查文件大小: ``` $ wc -l very-large-file.js 5000 very-large-file.js # Too large! ``` b) 拆分成较小的文件: ``` $ split -l 500 large-file.js part- $ roast part-aa $ roast part-ab ``` c) 只审查一部分: ``` $ head -300 large-file.js | roast # First 300 lines ``` d) 检查 Anthropic API 状态: ``` $ curl -I https://api.anthropic.com ``` ### 9. **模型未找到错误** **问题:** ``` $ roast --model claude-opus-99 src/app.js 💥 Error: model 'claude-opus-99' not found ``` **解决方案:** a) 使用有效的模型名称: ``` $ roast --model claude-sonnet-4-5 src/app.js $ roast --model claude-opus-4 src/app.js $ roast --model claude-haiku-4-5 src/app.js ``` b) 在 [docs.anthropic.com](https://docs.anthropic.com/en/docs/models-overview) 查看可用模型 c) 省略该标志以使用默认值: ``` $ roast src/app.js # Uses default model ``` ### 10. **网络/连接错误** **问题:** ``` $ roast src/app.js 💥 Error: connect ETIMEDOUT ``` **解决方案:** a) 检查互联网连接: ``` $ ping api.anthropic.com ``` b) 检查防火墙/VPN 是否阻止: ``` $ curl https://api.anthropic.com ``` c) 如果在公司防火墙后设置代理: ``` export HTTP_PROXY=http://proxy.company.com:8080 export HTTPS_PROXY=http://proxy.company.com:8080 ``` ### 11. **Windows 上的权限错误** **问题:** ``` C:\> npm install -g @muin/roast Error: EACCES: permission denied ``` **解决方案:** a) 以管理员身份运行(PowerShell): ``` # 右键点击 PowerShell → “以管理员身份运行” PS> npm install -g @muin/roast ``` b) 或使用 npx(无需安装): ``` PS> npx @muin/roast src/app.js ``` ### 12. **文件编码问题(非 UTF-8)** **问题:** ``` $ roast legacy-code.php 💥 Error: Invalid UTF-8 sequence ``` **解决方案:** a) 将文件转换为 UTF-8: ``` $ iconv -f ISO-8859-1 -t UTF-8 legacy-code.php > legacy-code-utf8.php $ roast legacy-code-utf8.php ``` b) 检查当前编码: ``` $ file legacy-code.php legacy-code.php: PHP script, ISO-8859 text ``` ## 常见 (FAQ) ### 1. **我的代码会被发送到 Anthropic 的服务器吗?** **是的。** 当你运行 `roast` 时,文件内容会被发送到 Anthropic 的 Claude API 进行分析。 **安全提示:** 不要审查包含以下内容的文件: - API keys、密码或机密信息 - 专有算法(如果你有严格的保密协议) - 测试数据中的 PII(个人身份信息) - 任何你不愿意与第三方分享的内容 Anthropic 的隐私政策:https://www.anthropic.com/legal/privacy ### 2. **使用成本是多少?** `roast` 本身是免费开源的。但是,它使用 Anthropic 的 Claude API,这有使用成本: - **免费层级:** $5 额度(足够 ~100-300 次吐槽,取决于文件大小) - **之后:** 每次吐槽约 $0.01-0.05(1-5 美分) - **每月估算:** 如果你每天审查 20 个文件:约 $10-30/月 查看定价:https://www.anthropic.com/pricing ### 3. **可以离线使用吗?** **不可以。** `roast` 需要互联网连接来访问 Anthropic 的 API。 **离线替代方案:** - 搭建本地 LLM(复杂,超出范围) - 使用传统 linters(eslint, pylint 等) - 人工代码审查 ### 4. **幽默内容会冒犯人吗?** **吐槽模式:** 讽刺且直率,但从不针对个人。它批评的是代码,不是人。 **严肃模式:** 专业,没有幽默。 **严厉程度等级:** - **温和:** 友好和鼓励 - **中等:** 讽刺但有建设性(默认) - **严厉:** 非常直接,可能很刺耳 团队 PR 使用 `--serious`,初学者使用 `--severity mild`。 ### 5. **它真的能提高代码质量吗?** **是的,如果使用得当:** ✅ 发现安全问题(SQL 注入、XSS、不安全的 eval) ✅ 识别性能问题(O(n²) 循环、内存泄漏) ✅ 突出可维护性问题(长函数、紧耦合) ✅ 建议现代最佳实践 ✅ 通过解释*为什么*某样东西不好来教学 **但是:** - AI 可能会忽略特定上下文的问题 - 它是工具,不能替代人工审查 - 应用建议前务必验证 ### 6. **可以自定义吐槽风格吗?** **目前:** 严厉程度等级(温和/中等/严厉)和严肃模式。 **尚不支持:** 自定义吐槽角色(例如,“像 Linus Torvalds 一样吐槽”或“像 Uncle Bob 一样审查”)。 **未来:** 可自定义的提示词/风格已在路线图中。 ### 7. **支持哪些语言?** ✅ JavaScript / TypeScript / Node.js ✅ Python ✅ Go ✅ Rust ✅ Java / Kotlin ✅ C / C++ ✅ Ruby ✅ PHP ✅ Swift ✅ Shell / Bash ✅ SQL ✅ HTML / CSS ✅ 以及更多... Claude 拥有广泛的训练,所以即使是小众语言通常也能获得不错的结果。 ### 8. **它适用于框架(React、Django 等)吗?** **是的!** AI 理解特定于框架的模式: - **React:** Hooks、组件结构、props、状态管理 - **Django:** ORM 模式、视图、中间件 - **Express:** 路由处理器、中间件、错误处理 - **Rails:** ActiveRecord、控制器、迁移 - 等等。 它会吐槽框架特定的反模式(例如,React 中的 prop drilling,ORM 中的 N+1 查询)。 ### 9. **我可以用这个审查生产代码吗?** **可以,但:** ✅ 非常适合初步筛选 ✅ 发现明显的 bug 和安全问题 ✅ 确保代码符合基本质量标准 ⚠️ 不应替代人工代码审查用于: - 业务逻辑验证 - 架构决策 - 团队特定约定 - 细微的判断决定 **最佳实践:** 在请求人工审查*之前*使用 `roast --serious`。修复它发现的问题,然后再让人工审查。 ### 10. **每次结果会不同吗?** **是的,略有不同。** AI 模型有一定的随机性(temperature 设置)。 **通常:** - 核心问题总是会被标记 - 措辞可能会有所不同 - 吐槽的严厉程度可能略有不同 为了获得一致的结果,请使用更具确定性的 `--serious` 模式。 ### 11. **我可以为项目做贡献吗?** **当然!** 非常欢迎贡献: - 通过 GitHub Issues 报告 bug - 提议功能 - 提交 pull requests - 改进吐槽质量 - 添加语言支持 - 编写测试 请参阅[贡献](#contributing)部分。 ### 12. **它会存储我的代码或审查结果吗?** **无本地存储。** `roast` 不会在你的机器上保存文件或审查结果(除非你手动重定向输出)。 **API 端:** Anthropic 可能会临时记录请求以防止滥用。请查看其隐私政策了解保留详情。 ## 技巧 - **分享你的吐槽** —— 它们被设计成适合截图分享 - **PR 使用严肃模式** —— 把幽默留给自己的代码 - **提交前审查** —— 在你的 CI 发现 bug 之前先发现它们 - **吐槽遗留代码** —— 既治愈又有教育意义 - **从 git diff 管道输入** —— 只审查改动的内容:`git diff | roast` - **支持 stdin** —— `cat sketch.py | roast` 或 `pbpaste | roast` **创建项目专用的包装脚本:** ``` # scripts/review.sh #!/bin/bash find src -name "*.js" -mtime -1 | xargs -I {} roast --serious {} ``` **与其他工具结合:** ``` # 先 Lint,再 roast $ eslint src/app.js && roast src/app.js # 先 Roast,再测试 $ roast src/app.js && npm test ``` **团队使用:** ``` # 添加到 CI pipeline - name: AI Code Review run: | git diff origin/main...HEAD --name-only | \ grep -E '\.(js|ts|py)$' | \ xargs -I {} npx @muin/roast --serious {} ``` ## 路线图 ### v0.2(下一个版本) - [ ] **JSON 输出模式** —— 用于 CI 集成的结构化输出 - [ ] **配置文件支持** —— `.roastrc` 用于默认设置(严厉程度、模型等) - [ ] **多文件批量模式** —— 一次 API 调用审查 `roast src/*.js` - [ ] **忽略模式** —— 类似 `.gitignore` 的 `.roastignore` - [ ] **Diff 模式** —— 比较变更:`roast --diff main...feature` ### v0.3 - [ ] **自定义吐槽风格** —— “像 Linus 一样吐槽”、“像 Uncle Bob 一样审查” - [ ] **带 diff 的修复建议** —— 显示要应用的确切代码更改 - [ ] **性能评分** —— 给代码质量打分 0-100 - [ ] **安全扫描模式** —— 只关注漏洞 - [ ] **HTML 报告生成** —— `roast --html src/ > report.html` ### v1.0(未来) - [ ] **自动修复模式** —— 自动应用建议的更改 - [ ] **IDE 插件** —— VS Code, IntelliJ, Vim - [ ] **团队仪表板** —— 随时间追踪代码质量 - [ ] **学习模式** —— 根据你的技能水平提供个性化反馈 - [ ] **多模型支持** —— 使用 GPT-4, Gemini, 本地模型 - [ ] **离线模式** —— 本地模型集成 ### 社区请求 - [ ] 用于拖放文件吐槽的 Web UI - [ ] Slack/Discord 机器人集成 - [ ] GitHub PR 评论自动化 - [ ] GitLab CI/CD 集成 - [ ] Pre-commit hook 生成器 - [ ] 支持 Jupyter notebooks (.ipynb) **想要某个功能?** 在 GitHub 上提 issue 或给现有的 issue +1! ## 开发 ``` # Clone repo git clone https://github.com/muinmomin/roast.git cd roast # 安装依赖 npm install # Link locally for testing npm link # 用示例文件测试 roast examples/bad-code.js # 运行测试(如有) npm test ``` **项目结构:** ``` roast/ ├── bin/ │ └── roast.js # CLI entry point ├── lib/ │ └── roast.js # Core logic ├── examples/ │ └── bad-code.js # Test cases ├── package.json └── README.md ``` **测试:** ``` # 创建测试文件 cat > test.js << 'EOF' var x = 1; eval(userInput); EOF $ roast test.js ``` ## 贡献 发现了 bug?想添加功能? ``` # Clone the repo git clone https://github.com/muinmomin/roast.git cd roast # 安装依赖 npm install # Test locally npm link roast test-file.js # 运行测试(如有) npm test ``` 欢迎 pull requests!请: - 保持幽默犀利但不刻薄 - 为新功能添加测试 - 遵循现有代码风格(包含 ESLint 配置) - 如果添加了选项,请更新 README **代码风格:** - 使用 ESLint - 遵循现有模式 - 为函数添加 JSDoc 注释 - 保持吐槽巧妙,不要刻薄 **贡献想法:** - 更好的语言检测 - 特定框架的吐槽(React、Django、Rails 模式) - 安全漏洞检测 - 性能分析 - 自定义吐槽模板 ## 🛠️ 更多来自 MUIN 的 CLI 工具 喜欢 `roast`?看看我们其他的开发者生产力工具: | 工具 | 描述 | NPM | |------|-------------|-----| | **[git-why](https://github.com/muin-company/git-why)** | AI 驱动的 git 历史解释器。在吐槽代码之前,先了解它*为什么*存在。 | [![npm](https://img.shields.io/npm/v/git-why.svg)](https://www.npmjs.com/package/git-why) | | **[portguard](https://github.com/muin-company/portguard)** | 监控并杀死占用端口的僵尸进程。一条命令修复 `EADDRINUSE`。 | [![npm](https://img.shields.io/npm/v/portguard.svg)](https://www.npmjs.com/package/portguard) | | **[oops](https://github.com/muin-company/oops-cli)** | 将任何错误通过管道传给 AI 获取即时修复。当吐槽揭示了真正的 bug 时,`oops` 来修复它们。 | [![npm](https://img.shields.io/npm/v/@mj-muin/oops-cli.svg)](https://www.npmjs.com/package/@mj-muin/oops-cli) | **即将推出:** 更多让你的开发工作流更快的工具。关注 [@muincompany](https://x.com/muincompany) 获取更新! ## 媒体报道 📰 阅读 Dev.to 上的发布文章:**[每位开发者都需要(但你从未听说过)的 4 个 CLI 工具](https://dev.to/mjmuin/4-cli-tools-every-developer-needs-that-youve-never-heard-of-318b)** ## 许可证 MIT ## 致谢 构建于: - [Anthropic Claude](https://anthropic.com) —— 进行吐槽的 AI - [Commander.js](https://github.com/tj/commander.js) —— CLI 框架 - [Chalk](https://github.com/chalk/chalk) —— 终端颜色 灵感来自你收到(或给出)的每一次极其诚实的代码审查。
### 由 [MUIN](https://muin.company) 构建 🚀 **我们构建让开发者生活更轻松的 AI 驱动工具。** [网站](https://muin.company) • [Twitter](https://x.com/muincompany) • [GitHub](https://github.com/muin-company) *负责任地吐槽。未经许可,不要在公开场合吐槽生产代码。*
标签:AI代码审查, Claude, CVE检测, DLL 劫持, DNS解析, Git钩子, GNU通用公共许可证, IPv6支持, LNA, MITM代理, Node.js, NPM包, OSV-Scalibr, Product Hunt, 云安全监控, 代码优化, 大语言模型, 威胁情报, 幽默吐槽, 开发者工具, 开源项目, 效率工具, 编程助手, 自动审查, 自定义脚本, 静态分析