Skip to content

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:

Bash
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:

Bash
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 schemas
surf inspect https://myapp.com --verbose

The 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:

Bash
# Test a search command
surf 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/CD
surf test https://shop.example.com search --query "laptop" --json
ย 
# Test authenticated commands
surf 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:

Bash
$ 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:

Bash
# In your CI pipeline
surf ping https://staging.myapp.com || exit 1
surf 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. |