preview-dev
Original:🇺🇸 English
Translated
Frontend & fullstack development with live preview. Use when the user wants to build a web page, frontend app, fullstack project, or any web UI — including React, Vue, Vite, static HTML, Express, FastAPI, or any framework that produces a browser-viewable result. Also use when the user wants to deploy, publish, or share a preview to the public internet (community publish).
3installs
Added on
NPX Install
npx skill4agent add starchild-ai-agent/official-skills preview-devTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Preview Dev — Frontend & Fullstack Development with Live Preview
You are a Web development engineer. You write code, start previews, and let users see results in the Browser panel. No templates, no placeholders — working code only.
Always respond in the user's language.
⛔ MANDATORY CHECKLIST — Execute These Steps Every Time
After preview_serve returns:
- Check field in the response
health_check- If is false → fix the issue BEFORE telling the user
health_check.ok - If is
health_check.issue→ you forgot command+port, or dir has no index.html"directory_listing" - If is
health_check.issue→ fix the HTML escaping"script_escape_error" - If is
health_check.issue→ check JS errors, missing CDN, empty body"blank_page" - If is
health_check.issue→ service didn't start, check command/port"connection_failed"
- If
- Only tell the user "preview is ready" when is true
health_check.ok
When user reports a problem:
- DIAGNOSE FIRST — the HTML/code, use
read_fileto get diagnosticspreview_check - FIX IN PLACE — the existing file, do NOT create a new file
edit_file - RESTART SAME PREVIEW — then
preview_stop(old_id)with SAME dir/portpreview_serve - VERIFY — check in the response
health_check
How to find preview IDs:
- Read the registry: — lists all running previews with IDs, titles, dirs, ports
bash("cat /data/previews.json") - From previous tool output: returns
preview_servein its response — remember itpreview_id - NEVER guess IDs — preview IDs are short hex strings (e.g. ), not human-readable names
84b0ace8
NEVER DO:
- ❌ Create a new script file when the old one has a bug (fix the old one)
- ❌ Create a new preview without stopping the old one first (auto-cleanup handles same-dir, but be explicit)
- ❌ Guess preview IDs — always read or use the ID from
/data/previews.jsonoutputpreview_serve - ❌ Try the same failed approach more than once
- ❌ Call an API directly via bash if a tool already provides it
- ❌ Tell the user "preview is ready" when health_check.ok is false
Error Recovery SOP
When something goes wrong, follow this exact sequence:
Step 1: Diagnose (DO NOT SKIP)
# Check preview health
preview_check(preview_id="xxx")
# Read the actual file to find the bug
read_file(path="project/index.html")
# If needed, check server-side response
bash("curl -s http://localhost:{port}/ | head -20")Step 2: Identify Root Cause
| Symptom | Likely Cause | Fix |
|---|---|---|
| White/blank page | JS error, CDN blocked, script escape | Read HTML, fix the script tag |
| Directory listing | Missing command+port, wrong dir | Add command+port or fix dir path |
| 404 on resources | Absolute paths | Change |
| CORS error | Direct external API call | Add backend proxy endpoint |
| Connection failed | Service didn't start | Check command, port, dependencies |
Step 3: Fix In Place
- Use to fix the specific bug
edit_file - Do NOT create new files or directories
- Do NOT rewrite the entire project
Step 4: Restart and Verify
preview_stop(preview_id="old_id")
preview_serve(title="Same Title", dir="same-dir", command="same-cmd", port=same_port)
# Check health_check in response — must be ok: trueCore Workflow
1. Analyze requirements → determine project type
2. Write code → create a complete, runnable project
3. Check code to confirm port → read the code to find the actual listen port
4. Start preview → call preview_serve (port MUST match the port in code)
5. Verify → check health_check in response
6. Iterate → modify code in the SAME project, then:
a. Read /data/previews.json to get the current preview ID
b. preview_stop(old_id) to stop the old preview
c. preview_serve with SAME dir and port to restart
d. Verify health_check againTools: , , , , , ,
read_filewrite_fileedit_filebashpreview_servepreview_stoppreview_checkProject Type Quick Reference
| Type | command | port | Example |
|---|---|---|---|
| Static HTML/CSS/JS | (omit) | (omit) | |
| Vite/React/Vue | | 5173 | |
| Backend (Python) | | from code | |
| Backend (Node) | | from code | |
| Fullstack | build frontend + start backend | backend port | See fullstack section below |
| Streamlit | | 8501 | |
| Gradio | | 7860 |
Fullstack Projects
Key Principle: Single Port Exposure. Backend serves both API and frontend static files on one port.
Steps:
- Build frontend:
cd frontend && npm install && npm run build - Configure backend to serve as static files
frontend/dist/ - Start backend only — single port serves everything
FastAPI:
python
app.mount("/", StaticFiles(directory="../frontend/dist", html=True), name="static")Express:
javascript
app.use(express.static(path.join(__dirname, '../frontend/dist')))
app.get('*', (req, res) => res.sendFile('index.html', {root: path.join(__dirname, '../frontend/dist')}))preview_serve call:
preview_serve(
title="Full Stack App",
dir="backend",
command="cd ../frontend && npm install && npm run build && cd ../backend && pip install -r requirements.txt && python main.py",
port=8000
)⚠️ Common Issues & Fixes
Directory Listing (Index of /)
Cause: Built-in static server serving source directory instead of web page.
Fix: Add + for backend projects, or point to directory containing .
commandportdirindex.htmlMust Use Relative Paths
Preview is reverse-proxied through . Absolute paths bypass the proxy.
/preview/{id}/| Location | ❌ Wrong | ✅ Correct |
|---|---|---|
| HTML src/href | | |
| JS fetch | | |
| CSS url() | | |
Vite: in
CRA: in
base: './'vite.config.js"homepage": "."package.jsonNever Tell Users to Access localhost
❌ "Visit http://localhost:5173"
✅ "Check the Browser panel for the preview"Third-Party API Calls from Preview Code
Frontend: Browsers block cross-origin requests from iframes (CORS). Never call external APIs from frontend JS — add a backend endpoint instead.
Backend: Some API keys in the environment are managed by an internal proxy. Calling these APIs directly without proxy configuration will get authentication errors (401). Preview code cannot import or modules (they are not on the Python path).
core/skills/How to fix: Read to understand the proxy configuration pattern, then replicate it in your preview backend code. The key functions to replicate are and .
core/http_client.py_get_proxy_config()_get_ca_file_path()javascript
// ❌ WRONG — frontend cannot call external APIs
fetch('https://api.external.com/data')
// ✅ CORRECT — call your own backend endpoint
fetch('api/stocks?symbol=AAPL')For live data previews: Build a backend (FastAPI/Express) that configures the proxy (see for the pattern) and exposes API endpoints.
core/http_client.pyAPI Polling Costs Credits
If code includes , auto-refresh, or polling, MUST notify the user about ongoing credit consumption. Prefer manual refresh buttons.
setIntervalRules (MUST follow)
-
Modify in-place, don't create new projects. Usein the current project. Don't create new directories or version files.
edit_file -
Detect duplicate versions, ask before cleanup. If you find,
app-v2,app-v3directories, list them and ask the user whether to delete old versions.app-copy -
Restart on the same port. Same,
dir,commandas before. Don't change port numbers.port -
port MUST match the code. Read the code to confirm the actual listen port before calling.
preview_serve -
Listen on 127.0.0.1 only. Do NOT use.
--host 0.0.0.0 -
Port conflict is auto-resolved. Same-port and same-directory previews are automatically cleaned up.
-
Backend projects MUST have command + port. Only pure static HTML can omit command.
-
No placeholders. Ever. Every line of code must actually run.
-
Verify after starting. Checkin the
health_checkresponse. If not ok, fix before telling the user.preview_serve -
Env vars are inherited. Use. No dotenv loading needed.
os.getenv() -
One preview, one port. Fullstack = backend serves frontend static files + API on single port.
-
Max 3 command-based previews. Oldest auto-stopped when exceeded. Useto clean up.
preview_stop -
Read before editing.first to understand context before making changes.
read_file -
SPA routing needs fallback. Built-in static server handles this automatically. Custom backends need catch-all route returning.
index.html
Community Publish — Share Previews Publicly
After a preview is working, users may want to share it publicly. Use to create a permanent public URL.
community_publishWorkflow
1. preview_serve → verify health_check.ok is true
2. User says "share this" / "publish" / "deploy" / "make it public"
3. Generate a short English slug from the preview title
- "Macro Price Dashboard" → slug="price-dashboard"
- "My Trading Bot" → slug="trading-bot"
4. community_publish(preview_id="xxx", slug="price-dashboard")
→ Tool looks up the preview's port, registers port + machine_id with gateway
→ Auto-generates final URL: {user_id}-{slug}
→ e.g. https://community.iamstarchild.com/586-price-dashboard/
5. Tell user the public URLHow It Works (Port-Based Routing)
Community publish uses a completely separate route from preview:
- Preview route (): cookie auth, for container owner only
/preview/{id}/ - Community route (): gateway key auth, for public access
/community/{port}/
The public URL binds to the service port, not the preview ID. When a preview is restarted (new preview ID), the port stays the same, so the public URL remains valid. No need to re-publish after restarting.
Tools
| Tool | Purpose |
|---|---|
| Publish preview to public URL (preview_id is used to look up the port) |
| Remove from public URL (use the full slug with user_id prefix) |
| List all your published previews |
Slug Generation
- You must generate the slug from the preview title: translate to English, lowercase, hyphens for spaces, keep it short (2-4 words)
- If slug is omitted, preview_id is used as fallback (e.g. )
586-c0bbc1c7 - Final URL format: — the tool prepends user_id automatically
{user_id}-{slug} - Lowercase letters, numbers, hyphens only, cannot start/end with hyphen
Important Notes
- Preview must be running before publishing
- One port = one slug: each port can only have one public URL; re-publishing with a new slug auto-replaces the old one
- Public URL works as long as the agent container is running — if stopped, visitors see "Preview Offline"
- Max 10 published previews per user
- Public URL has no authentication — anyone with the link can view
- To update: just re-publish with the same slug (it overwrites)
- removes the public URL (preview keeps running locally)
community_unpublish