agentleFS
rikvanrielrikvanriel/code-hygiene/skills/code-structure/SKILL.md

code-structure

Skill2 starsChanged 56 days agoMITView on GitHub

Use when a function is too long, nests too deep, or mixes themes. Extracts helpers that earn their names.

16 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 16 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If split introduced a dep chain, order: preparatory helper before patch that needs it, or split to separate commit with "No change in …

    line 21
  2. Distinctive:

    When a hunk unrelated to patch's purpose rides along, split it out: "this doesn't affect any functionality before nor after the core of …

    line 22
  3. Distinctive:

    If series grows a function across patches without anyone acting because "already long before this patch", that series still owns growth — …

    line 28
  4. Very specific:

    Prefer intent-revealing local name over generic tmp, ret2.

    line 41
  5. Very specific:

    Run: git log --oneline -- <file> | head -n 20 + grep same file for sister pattern.

    line 51

“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Structure

<!-- GC-40 --> Prefer minimal obvious fix. Do not duplicate to rename; rename is its own change when safe.

GC-41 — Extract by logical theme, helper has intent name

  • One helper = one theme. Name by what it means, not how it's implemented.
  • If split introduced a dep chain, order: preparatory helper before patch that needs it, or split to separate commit with "No change in behavior" or "Prepare for..." if upstream allows preparatory trailers.
  • When a hunk unrelated to patch's purpose rides along, split it out: "this doesn't affect any functionality before nor after the core of this patch" — separate commit.

GC-42 — Function length signal (not hard gate)

  • Aim: majority functions ≤20 lines. Hard smell: >40 lines → examine for extractable logical pieces.
  • Size alone doesn't reveal seam; look for: mechanical conversion vs behavioral change; moved unchanged vs rewritten; case already correct just needing result reported differently vs genuinely new algorithm; helper extracted vs its first caller.
  • If series grows a function across patches without anyone acting because "already long before this patch", that series still owns growth — extract at point of addition, not retrofit later (retrofit forces re-derivation of every later patch and introduces resolution errors).

GC-43 — Guard early return over goto-ladder, bare {} scoping

  • Flatten via early returns. Exception: real cleanup path that goto out; genuinely unifies — keep when saves duplication.
  • Bare {} blocks to limit scope → declare at function top instead, or extract helper.

GC-44 — Predicate bools should_ / is_ / has_ / can_ / needs_ / try_

static bool helper that only tests state (even with guard flag) should use should_/is_/etc, not action verbs like drain/claim/flush/schedule. Bad: bool flush_cache(), Good: bool should_flush_cache().

GC-45 — Locals naming, MIN macro over ternary

  • Prefer intent-revealing local name over generic tmp, ret2.
  • Clamp → use language's min/MIN/clamp macro or stdlib, not hand-rolled ternary. Avoids future bugs.

GC-46 — Ownership + caller clear, bool ownership intent explicit

  • Who allocates → who frees? If ownership transfers, comment at transfer point and at definition, not just at call site.
  • Functions that conditionally take ownership use name + bool/param that makes intent obvious, or separate try/ensure helpers.

GC-47 — When in doubt, check existing codebase style first

Run: git log --oneline -- <file> | head -n 20 + grep same file for sister pattern. Match whatever codebase already does over "textbook ideal".

GC-48 — One literal, one home

When the same list, path set, or magic value appears in two or more places, hoist it to a single named definition and reference it. Duplicated literals diverge silently — copies added to one site but not the others, with no gate complaining. Applies to data (paths, IDs, thresholds), not just logic; if two copies cannot share a definition, that is a seam worth naming, not an excuse for two copies.

Related — what belongs elsewhere

  • Security invariants in comment: see comment-quality GC-22.
  • Numbers/perf deltas: see factual-integrity.
  • Multi-file splitting and bisectable units: see change-splitting GC-30..GC-35.
  • Strict-project worked example: references/kernel-style-as-example.md.

Verification checklist

  • Every new function has one theme + intent name.
  • Bool helper is predicate-named (GC-44) or renamed in same commit.
  • No bare {} block unless justified.
  • Function >40 lines: seams named + reason to keep together if not split.
  • Early return flattened where possible, goto kept only when cleanup truly unified.
  • No hand-rolled a < b ? a : b.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.