Skip to content

Commit 0e5809b

Browse files
authored
Merge pull request #55 from Robomous/feat/23-component-development-skill
feat: add the robomous-component-development agent skill (#23)
2 parents ddc2da6 + 20e1eb8 commit 0e5809b

7 files changed

Lines changed: 296 additions & 2 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
name: robomous-component-development
3+
description: Builds or changes a component of @robomous/ui-core, from requirement to a verified, documented, exported part. Covers deciding whether a new component is needed at all, choosing its foundation (reuse, compose, native HTML, Radix/Base UI/cmdk/vaul, UI SDK, custom), anatomy and data-slot, the public API, semantic tokens, accessible interaction, behaviour tests, the docs page and demos, and the verification commands. Use whenever a task in this repository adds a component, a part, a prop or a variant, or changes how a component behaves or looks.
4+
---
5+
6+
# Build a Robomous component
7+
8+
Work through the steps in order. Each one links to the document that owns the rule. Read the
9+
linked section the first time you meet it; this file does not repeat it. Repository-wide rules are
10+
in [AGENTS.md](../../../AGENTS.md).
11+
12+
## 1. Pin down the requirement
13+
14+
- Restate the contract in a few lines: what the reader does, what they see, which states exist.
15+
- Find the GitHub issue. If there is none, or the task grows past it, say so and update or open
16+
one before you build. If you cannot read it, say so in your report and work from the task as
17+
given.
18+
- Name the APG pattern it follows, if it is interactive: <https://www.w3.org/WAI/ARIA/apg/patterns/>.
19+
20+
## 2. Look for what already exists
21+
22+
- Read `docs/generated/llms.txt`, then the reference of every component that sounds close
23+
(`docs/generated/components/<slug>.md`), including its *When not to use* and *Related*.
24+
- A prop or variant on an existing component beats a new component. A new component that
25+
duplicates one is a defect.
26+
27+
## 3. Decide whether composition is enough
28+
29+
Compose existing Robomous components when they cover the behaviour: SplitButton is Button,
30+
ButtonGroup and DropdownMenu. See [references/examples.md](references/examples.md).
31+
32+
## 4. Choose the foundation
33+
34+
Take the first rung of [ADR 0001, section 1](../../../docs/adr/0001-ui-sdk-adoption.md#1-the-order-in-which-a-component-chooses-its-foundation)
35+
that meets the contract: native HTML, then Radix, Base UI, cmdk or vaul, which are already
36+
installed and wrapped here. A component from the shadcn registry starts with
37+
`yes n | pnpm dlx shadcn@latest add <name> --yes`. Never reinstall an existing one. What the CLI
38+
writes is a draft: read the diff, check that the files it offered to overwrite are unchanged, run
39+
`pnpm format`, and adapt it in the steps below.
40+
41+
## 5. UI SDK only when the ADR allows it
42+
43+
Only when no primitive provides the behaviour ([ADR 0001, section 2](../../../docs/adr/0001-ui-sdk-adoption.md#2-when-ui-sdk-is-used)).
44+
Then use the `ui-sdk` skill, under the overrides in [AGENTS.md, *Agent skills*](../../../AGENTS.md#agent-skills).
45+
Interaction logic goes in `src/behaviors/<name>.ts`, presentation in `src/components/<name>.tsx`.
46+
Report the measurements in [ADR 0001, section 6](../../../docs/adr/0001-ui-sdk-adoption.md#6-how-adoption-is-judged).
47+
48+
## 6. Define the anatomy
49+
50+
- One file, `src/components/<name>.tsx`. One exported function per part, named
51+
`<Component><Part>`.
52+
- Every part renders a `data-slot` (`<name>`, `<name>-<part>`) and merges `className` last
53+
through `cn`. A part with no classes of its own, like Collapsible's, passes `className` through
54+
untouched.
55+
- Write the composition tree you will put on the docs page now. It keeps the parts honest.
56+
57+
## 7. Define the public API
58+
59+
- Match sibling components. Use the `variant` and `size` names that exist, and the
60+
controlled/uncontrolled pairs `value`/`defaultValue`/`onValueChange` and
61+
`open`/`defaultOpen`/`onOpenChange`.
62+
- Variants are a `cva` object with `defaultVariants`, and the variant function is exported.
63+
- Give every prop of your own a JSDoc comment, and the part one saying what it is for. Both feed
64+
the API tables and the agent docs.
65+
- The API table lists only props the part declares in its own type, and inherited props it gives
66+
a default in the destructuring (`ratio = 1`). A part that spreads everything documents nothing:
67+
declare or default the props a reader needs to see.
68+
- Spread the rest onto the element, typed from `React.ComponentProps<…>` or the primitive's props.
69+
An icon-only control requires its accessible name, as SplitButton requires `menuLabel`.
70+
71+
## 8. Paint with roles
72+
73+
Colour only through role utilities ([DESIGN, *Tokens*](../../../docs/DESIGN.md#tokens)). Write states
74+
with shadcn's variants, never the attribute a library emits
75+
([DESIGN, *State attributes*](../../../docs/DESIGN.md#state-attributes)). Check
76+
[DESIGN, *Status vocabulary*](../../../docs/DESIGN.md#status-vocabulary),
77+
[*Action hierarchy*](../../../docs/DESIGN.md#action-hierarchy) and
78+
[*Motion*](../../../docs/DESIGN.md#motion). Both themes must work through roles alone.
79+
80+
## 9. Make it accessible
81+
82+
Native semantics first, then the primitive's. Keyboard parity with the pointer, focus that stays
83+
visible and returns where it came from, names on every control, and state the component announces
84+
itself ([DESIGN, *Accessibility*](../../../docs/DESIGN.md#accessibility)). A `<button>` renders
85+
`type="button"` unless asked.
86+
87+
## 10. Test the behaviour
88+
89+
`tests/components/<name>.test.tsx`, or the file its group already uses. Query by role and name, and
90+
assert what a screen would lose: roles, names, `aria-*`, focus, and the outcome of every key and
91+
click the pattern defines. Cover both controlled and uncontrolled use. Never pin class strings
92+
([CONTRIBUTING, *Tests*](../../../docs/CONTRIBUTING.md#tests)).
93+
94+
## 11. Document it
95+
96+
- Export each part by name from `src/index.ts`, beside its group.
97+
- Add the page `examples/catalog/src/content/components/<name>.mdx`, with frontmatter `title`,
98+
`description`, `related`, `builtOn`, `whenToUse` and `whenNotToUse`. The last two are plain
99+
strings of one or two sentences, and `whenNotToUse` names the component to use instead.
100+
- Add demos in `examples/catalog/src/demos/<name>/`, one story per file: an overview, each variant
101+
and state, and a composition.
102+
- Add the slug to a group in `examples/catalog/src/lib/groups.ts`, and a row in
103+
`docs/components/README.md` (the component table; the root README has none).
104+
- A new component changes the component count written in prose. Find it with
105+
`grep -rniE "fifty-[a-z]+|[0-9]+ (react )?components" README.md src/index.ts docs/DESIGN.md docs/components examples/catalog/src/content`.
106+
Leave dated records (ADRs, baselines) as they are.
107+
- Copy the page's structure from a sibling (Usage, Composition, Examples, Guidelines,
108+
Accessibility). Only `Preview`, `Callout`, `Guidelines` and `Keyboard` may appear outside code
109+
fences.
110+
111+
## 12. Verify
112+
113+
Run, in this order, and fix before moving on. `docs:agents` comes before `pnpm test`, because
114+
the tests check that `docs/generated/` is current:
115+
116+
```
117+
pnpm format:check && pnpm lint
118+
pnpm build && pnpm docs:agents
119+
pnpm test && pnpm docs:check
120+
pnpm test:package # when exports, dependencies or styles.css changed
121+
```
122+
123+
Commit `docs/generated/`. Then walk [references/checklist.md](references/checklist.md) before you
124+
call the work done, and say in the PR which items do not apply and why. If you cannot open a
125+
browser for the light and dark check, say so instead of ticking it.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Checklist
2+
3+
Walk it before opening the PR. An item that does not apply gets a reason in the PR description, not
4+
silence. The rules behind each line live in the linked sections; this list only points at them.
5+
6+
## Foundation and API
7+
8+
- [ ] No existing component or variant already covered the need (step 2 of the skill).
9+
- [ ] The foundation is the first rung of
10+
[ADR 0001, section 1](../../../../docs/adr/0001-ui-sdk-adoption.md#1-the-order-in-which-a-component-chooses-its-foundation)
11+
that fits. If UI SDK was used, the PR reports the measurements of section 6.
12+
- [ ] Prop names, variant names and controlled/uncontrolled pairs match the sibling components.
13+
- [ ] Every prop of the component's own, and every part, has a JSDoc comment.
14+
- [ ] No UI SDK or other dependency type appears in an exported prop type.
15+
16+
## The adaptation checklist in DESIGN.md
17+
18+
[DESIGN, *Adding a component*](../../../../docs/DESIGN.md#adding-a-component), items 1–9:
19+
20+
- [ ] Behaviour from a primitive, wrapped; no floating surface hand-rolled from a `<div>`.
21+
- [ ] Colour only through roles. `pnpm lint` passes the colour-literal rule.
22+
- [ ] Geometry in the component, on the radius and spacing scales.
23+
- [ ] Icons from `lucide-react`, sized by the component.
24+
- [ ] `data-slot` on every part; `className` merged last through `cn`.
25+
- [ ] `type="button"`, no exit animation on a menu surface, status never a stroke on a container.
26+
- [ ] Exported by name from `src/index.ts`.
27+
- [ ] Behaviour test in `tests/components/`.
28+
- [ ] Docs page with demos, a row in `docs/components/README.md`, and a group in
29+
`examples/catalog/src/lib/groups.ts`.
30+
31+
## Accessibility
32+
33+
- [ ] Every control has an accessible name. Icon-only controls require one in the API.
34+
- [ ] Every key the APG pattern defines is implemented and tested.
35+
- [ ] Focus is visible, moves predictably, and returns to the trigger when a surface closes.
36+
- [ ] Disabled and invalid states are conveyed by attributes (`disabled`, `aria-invalid`), not
37+
colour alone.
38+
- [ ] Animated surfaces respect `prefers-reduced-motion`
39+
([DESIGN, *Motion*](../../../../docs/DESIGN.md#motion)).
40+
41+
## Definition of done
42+
43+
- [ ] Controlled and uncontrolled use are both tested, where both exist.
44+
- [ ] Light and dark themes checked in the docs site (`pnpm docs:dev`), or the PR says this could
45+
not be checked without a browser.
46+
- [ ] `docs/generated/` regenerated with `pnpm docs:agents` and committed.
47+
- [ ] `pnpm verify` passes, or each stage listed in step 12 of the skill does, in that order.
48+
- [ ] The component count written in prose is updated (step 11).
49+
- [ ] No unapproved breaking change. A removal or rename comes with `docs/MIGRATION-<version>.md`.
50+
- [ ] The issue is linked, and its acceptance criteria are checked off in the PR.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Two components to copy from
2+
3+
## Toggle: a primitive, wrapped
4+
5+
[`src/components/toggle.tsx`](../../../../src/components/toggle.tsx) is the smallest complete
6+
example of steps 4–8.
7+
8+
- **Foundation.** `Toggle as TogglePrimitive` from `radix-ui`. Radix owns `aria-pressed`, keyboard
9+
activation and the controlled/uncontrolled `pressed` / `defaultPressed` / `onPressedChange` pair,
10+
so the file writes none of it.
11+
- **API.** `React.ComponentProps<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>`.
12+
Everything Radix accepts passes through, plus `variant` and `size`, with their defaults in both
13+
`defaultVariants` and the destructuring. `toggleVariants` is exported, so ToggleGroup styles its
14+
items the same way.
15+
- **Anatomy.** One part, `data-slot="toggle"`, with `className` merged through
16+
`cn(toggleVariants({ variant, size, className }))`.
17+
- **Paint.** Roles only (`bg-muted`, `text-foreground`, `ring-ring/50`, `border-destructive`).
18+
`data-[state=on]:` is a bracket because shadcn's layer declares no variant for `on`, which is the
19+
exception [DESIGN, *State attributes*](../../../../docs/DESIGN.md#state-attributes) allows.
20+
- **Tests.** `tests/components/components.test.tsx`, *Toggle and ToggleGroup*: pressed state by role
21+
and `aria-pressed`, not by class.
22+
23+
## SplitButton: composition only
24+
25+
[`src/components/split-button.tsx`](../../../../src/components/split-button.tsx) shows step 3. It
26+
owns no behaviour at all.
27+
28+
- **Composition.** Button + ButtonGroup + DropdownMenu, imported as `./button.js` and the rest.
29+
Focus, the menu's keyboard and dismissal all come from those components, so they are already
30+
tested.
31+
- **API that encodes the design rules.** `variant` is narrowed to `default | secondary | outline`,
32+
because a destructive action hidden in a dropdown is a sharp edge
33+
([DESIGN, *Action hierarchy*](../../../../docs/DESIGN.md#action-hierarchy)). The icon-only
34+
trigger's name, `menuLabel`, is a **required** prop.
35+
- **JSDoc.** The function explains when to use it, and each prop of its own says what it is for.
36+
That text becomes the API table and the agent reference.
37+
- **Tests.** `tests/components/kit.test.tsx`, *SplitButton*: the primary action runs, and the menu
38+
opens from a trigger found by its accessible name.
39+
40+
## Where to look for the rest
41+
42+
- A controlled/uncontrolled pair implemented by hand: `src/components/search-input.tsx` (`value`,
43+
`defaultValue`, `onValueChange`).
44+
- A compound component with many parts and context: `src/components/sidebar.tsx`.
45+
- A page that follows the template closely: `examples/catalog/src/content/components/tabs.mdx`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.agents/skills/robomous-component-development

‎AGENTS.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Node 24 (`.nvmrc`), pnpm from `package.json#packageManager`. What each one does:
6363
([why the `yes n`](docs/CONTRIBUTING.md#adding-or-changing-a-component)). Never reinstall an
6464
existing component; answer every overwrite prompt no.
6565
3. Adapt it with the checklist in [DESIGN, *Adding a component*](docs/DESIGN.md#adding-a-component).
66-
It ends in an export from `src/index.ts`, a behaviour test, a docs page with demos and a README
67-
row.
66+
It ends in an export from `src/index.ts`, a behaviour test, a docs page with demos and a row in
67+
`docs/components/README.md`. The `robomous-component-development` skill walks the whole road.
6868
4. A caller who needs something new gets a prop or variant in the component, never a class string
6969
spread onto it from outside.
7070

@@ -121,6 +121,9 @@ any composite widget. Automated checks do not replace a keyboard and screen-read
121121
Project skills live in `.agents/skills/` (read by Codex). `.claude/skills/` links to the same
122122
directories for Claude Code.
123123

124+
- `robomous-component-development` walks an agent from a requirement to a verified, documented
125+
component: reuse, foundation, anatomy, API, tokens, accessibility, tests, docs and verification.
126+
Use it for any task that adds or changes a component.
124127
- `ui-sdk` is UI SDK's official skill, linked to the copy inside the installed `@ui-sdk/core`, so
125128
it always matches the pinned version. `pnpm skills:sync` re-links it after an upgrade, and
126129
`tests/docs/skills.test.ts` fails until you do. See

‎docs/CONTRIBUTING.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ demos and islands.
108108
Project skills for coding agents live in `.agents/skills/<name>/`, where Codex reads them.
109109
`.claude/skills/<name>` is a link to the same directory, for Claude Code.
110110

111+
**Skills of this repository** (`robomous-component-development`) are directories under
112+
`.agents/skills/`, written and reviewed like any other file. Each gets a relative link for Claude
113+
Code, `ln -s ../../.agents/skills/<name> .claude/skills/<name>`. `tests/docs/skills.test.ts` checks
114+
that every skill has its link, a `name` matching its directory, a description, and links that
115+
resolve. `pnpm skills:sync` leaves them alone; it only manages skills that come from packages.
116+
111117
**UI SDK's `ui-sdk` skill** is not copied into this repository. `@ui-sdk/core` ships a copy that
112118
matches its version, and the [`skills`](https://www.npmjs.com/package/skills) CLI links agents to
113119
it:

‎tests/docs/skills.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* `skills-lock.json`. There is no copy of the skill in this repository to drift.
77
* These tests hold the links and the lock to the installed package, so
88
* upgrading `@ui-sdk/core` without re-syncing (`pnpm skills:sync`) fails here.
9+
*
10+
* Skills written in this repository are directories in `.agents/skills/` with
11+
* a link in `.claude/skills/`; they are held to the shape agents discover them
12+
* by, and to links that resolve.
913
*/
1014
import fs from "node:fs";
1115
import path from "node:path";
@@ -14,6 +18,20 @@ import { describe, expect, it } from "vitest";
1418

1519
const REPO = path.resolve(import.meta.dirname, "..", "..");
1620
const packaged = path.join(REPO, "node_modules", "@ui-sdk", "core", "skills", "ui-sdk");
21+
const OWN_SKILLS = fs
22+
.readdirSync(path.join(REPO, ".agents", "skills"), { withFileTypes: true })
23+
.filter((entry) => entry.isDirectory() && !entry.isSymbolicLink())
24+
.map((entry) => entry.name)
25+
.sort();
26+
27+
/** GitHub's heading anchor for a Markdown heading. */
28+
function anchor(heading: string): string {
29+
return heading
30+
.trim()
31+
.toLowerCase()
32+
.replace(/[^\p{L}\p{N}\s-]/gu, "")
33+
.replace(/\s/g, "-");
34+
}
1735

1836
function json<T>(file: string): T {
1937
return JSON.parse(fs.readFileSync(path.join(REPO, file), "utf8")) as T;
@@ -43,3 +61,49 @@ describe("the ui-sdk agent skill", () => {
4361
expect(lock.skills["ui-sdk"]).toMatchObject({ source: "@ui-sdk/core", version: installed });
4462
});
4563
});
64+
65+
describe("the skills of this repository", () => {
66+
it("include the component development skill", () => {
67+
expect(OWN_SKILLS).toContain("robomous-component-development");
68+
});
69+
70+
it.each(OWN_SKILLS)("%s is discoverable by Codex and by Claude Code", (name) => {
71+
const dir = path.join(REPO, ".agents", "skills", name);
72+
const link = path.join(REPO, ".claude", "skills", name);
73+
expect(fs.lstatSync(link).isSymbolicLink(), `.claude/skills/${name} is a link`).toBe(true);
74+
expect(fs.realpathSync(link)).toBe(fs.realpathSync(dir));
75+
76+
const skill = fs.readFileSync(path.join(dir, "SKILL.md"), "utf8");
77+
const front = /^---\n([\s\S]*?)\n---\n/.exec(skill)?.[1] ?? "";
78+
expect(front).toMatch(new RegExp(`^name: ${name}$`, "m"));
79+
expect(front).toMatch(/^description: .{80,}$/m);
80+
});
81+
82+
it.each(OWN_SKILLS)("%s links only to files and headings that exist", (name) => {
83+
const dir = path.join(REPO, ".agents", "skills", name);
84+
const files = fs
85+
.readdirSync(dir, { recursive: true, withFileTypes: true })
86+
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
87+
.map((entry) => path.join(entry.parentPath, entry.name));
88+
const broken: string[] = [];
89+
for (const file of files) {
90+
const text = fs.readFileSync(file, "utf8");
91+
for (const [, target] of text.matchAll(/\]\(([^)]+)\)/g)) {
92+
if (/^(https?:|<|mailto:)/.test(target!)) continue;
93+
const [relative, hash] = target!.split("#");
94+
const resolved = relative ? path.resolve(path.dirname(file), relative) : file;
95+
if (!fs.existsSync(resolved)) {
96+
broken.push(`${path.relative(REPO, file)} → ${target}`);
97+
continue;
98+
}
99+
if (hash && fs.statSync(resolved).isFile()) {
100+
const headings = [...fs.readFileSync(resolved, "utf8").matchAll(/^#+ (.*)$/gm)];
101+
if (!headings.some(([, heading]) => anchor(heading!) === hash)) {
102+
broken.push(`${path.relative(REPO, file)} → ${target}`);
103+
}
104+
}
105+
}
106+
}
107+
expect(broken).toEqual([]);
108+
});
109+
});

0 commit comments

Comments
 (0)