agentleFS
epamepam/ketcher/.agents/skills/split-component/SKILL.md

split-component

Skill927 starsChanged 2 days agoApache-2.0View on GitHub

Split a bloated React component file into multiple co-located files following Ketcher project conventions. Use when: a component file has grown too large; it mixes constants, utility functions, and subcomponents in one file; you want to improve maintainability by separating concerns. Produces: ComponentName.constants.ts, ComponentName.utils.ts, SubComponentName.tsx — all co-located flat in the same folder, with a barrel index.ts. A ComponentName.types.ts may be created for shared domain types, but component props interfaces always stay local to their component file.

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    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:

    Read the target file and categorise its top-level declarations:

    line 30
  2. Distinctive:

    Create a file only if it will contain at least one item:

    line 41
  3. Distinctive:

    Remove the extracted constants, utilities, and sub-components

    line 92
  4. Distinctive:

    Add imports from the new files

    line 93
  5. Very specific:

    Keep Props unexported unless it is used outside the folder

    line 95
  6. Very specific:

    Run npm run test:types and eslint (npx eslint <component folder>) on the component folder, and fix any issues found.

    line 99

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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

Split Component

Splits a large component file into multiple co-located files following Ketcher project conventions.

File Layout (Ketcher conventions)

ContentFileExample
Main componentComponentName.tsxColorPicker.tsx
ConstantsComponentName.constants.tsColorPicker.constants.ts
Utilities & helpersComponentName.utils.tsColorPicker.utils.ts
Sub-componentsSubComponentName.tsx (flat, sibling)ColorSlider.tsx
CSS moduleComponentName.module.lessColorPicker.module.less
Barrel exportindex.tsindex.ts
Shared domain typesComponentName.types.ts (optional)ColorPicker.types.ts
Props / interfacesStay local in the component file—

A .types.ts file may be created for types shared across multiple files in the folder (domain types, enums, utility types). Component props interfaces are NOT placed there — they live in the same file as the component that owns them.

Steps

1. Analyse the source file

Read the target file and categorise its top-level declarations:

  • Constants — module-level const values (arrays, numbers, strings)
  • Utilities — pure functions that contain no JSX and use no React hooks
  • Sub-components — functions/arrow functions that return JSX (other than the main component)
  • Shared domain types — types/enums used across multiple files in the folder → ComponentName.types.ts
  • Props interfaces — stay in place in their component file, do not move
  • Main component — stays in the original file

2. Create only the files that are needed

Create a file only if it will contain at least one item:

ComponentName.constants.ts

// license header

export const MY_CONSTANT = ...;
export const MY_ARRAY = [...];

ComponentName.utils.ts

// license header

import { MY_CONSTANT } from './ComponentName.constants'; // if needed

export function myHelper(...) { ... }
export function anotherHelper(...) { ... }

SubComponentName.tsx (one file per sub-component)

// license header

import { ... } from 'react';
import classes from './ParentComponent.module.less'; // reuses the parent CSS module

interface SubComponentNameProps { // interface stays local to this file
  ...
}

function SubComponentName({ ... }: SubComponentNameProps) {
  ...
}

export default SubComponentName;

index.ts

// license header

export { default } from './ComponentName';

4. Update the main file

  • Remove the extracted constants, utilities, and sub-components
  • Add imports from the new files
  • Merge split Props + CallProps into a single interface if they were separate
  • Keep Props unexported unless it is used outside the folder

5. Check for errors

Run npm run test:types and eslint (npx eslint <component folder>) on the component folder, and fix any issues found. Pay special attention to:

  • import type instead of import for type-only imports (@typescript-eslint/consistent-type-imports enforces it)

What NOT to do

  • ❌ Do not put component props interfaces in ComponentName.types.ts — props stay in their component file
  • ❌ Do not extract functions that use React hooks (useState, useCallback, etc.) into utils
  • ❌ Do not create a components/ sub-folder for simple sub-components — they live flat alongside the parent
  • ❌ Do not rename CSS classes or modify the .module.less file
  • ❌ Do not add export to props interfaces unless they are consumed outside the folder

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.