@radicool/throughline 0.13.0 → 0.15.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.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/adapters/codex/AGENTS.md +11 -10
  3. package/adapters/codex/prompts/component-builder.md +107 -0
  4. package/adapters/codex/prompts/design-system-audit.md +20 -0
  5. package/adapters/codex/prompts/document-component.md +58 -0
  6. package/adapters/codex/prompts/repository-builder.md +14 -0
  7. package/adapters/codex/prompts/retrofit-planner.md +21 -1
  8. package/adapters/codex/prompts/storybook-chromatic-builder.md +84 -2
  9. package/adapters/cursor/.cursor/commands/document-component.md +58 -0
  10. package/adapters/cursor/.cursor/rules/component-builder.mdc +108 -1
  11. package/adapters/cursor/.cursor/rules/component-pipeline.mdc +1 -1
  12. package/adapters/cursor/.cursor/rules/design-system-audit.mdc +21 -1
  13. package/adapters/cursor/.cursor/rules/figma-environment-setup.mdc +1 -1
  14. package/adapters/cursor/.cursor/rules/icon-system-builder.mdc +1 -1
  15. package/adapters/cursor/.cursor/rules/repository-builder.mdc +15 -1
  16. package/adapters/cursor/.cursor/rules/retrofit-planner.mdc +22 -2
  17. package/adapters/cursor/.cursor/rules/storybook-chromatic-builder.mdc +85 -3
  18. package/adapters/cursor/.cursor/rules/token-builder.mdc +1 -1
  19. package/adapters/cursor/.cursor/rules/token-crosswalk-builder.mdc +1 -1
  20. package/adapters/cursor/.cursor/rules/token-sheet-builder.mdc +1 -1
  21. package/adapters/cursor/.cursor/rules/token-sync-layer.mdc +1 -1
  22. package/adapters/generic/AGENTS.md +11 -10
  23. package/adapters/generic/commands/document-component.md +58 -0
  24. package/adapters/generic/skills/component-builder/SKILL.md +107 -0
  25. package/adapters/generic/skills/design-system-audit/SKILL.md +20 -0
  26. package/adapters/generic/skills/repository-builder/SKILL.md +14 -0
  27. package/adapters/generic/skills/retrofit-planner/SKILL.md +21 -1
  28. package/adapters/generic/skills/storybook-chromatic-builder/SKILL.md +84 -2
  29. package/package.json +1 -1
  30. package/references/component-doc-archetypes.md +90 -0
  31. package/references/component-doc-schema.md +154 -0
  32. package/references/doc-card-builder.md +565 -0
  33. package/references/doc-writing-standard.md +144 -0
  34. package/references/figma-component-standards.md +63 -16
  35. package/references/guide-voice.md +96 -0
  36. package/references/manifest-schema.md +46 -6
  37. package/scripts/README.md +34 -0
  38. package/scripts/build-doc-card-builder.mjs +143 -0
  39. package/scripts/build-docs-digest.mjs +74 -0
  40. package/scripts/docs-check.mjs +117 -0
  41. package/scripts/docs-lint.mjs +163 -0
  42. package/scripts/install.mjs +13 -1
  43. package/scripts/lib/doc-card-plan.mjs +101 -0
  44. package/scripts/lib/doc-card-render.figma.js +371 -0
  45. package/scripts/lib/doc-record.mjs +54 -0
package/README.md CHANGED
@@ -51,7 +51,7 @@ Most teams aren't starting from a blank file — they have a mature codebase wit
51
51
 
52
52
  1. **Audit before anything changes.** `design-system-audit` sizes both sides of your system — it greps your codebase to measure the real color surface and inventories your Figma file with verified, per-class reads — then tells you how big the migration actually is and how semantic your system already is.
53
53
  2. **A crosswalk that guarantees nothing shifts.** `token-crosswalk-builder` maps every new token to its old Figma variable and old code value, then installs a `tokens:validate` gate that fails unless every resolved new value matches the old one (N/N). A zero-reference guard blocks removing an old token while any code still references it.
54
- 3. **A gated, reversible migration.** `retrofit-planner` walks the safe seven-phase sequence — audit → refine variables in place → rebind → sync → capture a visual baseline → retrofit the code → remove the old tokens — pausing for your confirmation between every phase, with an optional decision journal recording each call.
54
+ 3. **A gated, reversible migration.** `retrofit-planner` walks the safe seven-phase sequence — audit → refine variables in place → rebind → sync → capture a visual baseline → retrofit the code → adopt existing docs → remove the old tokens — pausing for your confirmation between every phase, with an optional decision journal recording each call.
55
55
 
56
56
  The payoff: your live product looks identical at every step, and you can prove it with a Chromatic baseline captured before the first change.
57
57
 
@@ -4,22 +4,23 @@ ThroughLine builds a design system end to end. Load the matching prompt for the
4
4
 
5
5
  ## ThroughLine skills
6
6
 
7
- - `component-builder` — Build a foundational set of Figma components — buttons, inputs, cards, badges, chips, modals, and more — as properly structured components with variant matrices (types, sizes, states) and icon/component/content slots, bound to the design system's tokens and styles. → load `prompts/component-builder.md`.
7
+ - `component-builder` — Build Figma components — buttons, inputs, cards, badges, chips, modals, and more — with variant matrices (types, sizes, states) and icon/component/content slots bound to the design system's tokens and styles. → load `prompts/component-builder.md`.
8
8
  - `component-pipeline` — Take a single new component from Figma to fully-built-and-storied code, end to end — build it in Figma, sync any new tokens it introduced, then build its code component and stories. → load `prompts/component-pipeline.md`.
9
- - `design-system-audit` — Measure a pre-existing design system before retrofitting it onto tokens — size the code-side color surface and inventory the existing Figma file with verified per-class reads, then compute how semantic the system already is so the retrofit is right-sized. → load `prompts/design-system-audit.md`.
9
+ - `design-system-audit` — Measure a pre-existing design system before retrofitting it onto tokens, so the retrofit is right-sized. → load `prompts/design-system-audit.md`.
10
10
  - `figma-environment-setup` — Set up the local working folder and connect Codex to Figma so the design-system skills can read and write variables, styles, and components. → load `prompts/figma-environment-setup.md`.
