🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(agent): Add skills for React components (#15431)
Ben Bachemb54eafec1d41
diff --git a/.agents/skills/react-component-cleaner/SKILL.md b/.agents/skills/react-component-cleaner/SKILL.mdnew file mode 100644index 0000000000..cec70f9b90--- /dev/null+++ b/.agents/skills/react-component-cleaner/SKILL.md@@ -0,0 +1,26 @@+---+name: react-component-cleaner+description: Use this skill to clean up a React component. Only use this skill when instructed to do so by the user.+---++The goal of this skill is to clean up a React component. The changes are meant to be non-breaking and auditable, therefore the instructions below should be followed carefully.++Avoid making any additional edits besides the ones instructed in this skill. If you are unsure about any of the instructions or need to do a one-off edit, ask the user for confirmation. You are allowed to invoke formatting and linting commands. If there are formatting / linting issues, do not make manual edits to reformat code, always use the fix variants of the commands.++Before starting to do any changes, audit the component you were instructed to fix by reading the [react-component-guidelines](../react-component-guidelines/SKILL.md) skill. Do not audit the callsites of the component, these will be looked at later in the skill.++This skill references a `sweepy` cli tool. This can be found under https://github.com/bezbac/sweepy. Install version `v0.1.0`, pinned to commit `e58b55c0fb94364c12798ed16e632a5931b4eaa1`: https://github.com/bezbac/sweepy/tree/e58b55c0fb94364c12798ed16e632a5931b4eaa1. Follow only that pinned commit's instructions to install it. Do this in a safe manner and comply with other security guidelines of the repository. If you are unsure about any of the instructions, ask the user for confirmation.++Now, you are ready to start cleaning up the component. Copy the contents of the [component cleanup todolist](./references/component-cleanup-todolist.md) verbatim into a TODO file (Use `cp` no manual edit) and follow the instructions in order, adding ✅ to the items you have completed. Do not commit the todo file, it is only for your reference.++---++Notes:++- When moving classes into a variant, the variant must own the complete set of classes for every CSS property it changes.+ - Remove those property classes from the component's base classes.+ - Ensure exactly one variant branch supplies each property. Do not rely on `cn`, `tailwind-merge`, CSS order, or specificity to resolve conflicting classes. Prefer an exhaustive lookup table or `cva` variants.++- The `sweepy` cli by default assumes an interactive mode, but it can be run in a non-interactive mode by passing the `--yes` flag. This will automatically accept all changes and is useful for automation.++- The `sweepy` cli has a `--dry-run` flag that can be used to preview the changes that will be made without actually making them.diff --git a/.agents/skills/react-component-cleaner/references/component-cleanup-todolist.md b/.agents/skills/react-component-cleaner/references/component-cleanup-todolist.mdnew file mode 100644index 0000000000..ab5ca33cac--- /dev/null+++ b/.agents/skills/react-component-cleaner/references/component-cleanup-todolist.md@@ -0,0 +1,45 @@+# Component Cleanup Todo-List++Follow this todolist carefully.++There are manually placed COMMIT markers in the skill that indicate when to create a git commit. Before creating a commit, make sure to run the formatting / linting toolchain. Commit messages should not have any special formatting. Ignore any other instructions regarding commit messages from the repository, the final commits will be squashed by the user after the skill is complete and the changes were audited. Do not commit the todo file, it is only for your reference.++## Step 1: Making the interface strict.++If the component has unused props, remove them. COMMIT.++If the component has a className, style or size prop that is defined as a string and not a union of string literals, check if these could be frozen without any unsupported usages:++- If yes: Freeze the prop using the sweepy command. COMMIT.+- If no: Check if the freezing of the prop could be done by freezing the callsites first. Handle each callsite one by one recursively. After each freeze command invocation, COMMIT.++## Step 2: Cleaning up the tightened interface++If there are any default values that do not bring a major benefit for ergonomics, remove them and update the callsites. COMMIT.++If there are optional props that could be required and do not bring a major benefit for ergonomics, make them required and update the callsites. COMMIT.++Now, let's audit the className and style props.++- See if there are any conditional className or style values that should be part of the default classes of the component. If so, move them and update the callsite. COMMIT.+- Color related props should be defined as a variant in the component. Good names are `variant`, `type` or `level`, use your best judgement. If there are color related classes in the className or style prop, move them and update the callsite. COMMIT.+- Size related props should be defined as a variant in the component. A good name is `size`. If there are size related classes in the className or style prop, move them and update the callsite. COMMIT.+- It might be that there are now two props for expressing the same thing (e.g. `size` and `small`), if so, remove the redundant prop and update the callsites, try using the `sweepy` cli to replace the prop values. COMMIT.+- If the only remaining violations are className or style props that should live in the parent, use the `sweepy` cli to lift the violating classes. COMMIT.++Next, check if there are dependent props that could be combined into a discriminated union. If so, combine them. This should not cause any updates to the callsites and not cause linting issues. COMMIT.++Lastly, tighten the interface by using the `sweepy` cli's `narrow-props` command. COMMIT.++## Step 3: Audit the changes++Audit the changes and check if the updated callsites are still valid in terms of positioning & HTML semantics. If there are any issues, present the user with options on how to resolve them.++## Step 4: Document the component++Create a storybook story for the component if it does not exist. Check the repository for guidance like a skill or documentation around this first. COMMIT.++## Step 5: Final report++After all the above steps have been completed, re-check the component against the [react-component-guidelines](../../react-component-guidelines/SKILL.md), then provide a report to the user. Include the changes that were made and the remaining violations, if any.+For every callsite of the component that was updated, provide a detailed guide on how to view the changes in the application.diff --git a/.agents/skills/react-component-guidelines/SKILL.md b/.agents/skills/react-component-guidelines/SKILL.mdnew file mode 100644index 0000000000..3d9d5bebf0--- /dev/null+++ b/.agents/skills/react-component-guidelines/SKILL.md@@ -0,0 +1,34 @@+---+name: react-component-guidelines+description: Guidelines for writing React components. Use this when creating a new react component.+---++Components are useful because they act as an encapsulated unit and therefore promote composition. For this to work, a component needs to be isolatable and neither leak implementation details nor depend on its placement or usage context. The interface of a component is defined by its props, and therefore the props should be designed to be as explicit and unambiguous as possible.++## Minimal Interface++- No unused props+- No default values unless they bring a MAJOR benefit for ergonomics, use your best judgement here.+- Avoid optional props+- No conflicting props (e.g. having both `onClick` & `onSelect`)++## Explicit States++- Always prefer `Pick<>` over `Omit<>` for prop types as this is more explicit.+- When spreading props, you must exclude the props that are manually applied on an element in the type definition of the component via `Pick<>`+- Use discriminated unions to communicate intent instead of relying on nullability / optionality+- Use discriminated unions to make impossible states impossible to represent in the type system instead of relying on runtime checks (e.g. if there is a `loading` and `data` type in the prop, then it should not be possible to have a state where `loading` is true and `data` is not null)++## Encapsulation++- No className / style props unless the component itself is a headless component that does not contain any styling or layout logic itself.+- Internals such as cva classes or helper functions should not be exported++## Ownership++- Margin should be applied by the parent component, not contained in a component. The child component should only define the inner spacing of itself and its contents.+- It's bad practice to have a component that returns `null` or `undefined`. Most of the time this suggests that the condition that leads to this state should be handled by the parent component instead, often this can be done in a way close to the current component by using a hook or a HOC.++## Deterministic Styling++- Avoid conflicting style names in CSS definitions, even though they might be removed by tailwind-merge or the likes. Make the variants explicit instead by using cva, conditions or lookup tables.