ai-coding-discipline
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "ai-coding-discipline":https://skillpi.com/zh/skills/deepskill-774e6125298017f180bceeb7c2ea983f2d4acd66984e30705bc7c95504afc735。安装前核对上游来源和版本:https://github.com/luoling8192/ai-coding-principles。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
强制执行的编码规范规则,用于防止常见的 AI 编码反模式。必须在所有代码编写、编辑、审查、修复和测试任务中加载。触发场景包括:编写/编辑代码、修复缺陷、编写测试、实现功能、重构、代码审查、创建函数、添加错误处理、调试。该规则强制快速失败原则、正确的错误传播、有意义的测试以及规范的调试流程;只要 Claude 编写或修改代码,该规则始终激活。
介绍来源: third_party · luoling8192 · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: ai-coding-discipline
description: >
Mandatory coding discipline rules that prevent common AI coding anti-patterns.
MUST be loaded for ALL code writing, editing, reviewing, bug fixing, and testing tasks.
Trigger on: writing code, editing code, fixing bugs, writing tests, implementing features,
refactoring, code review, creating functions, adding error handling, debugging.
This skill enforces fail-fast principles, proper error propagation, meaningful tests,
and disciplined debugging workflows. Always active when Claude writes or modifies code.AI Coding Discipline
These rules override default AI coding tendencies. Follow them in ALL code you write or modify.
Rule 1: No Silent Fallbacks
Never use fallback values to mask data that should not be missing.
// FORBIDDEN — hides upstream bugs
const price = product?.price ?? 0;
const userName = user?.name || "Unknown";
// CORRECT — fail fast when data contract is violated
if (product.price == null) {
throw new Error(`Product ${product.id} is missing price`);
}
const price = product.price;
When fallbacks ARE acceptable:
- User-facing display with explicit design intent (e.g., avatar placeholder)
- Optional configuration with documented defaults
- External input parsing where absence is a valid state
Checklist before writing ??, ||, or ?.:
- Can this value legitimately be null/undefined at this point?
- If it is null, will the fallback produce a correct result downstream?
- Would a thrown error help me find a bug faster?
If the answer to #3 is yes, throw instead of falling back.
Rule 2: No Catch-All try/catch in Business Logic
Business logic functions must NOT wrap everything in try/catch. Let errors propagate naturally.
// FORBIDDEN — swallows all errors into a useless null
async function createOrder(data: OrderInput) {
try {
const user = await getUser(data.userId);
const coupon = await validateCoupon(data.couponCode);
const order = await saveOrder({ ...data, discount: coupon.value });
return order;
} catch (error) {
console.log('Error creating order:', error);
return null; // caller gets null, has no idea what failed
}
}
// CORRECT — let errors bubble up, catch at the boundary
async function createOrder(data: OrderInput) {
const user = await getUser(data.userId);
const coupon = await validateCoupon(data.couponCode);
const order = await saveOrder({ ...data, discount: coupon.value });
return order;
}
// Catch ONLY at the API/controller boundary
app.post('/orders', async (req, res) => {
try {
const order = await createOrder(req.body);
res.json(order);
} catch (error) {
logger.error('Order creation failed', { error, body: req.body });
res.status(500).json({ error: 'Order creation failed' });
}
});
Where try/catch IS appropriate:
- API route handlers / controller boundaries
- Top-level event handlers (message queues, cron jobs)
- Operations where partial failure is expected and recovery is defined (e.g., batch processing with per-item error handling)
- Specific, named error types you intend to handle differently
Never catch Error just to return null, undefined, false, or an empty object.
Rule 3: Tests Must Fail When Code Breaks
Every test must verify specific business outcomes. A test that passes when the core logic is deleted is worthless.
// FORBIDDEN — passes even if processOrder returns garbage
test('should process order', async () => {
const result = await processOrder(mockOrder);
expect(result).toBeDefined();
});
// CORRECT — verifies exact business behavior
test('should calculate total with 10% discount', async () => {
const result = await processOrder({
...mockOrder,
discount: 0.1,
});
expect(result.totalAmount).toBe(900); // 1000 * 0.9
expect(result.discountAmount).toBe(100);
expect(result.status).toBe('confirmed');
});
Test quality checklist:
- If I delete the function body, does this test fail? If not, the test is useless.
- Am I testing behavior or just testing that "something exists"?
- Do my assertions check concrete values, not just truthiness?
Banned weak assertions (unless testing existence is the actual requirement):
toBeDefined(),toBeTruthy(),toBeFalsy()as sole assertiontoHaveLength(expect.any(Number))expect(result).not.toBeNull()without further value checks
Rule 4: No Hardcoded Lookup-Table Implementations
Never implement business logic by hardcoding return values that match test cases.
// FORBIDDEN — fake implementation that "fits" the tests
function calculateDiscount(amount: number, level: string): number {
if (amount === 1000 && level === 'gold') return 100;
if (amount === 500 && level === 'silver') return 25;
return 0;
}
// CORRECT — real logic
function calculateDiscount(amount: number, level: string): number {
const rates: Record<string, number> = { gold: 0.1, silver: 0.05, bronze: 0.02 };
const rate = rates[level] ?? 0;
return amount * rate;
}
How to prevent this:
- Use diverse test data: multiple amounts, edge cases, boundary values
- Add property-based / fuzzy tests where appropriate
- Test with values NOT in the original spec to catch lookup-table fakes
Rule 5: Red-Green Testing (TDD Order)
When fixing a bug, always write the failing test FIRST, then fix the code.
Correct order:
1. Discover bug
2. Write a test that reproduces the bug
3. Run the test — confirm it FAILS (red)
4. Fix the code
5. Run the test — confirm it PASSES (green)
Why this matters: If you fix the code first and then write a test, you can never be sure the test would have caught the bug. The test might pass for the wrong reason.
Never skip step 3. Seeing the test go from red to green is the proof that the test is valid.
Rule 6: Never Remove Debug Logs During a Fix
When debugging, debug logs are removed ONLY after the human confirms the fix works.
FORBIDDEN workflow:
1. Human asks to add debug logs
2. AI adds logs
3. Human runs code, shares log output
4. AI "finds the problem", applies fix AND removes debug logs in the same edit
5. Fix doesn't work — logs are gone, must re-add them
CORRECT workflow:
1. Human asks to add debug logs
2. AI adds logs
3. Human runs code, shares log output
4. AI applies fix ONLY — debug logs stay untouched
5. Human verifies the fix
6. Human decides when to remove debug logs (or asks AI to remove them)
Rule: Never touch debug/diagnostic logs in the same commit as a fix. They are separate concerns.
Quick Reference: Self-Check Before Submitting Code
Before finalizing any code change, run through this checklist:
| Check | Question |
|---|---|
| Fallbacks | Did I use ?? or \|\| to hide a value that should never be missing? |
| Error handling | Did I add try/catch in business logic that should just let errors propagate? |
| Test strength | Would my tests still pass if I deleted the implementation? |
| Test honesty | Did I hardcode values to match test cases instead of implementing real logic? |
| TDD order | For bug fixes: did I see the test fail before applying the fix? |
| Debug logs | Am I removing diagnostic logs in the same change as the fix? |
If any answer is "yes", revise before proceeding.
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 AI 编码规范强制执行能力,解决常见反模式问题
- 适用于代码编写、编辑、审查、测试等多个高频开发场景
- 显著提升代码质量与调试效率
亮点
- 触发场景描述完整且边界清晰
- 覆盖多种代码相关任务变体
- 无歧义或重叠风险
亮点
- 6条核心规则结构清晰完整
- 每条规则包含禁止示例、正确示例和检查清单
- Quick Reference清单便于快速自查
亮点
- 纯文档型Skill无外部依赖风险
- 所有代码示例语法正确且逻辑严密
- Rule 6明确禁止在修复时移除调试日志,确保调试可靠性
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。