Commit 27fc379
feat: build-time component-style attribution (RFC 0001 — Task A) (#49)
* feat(core): add StyleSource + ComponentStyles schemas; bump ANNOTATION_SCHEMA_VERSION to 2
Introduces optional `styleSource` on `ManifestEntry` (build-time className
tokens + CSS-in-JS source-block location) and optional `componentStyles`
on `RuntimeContextSchema` (≤32-property computed allowlist + resolved CSS
custom properties), per RFC 0001. Lands the schema half so transform,
runtime, and relay packages can build against it without circular work.
The v1 → v2 migration is purely additive — fields are optional, so v1
payloads pass through untouched. A no-op `migrationSteps[1]` is registered
so `migrateAnnotation` can stamp persisted v1 annotations to v2 without
throwing on the version walk. Forward-compat guarantee for v1-pinned
clients reading v2 annotations is asserted in the migration spec.
Also adds `COMPONENT_STYLES_ALLOWLIST` as the authoritative computed-style
property list so the runtime, the relay, and downstream tooling agree on
the capture contract.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(transform): build-time style attribution behind captureStyles flag
Adds a parser-agnostic style extractor that piggybacks on the existing
JSX AST visit:
- `extractClassNameFromJSX` resolves className tokens through string
literals, no-interpolation template literals, conditional/logical
expressions, array/object expressions, and clsx/cn/tw/classNames/twMerge/
cva helpers (incl. member-expression helpers like `utils.cn`).
Unknown helpers and bare identifiers yield an empty token set rather
than guessing — the agent can read source if static reasoning fails.
- `collectCssInJsDeclarations` scans top-level `const X = styled.foo\`\``,
`styled(Y)\`\``, and emotion `css\`\`` declarations and records source
location + verbatim block text (4 KB cap). Library is inferred from the
imported module specifier; no theme or config resolution at transform
time (per RFC 0001).
- The injector calls both on the same AST pass when `captureStyles` is on,
resolves the JSX tag name to its binding via `resolveTagToBindingName`,
and attaches an optional `styleSource` to each manifest entry.
`captureStyles` defaults off in v0.x per RFC 0001 reversibility plan and
is plumbed through `InjectorOptions`, `InjectorRegistry`, Vite, webpack,
and turbopack plugins.
Tests:
- 33-case real-world corpus under `test/className-corpus/` exercising
every pattern the RFC review flagged (literals, helpers, templates,
conditionals, spread, CSS-in-JS).
- End-to-end injector spec runs the real Babel parser with
`captureStyles: true` to verify className tokens and styled-component
source-block linkage land on manifest entries.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(relay): surface styleSource through resolve + manifest.query MCP tools
`ManifestEntrySchema` now carries an optional `styleSource`, so
`manifest.query` returns it automatically via the existing schema-driven
output. `resolve` extracts individual fields and previously dropped
unknown ones — extended to forward `styleSource` alongside `file`/
`start`/`end`/`componentName`/`tagName`.
Tool descriptions are updated so agents know they can request styling
context via the static `styleSource` (build-time className tokens + CSS-
in-JS source-block location) before reaching for the runtime
`query.bySource` path. Description text deliberately conditions on
"when build-time style capture is enabled" — the field is absent when
the transform was run with the default `captureStyles: false`.
Storage-layer specs are updated to reference `ANNOTATION_SCHEMA_VERSION`
rather than hard-coding `1`, so the v2 bump in @domscribe/core doesn't
silently regress the on-read migration assertions.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Domscribe Staff SWE (bot) <staff-swe-bot@domscribe.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent d15c077 commit 27fc379
23 files changed
Lines changed: 1638 additions & 20 deletions
File tree
- packages
- domscribe-core/src/lib
- migrations
- types
- domscribe-relay/src
- mcp/tools
- server/services/storage
- domscribe-transform
- src
- core
- plugins
- turbopack
- vite
- webpack
- test/className-corpus
Lines changed: 43 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
105 | 144 | | |
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 19 | | |
23 | 20 | | |
24 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
57 | 91 | | |
58 | 92 | | |
59 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
60 | 97 | | |
61 | 98 | | |
62 | 99 | | |
| |||
68 | 105 | | |
69 | 106 | | |
70 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
71 | 114 | | |
72 | | - | |
| 115 | + | |
73 | 116 | | |
74 | 117 | | |
75 | 118 | | |
| |||
196 | 239 | | |
197 | 240 | | |
198 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
28 | 108 | | |
29 | 109 | | |
30 | 110 | | |
| |||
73 | 153 | | |
74 | 154 | | |
75 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
76 | 159 | | |
77 | 160 | | |
78 | 161 | | |
| |||
107 | 190 | | |
108 | 191 | | |
109 | 192 | | |
| 193 | + | |
| 194 | + | |
110 | 195 | | |
111 | 196 | | |
112 | 197 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
48 | 87 | | |
49 | 88 | | |
50 | 89 | | |
| |||
68 | 107 | | |
69 | 108 | | |
70 | 109 | | |
| 110 | + | |
71 | 111 | | |
72 | 112 | | |
73 | 113 | | |
| |||
0 commit comments