11
- - `icon-system-builder` — Build an icon system in Figma — a dedicated "Icons" page populated with the user's chosen icon library (Lucide, Material, or custom SVGs) as well-named, scalable components using the fastest, most-automated mechanism per library (for Lucide, batch-fetching the curated subset's official SVGs from the source repo and componentizing them hands-off; for Material, the official community file or importer plugin) rather than hand-generating icons or making the user copy components by hand. → load `prompts/icon-system-builder.md`.
12
- - `repository-builder` — Graduate the local design-system folder into a real monorepo — a pnpm + Turborepo workspace with packages for tokens and UI components and room for apps — and walk the user from a plain folder to local git to a GitHub remote with PRs and CI. → load `prompts/repository-builder.md`.
13
- - `retrofit-planner` — Orchestrate a full brownfield design-system retrofit end to end — audit, refine variables in place, rebind components, sync, capture a Chromatic baseline, retrofit the code with dual output, then remove the old tokens only after a zero-reference grep — with a human confirmation gate between every phase. → load `prompts/retrofit-planner.md`.
14
- - `storybook-chromatic-builder` — Stand up Storybook in the monorepo, build code components matching the Figma design system (consuming the synced tokens and implementing the captured slot contracts), generate stories for every component, set up Chromatic for visual regression testing, and wire Code Connect when the user's Figma plan supports it. → load `prompts/storybook-chromatic-builder.md`.
15
- - `token-builder` — Build a two-tier (primitive + semantic) design token system as Figma variables — color ramps, spacing, type scale, radius, shadows — with light/dark or brand modes. → load `prompts/token-builder.md`.
16
- - `token-crosswalk-builder` — Build the brownfield token crosswalk — a persistent three-way map between each new token, the old Figma variable, and the old code identifier(s) — as crosswalk.json, then install the vetted validator/reverse-index scripts into the monorepo and wire the tokens:validate CI gate. → load `prompts/token-crosswalk-builder.md`.
17
- - `token-sheet-builder` — Build a beautiful, on-brand "Foundations" page in Figma that visually documents every variable collection and style — color ramps with swatches, the type scale, spacing, radius, shadows/elevations — with swatches live-bound to the actual variables where Figma allows. → load `prompts/token-sheet-builder.md`.
18
- - `token-sync-layer` — Sync Figma design variables into code-ready token files by extracting them to DTCG-format JSON, running them through Style Dictionary, and emitting framework-specific outputs via per-platform adapters (shadcn/Tailwind, MUI, vanilla CSS, iOS Swift, Android Kotlin, or custom). → load `prompts/token-sync-layer.md`.
11
+ - `icon-system-builder` — Build an icon system in Figma — a dedicated "Icons" page of well-named, scalable icon components from Lucide, Tabler, Phosphor, Material, or custom SVGs. → load `prompts/icon-system-builder.md`.
12
+ - `repository-builder` — Graduate the local design-system folder into a real monorepo — a pnpm + Turborepo workspace with packages for tokens and UI components — and walk the user from a plain folder to local git to a GitHub remote with PRs and CI. → load `prompts/repository-builder.md`.
13
+ - `retrofit-planner` — Orchestrate a full brownfield design-system retrofit end to end — audit, refine, rebind, sync, baseline, code, docs, cleanup — with a human confirmation gate between every phase. → load `prompts/retrofit-planner.md`.
14
+ - `storybook-chromatic-builder` — Stand up Storybook in the monorepo, build code components matching the Figma design system, generate stories for every component, set up Chromatic for visual regression testing, and wire Code Connect when the user's Figma plan supports it. → load `prompts/storybook-chromatic-builder.md`.
15
+ - `token-builder` — Build a two-tier (primitive + semantic) design token system as Figma variables — color ramps, spacing, type scale, radius, shadows — with light/dark or brand modes, using one collection per category per tier. → load `prompts/token-builder.md`.
16
+ - `token-crosswalk-builder` — Build the brownfield token crosswalk — a persistent three-way map between each new token, the old Figma variable, and the old code identifier(s) — then wire the tokens:validate CI gate. → load `prompts/token-crosswalk-builder.md`.
17
+ - `token-sheet-builder` — Build an on-brand "Foundations" page in Figma that visually documents every variable collection and style — color ramps with swatches, the type scale, spacing, radius, shadows/elevations. → load `prompts/token-sheet-builder.md`.
18
+ - `token-sync-layer` — Sync Figma design variables into code-ready token files via DTCG JSON and Style Dictionary, emitting framework-specific outputs (shadcn/Tailwind, MUI, vanilla CSS, iOS Swift, Android Kotlin, or custom), and set up the reusable "sync figma tokens" command. → load `prompts/token-sync-layer.md`.
19
19
 
20
20
  ## ThroughLine commands
21
21
 
22
22
  - `design-system-status` — Show a plain-language summary of the current design system state — what's set up, what's not, and sensible next steps — read from design-system.json. → load `prompts/design-system-status.md`.
23
+ - `document-component` — Author, refresh, or reconcile the usage documentation for one existing component — draft its canonical doc record from four sources, project it to Figma, the doc card, and code, and resolve any drift via a reviewable per-item choice. → load `prompts/document-component.md`.
23
24
  - `new-component` — Build a single new component end to end — in Figma, then sync any new tokens, then build its code component and stories — with a confirmation between each stage. → load `prompts/new-component.md`.
24
25
  - `start` — Start building your design system — the deterministic entry point. → load `prompts/start.md`.
25
26
  - `sync-figma-tokens` — Re-run the Figma-to-code token sync — extract current Figma variables, rebuild code outputs via Style Dictionary, and open a PR with the changes for review. → load `prompts/sync-figma-tokens.md`.
@@ -227,6 +227,110 @@ Two rules for every slot:
227
227
  Record each component's slots, variant matrix, and token bindings in the
228
228
  component spec (for Code Connect when available, else the repo component spec).
