Tooling
CLI
Developer tool for building and debugging Surf integrations
CLI#
The @surfjs/cli is a developer tool for building and debugging Surf integrations. It sends HTTP requests to your server โ it cannot execute browser-only commands or show UI changes.
The CLI is not an agent interface. Browser agents use
window.surf. Headless agents use@surfjs/client. The CLI is for you, the developer.
When to Use the CLI#
surf ping โ Verify Your Site Is Surf-Enabled
Quick health check during development or in CI:
surf ping https://shop.example.com# โ
https://shop.example.com is Surf-enabled (42ms)surf inspect โ Discover Available Commands
Explore the manifest to verify your commands are registered correctly. The output includes execution hints so you know where each command runs:
surf inspect https://myapp.comย # ๐ My Canvas App (Surf v0.2)# 5 commands available:## canvas.addCircle(x, y, radius, fill) ๐ browser# Add circle to canvas## canvas.getState() ๐ก any# Get current canvas state## canvas.export(width?, height?) ๐ก server# Export canvas as image## product.search(query, limit?) ๐ก any# Search products## order.create(sku, quantity?) ๐ server# Create an orderย # Full parameter schemassurf inspect https://myapp.com --verboseThe icons indicate execution mode:
- ๐
browserโ runs in the browser only - ๐ก
any/serverโ available over HTTP - ๐ โ requires authentication
surf test โ Test Commands During Development
Execute commands from your terminal to verify server-side handlers work:
# Test a search commandsurf test https://shop.example.com search --query "laptop"# Executing search on https://shop.example.com...# OK# { "results": [...], "total": 42 }# โฑ 47ms execute / 89ms totalย # Machine-readable output for CI/CDsurf test https://shop.example.com search --query "laptop" --jsonย # Test authenticated commandssurf test https://shop.example.com order.create --auth sk-token --sku LAPTOP-01ย # For @surfjs/next deployments (custom execute path)surf test https://my-app.vercel.app search --base-path /api/surf/execute --query "laptop"Browser-only commands return a helpful error:
$ surf test myapp.com canvas.addCircle --x 400โ ๏ธ canvas.addCircle requires browser execution Open the site and run: await window.surf.execute('canvas.addCircle', { x: 400 })The CLI prompts for missing required parameters interactively and coerces values to the correct type.
CI/CD โ Automated Testing
Use the CLI in your test pipeline to verify Surf endpoints after deployment:
# In your CI pipelinesurf ping https://staging.myapp.com || exit 1surf test https://staging.myapp.com search --query "test" --json | jq '.ok'When NOT to Use the CLI#
| Instead of... | Use... | Why |
|---------------|--------|-----|
| CLI as agent interface | window.surf (browser) or @surfjs/client (headless) | CLI is for development, not production |
| CLI for browser-only commands | window.surf in a browser | Browser commands need browser context |
| CLI for visual verification | A browser agent that can see the UI | CLI shows JSON, not UI changes |
| CLI for production workflows | @surfjs/client with error handling | CLI is not designed for automation |
The CLI sends HTTP requests and prints JSON. It can't show you whether the cart icon updated or a circle appeared on the canvas. For that, you need a browser.
Reference#
| Flag | Description |
|------|-------------|
| --json | Machine-readable JSON output |
| --auth <token> | Bearer token for authenticated commands |
| --verbose | Show full parameter schemas (inspect only) |
| --base-path <path> | Override execute path (default: /surf/execute). Use /api/surf/execute for @surfjs/next. |