@codepress/design-kit 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,15 +48,21 @@ needs nothing installed beforehand. Following it, the agent:
48
48
  5. Builds the kit once, checks what it captured, and opens the pull request
49
49
  with the counts, any gaps and a screenshot of one composed screen.
50
50
 
51
- No Storybook yet and you want one? Add a line to the prompt:
51
+ No Storybook yet and you want one? Ask for it on its own, before or after the
52
+ kit:
52
53
 
53
54
  ```text
54
- We don't have Storybook. Add it, with stories for our shared components
55
- covering their default, empty, loading, error and long-text states.
55
+ Set up Storybook in this repository, with stories for our components. Run
56
+ `npx --yes @codepress/design-kit storybook-guide` and follow what it prints.
57
+ Open one pull request and don't merge it.
56
58
  ```
57
59
 
58
- New stories are written for React. On another stack the agent captures your
59
- real pages and says so in the pull request.
60
+ `storybook-guide` prints a second skill. The agent installs Storybook 9 (8 for
61
+ older apps) without changing your React, Next.js or TypeScript versions,
62
+ writes a stories file next to each component covering every variant and the
63
+ empty, loading, error and long-text states, adds a tokens story, and lists
64
+ anything it skipped, with the reason. React with Vite or Next.js is supported
65
+ first; on another stack the agent says plainly what it did not try.
60
66
 
61
67
  Once the pull request merges, the daily workflow uploads the kit, and the
62
68
  `design-kit` skill it installed tells your agents to use it. Ask for a mockup
@@ -69,6 +75,77 @@ Mock up a Billing tab on our settings page, using the design kit.
69
75
  The agent fetches the newest kit, composes the screen from your real frame and
70
76
  components, and draws only what is new.
71
77
 
78
+ ## Keeping the kit in sync
79
+
80
+ Nothing needs re-running after setup.
81
+
82
+ - **It rebuilds itself, only when the UI changed.** The workflow `init`
83
+ wrote (`.github/workflows/design-kit.yml`) checks every day, and on demand
84
+ from "Run workflow" in the Actions tab or with
85
+ `gh workflow run design-kit.yml`. It builds only when a path in the
86
+ config's `watch` list changed since the newest kit's commit, and at least
87
+ every 75 days (`DESIGN_KIT_MAX_AGE_DAYS` in the workflow) so the kit never
88
+ expires. Any other day it stops after a few seconds, and the run's summary
89
+ says why it built or skipped. "Run workflow" with `force` builds anyway.
90
+ - **Kits are kept 90 days, and older ones deleted.** 90 days is the most a
91
+ public repository allows; a private one may raise `retention-days` in the
92
+ workflow to 400 (raise `DESIGN_KIT_MAX_AGE_DAYS` with it). After each
93
+ upload the workflow deletes the branch's older kits, so only the newest is
94
+ stored. A failed delete is a warning, never a failed run.
95
+ - **It captures what exists at that commit.** Every build captures the
96
+ stories and pages that exist at the commit it runs on. It never writes
97
+ stories, so a new component shows up in the kit once it has a story. With
98
+ `gaps.componentGlob` set, every component without one is listed in the
99
+ kit's `gaps.json`. The `design-kit` skill and `storybook-guide` ask agents
100
+ to add or update a component's story in the same pull request as the
101
+ component.
102
+ - **Agents always use the newest kit.** The installed `design-kit` skill
103
+ fetches the newest kit each time. When UI commits have landed since that
104
+ kit was built, the mockup's caption says so.
105
+ - **Re-run `init` only to start over** (`--force`). To pick up a new release
106
+ of this package, update the pinned version in the workflow
107
+ (`DESIGN_KIT_PACKAGE`); the "Run workflow" form's `package` input tries
108
+ another version for one run (and always builds).
109
+
110
+ ### What makes it rebuild: `watch`
111
+
112
+ `watch` in `design-kit.config.json` lists the folders and files, relative to
113
+ the repository root, whose change rebuilds the kit. `init` writes:
114
+
115
+ - the Storybook folder and the app's folder (when either is the repository
116
+ root, its UI folders such as `src`, `app` and `.storybook` and files such
117
+ as `package.json` and `tailwind.config.ts`, since watching the whole root
118
+ would rebuild on every commit);
119
+ - the workspace packages they depend on, directly or through each other,
120
+ since shared UI usually lives there in a monorepo;
121
+ - global styles and tokens at the root (`styles`, `tokens`, `theme`, a
122
+ Tailwind or PostCSS config);
123
+ - `design-kit.config.json` itself, the lockfile and the workflow.
124
+
125
+ A pages-only repository (no Storybook) gets the app's folder and its
126
+ workspace dependencies. Edit the list freely: add a folder the UI reads from
127
+ (fixtures, a shared assets package), or drop one that changes often without
128
+ changing what renders. Paths only, no globs. Without `watch`, any commit
129
+ rebuilds. The installed `design-kit` skill reads the same list when it counts
130
+ the UI commits since a kit, so its caption matches what triggers a rebuild.
131
+
132
+ ### Updating a setup made by an older version
133
+
134
+ An older workflow keeps working as it is. To switch to the one above, run:
135
+
136
+ ```bash
137
+ npx @codepress/design-kit@latest init --workflow-only --force
138
+ ```
139
+
140
+ It rewrites only `.github/workflows/design-kit.yml`, at the new pinned
141
+ version, and leaves the config, the skill and `AGENTS.md` alone. When the
142
+ config has no `watch` list, it prints the one `init` would write; paste it
143
+ into `design-kit.config.json`, or the kit rebuilds after any commit. If you
144
+ edited the old workflow, copy the new `check` and `cleanup` jobs, the `id:
145
+ upload` and `retention-days: 90` on the upload step, the build job's
146
+ `artifact-id` output and `DESIGN_KIT_MAX_AGE_DAYS` into it instead. To
147
+ refresh the skill as well, run `init --force`, which rewrites the config too.
148
+
72
149
  ## Set up in your repository