229
229
 
230
+ ## Step 4.5 — Author the documentation record (and project it)
231
+
232
+ Every component gets a canonical documentation record — the source of truth for
233
+ its usage docs — written to the working folder next to `design-system.json`
234
+ (**folder-resident from day one**, exactly like the manifest; no repo required).
235
+ Read `.throughline/references/component-doc-schema.md` for the exact JSON
236
+ schema, the fingerprint algorithm, and the projection contract.
237
+
238
+ **Run the generation pipeline (each layer only fills what it legitimately knows;
239
+ stamp `provenance` per block):** all authored prose follows
240
+ `.throughline/references/doc-writing-standard.md` — its plain
241
+ reference register, not this skill's guide voice.
242
+
243
+ 0. **Ingest existing docs — brownfield only, runs first.** If docs already exist
244
+ for this component (code JSDoc/MDX/README, or a populated Figma component
245
+ `description`), read them and seed the record marked `provenance: imported`.
246
+ **Never silently overwrite existing human-written docs** — this is the
247
+ read-before-you-assert rule. Skip on greenfield.
248
+ 1. **Infer from the built artifact.** From the component you just built — its
249
+ variants, states, slots, and bound tokens — author `description`, `variants`,
250
+ `states`, and `tokensUsed` (`tokensUsed` comes from the real variable bindings,
251
+ not a guess). Provenance `ai-inferred`.
252
+ 2. **Enrich from the archetype knowledge base.** Match the component to the nearest
253
+ archetype in `.throughline/references/component-doc-archetypes.md` and
254
+ seed `dos`, `donts`, `accessibility`, `whenToUse`, `whenNotToUse`. Provenance
255
+ `best-practice` (or `w3c-apg` for the accessibility block).
256
+ 3. **Specialize to `project.uiFramework`.** Align variant-meaning wording and the
257
+ accessibility idiom to the target framework (the same field you read for variant
258
+ vocabulary). Provenance `framework`.
259
+ 4. **Interview for the non-inferable.** Ask the user for brand/product-specific
260
+ do's & don'ts and intent. Provenance `user`. Write the draft to
261
+ `design-system/docs/components/<Name>.doc.json`, run
262
+ `node .throughline/scripts/docs-lint.mjs design-system/docs/components/<Name>.doc.json`,
263
+ and fix the warnings it raises. Do not raise a separate confirmation for
264
+ a warning on an `imported`/`user` block: draft the rewrite and carry it
265
+ into the approval gate below, shown as before/after and labelled with the
266
+ block's provenance. **Show the whole drafted record and get explicit
267
+ approval before projecting it anywhere** (Figma description, doc card,
268
+ manifest) — one approval covers the whole record. Blocks the user did not
269
+ clear keep their existing text; blocks the user did clear are stamped
270
+ `imported+user` so a later run neither re-asks nor rewrites them.
271
+
272
+ **Write the record and project it:**
273
+
274
+ - Write `design-system/docs/components/<Name>.doc.json` (JSON; required fields
275
+ `name`, `summary`, `description`).
276
+ - **Figma component description.** Set the component's native `description` field
277
+ (via `figma_set_description`) from this exact template — this is the surface
278
+ Dev Mode and Code Connect read, and it must be reproducible byte-for-byte by
279
+ any agent from the same record:
280
+
281
+ ```
282
+ <summary>
283
+
284
+ **When to use**
285
+ - <whenToUse[n]>
286
+
287
+ **When not to use**
288
+ - <whenNotToUse[n]>
289
+
290
+ **Do**
291
+ - <dos[n]>
292
+
293
+ **Don't**
294
+ - <donts[n]>
295
+
296
+ **Accessibility**
297
+ - <accessibility.keyboard[n]>
298
+ - <accessibility.notes[n]>
299
+
300
+ <!-- tl:doc <fp> -->
301
+ ```
302
+
303
+ Rules: every line is a record string **verbatim** — no re-wording, no added
304
+ connectives, no sentences that appear nowhere in the record. A block whose
305
+ source array is empty is omitted along with its bold label. The **Accessibility**
306
+ label is omitted only when both `accessibility.keyboard` and `accessibility.notes`
307
+ are empty; when one is empty its bullets are simply absent and the label stays.
308
+ Sections are separated by exactly one blank line, and the fingerprint marker is
309
+ always last.
310
+ - **Doc card body.** Render the card's `Usage` band with the canonical builder
311
+ snippet in `.throughline/references/doc-card-builder.md` (via
312
+ `figma_execute` with an explicit `timeout`, one card per call): fill the
313
+ RECORD/CANONICAL_FP slots, resolve the nine required semantic variables and
314
+ the `Body/Default` text style per that file's call contract, run it, and
315
+ verify the returned summary (`rowsRendered`, `blocksCreated`, `cardWidth`) —
316
+ not a screenshot. The builder creates the `Doc Fingerprint` node itself and
317
+ is the only thing that may build the usage body — never hand-assemble it.
318
+ - Compute `<fp>` as the canonical fingerprint defined in the schema reference
319
+ (sha256 of the projected record without `provenance`, first 16 hex chars).
320
+
321
+ **Update the manifest (fields this skill owns):** set
322
+ `components.meta[<Name>].doc` to `{ path, fingerprint: <fp>, surfaces: {
323
+ figmaDescription: { src: <fp>, render: <hash of the description text> }, docCard: {
324
+ src: <fp>, render: <summary.renderHash>, renderer: <summary.rendererVersion> } } }`
325
+ — the docCard entry is stamped from the builder's returned summary, never by
326
+ re-reading the card. The code surfaces (`storybookMdx`) are added later by
327
+ `storybook-chromatic-builder`.
328
+
329
+ Run the standard doc-card visual-validation + post-build audit
330
+ (`.throughline/references/figma-component-standards.md`) after enriching
331
+ the card. `docs:check` runs at the code stage; at folder stage the record + Figma
332
+ surfaces are the fallback.
333
+
230
334
  ## Step 5 — Naming as contract
231
335
 
