Skip to content

Commit 2d0ac6a

Browse files
DeDuckProjectclaude
andcommitted
docs: add README
Covers quick start (Action + CLI), full configuration reference, action inputs/outputs, requirements, route detection conventions, retry/fallback behavior, and development setup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c321cb7 commit 2d0ac6a

1 file changed

Lines changed: 238 additions & 0 deletions

File tree

README.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# GitGlimpse
2+
3+
Automatically generate visual demo clips of UI changes in pull requests.
4+
5+
When a PR is opened, GitGlimpse reads the diff, uses an LLM to understand what changed, generates a Playwright interaction script, records a demo, and posts it as a PR comment — all without leaving CI.
6+
7+
![Example PR comment showing a GIF demo](docs/example-comment.png)
8+
9+
## How it works
10+
11+
```
12+
PR opened/updated
13+
14+
15+
Diff Analyzer ── identifies changed files and affected routes
16+
17+
18+
Script Generator ── LLM reads diff → generates Playwright script
19+
20+
21+
Recorder ── Playwright executes script + captures video
22+
23+
24+
Publisher ── FFmpeg converts to GIF, posts as PR comment
25+
```
26+
27+
## Quick start
28+
29+
### GitHub Action
30+
31+
Add a workflow file to your repo:
32+
33+
```yaml
34+
# .github/workflows/git-glimpse.yml
35+
name: GitGlimpse
36+
37+
on:
38+
pull_request:
39+
types: [opened, synchronize]
40+
paths:
41+
- 'app/**'
42+
- 'src/**'
43+
44+
jobs:
45+
demo:
46+
runs-on: ubuntu-latest
47+
permissions:
48+
pull-requests: write
49+
contents: read
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
55+
- uses: actions/setup-node@v4
56+
with:
57+
node-version: '20'
58+
59+
- run: npm ci
60+
61+
- uses: git-glimpse/action@v1
62+
env:
63+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
```
66+
67+
Add a `git-glimpse.config.ts` at your repo root:
68+
69+
```typescript
70+
import type { GitGlimpseConfig } from '@git-glimpse/core';
71+
72+
export default {
73+
app: {
74+
startCommand: 'npm run dev',
75+
readyWhen: { url: 'http://localhost:3000' },
76+
},
77+
recording: {
78+
format: 'gif',
79+
maxDuration: 30,
80+
},
81+
llm: {
82+
provider: 'anthropic',
83+
model: 'claude-sonnet-4-6',
84+
},
85+
} satisfies GitGlimpseConfig;
86+
```
87+
88+
Add your Anthropic API key as a GitHub secret: **Settings → Secrets → `ANTHROPIC_API_KEY`**.
89+
90+
### With Vercel / Netlify deploy previews
91+
92+
If your app already has deploy previews, skip the `startCommand` — point GitGlimpse at the preview URL instead:
93+
94+
```yaml
95+
- uses: git-glimpse/action@v1
96+
with:
97+
preview-url: ${{ steps.vercel.outputs.preview-url }}
98+
env:
99+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
```
102+
103+
```typescript
104+
export default {
105+
app: {
106+
previewUrl: 'VERCEL_URL', // env var name or literal URL
107+
},
108+
} satisfies GitGlimpseConfig;
109+
```
110+
111+
### CLI (local use)
112+
113+
```bash
114+
npx git-glimpse run --diff HEAD~1 --url http://localhost:3000 --open
115+
```
116+
117+
Initialize a config file:
118+
119+
```bash
120+
npx git-glimpse init
121+
```
122+
123+
## Configuration
124+
125+
All options in `git-glimpse.config.ts`:
126+
127+
```typescript
128+
import type { GitGlimpseConfig } from '@git-glimpse/core';
129+
130+
export default {
131+
// ── App startup ───────────────────────────────────────
132+
app: {
133+
// Option A: GitGlimpse starts the app
134+
startCommand: 'npm run dev',
135+
readyWhen: { url: 'http://localhost:3000', status: 200, timeout: 30000 },
136+
env: { DATABASE_URL: 'sqlite::memory:' },
137+
138+
// Option B: use an existing deploy preview
139+
// previewUrl: 'VERCEL_URL', // env var name or literal URL
140+
},
141+
142+
// ── Route map (optional, improves LLM accuracy) ───────
143+
// Maps source file globs → URLs where changes are visible
144+
routeMap: {
145+
'app/routes/products.$id.tsx': '/products/sample-product',
146+
'src/components/Header.tsx': '/',
147+
'extensions/my-block/**': '/products/sample-product',
148+
},
149+
150+
// ── Setup (optional) ──────────────────────────────────
151+
setup: 'node scripts/seed.js',
152+
153+
// ── Recording ─────────────────────────────────────────
154+
recording: {
155+
format: 'gif', // 'gif' | 'mp4' | 'webm'
156+
maxDuration: 30, // seconds
157+
viewport: { width: 1280, height: 720 },
158+
deviceScaleFactor: 2,
159+
},
160+
161+
// ── LLM ───────────────────────────────────────────────
162+
llm: {
163+
provider: 'anthropic', // 'anthropic' | 'openai'
164+
model: 'claude-sonnet-4-6', // or 'gpt-4o', etc.
165+
},
166+
} satisfies GitGlimpseConfig;
167+
```
168+
169+
### Action inputs
170+
171+
| Input | Default | Description |
172+
|---|---|---|
173+
| `config-path` | `git-glimpse.config.ts` | Path to config file |
174+
| `preview-url` | — | External preview URL (overrides config) |
175+
| `start-command` | — | App start command (overrides config) |
176+
| `format` | `gif` | Output format: `gif`, `mp4`, `webm` |
177+
| `max-duration` | `30` | Max recording duration in seconds |
178+
179+
### Action outputs
180+
181+
| Output | Description |
182+
|---|---|
183+
| `recording-url` | URL of the uploaded recording artifact |
184+
| `comment-url` | URL of the posted PR comment |
185+
| `success` | Whether recording succeeded (`true`/`false`) |
186+
187+
## Requirements
188+
189+
- **Node.js** ≥ 20
190+
- **Anthropic API key** — set as `ANTHROPIC_API_KEY` environment variable
191+
- **FFmpeg** — required for GIF/MP4 conversion
192+
- Ubuntu/Debian: `apt-get install ffmpeg`
193+
- macOS: `brew install ffmpeg`
194+
- GitHub Actions: pre-installed on `ubuntu-latest`
195+
- **Playwright Chromium** — installed automatically by the action; for local use run `npx playwright install chromium`
196+
197+
## How app startup works
198+
199+
GitGlimpse supports two modes:
200+
201+
**Preview URL mode** (recommended when available): Point it at a Vercel, Netlify, or Cloudflare Pages deploy preview. No app startup needed — more reliable and faster.
202+
203+
**Start command mode**: GitGlimpse runs `startCommand`, waits for `readyWhen.url` to return HTTP 200, then begins recording. Works well for Next.js, Remix, SvelteKit and other apps that start cleanly with `npm run dev`. Apps requiring tunnels, OAuth flows, or external services must use preview URL mode.
204+
205+
## Route detection
206+
207+
GitGlimpse automatically maps changed files to URLs using framework conventions:
208+
209+
| Framework | Convention | Example |
210+
|---|---|---|
211+
| Remix | `app/routes/products.$id.tsx` | `/products/:id` |
212+
| Next.js App Router | `app/products/[id]/page.tsx` | `/products/:id` |
213+
| Next.js Pages Router | `pages/products/[id].tsx` | `/products/:id` |
214+
| SvelteKit | `src/routes/products/[id]/+page.svelte` | `/products/:id` |
215+
216+
For files that don't follow a convention (shared components, Liquid templates, etc.), use the `routeMap` config option to tell GitGlimpse which URL to visit.
217+
218+
## Retry and fallback behavior
219+
220+
If the generated Playwright script fails (element not found, timeout), GitGlimpse:
221+
222+
1. Captures the error and retries with the error context fed back to the LLM (up to 2 retries)
223+
2. Falls back to static screenshots if all attempts fail
224+
225+
The PR comment is always posted — either with the GIF or with screenshots as a fallback.
226+
227+
## Development
228+
229+
```bash
230+
pnpm install
231+
pnpm test # unit tests
232+
pnpm run test:integration # Playwright + FFmpeg tests (no API key needed)
233+
pnpm run test:llm # full pipeline with real LLM (requires ANTHROPIC_API_KEY)
234+
```
235+
236+
## License
237+
238+
MIT

0 commit comments

Comments
 (0)