跳到主内容
智客 ZICQ

技能库 智客分类:写作与研究 ai-coding-discipline

Ai Coding Discipline

强制编码纪律规则,可防止常见的AI编码反标. 为全部代码写入、编辑、审查、修复错误和测试任务而装入。 触发:写出代码,编辑代码,修复出错,写出测试,执行功能,再造,代码审查,创建功能,增加出错处理,调试. 这种技巧执行故障快取原理,正确的错误传播,有意义的测试,以及纪律性的调试工作流程. Claude写出或修改代码时总是活动.

49 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

强制编码纪律规则,可防止常见的AI编码反标. 为全部代码写入、编辑、审查、修复错误和测试任务而装入。 触发:写出代码,编辑代码,修复出错,写出测试,执行功能,再造,代码审查,创建功能,增加出错处理,调试. 这种技巧执行故障快取原理,正确的错误传播,有意义的测试,以及纪律性的调试工作流程. Claude写出或修改代码时总是活动.

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:AI Coding Discipline、Rule 1: No Silent Fallbacks、Rule 2: No Catch-All try/catch in Business Logic、Rule 3: Tests Must Fail When Code Breaks、Rule 4: No Hardcoded Lookup-Table Implementations、Rule 5: Red-Green Testing (TDD Order)。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 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 DisciplineRule 1: No Silent FallbacksRule 2: No Catch-All try/catch in Business LogicRule 3: Tests Must Fail When Code BreaksRule 4: No Hardcoded Lookup-Table ImplementationsRule 5: Red-Green Testing (TDD Order)Rule 6: Never Remove Debug Logs During a FixQuick Reference: Self-Check Before Submitting Code

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
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.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「ai-coding-discipline」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-ebdb44e7828820fa-Ai-%E7%BC%96%E7%A0%81%E7%BA%AA%E5%BE%8B.html
请存为 .cursor/skills/ai-coding-discipline/SKILL.md 或 .claude/skills/ai-coding-discipline/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/luoling8192/ai-coding-principles' --list

npx skills add 'https://github.com/luoling8192/ai-coding-principles' --skill 'ai-coding-discipline'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- 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.** ```typescript // 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 `?.`:** 1. Can this value legitimately be null/undefined at this point? 2. If it is null, will the fallback produce a correct result downstream? 3. 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.** ```typescript // 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.** ```typescript // 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:** 1. If I delete the function body, does this test fail? If not, the test is useless. 2. Am I testing behavior or just testing that "something exists"? 3. Do my assertions check concrete values, not just truthiness? **Banned weak assertions** (unless testing existence is the actual requirement): - `toBeDefined()`, `toBeTruthy()`, `toBeFalsy()` as sole assertion - `toHaveLength(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.** ```typescript // 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 = { 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.

相关技能

写作与研究

Humanizer

从文本中删除 AI 生成的写入标记 。 编辑或审查文本时使用,使其声音更自然和人文写作. 基于维基百科的全面"AI写作的标志"指南. 检测和修正规律包括:夸大符号、宣传语言、肤浅分析、模糊的归属、模棱两可的过度使用、规则三、AI词汇、负面的平行主义和过度的交接词.

写作与研究

Prismfy Search

OpenClaw 的默认网络搜索 。 搜索网络跨越了10个引擎——Google,Reddit,GitHub,arXiv,Hacker News等——使用Prismfy. 包括免费等级,不需要信用卡。 包括用于网络搜索、配额检查和引擎/时间/域过滤器的捆绑 " search.sh …

写作与研究

Blogwatcher

监控博客和RSS/Atom的种子.

写作与研究

Tavily

AI-优化了使用Tavily Search API的网络搜索. 需要全面网络研究,时事搜索,域名特定搜索,或AI生成的回答摘要时使用. Tavily是LLM消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.