232
336
  Name components deterministically so Figma↔code mapping is automatic: `Button` ↔
@@ -284,4 +388,7 @@ Offer next steps: build the code counterparts and stories
284
388
  internal architecture) **detaches every instance** that referenced its variants (the
285
389
  Card's footer buttons, etc.). Record which components consume which, warn before an
286
390
  architectural rebuild, and re-instance the affected consumers afterward.
391
+ - Never overwrite an existing component `description` or imported doc content
392
+ without reading it first and marking it `provenance: imported` — brownfield docs
393
+ are seeds, not blank slates.
287
394
 
@@ -56,6 +56,23 @@ counts:
56
56
  repo with no Tailwind simply scores `0` there. Detect what the repo actually uses (is
57
57
  there a `tailwind.config`? SCSS? CSS-in-JS?) and explain the counts in those terms.
58
58
 
59
+ ## Step 1.5 — Size the documentation surface
60
+
61
+ Inventory existing documentation the same way the code surface is sized — from
62
+ **verified reads, never assumptions**. Per component (or per code component when no
63
+ Figma component exists yet), record whether usage docs already exist and where:
64
+
65
+ - **Code:** JSDoc/TSDoc on the component, an `.mdx` doc page, a per-component
66
+ README.
67
+ - **Figma:** a populated component `description` field.
68
+
69
+ Write the totals to `audit.docSurface` in the manifest, e.g. `{ "documented": 12,
70
+ "undocumented": 34, "sources": { "codeJsdoc": 8, "mdx": 4, "figmaDescription": 6,
71
+ "readme": 3 } }`. This right-sizes the documentation retrofit (how much exists to
72
+ adopt vs. author from scratch) so `retrofit-planner`'s `docs` phase can be planned
73
+ against real numbers. See `.throughline/references/component-doc-schema.md`
74
+ for what a full record contains.
75
+
59
76
  ## Step 2 — Inventory the Figma file (verified per-class reads)
60
77
 
61
78
  Variables, text styles, and effect/paint styles are **different surfaces** — read each
@@ -103,6 +120,9 @@ Set `tokens.intakeMode: "retrofit"` (this skill establishes the brownfield path
103
120
  owns this transition). Append `design-system-audit` to `completedSkills`.
104
121
 
105
122
  Then recommend the next step:
123
+ - Report the documentation debt from `audit.docSurface` (documented vs.
124
+ undocumented) and note that the retrofit's `docs` phase will adopt existing docs
125
+ before authoring the gaps.
106
126
  - If the user wants the guided, gated end-to-end retrofit → **`retrofit-planner`**
107
127
  (the orchestrator; recommended for multi-session retrofits).
108
128
  - If they only want the crosswalk backbone next → **`token-crosswalk-builder`** (it
@@ -0,0 +1,58 @@
1
+ Document a single existing component end to end, using the settings already in
2
+ `design-system.json` (`project.uiFramework`, `figma.mechanism`, `sync.platforms`)
3
+ rather than re-asking configuration. Scale explanation to `user.codingLevel`.
4
+
5
+ Ask which component to document (e.g. "Button"), then:
6
+
7
+ 1. **Author/refresh the record.** Run the doc-authoring pipeline from
8
+ the `component-builder` prompt's *Author the documentation record* step —
9
+ ingest any existing docs first (brownfield), then infer → enrich (from
10
+ `.throughline/references/component-doc-archetypes.md`) → specialize →
11
+ interview. Authored prose follows
12
+ `.throughline/references/doc-writing-standard.md`. Set `updatedAt` to
13
+ today's date (ISO, `YYYY-MM-DD`) whenever the record is written or rewritten —
14
+ it is a projected field and the doc card's header renders it. Once the record is
15
+ written, run `node .throughline/scripts/docs-lint.mjs
16
+ design-system/docs/components/<Name>.doc.json` and fix its warnings. Do not
17
+ raise a separate confirmation for a warning on an `imported`/`user` block:
18
+ draft the rewrite and carry it into the approval gate below, shown as
19
+ before/after and labelled with the block's provenance, so one approval covers
20
+ the whole record. The user approves the drafted record before anything is
21
+ projected (Figma description, doc card, manifest). Blocks the user did not
22
+ clear keep their existing text; blocks the user did clear are stamped
23
+ `imported+user` so a later run neither re-asks nor rewrites them.
24
+ 2. **Project it.** Write `design-system/docs/components/<Name>.doc.json`, set the
25
+ Figma component `description`, rebuild the doc card's `Usage` band with the
26
+ canonical builder (`.throughline/references/doc-card-builder.md` —
27
+ verify its returned summary and stamp `surfaces.docCard.{src,render,renderer}`
28
+ from it), and (if the repo/code side exists) render MDX/JSDoc and run
29
+ `docs:digest` per the `storybook-chromatic-builder` render step.
30
+ 3. **Reconcile drift.** Before trusting `docs:check`, confirm the repo's copy of
31
+ the doc scripts is current: compare `DOC_CARD_RENDERER_VERSION` in the repo's
32
+ `scripts/lib/doc-card-plan.mjs` against the same constant in
33
+ `.throughline/scripts/lib/doc-card-plan.mjs`. If the repo file is
34
+ missing, or its version is lower, `docs:check` is reading stale rules and its
35
+ "no drift" is meaningless — say so plainly, and offer to refresh the repo's
36
+ doc scripts from the plugin copy. Refresh the whole set and re-check the npm
37
+ registrations, both per **Documentation scripts — install as a set** in
38
+ `.throughline/scripts/README.md` — a refreshed file whose script was
39
+ never registered is the same failure in a new place. Run `docs:check` (with the
40
+ refreshed scripts, if any). For each drifted surface, offer a per-item
41
+ choice — **re-render** (canonical wins) or **pull-back**
42
+ (fold the surface edit into the record) — and land the result as a reviewable
43
+ change. On a brownfield component's first pass, adopt existing content
44
+ (`provenance: imported`) rather than overwriting it.
45
+ `docs:check` may also report `layout-upgrade-available` (informational, never
46
+ failing): the card's layout predates the current builder. Offer to re-render
47
+ the `Usage` band now — rebuild happens on this touch, never unprompted.
48
+ 4. **Close the flow.** Hand back in the four-beat guide voice from
49
+ `.throughline/references/guide-voice.md`: the outcome, what you set
50
+ aside and why, one recommended next step, and at most one light alternative.
51
+ Read existing state to name what is actually outstanding rather than guessing —
52
+ a component at `status: "draft"` with no code surface in `meta[name].doc.surfaces`
53
+ means the code side is deferred. Do not close with a grid of co-equal options.
54
+
55
+ See `.throughline/references/component-doc-schema.md` for the record schema,
56
+ fingerprint contract, and projection mapping. If a component was never built in
57
+ Figma, point the user at `component-builder` first.
58
+
@@ -106,6 +106,20 @@ in it" — they already have a working local repo.
106
106
  On success, set `workspace.stage` and `repo.stage` to `github` and record
107
107
  `repo.remote`. Append `repository-builder` to `completedSkills`.
108
108
 
109
+ ### Adopt the documentation store
110
+
111
+ The folder-resident documentation store at `design-system/docs/` (canonical
112
+ `*.doc.json` records plus the generated `index.json` + `llms.txt`) already exists
113
+ from the Figma phase. Bring it under version control as-is — **do not relocate it**
114
+ (the path is stable across folder→repo, and every manifest `doc.path` points at it).
115
+ Ensure it is committed (not git-ignored).
116
+
117
+ Wire the documentation drift gate into the repo's verification so it runs in CI
118
+ alongside `tokens:validate`: add a `docs:check` step (the `docs-check.mjs` script is
119
+ installed by `storybook-chromatic-builder`; if code hasn't been set up yet, note
120
+ that the gate comes online with the Storybook step). `docs:check` exits non-zero on
121
+ drift; Figma surfaces report `edit-unverified` and are checked in a Figma session.
122
+
109
123
  ## Secrets: the part most people have never done
110
124
 
111
125
  This is where users with low coding experience get stuck — many have never made
@@ -1,6 +1,7 @@
1
1
  # Retrofit planner (orchestrator)
2
2
 
3
- Sequences a brownfield retrofit through the safe 7-phase order, gating each phase on a
3
+ Sequences a brownfield retrofit through the safe seven-phase order (with `docs` inserted
4
+ as a gated Phase 6.5), gating each phase on a
4
5
  human confirmation. Like `component-pipeline`, this skill holds **zero domain logic of
5
6
  its own** — it is a sequencer that invokes the real skills and the phase work, and only
6
7
  updates the manifest fields it owns (`retrofit.*`, `completedSkills`). All the
@@ -102,6 +103,25 @@ triad as you go — `check-types`, `build-storybook` + Chromatic, **and run the
102
103
  + spot-check 5–7 routes (the build alone is blind to story-unreachable SCSS). **Gate:**
103
104
  confirm the triad passes before continuing.
104
105
 
106
+ ### Phase 6.5 — `docs` (adopt existing documentation, then fill gaps)
107
+
108
+ Set `retrofit.phase = "docs"`. Bring the documentation layer onto the system's
109
+ components **adopt-first**, so no existing human-written doc is lost:
110
+
111
+ 1. **Adopt.** For each component, run the doc-authoring ingest (Step 4.5 of
112
+ `component-builder`): read existing code JSDoc/MDX/README and Figma
113
+ `description`, seed the canonical `.doc.json` marked `provenance: imported`, and
114
+ stamp fingerprints. This first pass **claims** existing content — it is not a
115
+ re-render and must not overwrite it.
116
+ 2. **Fill gaps.** Run the remaining generation layers (infer → enrich → specialize
117
+ → interview) only for blocks the adoption did not populate; the user approves.
118
+ 3. **Project + gate.** Render the code surfaces (Step 5.5 of
119
+ `storybook-chromatic-builder`), run `docs:digest`, and run `docs:check` — it
120
+ should pass (surfaces just rendered) with Figma surfaces `edit-unverified`.
121
+
122
+ Confirm with the user before writing, consistent with every other phase. On a large
123
+ system, size the batch from `audit.docSurface` and adopt in reviewable chunks.
124
+
105
125
  ### Phase 7 — `cleanup`
106
126
 
107
127
  Remove the old token outputs **only after** the repo-wide token-removal guard returns
@@ -27,6 +27,17 @@ system). Wire it to consume `packages/tokens` output so stories render with the
27
27
  real design tokens (import the generated CSS/theme). Checkpoint: confirm
28
28
  Storybook runs and shows the token-themed canvas.
29
29
 
30
+ Install the documentation scripts alongside the token scripts: copy the five
31
+ files and register the three npm scripts listed under **Documentation scripts —
32
+ install as a set** in `.throughline/scripts/README.md`. That table is
33
+ the single source of truth for what a consuming repo gets; do not restate the
34
+ list here.
35
+
36
+ These are the documentation analog of `tokens:validate`; see
37
+ `.throughline/scripts/README.md`. This copy is setup, not a forever-fork:
38
+ `/document-component` re-checks these files' freshness on every run and refreshes
39
+ them from the plugin when it has moved on.
40
+
30
41
  **pnpm build-script allowlist (first-run gotcha).** On pnpm workspaces, the
31
42
  `@storybook/react-vite` install pulls `esbuild`, whose postinstall is blocked by
32
43
  pnpm's default `onlyBuiltDependencies` policy — Storybook then fails to start with a
@@ -149,6 +160,43 @@ Configure Chromatic to snapshot everything (do **not** set `onlyChanged`), and
149
160
  verify a token-only PR re-snapshots all stories — they should flip orange against
150
161
  the green baseline.
151
162
 
163
+ ### Usage & cost guardrails
164
+
165
+ The full-snapshot default above is the right call for catching regressions, and it
166
+ is also the **maximum-usage** choice: every story, every run. Chromatic bills per
167
+ snapshot, so name this cost shape to the user when you set Chromatic up, and put the
168
+ guardrails in *before* the first big token PR, not after the bill.
169
+
170
+ What Chromatic actually offers (re-verify the live numbers at
171
+ `chromatic.com/pricing` — they drift):
172
+
173
+ - **Free plan (~5,000 snapshots/month):** testing **auto-pauses** when the ceiling
174
+ is hit. No surprise bill, but visual-regression coverage silently *stops* until
175
+ the monthly reset or an upgrade. For a full-suite design system that ceiling
176
+ arrives fast — treat a *paused* build as a red flag, not a passing one.
177
+ - **Paid plans: no hard spending cap.** Overage snapshots auto-bill at month-end.
178
+ The only native guardrail is **usage alerts** — an email when consumption crosses
179
+ a threshold you set (e.g. 90%).
180
+
181
+ The math, so the user sizes the plan honestly: **snapshots ≈ stories × modes ×
182
+ builds.** One `/sync-figma-tokens` PR re-snapshots the *entire* suite × every mode
183
+ in a single build — e.g. 40 components × 2 modes = 80 snapshots per build, and a
184
+ handful of token PRs plus daily `main` builds clears a free tier in a week.
185
+
186
+ So the guardrails, all of them user-controlled (Chromatic will not cap you):
187
+
188
+ 1. **Set usage alerts** at ~80% on a paid plan so the bill cannot sneak up. On the
189
+ free plan, make sure the user knows testing *pauses* at the ceiling.
190
+ 2. **Scope the CI trigger.** Run Chromatic on **pull requests and `main` only** —
191
+ never on every branch push — path-filter out docs-only changes, and keep it to
192
+ one Chromatic build per commit (no duplicate runs).
193
+ 3. **Size the plan to the math** before the first token PR. A large story count is
194
+ also the *only* reason to revisit TurboSnap (see above), and even then treat
195
+ every token change as a full run.
196
+
197
+ Do not silently pick a plan or leave the trigger wide open. Name the tradeoff and
198
+ let the user choose with the numbers in front of them.
199
+
152
200
  ## Step 5 — Code Connect (plan-gated, skip gracefully)
153
201
 
154
202
  Code Connect ties Figma components to their code counterparts so Figma's dev
@@ -170,6 +218,32 @@ mode shows the real code. It's plan-gated (Figma Organization/Enterprise).
170
218
  run after the user publishes. This does **not** block the code side: implement
171
219
  each slot prop from the recorded slot contract regardless of the Figma dropdown.
172
220
 
221
+ ## Step 5.5 — Render documentation to code
222
+
223
+ For each component that has a canonical record
224
+ (`design-system/docs/components/<Name>.doc.json`), render the code-side surfaces
225
+ from it (read `.throughline/references/component-doc-schema.md` for the
226
+ projection contract):
227
+
228
+ - **Storybook autodocs (MDX).** Generate `<Name>.mdx` next to the component (e.g.
229
+ `packages/ui/src/<Name>/<Name>.mdx`) rendering summary, description,
230
+ when-to-use/not, do's/don'ts, accessibility, and a variant/state table. Put the
231
+ record's fingerprint in MDX frontmatter as `docFingerprint: <fp>`.
232
+ - **JSDoc.** Add a doc comment to the code component from `summary` + `description`
233
+ and per-prop descriptions from `variants`/`states` meanings, so `argTypes`
234
+ descriptions surface in the Storybook controls table.
235
+ - **AI digest.** Run `docs:digest` to (re)generate `design-system/docs/index.json`
236
+ + `design-system/docs/llms.txt` from all records.
237
+
238
+ **Update the manifest:** add the `storybookMdx` surface to
239
+ `components.meta[<Name>].doc.surfaces` as `{ src: <fp>, render: <hash of the MDX
240
+ file>, file: "<repo-relative MDX path>" }`.
241
+
242
+ **Wire the gate.** Ensure `docs:check` is part of the repo's verification (a CI
243
+ step and/or a Turbo task). It compares every surface against its record and exits
244
+ non-zero on drift; Figma surfaces report `edit-unverified` (checked live in a Figma
245
+ session). Run `docs:check` once here and confirm it passes before handing off.
246
+
173
247
  ## Step 6 — Finalize component status (Figma write-back)
