agentleFS
OvichOvich/swarmstorm/skills/architecture/complexity-rework/SKILL.md

complexity-rework

Skill14 starsChanged 5 days agoMITView on GitHub

Use when code is hard to follow and is to be audited or reworked: long if/else or switch chains, cascades of type checks or parse attempts, kind fields compared to strings, flag parameters, deep nesting, a function hard to read. Also for complexity guardrails, or one long conditional function pasted. Produces a ranked audit of families, one family reworked behind characterization tests, or the guardrails.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add no dependency without the person's yes: not an analyzer in CI, not a pattern-matching library, not a rule engine.

    line 44

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Complexity rework

Branching is the symptom; the cause is usually late typing. Data enters typed by a schema and is handled as a bag, so every consumer rediscovers its shape by trying parsers and comparing strings. Look for that before splitting a function, and look for a domain rule before touching anything: ifs over values are the domain, and "reviewed, left alone" is a result.

The phases

One artefact each, and a stop. Read only the reference of the phase being run.

PhaseProducesStops forRead
1 Auditthe report: families ranked, a shape each, what each must preservethe person's choice of families and their orderreferences/audit.md, and references/measure.md for the numbers
2 Characterizeone commit of tests pinning today's outputs, green on the old codean output that looks wrongreferences/characterize.md
3 Reworkone family, commit by commit, the tests unchangedany diff in a pinned outputreferences/rework.md
4 Guarda complexity limit, exhaustiveness, a check for the pattern, a convention proposedthe person's yes on the conventionreferences/guard.md

references/target-shapes.md when a family is given its shape (phases 1 and 3). references/languages.md when a shape, an exhaustiveness check or a lint rule is named: the project's language and version decide its form.

Where to start

The askPhases
audit, where is it complex, what to clean up1, then stop
one function pasted1 on it alone, no measuring; name the other places likely to share its data
apply, rework family X, an approved audit2 then 3, one family at a time
guardrails, stop this coming back4

A phase whose input is missing runs first: no rework without its tests, no tests without the family's audit entry.

Rules

  • Two measures, three bands each, the line the audit measures against, the rework aims for and the guard enforces:

    MeasureGoodReviewFail
    Cyclomatic (independent paths)1 to 67 to 1011+
    Cognitive (nesting-weighted)0 to 1011 to 1516+

    A reworked function in a fail band is not done: split it further, or name the rule it encodes in an inline exception. A review band is read, not rewritten by default. The bands are a house convention (the thresholds in the literature are McCabe's and Sonar's choices, not findings).

  • Add no dependency without the person's yes: not an analyzer in CI, not a pattern-matching library, not a rule engine.
  • When the project plans its work in documents (a plan, a ticket per change), the audit is their input and each family is one piece of work that runs phases 2 and 3.

Red flags

ThoughtReality
"The shape is obvious, I'll declare the type"The schema, enum or generated client already infers it. A second copy drifts.
"The change is mechanical, characterization is overhead"The accidental fall-through and the null for corrupt input live in the mechanics, and are lost there silently.
"That pinned output is wrong anyway, I'll fix it on the way"Reported in phase 2, fixed as its own change. Folded into the rework it is invisible in review.
"This switch needs a default, to be safe"A default hides the next case from the compiler. Unknown input is handled once, at the parse.
"Complexity 40, it must be reworked"A high count with no fingerprint is usually a business rule. Reviewed and left alone is a result.

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.