From 6e48cb82b7fd37311a8aea7405ad1c61982795de Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 1 Nov 2026 16:23:33 -0800 Subject: [PATCH] sitesmith: form text repairs pick neutrals; note when uploads were not used - contrast repair: ContactForm labelColor / inputTextColor are repaired to a neutral (text/bg/muted token, black, white), never the accent. Measured on the ttm-likes eval response in Chromium: before, dark typed text, UA-grey placeholders and an invalid border on the dark inputs; after, white text, placeholders at 70% of it, visible border. - a page/site build that shows none of the owner's offered uploads gets an honest note (the brief now requires one in the hero or a feature). Co-Authored-By: Claude Opus 5.5 --- craft/src/panels/sitesmith/SitesmithModal.tsx | 6 ++++-- craft/src/sitesmith/replace-plan.test.ts | 12 ++++++++++++ craft/src/sitesmith/replace-plan.ts | 10 ++++++++++ craft/src/utils/contrast-repair.test.ts | 1 + craft/src/utils/contrast-repair.ts | 9 +++++++-- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/craft/src/panels/sitesmith/SitesmithModal.tsx b/craft/src/panels/sitesmith/SitesmithModal.tsx index 502b694..fea9f53 100644 --- a/craft/src/panels/sitesmith/SitesmithModal.tsx +++ b/craft/src/panels/sitesmith/SitesmithModal.tsx @@ -31,7 +31,7 @@ import { summarizeCanvas } from '../../utils/canvas-summary'; import { SitesmithTarget } from '../../state/SitesmithContext'; import { UpgradeBanner } from './UpgradeBanner'; import { ScopeConfirmDialog } from './ScopeConfirmDialog'; -import { planReplace, isDefaultChrome, withoutChrome } from '../../sitesmith/replace-plan'; +import { planReplace, isDefaultChrome, withoutChrome, missingUploadedImageNote } from '../../sitesmith/replace-plan'; import { MessageList } from './MessageList'; import { ChatInput } from './ChatInput'; import { SitesmithResponse } from '../../types/sitesmith'; @@ -262,7 +262,9 @@ export const SitesmithModal: React.FC = ({ onClose, target }) => { // when they are untouched defaults and the owner says yes (replace-plan.ts). const userText = lastRequestRef.current ?? [...messages].reverse().find((m) => m.role === 'user')?.content ?? null; const plan = planReplace(res.response, { userText, chromeDefault: chromeDefault() }); - setNotes([...(res.notes ?? []), ...(plan.note ? [plan.note] : [])]); + const offered = useAssetsFlag ? (assetFilter ? assetFilter.length : assets.length) : 0; + const imgNote = missingUploadedImageNote(plan.resp, offered); + setNotes([...(res.notes ?? []), ...(plan.note ? [plan.note] : []), ...(imgNote ? [imgNote] : [])]); if (plan.confirm) { setPendingReplace({ resp: plan.resp, review, mode: plan.confirm }); return; diff --git a/craft/src/sitesmith/replace-plan.test.ts b/craft/src/sitesmith/replace-plan.test.ts index 273e31e..79ef53a 100644 --- a/craft/src/sitesmith/replace-plan.test.ts +++ b/craft/src/sitesmith/replace-plan.test.ts @@ -115,3 +115,15 @@ describe('fullBleedPageRoots (AI-built pages have no white frame around every se expect((r as any).pages[0].tree.props.style).toBeUndefined(); }); }); + +import { missingUploadedImageNote } from './replace-plan'; +describe('missingUploadedImageNote (the brief requires an uploaded image when there are uploads)', () => { + const pageWith = (props: any): SitesmithResponse => ({ type: 'replace', scope: 'page', message: 'm', pages: [{ name: 'Home', tree: { type: { resolvedName: 'Container' }, props: {}, nodes: [{ type: { resolvedName: 'ImageBlock' }, props, nodes: [] }] } as any }] }); + test('uploads offered but none used -> an honest note; used (src or bgImage) or no uploads -> none', () => { + expect(missingUploadedImageNote(pageWith({ src: 'https://placehold.co/800x600' }), 2)).toMatch(/did not use any of your 2 uploaded images/); + expect(missingUploadedImageNote(pageWith({ src: 'assets/team.jpg' }), 2)).toBeNull(); + expect(missingUploadedImageNote(pageWith({ bgImage: 'assets/team.jpg' }), 1)).toBeNull(); + expect(missingUploadedImageNote(pageWith({ src: 'https://placehold.co/800x600' }), 0)).toBeNull(); + expect(missingUploadedImageNote({ type: 'patch', message: 'm', ops: [] }, 3)).toBeNull(); + }); +}); diff --git a/craft/src/sitesmith/replace-plan.ts b/craft/src/sitesmith/replace-plan.ts index 5c13560..c6f2d7f 100644 --- a/craft/src/sitesmith/replace-plan.ts +++ b/craft/src/sitesmith/replace-plan.ts @@ -120,3 +120,13 @@ export function fullBleedPageRoots(resp: SitesmithResponse): SitesmithResponse { }), }; } + +/** + * A page/site build that shows none of the owner's uploads although some were offered (the brief requires + * one in the hero or a feature): say so instead of leaving the owner to wonder. Null when fine. + */ +export function missingUploadedImageNote(resp: SitesmithResponse, offeredUploads: number): string | null { + if (offeredUploads <= 0 || resp.type !== 'replace' || resp.scope === 'section') return null; + if (/"assets\/[^"]+"/.test(JSON.stringify(resp.pages))) return null; + return `Sitesmith did not use any of your ${offeredUploads} uploaded image${offeredUploads === 1 ? '' : 's'} on this page. Ask it to "use my photos", or add one with an Image block.`; +} diff --git a/craft/src/utils/contrast-repair.test.ts b/craft/src/utils/contrast-repair.test.ts index 0d1d257..782decd 100644 --- a/craft/src/utils/contrast-repair.test.ts +++ b/craft/src/utils/contrast-repair.test.ts @@ -379,6 +379,7 @@ describe('color-mix() surfaces and ContactForm inputs (eval 2026-11-01: placehol const out = repairResponseContrast(resp, D); const f = firstTree(out.response).nodes![0].props as any; expect(typeof f.inputTextColor).toBe('string'); + expect(['var(--wsb-text)', 'var(--wsb-bg)', 'var(--wsb-muted)', '#000000', '#ffffff']).toContain(f.inputTextColor); // a neutral, never the accent expect(ratio(f.inputTextColor, '#1b1530')).toBeGreaterThan(4.5); expect(out.adjustments.some((a) => a.node === 'ContactForm')).toBe(true); }); diff --git a/craft/src/utils/contrast-repair.ts b/craft/src/utils/contrast-repair.ts index a5f0918..03c46e6 100644 --- a/craft/src/utils/contrast-repair.ts +++ b/craft/src/utils/contrast-repair.ts @@ -139,6 +139,10 @@ function candidates(design: SiteDesign): Candidate[] { return out; } +/** Form text (labels, typed text, placeholders) is repaired to a neutral, never to a brand/accent colour. */ +const NEUTRALS = new Set([tokenRef('text'), tokenRef('bg'), tokenRef('muted'), '#000000', '#ffffff']); +const NEUTRAL_FG = new Set(['labelColor', 'inputTextColor']); + /** Lowest contrast of `fg` against any of `bg` (a single colour or the stops of a gradient). */ function worstRatio(fg: RGB, bg: RGB | RGB[]): number { const stops = isStops(bg) ? bg : [bg]; @@ -147,10 +151,11 @@ function worstRatio(fg: RGB, bg: RGB | RGB[]): number { const isStops = (bg: RGB | RGB[]): bg is RGB[] => Array.isArray(bg[0]); /** Nearest (in RGB) candidate that passes `need` against `bg` (every stop when given several), or null. Against one colour black/white always exist so one passes at 3:1 and at 4.5:1. */ -export function nearestPassing(fg: RGB, bg: RGB | RGB[], need: number, design: SiteDesign): Candidate | null { +export function nearestPassing(fg: RGB, bg: RGB | RGB[], need: number, design: SiteDesign, neutralOnly = false): Candidate | null { let best: Candidate | null = null; let bestD = Infinity; for (const c of candidates(design)) { + if (neutralOnly && !NEUTRALS.has(c.value)) continue; if (worstRatio(c.rgb, bg) < need) continue; const d = dist(c.rgb, fg); if (d < bestD) { best = c; bestD = d; } @@ -389,7 +394,7 @@ class Repairer { const need = isLargeText(style ?? props.style) ? AA_LARGE : AA; const before = worstRatio(fg, bg.stops); if (before >= need) return; - const pick = nearestPassing(fg, bg.stops, need, this.design); + const pick = nearestPassing(fg, bg.stops, need, this.design, NEUTRAL_FG.has(fgKey)); const after = pick ? worstRatio(pick.rgb, bg.stops) : 0; // Never make text worse: only apply a colour that reaches the target and strictly beats the old one. if (!pick || after < need || !(after > before)) { this.notChecked++; return; }