cohesive
npx machina-cli add skill recrsn/agent-skills/cohesive --openclawCheck the diff against origin/main, and review the changed code for cohesiveness.
Run git fetch origin to make sure git context is up-to-date.
Here is the list of files changed in this branch:
!git diff --name-only origin/main
For each changed file, read the full file and assess whether the modifications maintain or improve cohesion. Then execute refactors to fix any issues found.
What to look for
Single Responsibility violations
- Functions/methods that now handle multiple unrelated concerns after the change
- Classes that gained responsibilities outside their original purpose
- Modules that mix abstraction levels (e.g., business logic interleaved with I/O)
Misplaced code
- Logic added to a file/module where it doesn't conceptually belong
- Utility code inlined where it should live in a shared module (only if one already exists)
- Data transformations happening far from the data's source or consumer
Coupling introduced by the change
- New dependencies between modules that should be independent
- Functions that reach deep into other modules' internals
- Shared mutable state introduced across boundaries
Scattered related logic
- Related logic for a single feature spread across many files unnecessarily
- Duplicated logic that should be consolidated
- Related constants, types, or helpers that belong together but are separated
How to refactor
- Extract functions/methods when a block handles a distinct sub-task
- Move code to the module where it conceptually belongs
- Group related logic together within a file
- Consolidate duplicated logic into a single location
- Split files only when they clearly serve multiple unrelated purposes
Rules
- Only refactor code touched by the branch diff — do not reorganize unrelated code
- Preserve external behavior exactly; no functional changes
- Follow existing project conventions for file organization and naming
- Do not create new files unless a clear, existing organizational pattern calls for it
- Run the project's linter/formatter after refactoring if one is configured
Report at the end with a brief summary of refactors performed.
Source
git clone https://github.com/recrsn/agent-skills/blob/main/skills/cohesive/SKILL.mdView on GitHub Overview
This skill audits code changed in the current branch against origin/main to assess cohesion. It highlights single-responsibility violations, misplaced logic, and increased coupling, and guides targeted refactors to improve structure without changing external behavior.
How This Skill Works
It runs git fetch origin, lists changed files with git diff --name-only origin/main, and reads each modified file to judge cohesion. For issues found, it suggests and executes targeted refactors like extracting subroutines, relocating code to appropriate modules, and consolidating duplicate logic, all while preserving external behavior.
When to Use It
- When a PR touches multiple files and cohesion is unclear
- After a diff adds multiple responsibilities to a single module
- When utilities or helpers are scattered across files that should be shared
- If duplicated logic exists across touched files needing consolidation
- Before code review to ensure changes adhere to module boundaries and architecture
Quick Start
- Step 1: Run git fetch origin
- Step 2: Inspect changed files with git diff --name-only origin/main
- Step 3: For each changed file, read the full content, assess cohesion, and apply targeted refactors, then run linter/formatter
Best Practices
- Only refactor code touched by the diff; avoid unrelated changes
- Look for single-responsibility violations and misplaced logic
- Move logic to the module where it conceptually belongs
- Consolidate duplicated logic and related helpers
- Run the project's linter/formatter after refactoring
Example Use Cases
- Refactor a touched module to extract a distinct sub-task into a dedicated function
- Move I/O-related code out of business logic in a changed file
- Consolidate duplicate parsing logic into a shared utility
- Split a monolithic function into smaller, cohesive pieces within the diff path
- Unify similar constants and helpers that appear across changed files