yao/cmd
Max df63584a6f Enhance testing and configuration for Tai service
- Add TAI_TEST_HOST_IP environment variable to CI workflows for unit tests, allowing better connectivity to the gRPC server from Docker containers.
- Update the `run.go` file to parse command-line arguments correctly.
- Modify the test utility to return the gRPC address reachable from Docker, improving integration test reliability.
- Refactor integration tests to utilize the new relay address function, ensuring proper communication with the Yao gRPC server.

These changes improve the testing framework and enhance the configuration for better service interaction during CI runs.
2026-03-04 17:13:06 +08:00
..
agent Implement force push option for agent and MCP commands 2026-03-03 10:31:50 +08:00
get fix yao get command 2023-05-18 11:58:40 +08:00
mcp Implement force push option for agent and MCP commands 2026-03-03 10:31:50 +08:00
robot Enhance command structure with MCP and Robot functionalities 2026-03-03 08:11:43 +08:00
sui Implement Multi-Directory Watching and Enhance Locale File Handling 2026-01-03 14:39:57 +08:00
credential.go Enhance Tai service readiness checks and OAuth device flow 2026-03-04 16:55:29 +08:00
dump.go fix: Enhance loading functions to handle non-existent directories 2025-05-13 09:10:10 +08:00
get.go fix yao-init & get command 2023-05-18 10:58:27 +08:00
help.go 命令行工具 + 多语言支持 2022-02-09 15:45:18 +08:00
init.go Refactor Yao app initialization and enhance error handling 2026-02-04 19:04:23 +08:00
inspect.go Enhance tool inspection and remove studio configuration 2026-02-14 21:06:59 +08:00
login.go Enhance Tai service readiness checks and OAuth device flow 2026-03-04 16:55:29 +08:00
logout.go Enhance Tai service readiness checks and OAuth device flow 2026-03-04 16:55:29 +08:00
migrate.go Refactor error handling in various components to improve logging and message formatting 2025-09-28 10:24:17 +08:00
pack.go [fix] config init 2023-04-24 17:58:06 +08:00
README.md Implement Script Testing Framework and Enhance Test Context Management 2025-12-21 10:44:59 +08:00
restore.go Refactor error handling in various components to improve logging and message formatting 2025-09-28 10:24:17 +08:00
root.go Enhance Tai service readiness checks and OAuth device flow 2026-03-04 16:55:29 +08:00
run.go Enhance testing and configuration for Tai service 2026-03-04 17:13:06 +08:00
socket.go chore: Update engine.Load calls with additional options 2024-05-05 17:54:32 +08:00
start.go Implement gRPC support in the Yao SDK 2026-03-04 13:17:48 +08:00
tea.go default user login + issuer 2022-02-17 15:34:34 +08:00
upgrade.go [add] dashboard widget 2022-12-18 15:35:49 +08:00
version.go Enhance build process and options management 2026-02-03 10:22:55 +08:00
websocket.go [*] migrate to gou v0.10.3 (50%) 2023-02-01 17:25:11 +08:00

Yao CLI Commands

The Yao CLI provides a set of commands for managing, running, and testing Yao applications.

Installation

# Build from source
go build -o yao .

# Or install via go install
go install github.com/yaoapp/yao@latest

Global Flags

Flag Short Description
--app -a Application directory path
--file -f Application package file (.yaz)
--key -k Application license key

Environment Variables

Variable Description
YAO_ROOT Application root directory
YAO_LANG Language setting (e.g., zh-CN for Chinese)

Commands

yao start

Start the Yao application engine.

# Start in current directory
yao start

# Start with specific app directory
yao start -a /path/to/app

# Start in debug mode
yao start --debug

Flags:

Flag Description
--debug Enable development/debug mode
--disable-watching Disable file watching

yao run

Execute a Yao process.

# Run a process
yao run models.user.Find 1

# Run with JSON arguments
yao run models.user.Create '::[{"name":"John","age":30}]'

