Coding principles

From xoai/sage · View interactive version

Coding principles is an AI agent skill from the GitHub repository xoai/sage. Use during implementation — loaded by build-loop before each task — whenever code is being written and should hold to universal quality standards, regardless of language or stack. Active while writing, not a post-hoc review checklist.

How to use this skill

Skill file

<!-- sage-metadata

cost-tier: sonnet

activation: auto

tags: [execution, quality, principles, coding, implementation]

inputs: [plan-task, codebase-context]

outputs: [implementation]

requires: []

-->

Coding Principles

Seven universal principles for writing production-quality code.

Apply these to every line, in every language. They are not a

post-hoc checklist — they shape decisions AS you write.

Stack skills (react, flutter, nextjs, etc.) add language-specific

idioms on top. These principles are the foundation.

Principle 1: Clarity Over Cleverness

Write code a stranger can read without asking you what it does.

Do:

MAX_RETRY_ATTEMPTS

says why it's surprising or non-obvious.

if (checkAccess(user, 2)).

Don't:

Principle 2: Fail Loudly, Recover Gracefully

Every external call can fail. Handle it explicitly. Never swallow

errors. Give the caller something useful when things go wrong.

Do:

do about it.

without all three.

stop).

Don't:

WHY.

Principle 3: Guard the Boundaries

Validate at every entry point. Don't trust input from users, APIs,

files, or even your own internal modules.

Do:

response?.data?.user?.id not response.data.user.id.

when the missing value is first accessed.

Don't:

Principle 4: Smallest Scope, Shortest Lifetime

Variables close to where they're used. Functions close to what

calls them. Reduce the blast radius of every change.

Do:

Don't:

"it's convenient."

Principle 5: Make the Right Thing Easy, the Wrong Thing Hard

Design APIs and interfaces so correct usage is obvious and misuse

requires effort.

Do:

non-nullable when null is invalid.

Don't:

Principle 6: Consistency Beats Perfection

Match the existing codebase. Consistency across the project matters

more than your personal preference.

Do:

Don't:

async/await in a third.

Principle 7: Test What Matters, Not What's Easy

Write tests that catch bugs, not tests that inflate coverage numbers.

Do:

Don't:

How This Loads

Build-loop loads this capability at Step 3, before each task:

Sage: Loading coding principles for implementation.
Following: clarity, error handling, boundary guards, minimal scope,
safe APIs, consistency, behavior testing.

These principles are active for every line written during the task.

They are NOT a post-hoc checklist — they shape the code as it's

written.

The announcement Loading coding principles for implementation. is the

compliance marker: it MUST appear before each task's implementation, making the

standard active and observable rather than assumed.

Rationalization table

Derived from the RED baseline in TESTS.md — the excuses for skipping the load

step and just coding. The marker must appear on every task, no size exception.

| The excuse (observed) | Why it's wrong | The rule |

|---|---|---|

| "It's a tiny change, principles don't matter." | Small changes are exactly where magic numbers and swallowed errors slip in unnoticed. | Principles load before every task — there is no size exception. |

| "I know clean code by heart." | The load isn't a reminder for you; it makes the standard active and observable for the task. | Announce and apply on every task, not only when you feel you need it. |

| "I'll clean it up in review." | Principles shape code as it's written; review only catches what shaping would have prevented. | They are a mindset during implementation, not a post-hoc checklist. |

| "The stack skill already covers quality." | Stack idioms sit on top of the universal foundation — they don't replace it. | Both apply; principles are the foundation. |

Relationship to Other Capabilities

idioms. Principles provide the universal foundation.

guides WHAT to test within that workflow.

Principles guide DURING implementation. Both are needed.

code is well-crafted regardless of spec compliance.

Rules

when explicitly justified.

(Principle 6).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.