174
248
 
175
249
  A component built and storied here is now **done** — but its Figma doc card was
@@ -193,10 +267,15 @@ the `figma_execute` scripting gotchas — `getNodeByIdAsync` and an explicit
193
267
 
194
268
  - Set `components.meta[name].status` = `"stable"` and refresh
195
269
  `components.meta[name].updatedAt` to today.
270
+ - When promoting status (e.g. draft → stable), also set `status` + `updatedAt` in
271
+ the component's `.doc.json`, recompute its fingerprint, re-run `docs:digest`, and
272
+ re-render the affected surfaces so `docs:check` stays green.
196
273
  - If Figma is connected (per `figma.mechanism`), open the component's doc card and
197
274
  update the `Status Label` text to `stable`, re-bind the `Status` chip fill to
198
- the **success** semantic color variable (mode-aware, not a hardcoded hex), and
199
- set `Last Updated` to today's date then screenshot to confirm the chip
275
+ the **success** semantic color variable (mode-aware, not a hardcoded hex), then
276
+ re-run the canonical doc-card builder against the same card to refresh the
277
+ header date from the `record.updatedAt` already set above (it locates the date
278
+ node under either header shape) — then screenshot to confirm the chip
200
279
  recolored and the date changed.
201
280
  - If Figma isn't connected, still update the manifest and tell the user the card
