Skip to content

Commit 81062a5

Browse files
committed
chore(ai): add storybook-sync skill for upstream change tracking
Add a Claude Code skill that analyzes upstream storybookjs/storybook commits and identifies changes needing sync to storybook-rsbuild. - Blobless git clone cache at ~/.cache/storybook-upstream/ - Automatic noise filtering (version bumps, merge commits) - Parallel subagent analysis for large commit ranges - Priority-based classification (high/medium/low/skip) - Markdown report generation with optional GitHub issue creation
1 parent 451d7f6 commit 81062a5

File tree

4 files changed

+446
-67
lines changed

4 files changed

+446
-67
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
name: storybook-sync
3+
internal: true
4+
description: Check and analyze upstream Storybook repository changes that may need to be synced to storybook-rsbuild. Use this skill whenever the user wants to check for upstream Storybook changes, review what's new in the official Storybook repo, identify changes needing sync, or compare storybook-rsbuild against the upstream. Activate for phrases like "check upstream", "sync check", "storybook changes", "need to sync", "what changed upstream", or any mention of tracking changes from storybookjs/storybook. Even casual mentions like "anything new in storybook?" should trigger this skill.
5+
---
6+
7+
# Storybook Upstream Sync Checker
8+
9+
Analyze recent changes in the official `storybookjs/storybook` repository and identify which ones may need to be synced to this `storybook-rsbuild` repo. The storybook-rsbuild project adapts Storybook's official builder and framework packages to work with Rsbuild, so when upstream changes builder-webpack5, builder-vite, or framework integrations, those changes may need to be reflected here.
10+
11+
## Upstream to Local Package Mapping
12+
13+
```plaintext
14+
+----------------------------------------+--------------------------------------+
15+
| Upstream (storybookjs/storybook) | Local (storybook-rsbuild) |
16+
+----------------------------------------+--------------------------------------+
17+
| code/builders/builder-webpack5 | packages/builder-rsbuild |
18+
| code/builders/builder-vite | packages/builder-rsbuild |
19+
| code/frameworks/react-vite | packages/framework-react |
20+
| code/frameworks/react-webpack5 | packages/framework-react |
21+
| code/frameworks/vue3-vite | packages/framework-vue3 |
22+
| code/frameworks/web-components-vite | packages/framework-web-components |
23+
| code/lib/core-webpack | packages/builder-rsbuild (prebundled)|
24+
+----------------------------------------+--------------------------------------+
25+
```
26+
27+
Both webpack5 and vite upstream variants are monitored because this repo borrows patterns from both.
28+
29+
## Upstream Commit History is Noisy
30+
31+
The Storybook repo uses a non-linear branching model with frequent merge commits and automated version bumps. The bundled script filters the most common noise automatically (version bump commits via `--invert-grep`, merge commits via `--no-merges`). Some noise may still slip through — NX upgrades, CI config, non-standard version bumps, reverts that cancel out.
32+
33+
**Always judge from the actual diff.** Storybook does not consistently follow conventional commits, so commit messages are unreliable for triage decisions.
34+
35+
## Sync Priority Criteria
36+
37+
**High** — sync soon:
38+
- Bug fixes in logic that was adapted into storybook-rsbuild
39+
- Security patches
40+
- API / type / interface changes (options, preset signatures, exports)
41+
- Breaking changes or deprecations
42+
43+
**Medium** — review and decide:
44+
- New features that could benefit storybook-rsbuild users
45+
- Significant refactoring of adapted code patterns
46+
- Performance improvements in shared logic
47+
48+
**Low** — nice to know:
49+
- Minor code quality improvements
50+
- Added error handling or edge-case guards
51+
- Test changes that reveal expected behavioral contracts
52+
53+
**Skip**:
54+
- Webpack/Vite internal plumbing with no Rsbuild parallel (e.g. webpack plugin hooks, Vite-specific HMR wiring, Vite module graph internals)
55+
- Documentation-only changes
56+
- CI/tooling changes internal to the Storybook repo
57+
- Changes to `storybook/internal/*` APIs (these arrive via the `storybook` npm dependency, not by manual sync)
58+
- Pure test file additions with no behavioral insight
59+
- Build system changes (NX, workspace config, import rewriting) that are specific to the Storybook monorepo structure
60+
61+
## Workflow
62+
63+
### 1. Preparation
64+
65+
Generate the report filename (anchored to system clock):
66+
```bash
67+
REPORT_NAME=$(bash <skill-dir>/scripts/fetch_upstream.sh --report-name)
68+
```
69+
70+
Determine the commit range from the user's request:
71+
- **Relative days**: "past 20 days", "last 30 days" → use `--days N`
72+
- **Absolute date range**: "since 2025-12-01", "Dec 1 to Dec 20" → use `--since` / `--until`
73+
- **Version tags**: "between v8.4.0 and v8.5.0" → use `--from` / `--to`
74+
- If unspecified, default to `--days 30`.
75+
76+
**Important**: For relative date ranges, always use `--days N`. The script reads the system clock to compute exact dates, avoiding date miscalculation.
77+
78+
### 2. Get commit summary and decide strategy
79+
80+
Fetch the commit list with diff line counts:
81+
82+
```bash
83+
bash <skill-dir>/scripts/fetch_upstream.sh --summary --days <N>
84+
```
85+
86+
Output: `HASH|DATE|AUTHOR|SUBJECT|LINES_ADDED+LINES_DELETED` (one per line, oldest first).
87+
88+
Based on the commit count:
89+
- **≤ 8 commits** → step 3a (direct analysis)
90+
- **> 8 commits** → step 3b (subagent analysis)
91+
92+
### 3a. Direct analysis (≤ 8 commits)
93+
94+
```bash
95+
bash <skill-dir>/scripts/fetch_upstream.sh --diff-all --days <N>
96+
```
97+
98+
For each commit in the output:
99+
1. **Read the diff** — this is the ground truth. Never skip a commit based on its message or file list alone.
100+
2. **Read the corresponding local source file** using the package mapping table above.
101+
3. **Classify** using the sync priority criteria above.
102+
4. **Check for revert chains** — if a commit and its revert both appear, check if the net effect is zero. If so, classify both as skip.
103+
104+
Then proceed to step 4.
105+
106+
### 3b. Subagent analysis (> 8 commits)
107+
108+
**Plan batches** using the `--summary` output:
109+
110+
1. Sum the total lines changed across all commits.
111+
2. Target 3–5 subagents. Calculate: `target_lines_per_batch = total_lines / batch_count`.
112+
3. Walk through the commit list in order. Accumulate commits into the current batch. When the accumulated lines exceed the target, start a new batch. Keep adjacent commits together when possible — they are often related.
113+
114+
**Spawn subagents** — one per batch. Launch all Agent calls in a single message without `run_in_background` so they execute in parallel as foreground calls. You will receive all results at once when they complete. Do NOT use `run_in_background`, do NOT `sleep` or poll.
115+
116+
Use this prompt template for each subagent (note `--no-fetch` — the primary agent already fetched in step 2):
117+
118+
```
119+
Analyze upstream Storybook commits for sync relevance to storybook-rsbuild.
120+
121+
storybook-rsbuild adapts Storybook's builder and framework packages for Rsbuild.
122+
When upstream changes their builder or framework code, those changes may need
123+
to be reflected in storybook-rsbuild.
124+
125+
Package mapping (upstream → local):
126+
code/builders/builder-webpack5 → packages/builder-rsbuild
127+
code/builders/builder-vite → packages/builder-rsbuild
128+
code/frameworks/react-vite → packages/framework-react
129+
code/frameworks/react-webpack5 → packages/framework-react
130+
code/frameworks/vue3-vite → packages/framework-vue3
131+
code/frameworks/web-components-vite → packages/framework-web-components
132+
code/lib/core-webpack → packages/builder-rsbuild (prebundled)
133+
134+
Steps:
135+
1. Run: bash <skill-dir>/scripts/fetch_upstream.sh --no-fetch --diff-all --hashes <COMMA_SEPARATED_HASHES>
136+
2. For each commit, read its diff carefully — this is the ground truth.
137+
Commit messages are often inaccurate; always judge from the actual diff.
138+
3. Read the corresponding local source file in storybook-rsbuild for comparison.
139+
4. Classify each commit and return the results in the exact format below.
140+
141+
Priority criteria:
142+
high — bug fix in adapted code, security patch, API/type change, breaking change
143+
medium — new feature worth adopting, significant refactoring of adapted patterns
144+
low — minor improvement, added error handling, test revealing behavioral contract
145+
skip — Vite/webpack internals with no Rsbuild parallel, docs, CI, storybook/internal API changes
146+
147+
Return format (one block per commit, separated by ---):
148+
149+
COMMIT: <full hash>
150+
PRIORITY: high|medium|low|skip
151+
UPSTREAM: <upstream package path, e.g. builders/builder-webpack5>
152+
LOCAL: <local package path, e.g. packages/builder-rsbuild>
153+
SUBJECT: <commit subject>
154+
DATE: <YYYY-MM-DD>
155+
AUTHOR: <author name>
156+
WHAT_CHANGED: <1-2 sentence summary of the actual code change>
157+
REASON: <why sync is needed, or why it can be skipped>
158+
KEY_FILES: <comma-separated list of relevant changed files>
159+
---
160+
```
161+
162+
**Aggregate results**: Collect all subagent responses. Group commits by priority level. For revert chains where both the original and revert appear, check if the net effect is zero — if so, move both to skip.
163+
164+
### 4. Write the report
165+
166+
Save to `$REPORT_NAME` in the project root.
167+
168+
```markdown
169+
# Storybook Upstream Sync Report
170+
171+
- **Range**: <range description>
172+
- **Generated**: YYYY-MM-DD
173+
- **Upstream branch**: next
174+
- **Commits scanned**: N (after filtering out version bumps and merges)
175+
- **Needs attention**: X (H high, M medium, L low)
176+
177+
---
178+
179+
## High Priority
180+
181+
### [`abcdef0`](https://github.com/storybookjs/storybook/commit/FULL_HASH) commit subject here
182+
- **Date**: YYYY-MM-DD | **Author**: name
183+
- **Upstream package**: builders/builder-webpack5
184+
- **Local package**: packages/builder-rsbuild
185+
- **What changed**: 1-2 sentence summary of the actual code change.
186+
- **Why sync**: Explanation of why this matters for storybook-rsbuild.
187+
- **Key files**: list of relevant changed files
188+
189+
---
190+
191+
## Medium Priority
192+
193+
(same format as High)
194+
195+
## Low Priority
196+
197+
(briefer format — one paragraph per commit is sufficient)
198+
199+
## Skipped
200+
201+
(bullet list: `short-hash` subject — reason for skipping)
202+
```
203+
204+
Commits within each priority section should be in chronological order (oldest first).
205+
206+
### 5. Offer to create an issue
207+
208+
After writing the report, ask the user if they want to publish it as a GitHub issue in this repository. If yes, create the issue using `gh`:
209+
210+
```bash
211+
gh issue create --title "<TITLE>" --body-file "$REPORT_NAME"
212+
```
213+
214+
**Title format**: `Storybook Sync: <range>` — where `<range>` matches the range used in the report. Examples:
215+
- Date range: `Storybook Sync: 2026-03-12 – 2026-04-11`
216+
- Version range: `Storybook Sync: v8.4.0 – v8.5.0`

0 commit comments

Comments
 (0)