Skip to content
Book demo

Coding

Continuous code simplification

Find overly complex functions each night and propose simpler rewrites for human review.

code-qualitycomplexityrefactoringscheduledreadability

[ workflow / coding ]

Continuous code simplification

Complexity grows one condition at a time. Each night, Cosmos scores recently changed files for cognitive complexity, rewrites functions over the threshold with established simplification patterns, and opens a draft PR. A human reviewer adjusts or approves before merge so intent stays intact.

07 nodes

05 edges

Trigger[trigger]
Nightly schedule

Cron: 03:00 UTC

AI Agent step[scan]
Complexity scorer

Files changed in last 30 days

Decision

Score > threshold?

Yes
Bypass (already solved)[skip]
No action

All files within threshold

YES
AI Agent step[rewrite]
Simplification rewrite

Guard clauses · extraction · decomposition

AI Agent step[test]
Run test suite

Verify behavior unchanged

Output / Result[pr]
Open draft PR

Side-by-side score comparison

Workflow prompt

Paste this into Augment to reproduce the workflow end-to-end.

Cosmos, each night identify all functions modified in the past 30 days whose cognitive complexity score exceeds 15. For each, attempt a simplification rewrite using patterns such as early-return guard clauses, extracted helper functions, and loop decomposition. Verify behavior is unchanged by running the existing test suite against the rewrite. Open a draft PR per file with a side-by-side complexity score comparison and an explanation of each transformation applied. Do not merge automatically: flag for human review.