202
281
  will reconcile next Figma session (or offer to reconnect and fix it now).
@@ -257,6 +336,9 @@ that may not exist.
257
336
  - Never rely on TurboSnap (`onlyChanged: true`) for a token-driven design system
258
337
  — its incremental model keeps missing global token changes. Default to full
259
338
  snapshots (every story, every run); revisit only at large story counts.
339
+ - Never leave Chromatic's cost shape unspoken or the CI trigger wide open — there
340
+ is no hard spend cap on paid plans, so set usage alerts, run it on PRs + `main`
341
+ only, and size the plan to stories × modes × builds before the first token PR.
260
342
  - Never use the sequential model for story-gen — parallelize via subagents.
261
343
  - Never capture the Chromatic baseline *after* a code retrofit — baseline before, so
262
344
  intended drift-fixes are distinguishable from regressions.
@@ -0,0 +1,58 @@
1
+ Document a single existing component end to end, using the settings already in
2
+ `design-system.json` (`project.uiFramework`, `figma.mechanism`, `sync.platforms`)
3
+ rather than re-asking configuration. Scale explanation to `user.codingLevel`.
4
+
5
+ Ask which component to document (e.g. "Button"), then:
6
+
7
+ 1. **Author/refresh the record.** Run the doc-authoring pipeline from
8
+ the `component-builder` rule's *Author the documentation record* step —
9
+ ingest any existing docs first (brownfield), then infer → enrich (from
10
+ `.throughline/references/component-doc-archetypes.md`) → specialize →
11
+ interview. Authored prose follows
12
+ `.throughline/references/doc-writing-standard.md`. Set `updatedAt` to
13
+ today's date (ISO, `YYYY-MM-DD`) whenever the record is written or rewritten —
14
+ it is a projected field and the doc card's header renders it. Once the record is
15
+ written, run `node .throughline/scripts/docs-lint.mjs
16
+ design-system/docs/components/<Name>.doc.json` and fix its warnings. Do not
17
+ raise a separate confirmation for a warning on an `imported`/`user` block:
18
+ draft the rewrite and carry it into the approval gate below, shown as
19
+ before/after and labelled with the block's provenance, so one approval covers
20
+ the whole record. The user approves the drafted record before anything is
21
+ projected (Figma description, doc card, manifest). Blocks the user did not
22
+ clear keep their existing text; blocks the user did clear are stamped
23
+ `imported+user` so a later run neither re-asks nor rewrites them.
24
+ 2. **Project it.** Write `design-system/docs/components/<Name>.doc.json`, set the
25
+ Figma component `description`, rebuild the doc card's `Usage` band with the
26
+ canonical builder (`.throughline/references/doc-card-builder.md` —
27
+ verify its returned summary and stamp `surfaces.docCard.{src,render,renderer}`
28
+ from it), and (if the repo/code side exists) render MDX/JSDoc and run
29
+ `docs:digest` per the `storybook-chromatic-builder` render step.
30
+ 3. **Reconcile drift.** Before trusting `docs:check`, confirm the repo's copy of
31
+ the doc scripts is current: compare `DOC_CARD_RENDERER_VERSION` in the repo's
32
+ `scripts/lib/doc-card-plan.mjs` against the same constant in
33
+ `.throughline/scripts/lib/doc-card-plan.mjs`. If the repo file is
34
+ missing, or its version is lower, `docs:check` is reading stale rules and its
35
+ "no drift" is meaningless — say so plainly, and offer to refresh the repo's
36
+ doc scripts from the plugin copy. Refresh the whole set and re-check the npm
37
+ registrations, both per **Documentation scripts — install as a set** in
38
+ `.throughline/scripts/README.md` — a refreshed file whose script was
39
+ never registered is the same failure in a new place. Run `docs:check` (with the
40
+ refreshed scripts, if any). For each drifted surface, offer a per-item
41
+ choice — **re-render** (canonical wins) or **pull-back**
42
+ (fold the surface edit into the record) — and land the result as a reviewable
43
+ change. On a brownfield component's first pass, adopt existing content
44
+ (`provenance: imported`) rather than overwriting it.
45
+ `docs:check` may also report `layout-upgrade-available` (informational, never
46
+ failing): the card's layout predates the current builder. Offer to re-render
47
+ the `Usage` band now — rebuild happens on this touch, never unprompted.
48
+ 4. **Close the flow.** Hand back in the four-beat guide voice from
49
+ `.throughline/references/guide-voice.md`: the outcome, what you set
50
+ aside and why, one recommended next step, and at most one light alternative.
51
+ Read existing state to name what is actually outstanding rather than guessing —
52
+ a component at `status: "draft"` with no code surface in `meta[name].doc.surfaces`
53
+ means the code side is deferred. Do not close with a grid of co-equal options.
54
+
55
+ See `.throughline/references/component-doc-schema.md` for the record schema,
56
+ fingerprint contract, and projection mapping. If a component was never built in
57
+ Figma, point the user at `component-builder` first.
58
+
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Build a foundational set of Figma components — buttons, inputs, cards, badges, chips, modals, and more — as properly structured components with variant matrices (types, sizes, states) and icon/component/content slots, bound to the design system's tokens and styles. Use this when the user wants to create components, build a component library, make buttons/inputs/cards/etc. in Figma, or set up the foundational UI kit. Also trigger after tokens and icons exist, when the user is ready to build actual UI components. Make sure to use this whenever someone wants real, variant-rich components in their Figma design system, not just tokens."
2
+ description: "Build Figma components — buttons, inputs, cards, badges, chips, modals, and more — with variant matrices (types, sizes, states) and icon/component/content slots bound to the design system's tokens and styles. Use this when the user wants to create components, build a component library, make buttons/inputs/cards/etc. in Figma, or set up the foundational UI kit. Also trigger after tokens and icons exist, when the user is ready to build actual UI components."
3
3
  alwaysApply: false