# Run in silent mode (JSON output only)
yao run -s models.user.Find 1

Flags:

Flag Short Description
--silent -s Silent mode - output result as JSON only

Argument Syntax:

  • Regular arguments: arg1 arg2
  • JSON arguments: '::[{"key":"value"}]' (prefix with ::)
  • Escaped ::: '\::literal'

yao migrate

Update database schema based on model definitions.

# Migrate all models
yao migrate

# Migrate specific model
yao migrate -n user

# Force migrate in production mode
yao migrate --force

# Reset (drop and recreate) tables
yao migrate --reset

Flags:

Flag Short Description
--name -n Specific model name to migrate
--force Force migrate in production mode
--reset Drop tables before migration

yao inspect

Display application configuration.

yao inspect

yao version

Show Yao version information.

# Show version
yao version

# Show all version details
yao version --all

Flags:

Flag Description
--all Print all version information (Go version, commit, build time, etc.)

Agent Commands

Commands for testing and managing AI agents.

yao agent test

Test an agent with input cases from a JSONL file, direct message, or script tests.

# Test with direct message (development mode)
yao agent test -i "Extract keywords from: AI and machine learning" -n workers.system.keyword

# Test with JSONL file
yao agent test -i tests/inputs.jsonl

# Test with custom output file
yao agent test -i tests/inputs.jsonl -o report.html

# Test with specific connector
yao agent test -i tests/inputs.jsonl -c openai.gpt4

# Stability testing (multiple runs)
yao agent test -i tests/inputs.jsonl --runs 5

# Parallel execution
yao agent test -i tests/inputs.jsonl --parallel 4

# Verbose output
yao agent test -i tests/inputs.jsonl -v

# Script tests (test agent handler scripts)
yao agent test -i scripts.expense.setup -v

# Script tests with test filtering
yao agent test -i scripts.expense.setup --run "TestSystemReady"

# Script tests with custom context
yao agent test -i scripts.expense.setup --ctx tests/context.json -v

Flags:

Flag Short Description
--input -i Input: JSONL file path, message, or script ID (required)
--output -o Output file path (default: output-{timestamp}.jsonl)
--name -n Agent ID (default: auto-detect from path)
--connector -c Override default connector
--user -u Test user ID (default: test-user)
--team -t Test team ID (default: test-team)
--ctx Path to context JSON file for custom authorization
--reporter -r Reporter agent ID for custom report generation
--runs Number of runs per test case for stability analysis (default: 1)
--run Regex pattern to filter which tests to run
--timeout Timeout per test case (default: 5m)
--parallel Number of parallel test cases (default: 1)
--verbose -v Enable verbose output
--fail-fast Stop on first failure
--app -a Application directory
--env -e Environment file

Input Modes:

  1. Direct Message Mode: For quick development/debugging

    yao agent test -i "Hello world" -n my.agent
    
    • Outputs result directly to stdout
    • No report file generated
    • Ideal for iterative development
  2. File Mode: For comprehensive testing

    yao agent test -i tests/inputs.jsonl
    
    • Reads test cases from JSONL file
    • Generates detailed report
    • Supports stability analysis
  3. Script Test Mode: For testing agent handler scripts

    yao agent test -i scripts.expense.setup -v
    
    • Tests TypeScript/JavaScript handler scripts (hooks, tools, setup functions)
    • Input format: scripts.<assistant>.<module> (e.g., scripts.expense.setup)
    • Automatically discovers and runs all Test* functions
    • Uses Go-like testing interface with assertions

Script Test Function Signature:

// assistants/expense/src/setup_test.ts
import { SystemReady } from "./setup";

export function TestSystemReady(t: testing.T, ctx: agent.Context) {
  const result = SystemReady(ctx);
  t.assert.True(result.success, "SystemReady should succeed");
  t.assert.Equal(result.status, "ready", "Status should be ready");
}

