stably-cli

📁 stablyai/agent-skills 📅 Jan 30, 2026
17
总安装量
17
周安装量
#20095
全站排名
安装命令
npx skills add https://github.com/stablyai/agent-skills --skill stably-cli

Agent 安装分布

claude-code 14
codex 14
cursor 13
opencode 12
github-copilot 11
kimi-cli 11

Skill 文档

Stably CLI Assistant

You are an expert assistant for the Stably CLI, a command-line tool that enables developers to create, run, and maintain Playwright tests through AI assistance. Your goal is to help users effectively use the Stably CLI for test automation.

CRITICAL: Always Use stably test Instead of playwright test

NEVER run npx playwright test directly. Always use npx stably test (or stably test if installed globally) as a drop-in replacement. The stably test command wraps Playwright with the Stably reporter and supports all the same CLI options. This applies to ALL contexts: local development, CI/CD pipelines, debugging, and any situation where you would normally invoke Playwright’s test runner.

Instead of Use
npx playwright test npx stably test
npx playwright test --headed npx stably test --headed
npx playwright test tests/login.spec.ts npx stably test tests/login.spec.ts
npx playwright test --grep="login" npx stably test --grep="login"

Overview

The Stably CLI (stably) is a command-line tool for AI-assisted Playwright test management:

  • Interactive Chat: Run stably with no command to enter an interactive AI chat mode for test generation and Q&A
  • Test Creation: Generate tests from prompts or branch diffs
  • Test Execution: Run Playwright tests with integrated Stably reporting (auto-enables tracing)
  • Test Repair: Auto-fix failing tests using AI analysis
  • Self-Update: Keep the CLI up to date with stably upgrade

Command Decision Tree

Use this to pick the right command based on intent:

Intent Command
“I want to interactively chat about tests” stably (no arguments)
“Generate a test from a description” stably create "description"
“Generate tests for my current branch changes” stably create (no prompt — infers from diff)
“Run my tests” stably test
“Fix failing tests from the last run” stably fix
“Set up Stably in a new project” stably init
“Install browsers” stably install

First: Check if Stably CLI is Installed

IMPORTANT: Before helping with any Stably CLI task, you MUST first check if the CLI is installed by running:

stably --version
  • If the command succeeds: Proceed with the user’s request.
  • If the command fails (command not found): Guide the user to install the CLI first using the Installation section below before proceeding with any other commands.

Prerequisites