4
4
  ---
5
5
  # Component builder
@@ -231,6 +231,110 @@ Two rules for every slot:
231
231
  Record each component's slots, variant matrix, and token bindings in the
232
232
  component spec (for Code Connect when available, else the repo component spec).
233
233
 
234
+ ## Step 4.5 — Author the documentation record (and project it)
235
+
236
+ Every component gets a canonical documentation record — the source of truth for
237
+ its usage docs — written to the working folder next to `design-system.json`
238
+ (**folder-resident from day one**, exactly like the manifest; no repo required).
239
+ Read `.throughline/references/component-doc-schema.md` for the exact JSON
240
+ schema, the fingerprint algorithm, and the projection contract.
241
+
242
+ **Run the generation pipeline (each layer only fills what it legitimately knows;
243
+ stamp `provenance` per block):** all authored prose follows
244
+ `.throughline/references/doc-writing-standard.md` — its plain
245
+ reference register, not this skill's guide voice.
246
+
247
+ 0. **Ingest existing docs — brownfield only, runs first.** If docs already exist
248
+ for this component (code JSDoc/MDX/README, or a populated Figma component
249
+ `description`), read them and seed the record marked `provenance: imported`.
250
+ **Never silently overwrite existing human-written docs** — this is the
251
+ read-before-you-assert rule. Skip on greenfield.
252
+ 1. **Infer from the built artifact.** From the component you just built — its
253
+ variants, states, slots, and bound tokens — author `description`, `variants`,
254
+ `states`, and `tokensUsed` (`tokensUsed` comes from the real variable bindings,
255
+ not a guess). Provenance `ai-inferred`.
256
+ 2. **Enrich from the archetype knowledge base.** Match the component to the nearest
257
+ archetype in `.throughline/references/component-doc-archetypes.md` and
258
+ seed `dos`, `donts`, `accessibility`, `whenToUse`, `whenNotToUse`. Provenance
259
+ `best-practice` (or `w3c-apg` for the accessibility block).
260
+ 3. **Specialize to `project.uiFramework`.** Align variant-meaning wording and the
261
+ accessibility idiom to the target framework (the same field you read for variant
262
+ vocabulary). Provenance `framework`.
263
+ 4. **Interview for the non-inferable.** Ask the user for brand/product-specific
264
+ do's & don'ts and intent. Provenance `user`. Write the draft to
265
+ `design-system/docs/components/<Name>.doc.json`, run
266
+ `node .throughline/scripts/docs-lint.mjs design-system/docs/components/<Name>.doc.json`,
267
+ and fix the warnings it raises. Do not raise a separate confirmation for
268
+ a warning on an `imported`/`user` block: draft the rewrite and carry it
269
+ into the approval gate below, shown as before/after and labelled with the
270
+ block's provenance. **Show the whole drafted record and get explicit
271
+ approval before projecting it anywhere** (Figma description, doc card,
272
+ manifest) — one approval covers the whole record. Blocks the user did not
273
+ clear keep their existing text; blocks the user did clear are stamped
274
+ `imported+user` so a later run neither re-asks nor rewrites them.
275
+
276
+ **Write the record and project it:**
277
+
278
+ - Write `design-system/docs/components/<Name>.doc.json` (JSON; required fields
279
+ `name`, `summary`, `description`).
280
+ - **Figma component description.** Set the component's native `description` field
281
+ (via `figma_set_description`) from this exact template — this is the surface
282
+ Dev Mode and Code Connect read, and it must be reproducible byte-for-byte by
283
+ any agent from the same record:
284
+
285
+ ```
286
+ <summary>
287
+
288
+ **When to use**
289
+ - <whenToUse[n]>
290
+
291
+ **When not to use**
292
+ - <whenNotToUse[n]>
293
+
294
+ **Do**
295
+ - <dos[n]>
296
+
297
+ **Don't**
298
+ - <donts[n]>
299
+
300
+ **Accessibility**
301
+ - <accessibility.keyboard[n]>
302
+ - <accessibility.notes[n]>
303
+
304
+ <!-- tl:doc <fp> -->
305
+ ```
306
+
307
+ Rules: every line is a record string **verbatim** — no re-wording, no added
308
+ connectives, no sentences that appear nowhere in the record. A block whose
309
+ source array is empty is omitted along with its bold label. The **Accessibility**
310
+ label is omitted only when both `accessibility.keyboard` and `accessibility.notes`
311
+ are empty; when one is empty its bullets are simply absent and the label stays.
312
+ Sections are separated by exactly one blank line, and the fingerprint marker is
313
+ always last.
314
+ - **Doc card body.** Render the card's `Usage` band with the canonical builder
315
+ snippet in `.throughline/references/doc-card-builder.md` (via
316
+ `figma_execute` with an explicit `timeout`, one card per call): fill the
317
+ RECORD/CANONICAL_FP slots, resolve the nine required semantic variables and
318
+ the `Body/Default` text style per that file's call contract, run it, and
319
+ verify the returned summary (`rowsRendered`, `blocksCreated`, `cardWidth`) —
320
+ not a screenshot. The builder creates the `Doc Fingerprint` node itself and
321
+ is the only thing that may build the usage body — never hand-assemble it.
322
+ - Compute `<fp>` as the canonical fingerprint defined in the schema reference
323
+ (sha256 of the projected record without `provenance`, first 16 hex chars).
324
+
325
+ **Update the manifest (fields this skill owns):** set
326
+ `components.meta[<Name>].doc` to `{ path, fingerprint: <fp>, surfaces: {
327
+ figmaDescription: { src: <fp>, render: <hash of the description text> }, docCard: {
328
+ src: <fp>, render: <summary.renderHash>, renderer: <summary.rendererVersion> } } }`
329
+ — the docCard entry is stamped from the builder's returned summary, never by
330
+ re-reading the card. The code surfaces (`storybookMdx`) are added later by
331
+ `storybook-chromatic-builder`.
332
+
333
+ Run the standard doc-card visual-validation + post-build audit
334
+ (`.throughline/references/figma-component-standards.md`) after enriching
335
+ the card. `docs:check` runs at the code stage; at folder stage the record + Figma
336
+ surfaces are the fallback.
337
+
234
338
  ## Step 5 — Naming as contract
235
339
 
236
340
  Name components deterministically so Figma↔code mapping is automatic: `Button` ↔
@@ -288,4 +392,7 @@ Offer next steps: build the code counterparts and stories
288
392
  internal architecture) **detaches every instance** that referenced its variants (the
289
393
  Card's footer buttons, etc.). Record which components consume which, warn before an
290
394
  architectural rebuild, and re-instance the affected consumers afterward.
395
+ - Never overwrite an existing component `description` or imported doc content
396
+ without reading it first and marking it `provenance: imported` — brownfield docs
397
+ are seeds, not blank slates.
291
398