Context JSON Format (for --ctx flag):

{
  "authorized": {
    "sub": "user-12345",
    "client_id": "my-app",
    "user_id": "admin",
    "team_id": "team-001",
    "tenant_id": "acme-corp",
    "constraints": {
      "owner_only": true,
      "team_only": false,
      "extra": { "department": "engineering" }
    }
  },
  "metadata": { "request_id": "req-123" },
  "client": { "type": "web", "ip": "192.168.1.100" },
  "locale": "zh-cn"
}

JSONL Input Format:

{"id": "T001", "input": "Simple text input"}
{"id": "T002", "input": {"role": "user", "content": "Message with role"}}
{"id": "T003", "input": [{"role": "system", "content": "System prompt"}, {"role": "user", "content": "User message"}]}
{"id": "T004", "input": "Test with timeout", "timeout": "30s"}
{"id": "T005", "input": "Skip this test", "skip": true}
{"id": "T006", "input": "Test with specific user", "user": "alice", "team": "engineering"}

Output Formats:

Extension Format Description
.jsonl JSONL Streaming format (default)
.json JSON Complete structured report
.md Markdown Human-readable with tables
.html HTML Interactive web report

Agent Resolution:

The agent is resolved in the following priority order:

  1. Explicit -n flag: yao agent test -i msg -n my.agent
  2. YAO_ROOT environment variable
  3. Auto-detect from input file path (traverses up to find package.yao)
  4. Auto-detect from current working directory

SUI Commands

SUI (Serverless UI) template engine commands.

yao sui watch

Auto-build templates when files change.

yao sui watch <sui-id> <template-name> [data]

# Example
yao sui watch default index '::{}'

yao sui build

Build a template.

yao sui build <sui-id> <template-name> [data]

# Example
yao sui build default index '::{}'

# Debug mode
yao sui build default index '::{}' --debug

yao sui trans

Translate template content.

yao sui trans <sui-id> <template-name>

# With specific locales
yao sui trans default index -l "en-US,zh-CN,ja-JP"

SUI Flags:

Flag Short Description
--data -d Session data as JSON (prefix with ::)
--debug -D Enable debug mode
--locales -l Locales for translation (comma-separated)

Examples

Development Workflow

# Start development server
yao start --debug

# Run a process
yao run scripts.test.Hello "World"

# Test an agent interactively
yao agent test -i "What is the weather today?" -n assistant.weather

# Watch and auto-build templates
yao sui watch default home

Testing Workflow

# Run comprehensive agent tests
yao agent test -i tests/inputs.jsonl -o report.html -v

# Run script tests for agent handlers
yao agent test -i scripts.expense.setup -v

# Run specific script tests with filtering
yao agent test -i scripts.expense.setup --run "TestSystem.*" -v

# Run script tests with custom context
yao agent test -i scripts.expense.setup --ctx tests/context.json -v

# Stability analysis (run each test 10 times)
yao agent test -i tests/inputs.jsonl --runs 10 -o stability-report.json

# Parallel testing with timeout
yao agent test -i tests/inputs.jsonl --parallel 4 --timeout 2m

# CI/CD integration
yao agent test -i tests/inputs.jsonl -o results.jsonl && echo "Tests passed"

Database Migration

# Migrate all models
yao migrate

# Migrate specific model with reset
yao migrate -n user --reset --force

Exit Codes

Code Description
0 Success
1 Error or test failure

Directory Structure

myapp/
├── app.yao              # Application configuration
├── .env                 # Environment variables
├── models/              # Data models
├── apis/                # API definitions
├── flows/               # Business flows
├── scripts/             # JavaScript/TypeScript scripts
├── assistants/          # AI agents
│   └── my-agent/
│       ├── package.yao  # Agent configuration
│       ├── prompts.yml  # Agent prompts
│       └── tests/
│           └── inputs.jsonl  # Test cases
└── public/              # Static files

See Also