Task: Refactor user authentication module
Task: Refactor user authentication module【免费下载链接】easy-vibe vibe coding 101The first course for AI-native product builders.项目地址: https://gitcode.com/GitHub_Trending/ea/easy-vibeRequirements:Extract all authentication logic into an independent AuthService classAdd unit tests, coverage 80%Update related documentationWhen all tests pass and docs are updated, output: task complete然后创建并运行循环脚本 bash chmod x loop.sh ./loop.sh更安全的改进版本为了避免死循环加上迭代上限#!/bin/bash MAX_ITERATIONS50 iteration0 while true; do iteration$((iteration 1)) echo Iteration $iteration/$MAX_ITERATIONS cat PROMPT.md | claude if [ $iteration -ge $MAX_ITERATIONS ]; then echo Reached maximum iterations, stopping break fi sleep 5 # small delay to avoid API rate limits done这个改进版增加了最大迭代限制、按轮显示进度、到达上限自动停止并每轮加入 5 秒延迟以避免触发 API 限流。方法二Ralph Wiggum 插件官方推荐Ralph Wiggum 是 Anthropic 官方专为长时任务构建的 Claude Code 插件。名字取自《辛普森一家》的角色代表屡败屡试的精神。核心机制Stop HookRalph 的核心是Stop Hook。当 Claude 想要退出时Stop Hook 拦截退出信号然后系统检查输出中是否包含特定的完成标记completion marker如果没有找到标记 → 重新注入原始 prompt开始新一轮迭代只有检测到完成标记→ 才允许 Claude 退出。这保证了 Claude 不会仅仅因为感觉差不多了就停下而必须完成明确标记的要求。安装Ralph Wiggum 是 Claude Code 官方插件有两种安装方式。方式 1从官方插件市场安装推荐# 在 Claude Code 中执行 claude # 添加官方插件市场 /plugin marketplace add anthropics/claude-code # 安装 Ralph Wiggum /plugin install ralph-wiggumclaude-code-plugins # 验证安装 /plugin方式 2直接从 GitHub 安装# 进入插件目录 cd ~/.claude/plugins/ # 克隆插件仓库 git clone https://github.com/anthropics/ralph-wiggum-plugin.git安装后可以使用以下命令/ralph-wiggum:ralph-loop—— 启动循环/ralph-wiggum:cancel-ralph—— 取消循环/ralph-wiggum:help—— 查看帮助基本使用使用/ralph-wiggum:ralph-loop/ralph-wiggum:ralph-loop Build a todo API with CRUD operations, input validation, and tests. Output promiseCOMPLETE/promise when everything is done. \ --max-iterations 50 \ --completion-promise COMPLETE参数说明最重要的两个参数是--max-iterations和--completion-promise参数作用建议取值--max-iterations硬性安全上限即使未完成Ralph 也会在此上限停止防止 API 无限消耗通常 20–100--completion-promise完成标记文本只有当 Claude 输出包含该标记时Ralph 才认为任务完成必须明确且唯一如COMPLETE、TASK_DONE避免歧义词Prompt 最佳实践写好 Prompt 是 Ralph 成功的关键。糟糕的 Prompt通常不定义完成标准。例如写一个 todo API可能让 AI 输出一个粗糙的骨架就停下——没有测试、没有验证、没有文档。好的 Prompt应该包含分阶段要求和清晰的验收标准。例如先描述分阶段任务阶段 1核心功能所有 CRUD 端点POST /todos创建、GET /todos列表、GET /todos/:id获取单个、PUT /todos/:id更新、DELETE /todos/:id删除阶段 2输入校验标题不能为空完成状态必须是布尔值阶段 3测试为每个端点编写测试覆盖率 80%。再定义验收标准所有测试通过、代码通过 linter、README 包含 API 文档。最后定义唯一的完成标记promiseTODO_API_COMPLETE/promise。这样 Claude 就知道具体要做什么以及何时才算真正完成。更多 Prompt 模板以下是常见任务的模板可直接使用或按需改编。模板 1测试迁移Jest → Vitest/ralph-wiggum:ralph-loop Migrate all tests in this project from Jest to Vitest: - Keep all test logic unchanged - Update config files (vite.config.js, vitest.config.js) - Replace Jest-specific APIs (e.g., jest.mock - vi.mock) - Ensure all tests pass - Remove Jest-related dependencies Acceptance criteria: - npm test passes fully - no Jest dependency in package.json - project builds successfully Output after completion: promiseVITEST_MIGRATION_COMPLETE/promise --max-iterations 40 --completion-promise VITEST_MIGRATION_COMPLETE模板 2UI/UX 优化移动优先/ralph-wiggum:ralph-loop Polish this projects UI/UX into a refined mobile-first language learning app: - unify spacing and whitespace (use 4px base unit) - establish clear type hierarchy (title/body/auxiliary text) - unify styles for cards, lists, and shared components - add bottom navigation (Home/Learn/Quiz/Progress/Settings) - ensure mobile rendering quality Acceptance criteria: - npm run build succeeds - no TypeScript errors - key pages preview correctly on mobile Output after completion: promiseUI_UX_COMPLETE/promise --max-iterations 25 --completion-promise UI_UX_COMPLETE模板 3批量 TypeScript 类型标注/ralph-wiggum:ralph-loop Add TypeScript type annotations to all functions in the project: - prioritize src/ directory - add types for function params and return values - avoid any, use concrete types or unknown - add necessary type definitions Acceptance criteria: - npm run typecheck passes - no ts-ignore or ts-any comments - code runs correctly Output after completion: promiseTYPES_ADDED/promise --max-iterations 30 --completion-promise TYPES_ADDED模板 4TDD 驱动的功能开发/ralph-wiggum:ralph-loop Implement checkout functionality using TDD: 1. Write tests first (checkout.test.ts) 2. Run tests (should fail) 3. Write minimal code to pass tests 4. Refactor and optimize 5. Repeat until all tests pass Feature requirements: - shopping cart item list - shipping fee calculation - coupon application - payment form validation Acceptance criteria: - all tests pass (npm test checkout.test.ts) - code coverage 80% - no ESLint errors Output after completion: promiseCHECKOUT_COMPLETE/promise --max-iterations 25 --completion-promise CHECKOUT_COMPLETE模板 5代码风格统一/ralph-wiggum:ralph-loop Unify code style across the project: - format all files with Prettier - unify naming conventions (variables camelCase, components PascalCase) - remove unused imports and variables - unify string quotes (single quotes) - unify semicolon style (no semicolons) Acceptance criteria: - npm run lint passes - consistent code style - build succeeds Output after completion: promiseSTYLE_UNIFIED/promise --max-iterations 20 --completion-promise STYLE_UNIFIED真实案例据原文档记载一个著名案例发生在 Y Combinator 的一次黑客松上一支团队使用了 Ralph Loop。晚上 23 点他们设定任务按顺序实现 6 份产品规格的 MVP并为每个 MVP 输出特定的完成标记。他们把最大迭代次数设为 200然后去睡觉。第二天早上他们得到了 6 个可演示的项目而 API 成本仅为 297 美元。这就是 Ralph 的力量你睡觉的时候AI 在继续工作。另一个案例来自 Boris ChernyClaude Code 负责人。使用 Ralph Opus 4.5他在 30 天内交付了 259 个 PR包含 497 个提交新增 40 000 行代码、删除 38 000 行代码。更惊人的是这一切都由 Claude Code 完成没有手写一行代码。更夸张的案例是CURSED 编程语言。Ralph 的创造者 Geoffrey Huntley 用 Ralph Loop 花了 3 个月自主构建了一门完整的编程语言。它的关键字使用 Z 世代俚语如slay、sus、based更重要的是它包含完整的 LLVM 编译器实现、标准库和部分编辑器支持。这展示了 Ralph Loop 的真正潜力只要你提供清晰的目标它可以持续工作数月直到一个复杂项目真正完成。更多实战案例自动化项目重构据文档记载一位开发者用 Ralph 重构了一个代码混乱、没有测试、缺少文档的遗留项目。分配的任务是为现有代码添加测试逐步重构确保每次改动后测试通过更新文档。Ralph 跑了一整个周末。周一早上仓库里多了 47 个提交代码结构更干净测试覆盖率达到 75%API 文档完整。成本约为 12 美元。Ralph 的哲学Ralph 体现了三条核心哲学迭代而非完美不要指望一次通过就完美用循环来改进。第一轮可能只搭出骨架第二轮修 bug第三轮优化第四轮补测试——每一轮都在变好。失败即数据每次测试失败都是改进的机会不要害怕失败要从中学习。坚持不懈一直尝试直到成功。这就是 Ralph 精神。Ralph 适用与不适用场景知道 Ralph 适合什么有助于节省时间和成本。适合 Ralph 的场景有清晰完成标准、适合自动迭代的任务场景原因测试迁移目标框架明确可用测试通过来验证大型重构可以定义具体的重构规则框架迁移迁移成功可通过功能代码验证批量类型标注typecheck 通过即完成提升测试覆盖率覆盖率百分比是客观的文档生成API 文档可自动验证UI/UX 统一可定义具体的设计规则可复现的 bug 修复成功条件可测试不适合 Ralph 的场景需要人类判断或探索场景原因架构决策例如微服务 vs 单体需要权衡判断安全敏感代码漏洞可能很隐蔽难以自动检测需求模糊没有清晰完成标准探索性工作方向不断变化创意设计需要人类审美判断简单的一次性任务用 Ralph 属于杀鸡用牛刀决策清单问自己三个问题我能定义明确的完成标准吗如果不能不适合有客观验证手段吗测试/构建/typecheck如果没有不适合这个任务需要持续的人类反馈吗如果需要不适合。如果三个答案都是否就让 Ralph 跑起来。方法三增强版 Ralph这是社区对官方 Ralph 的改进实现原文档引用了 frankbria/ralph-claude-code 项目其 README 与配置示例见下文。它增加了更强的安全机制。新增功能双重退出条件官方 Ralph 只检查完成标记而增强版要求完成标记 显式EXIT_SIGNAL同时出现才停止。这意味着即使 Claude 输出了完成标记只要没有显式退出信号循环仍会继续做额外检查。限流默认 100 次/小时防止 bug 导致死循环时 API 账单失控可自行调整限制。智能熔断器如果系统连续 5 次检测到完成标记则强制停止防止罕见的循环无法正常终止的边界情况。实时仪表盘提供命令行仪表盘显示当前迭代次数、任务进度和预估成本。安装克隆安装git clone https://github.com/frankbria/ralph-claude-code.git cd ralph-claude-code ./install.sh安装脚本会自动配置所需文件和配置。使用使用分两步。先用ralph-setup初始化项目ralph-setup my-project这会在项目中创建所需的配置文件。然后用ralph loop启动循环ralph loop配置文件增强版 Ralph 使用.claude/ralph-config.json{ maxIterations: 50, rateLimitPerHour: 100, completionPromise: TASK_COMPLETE, exitSignal: EXIT_NOW, costAlertThresholds: [10, 50, 100] }各字段含义字段含义maxIterations最大循环次数rateLimitPerHour每小时执行上限completionPromise完成标记文本exitSignal显式退出信号costAlertThresholds预算告警级别方法四Agent Teams多智能体并行当任务足够大时单个 Claude 不够用需要团队协作。Agent Teams是一项高级能力允许多个 Claude 实例并行工作并通过共享任务清单和依赖关系进行协调。它适用于超大型项目。据文档记载在 Nicholas Carlini 的实验中16 个并行智能体在两周内产出了超过 100 000 行代码并构建了一个能编译 Linux 内核的 C 编译器。Agent Teams 更复杂本课程在下一节 「3.3 Agent Teams 多智能体协作」 中有详细讲解。方法五后台任务CtrlB这是一种简单便捷的非阻塞执行方法。基本操作用法很简单当 Claude 开始执行某个任务时按CtrlB把它推到后台。例如你说运行完整的测试套件。 Claude 开始执行。你按下CtrlBClaude 回应任务已推送到后台IDtask_abc123。 然后你可以继续说与此同时分析一下这个日志文件。 Claude 就可以在测试后台运行的同时分析日志。查看后台任务有多种方式查看后台任务使用/tasks列出所有任务包含任务 ID、状态和开始时间按CtrlT快速查看状态摘要也可以把后台任务调回前台实时查看输出。适用场景后台任务适合这些典型场景长时间测试完整测试套件可能要跑几十分钟后台模式避免阻塞大型项目构建构建流水线运行时你可以继续做其他工作批量文件操作如批量重命名、批量格式化任何你不想同步等待的事情。安全机制防止死循环任何自动化循环系统都必须包含保护措施否则可能失控。严格限制最基础的保护是设置--max-iterations最大循环次数。这是必须的——无论完成状态如何任务都在此上限停止防止无限 API 消耗。还可以加上时间限制例如 4 小时后自动停止。也可以设置预算告警在花费达到阈值时停止并通知例如 10 美元、50 美元、100 美元。智能检测可以增加死循环智能检测。例如检查最近的提交是否包含实质性变更if [ $(git diff HEAD~5 | wc -l) -eq 0 ]; then echo No substantive changes in the last 5 commits, possible loop exit 1 fi如果最近几次提交的 diff 极少说明系统可能卡住了应该停止并告警。成本告警在配置中设置成本告警阈值{ costAlertThresholds: [10, 50, 100], alertAction: pause_and_notify }当花费达到 10、50、100 美元时系统停止并通知由你决定是否继续。手动检查点对于重要任务加入手动检查点if [ $((iteration % 10)) -eq 0 ]; then read -p Completed $iteration iterations. Continue? (y/n) answer if [ $answer ! y ]; then break fi fi每 10 轮迭代暂停一次请求确认允许人类快速介入。实战构建用 Ralph Loop 搭建完整 BBS 论坛用一个完整示例展示 Ralph Loop 的力量从零构建一个 BBS 论坛系统包含用户认证、发帖、个人中心和后台管理。项目目标构建一个功能完整的 BBS 论坛系统包含用户端功能用户注册、登录、登出浏览帖子列表分页查看帖子详情发布新帖子评论功能个人中心查看自己的帖子、更新资料管理后台功能管理员登录用户管理封禁/解封帖子管理删除/置顶评论管理系统统计技术栈后端Node.js Express SQLite前端React React Router Axios认证JWT token样式Tailwind CSS准备工作首先安装 Ralph Wiggum 插件claude /plugins:add ralph-wiggum启动 Ralph Loop现在启动 Ralph Loop 构建整个项目/ralph-wiggum:ralph-loop Please build a complete BBS forum system from scratch using TDD. Project structure requirements: - backend/ directory: Express API server - frontend/ directory: React frontend app - both directories have their own tests Backend requirements: - use Express framework - SQLite storage (better-sqlite3) - JWT auth (jsonwebtoken bcrypt) - user table: id, username, password, email, role, createdAt - post table: id, title, content, authorId, category, pinned, createdAt - comment table: id, content, postId, authorId, createdAt Backend API endpoints: - POST /api/auth/register - user register - POST /api/auth/login - user login - GET /api/posts - get post list (pagination category filter) - GET /api/posts/:id - get post detail - POST /api/posts - create post (auth required) - PUT /api/posts/:id - edit post (author or admin) - DELETE /api/posts/:id - delete post (author or admin) - POST /api/posts/:id/comments - add comment (auth required) - GET /api/user/profile - get profile (auth required) - PUT /api/user/profile - update profile (auth required) - GET /api/admin/stats - admin statistics (admin only) - GET /api/admin/users - user list (admin only) - PUT /api/admin/users/:id/ban - ban user (admin only) Frontend page requirements: - /login - login page - /register - register page - / - home page (post list) - /post/:id - post detail - /new - publish post - /profile - profile center - /admin - admin panel (admin permission required) Admin panel features: - user management (view, ban, unban) - post management (view, delete, pin) - comment management (view, delete) - system statistics (user count, post count, comment count) TDD requirements: - write tests first, then implementation - each feature must have corresponding tests - backend uses Jest, API tests cover all endpoints - frontend uses Vitest, component tests cover major features - auth middleware must have tests Acceptance criteria: - npm test (backend) passes - npm test (frontend) passes - frontend starts and works correctly - backend API responds correctly - proper permission isolation between normal users and admin - code passes ESLint checks Output after completion: promiseBBS_SYSTEM_COMPLETE/promise --max-iterations 150 --completion-promise BBS_SYSTEM_COMPLETE预估耗时根据复杂度估算如果手工编码约 40–60 小时包括 schema 设计、认证系统、前后端集成和测试使用 Ralph Loop基础版核心功能约 3–5 小时完整版管理后台 测试约 6–10 小时进度监控Ralph Loop 运行期间可以从多个维度监控进度迭代次数Ralph 显示当前和最大迭代次数帮助估算剩余时间日志可以看到 Claude 正在做什么比如设计 schema、编写 API、构建组件、修 bug测试状态每次测试运行结果都会显示。通过的测试在增加、失败的测试在减少当失败开始下降时项目接近完成。完成后的验证Ralph 输出完成标记后手动验证一遍# 后端测试 cd backend npm test # 前端测试 cd frontend npm test # 启动后端 cd backend npm start # 启动前端另一个终端 cd frontend npm run dev【免费下载链接】easy-vibe vibe coding 101The first course for AI-native product builders.项目地址: https://gitcode.com/GitHub_Trending/ea/easy-vibe创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考