73
150
 
74
151
  `design-kit init` sets a kit up as one reviewable change. Run it in the
@@ -87,14 +164,18 @@ other), the package manager and lockfile, the dev or start script and the
87
164
  app's local URL, an existing Playwright, and whether the app switches to dark
88
165
  with a class or a `data-theme` attribute. Then it writes:
89
166
 
90
- - `design-kit.config.json`: the `stories` section when Storybook is found, a
91
- `pages` section with `TODO` selectors to fill in, and the `theme`.
92
- - `.github/workflows/design-kit.yml`: a daily build (and `workflow_dispatch`)
93
- on `ubuntu-latest`. It skips when there are no commits since the newest
94
- `design-kit` artifact's commit; otherwise it installs dependencies, this
95
- package at a pinned version and Chromium, builds Storybook and captures the
96
- stories, captures the pages once no `TODO` is left in the config, and
97
- uploads the `design-kit` artifact for 30 days. A run with nothing to
167
+ - `design-kit.config.json`: the `watch` list, the `stories` section when
168
+ Storybook is found, a `pages` section with `TODO` selectors to fill in, and
169
+ the `theme`.
170
+ - `.github/workflows/design-kit.yml`: a daily check (and `workflow_dispatch`)
171
+ on `ubuntu-latest`. A `check` job runs `design-kit ci-check`, which skips
172
+ when no `watch` path changed since the newest `design-kit` artifact's
173
+ commit and that kit is under 75 days old; otherwise the build installs
174
+ dependencies, this package at a pinned version and Chromium, builds
175
+ Storybook and captures the stories, captures the pages once no `TODO` is
176
+ left in the config, and uploads the `design-kit` artifact for 90 days. A
177
+ `cleanup` job, the only one allowed to delete artifacts, then runs
178
+ `design-kit ci-cleanup` to delete the branch's older kits. A run with nothing to
98
179
  capture yet (no stories, pages still `TODO`) ends with a warning and
99
180
  uploads nothing. The page capture gets
100
181
  `DESIGN_KIT_USERNAME` and `DESIGN_KIT_PASSWORD` from repository secrets for
@@ -163,7 +244,7 @@ needs no config.
163
244
 
164
245
  ### `stories`
165
246
 
166
- Captures every story of a Storybook 7 or 8 static build (any renderer). The
247
+ Captures every story of a Storybook 7, 8 or 9 static build (any renderer). The
167
248
  build comes from `--storybook-dir`, `storybookDir`, or `buildCommand`, which
