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 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-01 16:43:01 -08:00
1 parent ed50732d58
commit 6e48cb82b7
5 files changed
+34 -4

No files matched your search

@@ -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<Props> = ({ 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;
+12
View File
@@ -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();
});
});
+10
View File
@@ -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.`;
}
+1
View File
@@ -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);
});
+7 -2
View File
@@ -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<string>([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; }