feat(web): extract hostContext utilities for the Apps host#1591
feat(web): extract hostContext utilities for the Apps host#1591cliffhall wants to merge 1 commit into
Conversation
) Add clients/web/src/components/elements/AppRenderer/hostContext.ts — a pure utilities module for the MCP Apps host: - currentTheme(): read the resolved Mantine color scheme from the DOM - currentStyles(): map the inspector's Mantine/-inspector design tokens to a McpUiHostStyles snapshot via STYLE_VARIABLE_SOURCES - measureContainerDimensions(): whole-pixel container measurement - snapshotHostContext(): assemble the initial McpUiHostContext seed Wave 1 of the PR #1510 decomposition (#1579). Pure extraction only — the AppRenderer/AppsScreen/createAppBridgeFactory rewrites belong to Wave 2. Full unit coverage (100% lines/statements/functions/branches). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S3fTN8H3R8YV4yUGvZjYnX
|
@claude review |
|
Claude finished @cliffhall's task in 3m 21s —— View job Review — hostContext utilities (Wave 1)
Overall this is a clean, well-scoped extraction. The module is genuinely pure/renderer-agnostic, the SSR/non-DOM guards are deliberate and tested, and the "omit optional fields rather than set them ✅ Verified
💡 Observations (non-blocking)
VerdictLooks good to merge as a Wave 1 base. No changes required; the duplication note (#1) is the only thing I'd consider addressing early, and it's optional. |
|
📋 Smoke test & AGENTS.md audit for this PR: #1559 (comment) (posted on the linked issue #1559). |
Closes #1559
Summary
Wave 1 of the PR #1510 decomposition (tracking issue #1579). Extracts the MCP Apps host-context logic into a new pure utilities module at
clients/web/src/components/elements/AppRenderer/hostContext.ts, so the follow-up hostContext-delivery / size-changed features can build on a testable, renderer-agnostic base.Scope is deliberately narrow: new module + test only. The
AppRenderer.tsx/AppsScreen.tsx/createAppBridgeFactory.tsrewrites that consume these utilities belong to Wave 2 and are untouched here (the existing inlinecurrentTheme()increateAppBridgeFactory.tsis left in place for Wave 2 to fold in).What's added
hostContext.ts:currentTheme()— reads the resolved Mantine color scheme from<html data-mantine-color-scheme>(DOM, not React state, to keep the bridge-factory identity stable across theme flips), with amatchMediafallback.currentStyles()— maps the inspector's Mantine /--inspector-*design tokens to a specMcpUiHostStylessnapshot viaSTYLE_VARIABLE_SOURCES; omits unresolved tokens and returnsundefinedrather than advertising an empty styles object.measureContainerDimensions()— whole-pixel{ width, height }measurement of the host container;undefinedfor a 0×0 / unattached element.snapshotHostContext()— assembles the initialMcpUiHostContextseed (theme,inlinedisplay mode, available modes, plus styles/dimensions when they resolve), omitting optional fields so the SDK diff stays accurate.Testing
hostContext.test.ts— 20 tests covering theme resolution (attribute, matchMedia fallback, SSR guards), token mapping / trimming / empty-omission, dimension rounding and zero-size handling, and snapshot assembly. Global stubs (vi.stubGlobal) exercise the non-DOM guard branches so nov8 ignoreis needed.validate:weband the full web coverage gate pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01S3fTN8H3R8YV4yUGvZjYnX