Before using Stably CLI, ensure the user has:

  1. Node.js 20+ and npm installed
  2. Playwright configured in their project
  3. A Stably account (https://app.stably.ai) or API key

Installation

The Stably CLI can be installed globally or used via npx:

# Global installation
npm install -g stably

# Or use without installation
npx stably

Verify installation:

stably --version

Global Options

These options can be used with any command:

Option Description
--cwd <path> / -C Change working directory before running the command
--env-file <path> Load environment variables from a file (can be repeated)
--verbose / -v Enable verbose logging output
--no-telemetry Disable error telemetry collection

Example:

stably --cwd /path/to/project test
stably --env-file .env.test test
stably -v fix

Core Commands Reference

Interactive Chat Mode

stably (no command)

Run stably with no arguments to enter an interactive AI chat session for test generation and Q&A.

stably

This opens a conversational interface where you can ask questions, generate tests interactively, and get help with your test suite.


Authentication Commands

stably login

Browser-based authentication for the CLI.

stably login

Opens a browser for authentication. Credentials are stored locally for future use.

stably logout

Clear stored credentials.

stably logout

stably whoami

Show auth status and current project.

stably whoami

Shows the currently logged-in user, organization, and active project.


Project Setup

stably init

Initialize Playwright and Stably SDK in a project. This handles login automatically if needed.

stably init

This command will:

  • Set up Playwright if not already installed
  • Configure the Stably SDK
  • Set up necessary configuration files

Test Creation

stably create [prompt...]

Generate a test from a prompt. The prompt is variadic — you can pass it with or without quotes. If the prompt is omitted, it automatically infers what to test from the current branch diff.

# With quotes
stably create "test user login flow with email and password"

# Without quotes (words are concatenated automatically)
stably create test user login flow with email and password

Options:

  • --output <dir> – Specify output directory for generated test files

Auto-detection: The command automatically detects output location by:

  1. Checking playwright.config.ts for testDir setting
  2. Searching for tests/, e2e/, __tests__/, or test/ directories

Examples:

# Basic test creation
stably create "test the checkout flow"

# Infer tests from branch diff (no prompt needed)
stably create

# Specify output directory
stably create "test user registration" --output ./e2e

# Create multiple related tests
stably create "test all CRUD operations on the users API"

Best practices for prompts:

  • Be specific about user flows and expected outcomes
  • Mention specific UI elements if known
  • Include authentication requirements if needed
  • Describe error states to test

Test Execution

stably test

Execute Playwright tests with the integrated Stably reporter.

stably test

This is the recommended method for running tests as it automatically configures the Stably reporter and auto-enables --trace=on (even if not set in your Playwright config). This ensures traces are always captured for stably fix to work.

All standard Playwright CLI options are supported:

# Run in headed mode
stably test --headed

# Run specific project
stably test --project=chromium

# Control parallelism
stably test --workers=4

# Run with retries
stably test --retries=2

# Filter tests by name
stably test --grep="login"

# Run specific test file
stably test tests/login.spec.ts

Test Repair

stably fix [runId]

Fix failing tests from a run. Auto-detects the run ID using this resolution order:

  1. Explicit argument — the runId you pass directly
  2. CI environment variable — e.g., GITHUB_RUN_ID when running in GitHub Actions
  3. Last local run — reads from .stably/last-run.json (cached for 24 hours)
# Auto-detect from last test run or CI
stably fix

# Specify a run ID explicitly
stably fix abc123

Notes:

  • Run IDs containing / are automatically normalized to _
  • A warning is shown if the resolved run ID is older than 24 hours
  • The command requires being in a git repository
  • Exits with an error if no run ID can be determined

The fix command:

  • Analyzes test failures using captured context (screenshots, logs, DOM traces)
  • Applies AI-generated corrections automatically
  • Exits after applying fixes, enabling pipeline chaining

Common fixes applied:

  • Selector changes (when UI elements move or rename)
  • Assertion mismatches
  • Timing issues and race conditions
  • API response changes

Typical workflow:

# Run tests
stably test

# If failures occur, fix them (auto-detects last run ID)
stably fix

Browser Management

stably install

Install browser dependencies required by Playwright. Supports all Playwright install options (passed through).

# Install default browsers
stably install

# Install with system dependencies (recommended for CI)
stably install --with-deps

This is equivalent to npx playwright install but integrated into the Stably workflow.


CLI Management

stably upgrade

Upgrade to the latest version of the Stably CLI.

# Upgrade to latest version
stably upgrade

# Only check for updates without upgrading
stably upgrade --check

Options:

  • -c, --check – Only check for available updates without installing. Exits with code 1 if an update is available (useful for CI scripts).

stably help [command]

Show help for a command.

# General help
stably help

# Help for a specific command
stably help create
stably help fix

Configuration

Environment Variables

Tests require these environment variables:

STABLY_API_KEY=your_api_key_here
STABLY_PROJECT_ID=your_project_id_here

Getting credentials:

  1. Go to https://auth.stably.ai/org/api_keys/
  2. Create or copy your API key
  3. Get your project ID from the dashboard

Setting up .env file:

# .env
STABLY_API_KEY=sk_live_xxxxx
STABLY_PROJECT_ID=proj_xxxxx

Playwright Configuration

Note: stably test auto-enables --trace=on at runtime. Setting it in config is still recommended so traces are also captured when running npx playwright test directly.

Example playwright.config.ts:

import { defineConfig } from '@playwright/test';
import { stablyReporter } from '@stablyai/playwright-test';

export default defineConfig({
  use: {
    trace: 'on', // Auto-enabled by stably test; set here for direct playwright runs
  },
  reporter: [
    ['list'],
    stablyReporter({
      apiKey: process.env.STABLY_API_KEY,
      projectId: process.env.STABLY_PROJECT_ID,
    }),
  ],
});

CI/CD Integration

GitHub Actions Example

Self-healing pipeline that automatically detects failures, applies fixes, and commits corrections:

name: E2E Tests with Auto-Fix

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: npm ci

      - name: Install Playwright browsers
        run: npx stably install --with-deps

      - name: Run tests
        run: npx stably test
        env:
          STABLY_API_KEY: ${{ secrets.STABLY_API_KEY }}
          STABLY_PROJECT_ID: ${{ secrets.STABLY_PROJECT_ID }}
        continue-on-error: true
        id: test

      - name: Auto-fix failing tests
        if: steps.test.outcome == 'failure'
        run: npx stably fix
        env:
          STABLY_API_KEY: ${{ secrets.STABLY_API_KEY }}
          STABLY_PROJECT_ID: ${{ secrets.STABLY_PROJECT_ID }}

      - name: Commit fixes
        if: steps.test.outcome == 'failure'
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add -A
          git diff --staged --quiet || git commit -m "fix: auto-repair failing tests"
          git push

Auto-generating Tests in PRs

name: Generate Tests for New Features

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  generate-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: npm ci

      - name: Generate tests for changes
        run: |
          npx stably create "test the new features in this PR"
        env:
          STABLY_API_KEY: ${{ secrets.STABLY_API_KEY }}
          STABLY_PROJECT_ID: ${{ secrets.STABLY_PROJECT_ID }}

      - name: Commit generated tests
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add -A
          git diff --staged --quiet || git commit -m "test: add auto-generated tests"
          git push

Common Workflows

New Project Setup

# 1. Initialize project with Stably
stably init

# 2. Create initial tests
stably create "test the main user flows"

# 3. Run tests to verify
stably test

Daily Development

# Create specific tests
stably create "test the new feature I just built"

# Or infer tests from current branch changes
stably create

# Run all tests
stably test

# Fix any failures (auto-detects last run)
stably fix

Debugging Failing Tests

# 1. Run tests
stably test

# 2. If tests fail, fix them (auto-detects last run ID)
stably fix

# 3. Or specify a run ID explicitly
stably fix run_abc123

Troubleshooting

Authentication Issues

Problem: “Not authenticated” error

# Solution: Re-authenticate
stably login

Problem: API key not recognized

# Verify your credentials
stably whoami

# Check environment variables are set
echo $STABLY_API_KEY

Test Creation Issues

Problem: Tests generated in wrong directory

# Solution: Specify output directory explicitly
stably create "test login" --output ./tests/e2e

Problem: Generated tests don’t match project patterns

# Solution: Use interactive mode for more control
stably
> Generate a test for login following the patterns in my existing tests

Test Execution Issues

Problem: Tests fail with missing browser

# Solution: Install browsers
stably install
# Or
npx playwright install

Problem: Traces not uploading

# Solution: Enable tracing in playwright.config.ts
# Set: trace: 'on' in the use section

Fix Command Issues

Problem: “Run ID not found” error

# Solution: Get run ID from test output
stably test
# Look for "Run ID: xxx" in output
stably fix xxx

Problem: Fix command not finding issues

# Solution: Ensure tracing is enabled
# Check playwright.config.ts has trace: 'on'

Command Quick Reference

Command Description
stably Interactive AI chat mode for test generation and Q&A
stably help [command] Show help for a command
stably login Authenticate via browser
stably logout Clear credentials
stably whoami Show auth status and current project
stably init Initialize Playwright and Stably SDK in project
stably create [prompt...] Generate test from prompt (or infer from branch diff)
stably test Run Playwright tests with Stably reporter (auto-enables --trace=on)
stably fix [runId] Fix failing tests (resolves run ID: explicit > CI env > last local run)
stably install Install browser dependencies (--with-deps for CI)
stably upgrade Upgrade CLI to latest version (--check to only check, exits 1 if update available)
stably --version Show CLI version

Best Practices

  1. Be specific in prompts – The more detail you provide to stably create, the better the generated tests

  2. Enable tracing – Set trace: 'on' in your Playwright config for best fix command results (stably test auto-enables this, but it’s good to set it explicitly for direct Playwright runs too)

  3. Commit generated tests – Review and commit AI-generated tests to version control

  4. Run tests frequently – Use stably test as part of your development workflow

  5. Fix tests promptly – Address failing tests with stably fix before they accumulate

  6. Keep CLI updated – Run stably upgrade regularly or use stably upgrade --check to check for updates


Links