Skip to content

Centralize agent preamble into a single build-time injection#246

Merged
jakemor merged 2 commits into
mainfrom
claude/centralize-agent-preamble
Jul 14, 2026
Merged

Centralize agent preamble into a single build-time injection#246
jakemor merged 2 commits into
mainfrom
claude/centralize-agent-preamble

Conversation

@claude

@claude claude Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Requested by Jake Mor · Slack thread

Before / After

Before: the ~110-line agent-only context block (Superwall subscription-infrastructure preamble, emitted only into the per-page .md / llms.txt agent output — humans never see it) was copy-pasted into 585 of 594 docs pages.

After: it lives once in AGENT_VISIBILITY_MARKDOWN and is injected at build time. Doc pages carry zero copies of it. The agent/LLM output is unchanged.

How

  • src/lib/visibility.tsgetAgentVisibilityMarkdownForPage() now returns the canonical AGENT_VISIBILITY_MARKDOWN for every docs page (it was previously gated to the 6 SDK changelog paths). Removed the now-dead sdkChangelogPaths set and the extractLeadingAgentVisibilityMarkdown() helper.
  • src/lib/source.tsgetPageMarkdownText() injects the preamble from the constant ahead of the page title, description, and body. The old "extract the inline block and re-hoist it" path is gone, since no page inlines the block anymore.
  • content/docs/** — stripped the inline <Visibility for="agents"> preamble block from all 585 pages that carried it (matched on the canonical title line, so unrelated Visibility usages and the em-dash outlier were handled correctly). The 9 pages that never had the inline block, and content/shared/, were left untouched.
  • src/lib/visibility.test.ts — updated to assert universal injection; dropped the test for the removed extract helper.

Output-equivalence verification

I captured the generated agent markdown (getPageMarkdownText) for all 594 pages before and after the change and diffed them:

  • 591 pages: byte-identical. This includes the em-dash outlier (paywall-editor-slider-component.mdx), whose output was already canonicalized by remark-visibility and stays identical.
  • 3 pages differ, in one direction only: integrations/onesignal.mdx, integrations/singular.mdx, and web-checkout/web-checkout-managed-payments.mdx — recently-added pages that were missing the preamble entirely — now gain the canonical preamble prepended (verified as exactly preamble + "\n\n" + previous output, nothing else changed). This is the intended normalization: they now match every other docs page.

Human-facing HTML is unaffected — Visibility renders null for agents.

Verification

  • bun run build — succeeds (594 static cache files + search index generated).
  • bun test — 64 pass / 0 fail (was 65; the one dropped test covered the removed extractLeadingAgentVisibilityMarkdown helper).
  • bun run types:check — no new errors; the tsc error set is identical to the pre-existing repo-wide baseline (28 errors, unrelated to this change).

Possible follow-up

There are now zero <Visibility> usages of any kind in content/. The Visibility component, plugins/remark-visibility.ts, and src/lib/search-visibility.ts are consequently unexercised by current content. They were intentionally left intact here to keep this diff focused and low-risk (they harmlessly no-op and preserve the mechanism for future use); removing that infrastructure could be a separate cleanup PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JEbbev62ETTL47KjKzX443


Generated by Claude Code

The ~110-line agent-only "preamble" block (Superwall subscription-
infrastructure context, rendered only into per-page .md / LLM output)
was copy-pasted into 585 of 594 docs pages. The canonical copy already
lived in AGENT_VISIBILITY_MARKDOWN and the render pipeline already
re-injected it for the 6 SDK changelog pages that lacked the inline
copy, so the inline copies were pure source bloat.

- visibility.ts: getAgentVisibilityMarkdownForPage() now returns the
  canonical AGENT_VISIBILITY_MARKDOWN for every docs page (was gated to
  SDK changelog paths). Removed the now-dead sdkChangelogPaths set and
  the extractLeadingAgentVisibilityMarkdown() helper.
- source.ts: getPageMarkdownText() injects the preamble from the
  constant ahead of title/description/body; the extract-inline path is
  gone since no page inlines the block anymore.
- content/docs: stripped the inline <Visibility for="agents"> preamble
  block from all 585 pages that carried it.
- visibility.test.ts: updated to assert universal injection; dropped the
  test for the removed extract helper.

Per-page agent .md / LLM output is byte-identical for the 591 pages that
already emitted the preamble (incl. the em-dash outlier, whose output
was already canonicalized by remark-visibility). The 3 recently-added
pages that were missing the preamble entirely (onesignal, singular,
web-checkout-managed-payments) now receive it, bringing them in line
with every other page. Human HTML is unaffected (Visibility renders
null for agents).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JEbbev62ETTL47KjKzX443
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
superwall-docs 8c50fa7 Commit Preview URL

Branch Preview URL
Jul 14 2026, 12:41 PM

@claude claude Bot marked this pull request as ready for review July 14, 2026 12:35
@jakemor jakemor merged commit d65d883 into main Jul 14, 2026
2 checks passed
@jakemor jakemor deleted the claude/centralize-agent-preamble branch July 14, 2026 12:45
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.

2 participants