fix(autofix): stop the write path mutating existing content (follow-on to #13) - #16
Conversation
Three mutations ran on saves of existing content and were surfaced only as "Auto-fixed N issue(s)", which reads like a courtesy. Found on a live site when a read-back returned content nobody had sent. 1. bricks_update_template ran autofix without a mode, so it defaulted to 'normalize' and Pass 5 rewrote el.name 'block' -> 'container' on any element carrying a flex property. That is a structural change to a layout a human authored. 06d34cd already fixed exactly this for pages (tools/pages.js passes mode:'preserve') and left the template writer normalizing. Now passes mode:'preserve' too. bricks_create_template still normalizes, deliberately: content the tool generates itself is what the aggressive repairs are for. 2. stripPxValues rewrote human-authored units on preserve saves. PX_SAFE_KEYS does not cover nested keys such as icon.height, so "20px" became "20". Bricks itself writes "20px" there, so on existing content the strip is a deviation rather than a fix. Pass 1 is now normalize-only. 3. BUILTIN_CSS_FIXES injected design-system global classes (ds-section-md, ds-gap-md) that may not exist on the target site, plus !important CSS. Now behind BRICKS_MCP_BUILTIN_FIXES. Point 3 changes a default, so it is the one worth arguing about — happy to invert it to an opt-out, or gate it on the classes actually existing on the site, whichever you prefer. Points 1 and 2 only affect saves of existing content and leave generated content normalized exactly as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for these — the measurements made all three PRs fast to verify. #11, #15 and #14 are merged; this one I'd like reshaped before it lands. Point 1 is right and lands as-is. It's exactly what Point 2 I've confirmed, but the fix is broader than the bug. The The problem is what disabling Pass 1 on Preferred shape, either of:
and keep it running in Point 3: taking the opt-in, as you proposed it. For a tool that runs on arbitrary sites, injecting So: please split. Points 1 + 3 in one PR and I'll merge it; point 2 as its own with the path-aware (or inverted) allowlist. On your two side notes:
|
Follow-on to #13 / v1.2.4. That release made saves of existing content non-destructive on the
page path; three mutations were still running elsewhere. All three were surfaced only as
Auto-fixed N issue(s), which reads like a courtesy rather than a rewrite. Found on a live sitewhen a read-back returned content nobody had sent.
1.
bricks_update_templatestill normalizedtools/templates.jscalledautofix(content)with no mode, so it defaulted to'normalize'andPass 5 rewrote
el.name'block'→'container'on any element carrying a flex property. That'sa structural change to a layout a human authored. Observed on one template: three blocks silently
promoted to containers.
06d34cd fixed exactly this for pages (
tools/pages.jspassesmode:'preserve') and the templatewriter was left normalizing. Now it passes
mode:'preserve'too.bricks_create_templatestill normalizes, deliberately — content the tool generates itself iswhat the aggressive repairs are for.
2.
stripPxValuesrewrote human-authored units on preserve savesPX_SAFE_KEYSdoesn't cover nested keys such asicon.height, so a preserve save turned"20px"into
"20". Bricks itself writes"20px"there — every icon in a stock header template stores itthat way — so on existing content the strip is a deviation, not a fix.
Pass 1 is now normalize-only. Generated content is unaffected.
3.
BUILTIN_CSS_FIXESinjected classes that may not exist on the target siteThese add design-system global classes (
ds-section-md,ds-gap-md) plus!importantCSS tocontent the caller never asked to restyle. On a site built with that design system they're a good
default. On any other site the classes resolve to nothing, and because the only report is
Auto-fixed N issue(s), nobody notices until it shows up in the browser.Now behind
BRICKS_MCP_BUILTIN_FIXES=1. Flagged rather than deleted, so it's one env var away.Points 1 and 2 only affect saves of existing content and leave generated content normalized
exactly as before, so I'd expect those to be uncontroversial. Point 3 flips a default for
everyone.
Happy to reshape it however you'd rather have it:
BRICKS_MCP_BUILTIN_FIXES=0), keeping today's defaultprecondition and would make it safe on by default
Say which and I'll push it.
Verification
Found and confirmed against a live Bricks site: a template save that reported
Auto-fixed 3 issue(s)and returned threeblockelements ascontaineron read-back, and an icon whose"20px"came back"20". Both stop after the change; a read-back returns exactly what was sent.node --checkpasses on both changed files. I didn't see an automated test suite to extend —tests/test-suite.jsonlooks like inspector fixtures rather than a runner. Point me at one ifthere is.
Branched off
main, 44 insertions across two files.