@micha.bigler/ui-core-micha 2.37.0 → 2.38.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.
@@ -0,0 +1,247 @@
1
+ # THEME-6 — An app-side check for `sx` values the theme already gives
2
+
3
+ **Target repo:** `ui-core-micha` (branch `main` — this repo has no `develop`)
4
+ **Tier:** 3 (shared core)
5
+ **Review:** independent `reviewer` — mandatory (new logic). **`ui_reviewer` does not apply**: this WO
6
+ adds a check and fixes nothing, so no rendered output changes. If that turns out to be false, it
7
+ applies after all.
8
+ **Version target:** the next **minor** after the published version — a new exported check is additive
9
+ API. Read the published version at implementation time.
10
+ **Strand:** `DS-18`, the app-side half. Trigger fired when cockpit adopted `createAppTheme` (`UI-6`);
11
+ deferred once because cockpit was mid-rebuild in `UI-3`, **which has since landed.**
12
+
13
+ ---
14
+
15
+ ## A. Envelope
16
+
17
+ ### Goal
18
+
19
+ `THEME-4` made it mechanical that no **kit** component defeats the baseline. Apps have no equivalent:
20
+ cockpit alone carries **464 `sx` props across 37 files** (measured 2026-08-11), and nothing checks any
21
+ of them against the theme they sit on.
22
+
23
+ Give apps an exported check they call from their own suite, the way they already call
24
+ `assertThemeComplete`.
25
+
26
+ ### This is NOT a port of `THEME-4`, and getting that wrong would flood the app
27
+
28
+ In the **kit**, an `sx` value that duplicates a baseline default is a bug by definition: the default
29
+ becomes inert for every consumer. So `THEME-4` compares **key sets** and demands disjointness.
30
+
31
+ In an **app**, `sx` beating the theme is **the intended mechanism** — that is how a screen customises
32
+ one instance. A key-collision check over 464 props would flag mostly legitimate customisation, get
33
+ blanket-exempted, and become the no-op `THEME-4`'s own WO warned about.
34
+
35
+ **So the app-side rule is different: flag an `sx` value that is *equal* to what the theme already
36
+ resolves for that component and property.** Not "you overrode a default" — "you re-stated a value you
37
+ already had". That is dead weight which **silently diverges the next time the token changes**, which is
38
+ the real failure mode and the one worth a check.
39
+
40
+ Grounded in cockpit, measured: `borderColor: 'divider'` (×2) and `bgcolor: 'background.paper'` (×3) on
41
+ surfaces whose theme already sets exactly that, and `borderRadius: 1` (×3) which resolves to the
42
+ baseline's own `shape.borderRadius`. Those are the findings this check exists for.
43
+
44
+ ### Scope
45
+
46
+ **1. An exported check, source-level.** Same finding contract as its siblings
47
+ (`{ findings: [{ surface, reason }] }`), same shape as `reportThemeAdoption` and
48
+ `reportOffPaletteColours`: it takes the app's own sources plus its theme, and returns findings. The app
49
+ globs its `src/**` in its own test and passes them.
50
+
51
+ For each `sx` entry it can attribute to a MUI component the theme styles, resolve what the theme gives
52
+ for that property and flag **equality**. The attribution comes from the JSX element name in the source
53
+ text — `<Paper sx={{ borderRadius: 1 }}>` → `MuiPaper` → compare against
54
+ `theme.components.MuiPaper.styleOverrides.root.borderRadius`.
55
+
56
+ **2. Report-only, with a ratchet.** New findings must not turn a green app red on a pin bump. Ship it
57
+ **report-only**, and let each app make it a hard assertion in its own cleanup WO — the same ratchet
58
+ `DS-2` used for `assertThemeComplete`, and for the same reason.
59
+
60
+ **3. Run it against cockpit and report the count. Fix nothing.** cockpit is the first real consumer and
61
+ the reason the trigger fired. The cleanup is cockpit's own work order, not this one — bundling an
62
+ unbounded app cleanup into a shared-core WO is what `AUTH-4` was split out of `DS-11` to avoid.
63
+
64
+ ### Reuse, do not rebuild — and one gap in the reuse
65
+
66
+ **The hardcoded-colour half already exists and is already app-callable.**
67
+ `reportOffPaletteColours(sources, { palette })` (`themeCompleteness.js:759`) takes sources and an
68
+ optional palette, so an app can pass its own files and its own palette today. cockpit's
69
+ `bgcolor: '#fff'` (×2) is exactly what it reports. **Do not duplicate it.**
70
+
71
+ **But its skip pattern assumes ucm's layout.** It skips paths matching `src/theme/` — with a trailing
72
+ slash (`:768`). ucm's tokens live in `src/theme/tokens.js`; an app's theme is usually
73
+ `src/theme.js`, which **does not match** and therefore gets scanned, so every identity token in it
74
+ (cockpit: `#3D5A99`, `#eff2f7`, `#e4e8f1`, …) would be reported as off-palette.
75
+
76
+ Resolve it **app-side**, not by widening the pattern: the app excludes its own theme file from the
77
+ sources it passes. That keeps ucm's behaviour unchanged and puts the knowledge where the layout is
78
+ known. Say so in the check's doc comment so the next app does not rediscover it.
79
+
80
+ ### The bound, and it is open
81
+
82
+ Attribution from source text is a **heuristic**. It will miss `sx` on a variable, spread props, an
83
+ aliased import (`import { Paper as Surface }`), a `styled()` component, and a MUI component rendered
84
+ through `component={...}`. **Write the bound as open — "unknown attribution gaps remain" — not as a
85
+ list.** `THEME-4`'s WO enumerated its limits and the first real miss (shorthand alias spelling) was not
86
+ on the list; `THEME-5` was told to phrase it openly and that phrasing then held when the fourth
87
+ shadowing layer appeared. An enumeration reads as coverage.
88
+
89
+ This check is a lower bound on redundancy, and green means "nothing found by this method".
90
+
91
+ ### Non-goals / do not touch
92
+
93
+ - **No fixes anywhere.** Not in cockpit, not in the kit. This WO ships a check and a count.
94
+ - **No change to `reportOffPaletteColours`**, `assertKitSxDisjoint`, `reportKitSxBypasses`,
95
+ `reportThemeAdoption` or `assertThemeComplete` — including no widening of the `src/theme/` skip.
96
+ - **Not a hard assertion anywhere yet.** Report-only; the ratchet is each app's own.
97
+ - `DS-18`'s remaining half — "which components *can violate* a rule", derived from a
98
+ `grep 'shadows\['` lower bound — stays out and stays without a driver.
99
+ - No baseline token, component default or public prop change.
100
+
101
+ ### Risks
102
+
103
+ - **False positives are the failure mode**, not false negatives. A check that flags legitimate
104
+ customisation gets switched off. That is why it compares values rather than keys, and why it ships
105
+ report-only.
106
+ - **The count from cockpit may be large.** 464 props is the denominator. If it is large enough that no
107
+ app could plausibly act on it, that is a finding to report — the check may need a narrower first
108
+ scope (e.g. only the ~23 component keys the baseline actually styles) rather than shipping noise.
109
+ - **No staging net.** A version bump on `main` publishes; the independent review is the only gate.
110
+ - **Other sessions are frequently active in this repo.** Read `git status` and
111
+ `git log origin/main..HEAD` before reviewing; this strand has had concurrent work in the same files
112
+ throughout.
113
+
114
+ ### Required tests to WRITE
115
+
116
+ 1. **Non-vacuity:** a fixture source with `<Paper sx={{ borderColor: 'divider' }}>` against a theme
117
+ whose `MuiPaper` already sets `borderColor: divider` produces a finding naming the file, line,
118
+ component and property.
119
+ 2. **The legitimate case produces nothing:** the same fixture with a *different* value
120
+ (`borderColor: 'error.main'`) is **not** flagged. This is the test that keeps the check usable.
121
+ 3. A component the theme does not style is not flagged at all.
122
+ 4. The finding shape matches its siblings, so a consumer handles one contract.
123
+ 5. `reportOffPaletteColours` is unchanged — its existing tests stay green untouched.
124
+
125
+ Plus `tsc -p tsconfig.build.json --noEmit` clean. **No full-suite run** — affected set is the theme
126
+ module's specs.
127
+
128
+ ### Verification
129
+
130
+ No rendered surface. The evidence is test 1 plus the cockpit count, reported in the register note with
131
+ the exact number and a sample of what it found. A check nobody has run against real code is not
132
+ verified, however green its fixtures.
133
+
134
+ ### Parity guardrail
135
+
136
+ Nothing renders differently. No existing check changes behaviour.
137
+
138
+ ---
139
+
140
+ ## B. Implementation map
141
+
142
+ *Filled by the Orchestrator on `git pull` — see `AGENTS.md` → "Work Order".*
143
+
144
+ ### Execution directive (read this first)
145
+
146
+ > **If you are the implementer reading this work order as your own specification: this section is
147
+ > NOT addressed to you.** It tells the Orchestrator how to invoke you. **You ARE that invocation —
148
+ > do NOT shell out to `codex exec`.**
149
+ >
150
+ > Implement through `codex exec` in the background — invoked directly via Bash (never the
151
+ > `debugger`/`*_coder` Agent wrappers) with BOTH flags `--skip-git-repo-check` and
152
+ > `--dangerously-bypass-approvals-and-sandbox`. **Pass the WO via stdin, not as a positional
153
+ > argument.** Fallback to direct Claude implementation only on Codex quota/rate-limit/non-zero exit —
154
+ > and that flips authorship, so the independent `reviewer` stays mandatory either way.
155
+ >
156
+ > **Do NOT edit `WORK_ORDERS.md`.** Before your own review read `git log origin/main..HEAD` and
157
+ > `git status`, and check the register row carries no review claim you did not make yourself.
158
+
159
+ ### Context package
160
+
161
+ **Precondition confirmed:** `SHELL-6` landed and published (`f119b70`/`3b746d4`, `package.json` reads
162
+ `2.37.1`). Clean starting tree.
163
+
164
+ **Reusable primitives already in `src/theme/themeCompleteness.js` — do not rebuild these:**
165
+ - `getPath(value, path)` (`:13-15`) and `sameValue(left, right)` (`:17-21`) — exactly what "resolve
166
+ what the theme gives for that property and flag equality" needs; both already handle the
167
+ string/JSON-stringify comparison this check requires.
168
+ - `BASELINE_STYLED_MUI_COMPONENTS` (`:484-508`, 23-entry list), `jsxOpeningTag(source, start)`
169
+ (`:510-530`, returns the full `<Tag ...>` text starting at a match) and `topLevelSxValue(tag)`
170
+ (`:532-553`, extracts the raw `sx={...}` attribute text, top-level braces only) — the exact
171
+ tag-scanning machinery `reportKitSxBypasses` (`:560-`) already uses. Reuse the same
172
+ `<(${componentPattern})\\b` regex approach for finding tags; you will need a NEW small parser to
173
+ walk `topLevelSxValue`'s result and extract individual top-level `property: value` pairs from a
174
+ literal object (`{ borderColor: 'divider', p: 2 }` → `[['borderColor', "'divider'"], ['p', '2']]`) —
175
+ this doesn't exist yet, write it narrowly (top-level only, matching the existing lower-bound
176
+ philosophy; do not attempt to parse nested objects, media-query keys, or `theme =>` callbacks).
177
+ - `reportOffPaletteColours`'s `normalizedSources`/path-skip pattern (`:747-753`, `:768-769`) — same
178
+ `{ path, source }` input shape, reuse `normalizedSources` directly, do NOT touch or widen its
179
+ `/(^|\/)src\/theme\//` skip (Non-goal, explicit).
180
+
181
+ **A real discrepancy found while preparing this map, worth resolving deliberately rather than
182
+ silently — the WO's own "grounded in cockpit" evidence does not match its own stated attribution
183
+ method:** the cited `borderColor: 'divider'` (×2), `bgcolor: 'background.paper'` (×3, one is inside a
184
+ `'&:hover'` nested selector), and `borderRadius: 1` (×3) all live in
185
+ `cockpit/frontend/src/cockpit/ChatView.jsx:75,82,95`, on **`<Box component="button" sx={{...}}>`** —
186
+ verified directly, not assumed. `Box` is not in `BASELINE_STYLED_MUI_COMPONENTS`, and the WO's own
187
+ "Scope" section describes attribution purely by JSX tag name (`<Paper sx=...> → MuiPaper`), while its
188
+ own "bound" section separately, explicitly lists a component rendered through `component={...}` as a
189
+ KNOWN, ACCEPTED GAP. **These two things conflict**: the check as scoped will NOT catch the WO's own
190
+ cited grounding examples. Meanwhile, cockpit's actual `<Paper>`/`<Card>`/etc. usages elsewhere
191
+ (`HeaderStrip.jsx`, `KnowledgeView.jsx`, `SettingsView.jsx`, and others) mostly use **template-literal**
192
+ sx values like `` border: `1px solid ${palette.divider}` `` — a JS expression referencing cockpit's own
193
+ imported `palette` object, not a plain string literal — which a source-level literal-value parser also
194
+ cannot resolve to "equals the theme's value" without evaluating arbitrary JS.
195
+
196
+ **Resolve this by NOT expanding scope to chase the cited numbers** (that would be exactly the
197
+ "enumeration reads as coverage" mistake the WO warns against, applied to attribution instead of the
198
+ bound's phrasing) — implement the check exactly as scoped (tag-name attribution, literal `'string'`/
199
+ `"string"`/numeric sx values only, skip anything that isn't a simple literal — a template literal,
200
+ identifier reference, or expression is out of scope and simply produces no finding for that property,
201
+ same lower-bound philosophy as every sibling check). **Then, when running it against cockpit for the
202
+ required count and sample, report what it ACTUALLY finds — which may be zero, or may differ from the
203
+ Envelope's cited 2+3+3 — and say so explicitly in the register note as a correction to the Envelope's
204
+ own grounding claim**, the same way prior WOs in this strand corrected their own stale counts
205
+ (`THEME-4`'s "51 files", `SHELL-4`'s "ten to six"). Do not silently match the cited numbers by quietly
206
+ special-casing `component=` or template-literal parsing to make them fit — if the honest run finds
207
+ different examples (or none) on properly-attributable tags, that is the real, reportable result.
208
+
209
+ **Where to add the new export:** same file, `src/theme/themeCompleteness.js`, alongside its siblings.
210
+ Suggested name (Codex's call, keep it short and consistent with `reportKitSxBypasses`/
211
+ `reportOffPaletteColours`): `reportRedundantThemeValues` or `reportAppSxRedundancy`. Same
212
+ `{ findings: [{ surface, reason }] }` contract; `surface` should follow the sibling convention
213
+ (`${path}:${line}.${property}` or similar — check `reportOffPaletteColours`'s `${path}:${line}.colour`
214
+ shape for the exact precedent). Export it from `src/theme/index.js` and `src/index.js` (follow the
215
+ existing export-list pattern in both — this is additive public API, matching the "next minor" version
216
+ target).
217
+
218
+ **Signature, per Scope item 1 + 2:** `reportRedundantThemeValues(sources, { theme })` — takes the
219
+ app's own sources (same `{path, source}`/string-array shape as siblings) and a **resolved theme
220
+ object** (an app passes its own `createAppTheme(...)` result, or — for ucm's own required tests — a
221
+ theme built the same way `assertKitSxDisjoint`'s tests do). For each JSX tag matching
222
+ `BASELINE_STYLED_MUI_COMPONENTS`, for each top-level literal `property: value` pair in its `sx`,
223
+ resolve `theme.components.Mui<Tag>.styleOverrides.root.<property>` via `getPath` and flag if
224
+ `sameValue(parsedValue, themeValue)` — matching value AND matching property AND matching component,
225
+ report-only (no exemption arm needed per the WO — this ships report-only with no hard-assertion path
226
+ yet, so skip building an exemption contract this round, that's each app's own future ratchet WO).
227
+
228
+ **Running it against cockpit (Scope item 3, required for the register note):** cockpit's frontend
229
+ source lives at `C:\Users\biglmi\Documents\webapps\cockpit\frontend\src` (37 `.jsx` files, confirmed).
230
+ Glob it (a small Node script or a throwaway test-like harness is fine — this does not need to be a
231
+ committed cockpit-side test, just evidence for the register note) the same way `reportOffPaletteColours`'s
232
+ own `'keeps current kit source free of hard off-palette findings'` test globs `src/` — exclude
233
+ `cockpit/frontend/src/theme.js` explicitly from the sources passed (per Scope's "resolve it app-side"
234
+ instruction — do NOT widen `reportOffPaletteColours`'s or this new check's own skip pattern to do it).
235
+ Build the theme via cockpit's own `createAppTheme(...)` call if one exists (check `theme.js` for the
236
+ palette it passes), or a reasonable equivalent. Report the exact count and 2-3 sample findings in the
237
+ register note, per Verification's explicit requirement — a check nobody has run against real code is
238
+ not verified.
239
+
240
+ **Invariants:** no fix in cockpit or the kit; no change to `reportOffPaletteColours`,
241
+ `assertKitSxDisjoint`, `reportKitSxBypasses`, `reportThemeAdoption`, or `assertThemeComplete`; no new
242
+ baseline token; no hard assertion anywhere (report-only only).
243
+
244
+ ### Mini-handover
245
+
246
+ Repo: `ui-core-micha` (`C:\Users\biglmi\Documents\webapps\ui-core-micha`), branch `main`.
247
+ WO: `work-orders/THEME-6.md`. Follow `orchestrate-codex`.