跳到正文
Skillpedia
通用编程6.5k · #14186

ub-mode

它能做什么

它为任何代码修改设定了一个简单的工作顺序:先让它能工作,再让它正确,然后遵循常见实践。适用于希望做出谨慎、最小化修改的开发者。

适用场景

  • ✓当开发者要求 AI 修改或添加代码,并希望步骤小且可测试时。
  • ✓当开发者希望 AI 在修改代码前先编写一个失败的测试时。
  • ✓当开发者希望 AI 在添加新功能前先降低复杂度时。

技能链接

https://github.com/unclebob/ub-mode/blob/master/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/unclebob/ub-mode/blob/master/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请做这个修改,但要保持简短,先测试,并避免增加额外的复杂度。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能设定了三个阶段:先用测试和最小的改动让修改能够工作,然后整理设计,最后遵循项目的常规做法。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

ub-mode

Every time you are asked to make a change follow:

  • First Make it Work.
  • Then Make it Right.
  • Follow Practice

First Make it Work

Laziness Protocol

  • One decision lives in one place.
  • Ship the smallest edit that solves the problem.

Foundational Thinking

  • Get the data shape right before you write the logic.
  • Do first whatever helps every later phase.
  • If a concurrent writer would matter, do not share state.

TDD

  • Write the failing test before you change the code.
  • See it fail for the reason you expect.
  • Make the smallest change that makes it pass.
  • If an honest test is impractical, do not write a bad one.

Redesign From First Principles

  • Do not bolt a new requirement onto the old design.
  • Ask what you would have built if it had been there from the start, think that through, and deliver it in pieces.

Attack the Premise

  • When two fixes that share one premise fail the same gate, write that premise in one sentence and count which actors hold the imbalance.
  • Remove the assignment.
  • Do not start another fix until you have done that.

Subtract Before You Add

  • Take complexity out before you add anything.

Outcome-Oriented Execution

  • Aim at the end state you can check.
  • A break in the middle is allowed when you planned it and can undo it.

Build the Lever

  • If the work is not obvious at a glance, build the tool that does it.
  • Do one unit by hand, then make the tool match that unit.

Architecture

Model the Domain

  • Put the domain in a structure that makes the illegal states impossible.
  • Maintain a glossary of domain terms.
  • If the code is already clear and local, leave it.

Boundary Discipline

  • Check the data where it enters.
  • Inside, trust it.
  • Keep the business logic in a pure function.

Type System Discipline

  • Make the illegal value impossible to write.
  • Parse outside data once, where it comes in.
  • Do not silence the compiler.

Make Operations Idempotent

  • Running it twice, or running it after a crash halfway through, ends in the same state.

Separate Before Serializing Shared State

  • If they do not need the same mutable thing, give each its own.
  • If they do, allow one writer, and enforce that in the structure.

Then Make it Right

Fix Root Causes

  • Reproduce it.
  • Fix the cause.
  • A guard that only hides the crash is not a fix.

Sequence work into verifiable units

  • Finish one small unit and check it.
  • Then start the next.

Test Behavior, Not Implementation

  • The test calls the code the way its user does and checks the result that user would see.
  • If the test would still pass when every function returned nothing, throw it out.

Crapper

  • Use the crapper tool
  • Reduce each function under CRAP 10 by splitting it, by testing it, or both.
  • Consider whether case statements are worth reducing.

Dryer

  • Use the dryer tool to eliminate duplication that rank 0.8 or above.

Mutator

  • Use the mutator tool
  • Cover the uncovered.
  • Kill the survivors.
  • Delete dead code.

Refactoring

  • Pin what the code does.
  • Change the structure.
  • Prove the behavior did not change.

Practice

Keep a Log

  • Keep a log of every action you take and the reason you took it.
  • Report that log upon completion.

Guard the Context Window

  • Keep the main thread small.
  • Send the bulk elsewhere, and keep the summary.

Worktree Cleanup

  • Find what is safe to remove, confirm nothing still in use needs it, then reclaim the disk.
  • Uncommitted work waits for a decision.

Commit and Push

  • Commit often, in small ordered commits.
  • Each commit says why, what changed, and how you proved it.
  • Push to the main line at the end.
常见问题

这里的先测试是什么意思?

该技能要求 AI 先编写一个因预期原因而失败的测试,然后做出能通过它的最小改动。

它要求重写吗?

不要求。它要求做最小的可用改动,并在添加更多内容之前先降低复杂度。

它面向谁?

希望对代码做出稳定且经过充分测试的修改的开发者。

详情

作者的原始描述

Follow the reduced principles when writing or changing code. Every change follows First Make it Work, then Then Make it Right, then Follow Practice. Use when the user runs /ub-mode or asks for the reduced principles.

repo: unclebob/ub-mode

热度

GitHub 星标
6.5k
排名
#14186
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

相似技能