Skip to content

Share the Wikimedia Commons plumbing via @spelling-creator/core - #17

Merged
playforge-coding merged 1 commit into
core-extract-leavesfrom
core-dedupe-wikimedia
Aug 5, 2026
Merged

Share the Wikimedia Commons plumbing via @spelling-creator/core#17
playforge-coding merged 1 commit into
core-extract-leavesfrom
core-dedupe-wikimedia

Conversation

@playforge-coding

@playforge-coding playforge-coding commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Second layer. Stacked on #16.

The premise I started with was wrong

I'd scoped this as "web 215 lines vs mcp 177, identical export surface, collapse to one module." That came from a crude grep that only matched export async function. The two clients are not interchangeable:

web mcp
download export fetchWikimediaImage(hit) resolveWikimediaImage(ref)
search returns {hits, total, totalHits} bare array
hit shape {id, title, tags, descriptionURL, licenseURL, …} {ref, description, source, …}
paging yes (gsroffset) no
perPage default 20, max 50 default 12, max 30
error wording Search failed (404). Wikimedia Commons request failed (404).

Those differences are part of each app's contract — the image dialog's shape and the MCP tool's documented shape — so collapsing them would have been a breaking change dressed up as a refactor.

What this does instead

Moves only what is genuinely common to @spelling-creator/core/wikimedia: the endpoint, the query/unwrap round-trip, search-rank restoration, the image/non-image filter, and the licence/author handling Commons' attribution norms require. Each app keeps a thin adapter, so its public shape and its user-facing strings stay its own.

Two runtime differences are handled by injection rather than duplication:

  • the MCP server passes the User-Agent Wikimedia's policy requires from datacenter egress (Node's default node gets throttled or 403'd);
  • the web app passes a DOMParser-based HTML stripper, keeping core DOM-free.

Core staying DOM-free matters here: the Worker pulls this module in through @spelling-creator/mcp/worker. The worker-env lint rule added in #16 now enforces that.

This is not a line saving

Net +73 lines. The win is that the attribution rules and the Commons API shape have one definition instead of two copies that had already drifted. If you'd rather carry the duplication than the indirection, this layer can be dropped without affecting #16.

Verification

pnpm run lint, pnpm run build, pnpm run build:docs, and all three suites pass. The mcp add_image test exercises resolveWikimediaImage end to end, so the refactor has real coverage.

Stack created with GitHub Stacks CLIGive Feedback 💬

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 89cd6bda-0013-45c4-90a4-480748231b02

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

The web app and the MCP server each carried their own Commons client. They were
never actually interchangeable — different exports (fetchWikimediaImage vs
resolveWikimediaImage), different hit shapes, paging only in the browser, and
different error wording — so this does not collapse them into one function.

Instead the parts that genuinely are the same move to core: the endpoint, the
query/unwrap round-trip, search-rank restoration, the image/non-image filter,
and the licence/author handling Commons' attribution norms require. Each app
keeps a thin adapter, so its public contract and its user-facing strings stay
its own.

Note this is not a net line saving (+73). The win is that the attribution and
API-shape rules now have one definition instead of two copies that had already
drifted apart.

Two runtime differences are handled by injection rather than duplication:
the MCP server passes the User-Agent that Wikimedia's policy requires from
datacenter egress, and the web app passes a DOMParser-based HTML stripper.
Core itself stays DOM-free, which the worker-env lint rule now enforces, since
the Worker pulls this in through @spelling-creator/mcp/worker.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@playforge-coding
playforge-coding merged commit cde68dc into master Aug 5, 2026
2 of 3 checks passed
@playforge-coding
playforge-coding deleted the core-dedupe-wikimedia branch August 5, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant