cf-cognitive
Skill1 starsChanged 27 days agoMITView on GitHub
Find or refactor local source-file cognitive complexity hotspots while preserving behavior. Use when a function or file is hard to read or reason about — overloaded functions, deep nesting, tangled branching, local readability pressure — with or without explicit file targets. Not for refactors or cleanups spanning several modules or the whole repository (cf-architecture).
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- cf-architectureSkill
- cf-brainstormSkill
- cf-cleanSkill
- cf-deadcodeSkill
- cf-docsSkill
- cf-mr-wolfSkill
- cf-placementSkill
- cf-scenarioSkill
- cf-testSkill
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
- Distinctive: line 28
Deferred: after execution only, per the report/action rule.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
Find or reduce cognitive complexity in local source files while preserving behavior.
Route elsewhere instead of working here, and when routing do not edit files: cf-placement for extracting responsibilities from one file into new files or regrouping related files; cf-architecture for module boundaries, ownership moves, or moving code into another package or module, even when the request names the destination.
Measure before judging: run a command that measures, for every function in the files in scope, its logical lines and its deepest nesting of control blocks, and prints the functions ranked by nesting then length, at most 30. Build it on a parser the project already has, in its dependencies or in the language's standard library. Count nesting as the control blocks inside a function — every if, loop, switch, select, or try, including one that only guards a break or return; an else if continues its chain and adds no level; a third nested block fires the trigger. Read references/navigation-cost.md for the thresholds, the named exemptions that allow keep as-is past a threshold, the file-length verdict, and the report/action rule.
- Discovery (no file named): run the measure over the source files of the area, rank functions by nesting then length, and report a shortlist of at most three with file, line, and the trigger each fires.
- Evaluation (a file named, asked whether it is worth cleaning): classify it
recommended,optional,keep as-is, orroute, naming the exemption when a trigger fires and the verdict is notrecommended; for a long function, say what the four tests of Execution would extract, or which test keeps it whole; give the file-length verdict. Execution (asked to reduce, refactor, or fix): when no function in the file fires the nesting trigger or passes 20 logical lines, edit nothing: report the measures and what could still change, and stop. Otherwise stay inside the file, do not create files or move responsibilities to shared utilities. Flatten the main path first (guard clauses, early returns). Then shape the code top-down with four tests:
- level: the function that orchestrates a behavior reads as a list of steps at one level of abstraction; what sits below that level moves to named functions placed below it in call order, as long as the caller can be read without opening them (when it cannot, the two are conjoined and stay together).
- owner: when state outlives a single step, because callbacks, threads, or later calls read and change it (flags, timers, handles, a running process), give it one named owner that hides it. Write its release once, next to where it is acquired, so that every exit path reaches it, errors included; use the form the language and the repository use for that: a destructor or drop guard,
defer, awith,using, or try-with-resources block, or astopoperation called from the cleanup of a lifecycle callback (a UI effect, a test fixture, a request handler). The orchestration still reads how the behavior starts and how it stops. Do not hand the whole lifecycle to the owner as one call, and do not leave the state in the orchestration. Locals that one step builds and returns need no owner. - pure core: a computation that only uses its inputs leaves the code that touches the outside world (timers, I/O, state, framework calls) as a named pure function; the call stays where it is and receives the computed value.
- consistency: shape every extraction with the forms the file and the repository already use (how they declare inner and top-level functions, how they build stateful owners, how they name) before choosing a form of your own. When a repository form and the call order of level clash, keep the repository form; the orchestration already gives the top-down reading.
A long function that passes all four tests stays as it is. Run the tests that cover the file with the repository's test runner, then measure again.
Output Format
Return only:
- Assessment: shortlist, classification, or the functions addressed, with the measures before and after; after execution, each unit extracted or kept whole with the test that decided it.
- Checks: commands run and results; the test command and its result, or
tests not runwith the reason. - Defects: behavior defects noticed against the code's documented rules, with file and line, or
nonenaming what you checked against. - Deferred: after execution only, per the report/action rule.
- Result: behavior preservation claimed only when the tests passed; next step when a route applies.
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
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.