168
249
  writes `staticDir`; without `staticDir`, `{out}` in the command names a
169
250
  temporary folder that is removed afterwards.
@@ -214,16 +295,34 @@ value>]` then replaces `slots`.
214
295
  ## Commands
215
296
 
216
297
  ```bash
217
- design-kit init [--root dir] [--dry-run] [--force]
298
+ design-kit init [--root dir] [--dry-run] [--force] [--workflow-only]
218
299
  design-kit capture stories [--config f] [--out dir] [--storybook-dir dir]
219
300
  [--only id,... | --only-file f] [--base previous-kit]
220
301
  design-kit capture pages [--config f] [--out dir] [--base-url url] [--only name,...]
221
302
  [--ready name=selector] [--screenshots dir] [--timeout ms]
222
303
  design-kit kit info|find|show|compose ... [--kit dir]
223
304
  design-kit validate [--config f]
305
+ design-kit ci-check [--config f] [--since sha --kit-created iso | --no-kit]
306
+ [--force] [--package spec] [--max-age-days n]
307
+ design-kit ci-cleanup --keep artifact-id
224
308
  design-kit setup-guide
309
+ design-kit storybook-guide
225
310
  ```
226
311
 
312
+ `ci-check` and `ci-cleanup` are the workflow's steps. `ci-check` finds the
313
+ newest unexpired `design-kit` artifact on the branch (through `gh`, from
314
+ `GITHUB_REPOSITORY` and `GITHUB_REF_NAME`, or `--repo` and `--branch`), or
315
+ takes it from `--since` and `--kit-created`. It fetches that commit (shallow,
316
+ no file contents) and compares the git tree or blob id of each `watch` path
317
+ there and at `HEAD`; a missing path is a value of its own, so a deleted path
318
+ counts as changed. It prints `build=true` or `build=false` and the reason
319
+ (`changed: src`, `watched files unchanged since 3f2a9c1`, `refresh before
320
+ expiry: …`, `no kit yet on this branch`, `forced …`, `an explicit package was
321
+ given …`) and writes them to `$GITHUB_OUTPUT` and the step summary. A kit
322
+ that cannot be looked up or fetched builds. `ci-cleanup` deletes the
323
+ branch's kits older than `--keep` and warns about any it could not delete;
324
+ both always exit 0 unless the config is invalid.
325
+
227
326
  `setup-guide` prints the agent skill for setting a kit up in a repository
228
327
  that has none, as one reviewable pull request: run `init`, decide between
229
328
  Storybook stories and page capture, wire sign-in through repository secrets,
@@ -231,6 +330,19 @@ build the kit once and report what it captured. An agent without the skill
231
330
  installed can run `npx --yes @codepress/design-kit setup-guide` and
232
331
  follow what it prints.
233
332
 
333
+ `storybook-guide` prints the agent skill for a repository with no Storybook,
334
+ or one with components that have no stories, as one reviewable pull request.
335
+ The agent surveys the components and tokens, installs Storybook 9 (8 for
336
+ older apps) pinned to the repository's React, Next.js and TypeScript, and fixes
337
+ the usual first-build failures: peer-dependency conflicts, modules that throw
338
+ on a missing environment variable, `next/font`, `next/image` and SVG imports,
339
+ and `public/` assets. It writes one stories file per component, covering
340
+ every variant and the empty, loading, error and long-text states, adds a
341
+ tokens story, and lists anything it skipped, with the reason. It typechecks,
342
+ builds Storybook and checks that `capture stories` captures it. An existing
343
+ Storybook is extended, never re-initialised. React with Vite or Next.js is
344
+ supported first. Run `npx --yes @codepress/design-kit storybook-guide`.
345
+
234
346
  `--only` re-captures just those stories (Storybook ids, with or without the
235
347
  `story:` prefix and width) and copies every other row from `--base`, byte for
236
348
  byte. The two captures share one kit folder and keep each other's files: run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codepress/design-kit",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Capture your Storybook and real app pages as a static design kit, and compose self-contained mockups from it",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,6 +21,16 @@
21
21
  "minLength": 1,
22
22
  "description": "Where captures write the kit when --out is not given."
23
23
  },
24
+ "watch": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string",
28
+ "minLength": 1,
29
+ "pattern": "^(?![/\\\\])(?!.*(^|/)\\.\\.(/|$))(?!.*[*?\\[])",
30
+ "description": "A folder or file, relative to the repository root (not to this file): no leading slash, no .., no glob."
31
+ },
32
+ "description": "The paths whose change rebuilds the kit in CI (`design-kit ci-check`), relative to the repository root. A run where none of them changed since the newest kit's commit builds nothing. Without it, any change in the repository rebuilds. `init` writes the Storybook and app folders, the workspace packages they use, global styles, this file, the lockfile and the workflow."
33
+ },
24
34
  "theme": { "$ref": "#/$defs/theme" },
25
35
  "stories": { "$ref": "#/$defs/stories" },
26
36
  "pages": { "$ref": "#/$defs/pages" }
@@ -66,7 +76,7 @@
66
76
  "stories": {
67
77
  "type": "object",
68
78
  "additionalProperties": false,
69
- "description": "`design-kit capture stories`: every story of a Storybook 7 or 8 static build.",
79
+ "description": "`design-kit capture stories`: every story of a Storybook 7, 8 or 9 static build.",
70
80
  "properties": {
71
81
  "root": {
72
82
  "type": "string",
@@ -28,11 +28,14 @@ npx --yes @codepress/design-kit init
28
28
  It detects Storybook and its version, the framework, the package manager, the
29
29
  dev script, Playwright and the dark-theme mechanism, then writes:
30
30
 
31
- - `design-kit.config.json`: the stories (when Storybook is found), a `pages`
32
- skeleton with `TODO` selectors, and the theme;
33
- - `.github/workflows/design-kit.yml`: a daily build (and manual dispatch) that
34
- skips when nothing was committed since the last kit, and uploads the
35
- `design-kit` artifact for 30 days;
31
+ - `design-kit.config.json`: the `watch` list (the UI folders, the workspace
32
+ packages the app uses, the lockfile and the workflow), the stories (when
33
+ Storybook is found), a `pages` skeleton with `TODO` selectors, and the
34
+ theme;
35
+ - `.github/workflows/design-kit.yml`: a daily check (and manual dispatch) that
36
+ builds only when a `watch` path changed since the last kit or that kit is 75
37
+ days old, uploads the `design-kit` artifact for 90 days and deletes the
38
+ older ones. Check the `watch` list covers every folder the UI renders from;
36
39
  - `.claude/skills/design-kit/SKILL.md` and `.agents/skills/design-kit`: how
37
40
  agents fetch the kit, compose mockups and caption them;
38
41
  - one line in `AGENTS.md` (or `CLAUDE.md`) pointing at that skill.
@@ -53,10 +56,11 @@ locally (step 3); a kit with pages has frames that new content can go into.
53
56
  **No Storybook.** Propose one of these to the person, through the Orchestrator
54
57
  when you work for one, in a short message with your recommendation:
55
58
 
56
- - (a) **add Storybook** with stories for the components the main screens use,
57
- covering their default, empty, loading, error and long-content states. For
58
- React with Vite or Next.js, `npx storybook@8 init` sets it up; write the
59
- stories next to the components;
59
+ - (a) **add Storybook** with stories for the components, covering their
60
+ default, empty, loading, error and long-content states: follow
61
+ `npx --yes @codepress/design-kit storybook-guide`, which installs a pinned
62
+ Storybook, writes a stories file next to each component, and adds the
63
+ `stories` section to the config `init` wrote;
60
64
  - (b) **capture real pages** from the dev server (step 3);
61
65
  - (c) **both**.
62
66
 
@@ -64,7 +68,7 @@ When nobody answers, do (b), plus (a) for components that are clearly reusable
64
68
  (buttons, inputs, cards, dialogs, tables that several screens share). Say in the
65
69
  pull request which you did and why.
66
70
 
67
- **Supported first:** Storybook 7 and 8 static builds of any renderer, page
71
+ **Supported first:** Storybook 7, 8 and 9 static builds of any renderer, page
68
72
  capture of any URL, and new stories for React only. For another stack (Vue,
69
73
  Svelte, Angular, an older Storybook), capture pages and say honestly in the
70
74
  pull request that new stories were not written, and why.