Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"plugins": [
{
"name": "visualci",
"version": "0.1.27",
"version": "0.1.28",
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
"author": { "name": "DocSpring", "url": "https://visualci.com" },
"homepage": "https://visualci.com/docs/skills/",
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "visualci",
"version": "0.1.27",
"version": "0.1.28",
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
"author": { "name": "DocSpring", "url": "https://visualci.com" },
"homepage": "https://visualci.com/docs/skills/",
Expand Down
2 changes: 1 addition & 1 deletion .cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "visualci",
"displayName": "VisualCI",
"version": "0.1.27",
"version": "0.1.28",
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
"author": {
"name": "DocSpring"
Expand Down
2 changes: 1 addition & 1 deletion gemini-extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "visualci",
"version": "0.1.27",
"version": "0.1.28",
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
"mcpServers": {
"visualci": {
Expand Down
15 changes: 9 additions & 6 deletions scripts/screenshots/capture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ async function main() {
],
})
const contexts = new Map()
async function context(variant, signedIn) {
const key = `${variant}/${signedIn}`
async function context(variant, signedIn, scale = 1) {
const key = `${variant}/${signedIn}/${scale}`
if (contexts.has(key)) return contexts.get(key)
const [width, theme] = variant.split('-')
const ctx = await browser.newContext({
baseURL: opts.baseUrl,
viewport: { width: Number(width), height: 900 },
deviceScaleFactor: 1,
deviceScaleFactor: scale,
colorScheme: theme,
reducedMotion: 'reduce',
locale: 'en-US',
Expand Down Expand Up @@ -141,8 +141,11 @@ async function main() {
let count = 0
for (const [name, target, signedIn, variants] of pages()) {
if (opts.only && !name.includes(opts.only)) continue
for (const variant of variants) {
const ctx = await context(variant, signedIn)
// Each screenshot at 1x (the baseline VisualCI compares). The app's, which the public gallery publishes, again at 2x
// (`<variant>-2x`) for high-density screens: visualci.com's own pages use it in their srcset.
const scales = name.startsWith('app/') ? [1, 2] : [1]
for (const [variant, scale] of variants.flatMap((v) => scales.map((x) => [v, x]))) {
const ctx = await context(variant, signedIn, scale)
const page = await ctx.newPage()
const api = async (path) => {
const res = await ctx.request.get(path)
Expand All @@ -154,7 +157,7 @@ async function main() {
if (!response || response.status() >= 400) throw new Error(`${name}: ${path} gave HTTP ${response?.status()}`)
await settle(page)
await unstick(page)
const file = join(opts.out, `${name}/${variant}.png`)
const file = join(opts.out, `${name}/${variant}${scale === 2 ? '-2x' : ''}.png`)
await mkdir(dirname(file), { recursive: true })
await page.screenshot({ path: file, fullPage: true, animations: 'disabled', caret: 'hide' })
await page.close()
Expand Down
2 changes: 1 addition & 1 deletion server/frontend/content/docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \

1. CI sends a build and finishes. When something changed, the CI job still passes, and the pull request's VisualCI check stays pending.
2. The agent calls `list_builds` or `get_build` to see what needs attention: changed, added, removed and failed snapshots.
3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff.
3. For each change, it calls `get_snapshot`. For PDFs and images that returns the base, head and diff images of the changed pages, the changed regions, the page's text diff, and lines that moved to another page. For text, JSON and HTML snapshots it returns the changes by JSON path (`items[3].price: 10 → 12`) and a unified diff. A contact sheet is for finding the changes, not for judging them: its thumbnails are too small to show a button covering a tab or a missing style. Open every sizeable UI change with `get_snapshot` and `crop: "changed"`, which shows the changed regions at full size.
4. The agent checks each change against the code and the task:
- **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed.
- **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline.
Expand Down
127 changes: 87 additions & 40 deletions server/frontend/scripts/prerender.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -176,67 +176,114 @@ async function galleryManifest() {

const escapeHtml = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')

/** A group's screenshots by screen: `screenshots/app/billing/free/1440-dark` is the screen `billing/free` at
* `1440-dark`. Light before dark, wide before narrow. */
function screens(items) {
const byScreen = new Map()
for (const item of items) {
const parts = item.name.split('/')
const variant = parts.pop()
const screen = parts.filter((p, i) => !(i === 0 && p === 'screenshots')).join('/') || item.name
if (!byScreen.has(screen)) byScreen.set(screen, [])
byScreen.get(screen).push({ ...item, variant })
}
const order = (v) => [-(parseInt(v, 10) || 0), v.includes('dark') ? 1 : 0]
for (const list of byScreen.values()) {
list.sort((a, b) => {
const [aw, ad] = order(a.variant)
const [bw, bd] = order(b.variant)
return aw - bw || ad - bd
})
/** `screenshots/app/billing/free/1440-dark-2x` → the screen `app/billing/free`, desktop, dark, 2x. A name that isn't
* `<width>-<theme>` is its own screen, shown as it is. */
function parseShot(name) {
const parts = name.split('/')
const last = parts.pop()
const m = /^(\d+)-(light|dark)(-2x)?$/.exec(last)
const screen = parts.filter((p, i) => !(i === 0 && p === 'screenshots')).join('/')
if (!m) return { screen: parts.length ? `${screen}/${last}` : last, device: 'desktop', theme: 'light', x2: false }
return { screen, device: Number(m[1]) >= 768 ? 'desktop' : 'phone', theme: m[2], x2: !!m[3] }
}

/** The page's sections, each a list of screens with their versions ({device, theme, url, url2x, width, height}).
* Screens under `app/` are the web app (on desktop and phone, whichever groups they came from); the rest are the
* site. */
function gallerySections(manifest) {
const sections = new Map()
for (const group of manifest.groups) {
for (const item of group.items) {
const shot = parseShot(item.name)
const key = shot.screen.startsWith('app/') ? 'app' : 'site'
if (!sections.has(key)) {
const title = key === 'app' ? 'The web app' : 'visualci.com and its docs'
sections.set(key, { key, title, screens: new Map() })
}
const screens = sections.get(key).screens
if (!screens.has(shot.screen)) screens.set(shot.screen, new Map())
const versions = screens.get(shot.screen)
const vkey = `${shot.device}-${shot.theme}`
const v = versions.get(vkey) ?? { device: shot.device, theme: shot.theme }
if (shot.x2) v.url2x = item.url
else Object.assign(v, { url: item.url, width: item.width, height: item.height })
versions.set(vkey, v)
}
}
return [...byScreen].map(([screen, variants]) => ({ screen, variants }))
const order = ['app', 'site']
return [...sections.values()]
.sort((a, b) => order.indexOf(a.key) - order.indexOf(b.key))
.map((s) => ({
...s,
screens: [...s.screens]
.map(([screen, versions]) => ({ screen, versions: [...versions.values()].filter((v) => v.url) }))
.filter((s) => s.versions.length)
.sort((a, b) => screenOrder(a.screen) - screenOrder(b.screen) || a.screen.localeCompare(b.screen)),
}))
}

const variantLabel = (v) => v.replace(/^(\d+)-/, '$1 px, ')
/** The homepage first, then the docs home, then the rest by name. */
const screenOrder = (screen) => (screen === 'landing' ? 0 : screen === 'docs/index' ? 1 : 2)

/** `app/billing/free` → "Billing, free"; `docs/ci/github-actions` → "Docs: CI, GitHub Actions"; `landing` →
* "Homepage". */
function screenTitle(screen) {
const words = { ci: 'CI', api: 'API', cli: 'CLI', pdf: 'PDF', json: 'JSON', html: 'HTML', github: 'GitHub', gitlab: 'GitLab', circleci: 'CircleCI', rspec: 'RSpec', vitest: 'Vitest', jest: 'Jest', insta: 'insta', syrupy: 'syrupy', buildkite: 'Buildkite' }
const word = (w) => w.split('-').map((p) => words[p] ?? p).join(' ')
const cap = (t) => t.charAt(0).toUpperCase() + t.slice(1)
if (screen === 'landing') return 'Homepage'
if (screen === 'docs/index') return 'Docs home'
const parts = screen.split('/')
if (parts[0] === 'docs') return `Docs: ${parts.slice(1).map((p) => cap(word(p))).join(', ')}`
if (parts[0] === 'app') parts.shift()
return cap(parts.map(word).join(', '))
}

/** The version a card shows for a theme and device: exactly that, else the same device, else the same theme, else any. */
function pickVersion(versions, device, theme) {
return (
versions.find((v) => v.device === device && v.theme === theme) ??
versions.find((v) => v.device === device) ??
versions.find((v) => v.theme === theme) ??
versions[0]
)
}

function galleryHtml(manifest) {
const intro = `<p>Screenshots VisualCI's own tests take of its web app and this site, as approved on main. They come from VisualCI's <a href="/docs/gallery/">public gallery</a>, so they change when a change to them is approved. As JSON: <a href="${GALLERY_MANIFEST}">visualci.json</a>.</p>`
const intro = `<p class="gx-lede">Every screen of VisualCI's web app, light and dark, on a desktop and on a phone. VisualCI's own tests take them, and they come from its <a href="/docs/gallery/">public gallery</a>, so each one changes when it is approved. As JSON: <a href="${GALLERY_MANIFEST}">visualci.json</a>.</p>`
if (!manifest?.groups?.length) {
return `${intro}<div id="screenshot-gallery" class="shots" data-manifest="${GALLERY_MANIFEST}"><p class="muted shots-empty">The screenshots couldn't be loaded when this page was built.</p></div>`
return `${intro}<div id="screenshot-gallery" class="gx"><p class="muted">The screenshots couldn't be loaded when this page was built.</p></div>`
}
const groups = manifest.groups.map((g, gi) => {
const id = `shots-${g.name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`
const cards = screens(g.items).map(({ screen, variants }) => {
const first = variants.find((v) => !v.variant.includes('dark')) ?? variants[0]
const dark = variants.find((v) => v.variant.includes('dark') && parseInt(v.variant, 10) === parseInt(first.variant, 10))
const data = escapeHtml(JSON.stringify(variants.map((v) => ({ url: v.url, label: variantLabel(v.variant), width: v.width, height: v.height }))))
const alt = escapeHtml(`${g.title || g.name}: ${screen}`)
return `<li class="shots-card"><a href="${escapeHtml(first.url)}" data-variants="${data}" aria-label="${alt}, ${variants.length} ${variants.length === 1 ? 'version' : 'versions'}"><picture>${dark ? `<source media="(prefers-color-scheme: dark)" srcset="${escapeHtml(dark.url)}">` : ''}<img src="${escapeHtml(first.url)}" width="${first.width}" height="${first.height}" alt="${alt}" loading="${gi === 0 ? 'eager' : 'lazy'}" decoding="async"></picture><span class="shots-caption"><span class="mono">${escapeHtml(screen)}</span><span class="muted">${variants.map((v) => escapeHtml(variantLabel(v.variant))).join(' · ')}</span></span></a></li>`
const sections = gallerySections(manifest).map((section) => {
const cards = section.screens.map(({ screen, versions }) => {
const shown = pickVersion(versions, 'desktop', 'light')
const title = screenTitle(screen)
const data = escapeHtml(JSON.stringify(versions))
return `<a class="gx-card" href="${escapeHtml(shown.url)}" data-title="${escapeHtml(title)}" data-versions="${data}"><span class="gx-thumb" data-device="${shown.device}"><img src="${escapeHtml(shown.url)}" width="${shown.width}" height="${shown.height}" alt="${escapeHtml(title)}" loading="lazy" decoding="async"></span><span class="gx-name">${escapeHtml(title)}</span></a>`
})
return `<section class="shots-group" id="${id}" data-name="${escapeHtml(g.name)}"><h2>${escapeHtml(g.title || g.name)}</h2><ul class="shots-grid">${cards.join('')}</ul></section>`
return `<section class="gx-section" data-section="${section.key}"><div class="gx-section-head"><h2>${escapeHtml(section.title)}</h2><span class="gx-count">${section.screens.length} screens</span></div><div class="gx-grid" data-device="desktop">${cards.join('')}</div></section>`
})
return `${intro}<div id="screenshot-gallery" class="shots" data-manifest="${GALLERY_MANIFEST}">${groups.join('')}</div>`
return `${intro}<div id="screenshot-gallery" class="gx">${sections.join('')}</div>`
}

function galleryMarkdown(manifest) {
const head = `VisualCI's own screenshots of its web app and this site, as approved on main, from its public gallery (${SITE}/docs/gallery.md). The manifest: ${GALLERY_MANIFEST}`
const head = `VisualCI's own screenshots of its web app, light and dark, on a desktop and on a phone, as approved on main, from its public gallery (${SITE}/docs/gallery.md). Each has a 2x copy for high-density screens (the same URL ending in -2x.png). The manifest: ${GALLERY_MANIFEST}`
if (!manifest?.groups?.length) return `${head}\n\nThe screenshots couldn't be loaded when this page was built.`
const groups = manifest.groups.map(
(g) =>
`## ${g.title || g.name}\n\n` +
screens(g.items)
.map(({ screen, variants }) => `- ${screen}: ${variants.map((v) => `[${variantLabel(v.variant)}](${v.url})`).join(', ')}`)
const sections = gallerySections(manifest).map(
(s) =>
`## ${s.title}\n\n` +
s.screens
.map(({ screen, versions }) => `- ${screenTitle(screen)}: ${versions.map((v) => `[${v.device}, ${v.theme}](${v.url})`).join(', ')}`)
.join('\n'),
)
return [head, ...groups].join('\n\n')
return [head, ...sections].join('\n\n')
}

const manifest = await galleryManifest()
await writeStandalone({
slug: 'screenshots',
title: 'Screenshots',
description: "VisualCI's web app and site, from its own public gallery: the screenshots its tests take, as approved on main.",
description: "Every screen of VisualCI's web app, light and dark, on a desktop and on a phone, from its own public gallery.",
html: galleryHtml(manifest),
copy: galleryMarkdown(manifest),
})
Expand Down
7 changes: 3 additions & 4 deletions server/frontend/src/components/AgentPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CopyButton } from './ui'
import { siteUrl } from '../lib/hosts'

/** The one-line setup for coding agents, to copy: the agent fetches install.md and follows it. */
export const AGENT_PROMPT = `Fetch ${siteUrl('/install.md')} and follow it`
/** The one-line setup for coding agents, to copy: the agent fetches install.md and follows it. Always visualci.com's,
* the only one worth giving an agent (a dev server or CI capture would otherwise show its own address). */
export const AGENT_PROMPT = 'Fetch https://visualci.com/install.md and follow it'

export function AgentPrompt({ label = 'Or ask your coding agent:' }: { label?: string }) {
return (
Expand Down
24 changes: 17 additions & 7 deletions server/frontend/src/components/GalleryImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,37 @@ export const GALLERY = 'https://app.visualci.com/g/docspring/visualci'

export const galleryUrl = (name: string) => `${GALLERY}/${name}.png`

/** One gallery screenshot, sized up front so nothing moves while it loads. If it can't load (the app is down, the
* screenshot was renamed), its description takes its place. */
/** The 2x copy of a gallery screenshot (`…/1440-light-2x`), captured at device scale 2 for high-density screens. */
export const galleryUrl2x = (name: string) => `${GALLERY}/${name}-2x.png`

/** One gallery screenshot, sized up front so nothing moves while it loads. High-density screens get its 2x copy
* (`srcset` by width, so a phone picks the 1x one). If the 2x copy can't load (not approved yet), the 1x one is used; if
* neither can (the app is down, the screenshot was renamed), its description takes its place. */
export function GalleryImage({
name,
width,
height,
alt,
sizes,
className,
}: {
name: string
/** The 1x image's size in CSS pixels. */
width: number
height: number
alt: string
/** How wide the image shows, for picking 1x or 2x (`sizes`). */
sizes: string
className?: string
}) {
const ref = useRef<HTMLImageElement>(null)
const [failed, setFailed] = useState(false)
const [stage, setStage] = useState<'srcset' | 'plain' | 'failed'>('srcset')
// An image that failed before the page hydrated fired its error event before React was listening.
useEffect(() => {
const img = ref.current
if (img && img.complete && img.naturalWidth === 0) setFailed(true)
}, [])
if (failed) {
if (img && img.complete && img.naturalWidth === 0) setStage((s) => (s === 'srcset' ? 'plain' : 'failed'))
}, [stage])
if (stage === 'failed') {
return (
<span className={`gallery-missing ${className ?? ''}`} role="img" aria-label={alt}>
{alt}
Expand All @@ -40,12 +48,14 @@ export function GalleryImage({
ref={ref}
className={className}
src={galleryUrl(name)}
srcSet={stage === 'srcset' ? `${galleryUrl(name)} ${width}w, ${galleryUrl2x(name)} ${width * 2}w` : undefined}
sizes={stage === 'srcset' ? sizes : undefined}
width={width}
height={height}
alt={alt}
loading="lazy"
decoding="async"
onError={() => setFailed(true)}
onError={() => setStage((s) => (s === 'srcset' ? 'plain' : 'failed'))}
/>
)
}
9 changes: 8 additions & 1 deletion server/frontend/src/pages/DocsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export function DocsPage({ page }: { page: DocsPageData }) {
</div>
</div>
</header>
<div className={standalone ? 'lp-wrap docs-layout docs-layout-single' : 'lp-wrap docs-layout'}>
<div
className={
standalone
? // The screenshots gallery uses the page's width; other pages outside the docs keep a reading column.
`lp-wrap docs-layout docs-layout-single${page.slug === 'screenshots' ? ' docs-layout-wide' : ''}`
: 'lp-wrap docs-layout'
}
>
{!standalone && (
<aside className="docs-side">
<details className="docs-menu">
Expand Down
2 changes: 2 additions & 0 deletions server/frontend/src/pages/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,15 @@ export function Landing() {
name="screenshots/app/snapshot/pdf/1440-light"
width={1440}
height={2459}
sizes="(max-width: 1200px) calc(100vw - 32px), 1112px"
alt="VisualCI's review of a changed receipt: page 2's total line boxed in both versions, its text diff, and an inserted page 3"
/>
<GalleryImage
className="lp-shot-dark"
name="screenshots/app/snapshot/pdf/1440-dark"
width={1440}
height={2459}
sizes="(max-width: 1200px) calc(100vw - 32px), 1112px"
alt="The same review in dark mode"
/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion server/frontend/src/pages/ProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function PublicList({ gallery }: { gallery: PublicGallery }) {
if (!gallery.manifest_url)
return (
<p className="hint">
Nothing is public. Add <span className="mono">gallery</span> groups to visualci.yml to publish screenshots.{' '}
The gallery is on, with nothing in it yet. Add <span className="mono">gallery</span> groups to visualci.yml to
publish screenshots.{' '}
<a href="/docs/gallery/">How</a>
</p>
)
Expand Down
Loading
Loading