| name | cli |
| description | Trebuchet CLI commands for initializing projects, deploying actors, checking status, local development, and infrastructure management. Use when users need to deploy, configure, or manage Trebuchet projects from the command line. |
Trebuchet CLI
Command-line interface for deploying and managing Trebuchet distributed actors.
Overview
The trebuchet CLI provides tools for:
- Initializing new projects
- Deploying actors to cloud platforms
- Managing deployments
- Running local development servers
- Generating infrastructure configuration
- Automatic Xcode project support (since v0.4.0)
- Intelligent dependency analysis for minimal deployments
Xcode Project Support
Zero configuration required! The CLI automatically detects and works with:
- Xcode projects (
.xcodeproj)
- Xcode workspaces (
.xcworkspace)
- Swift Package Manager projects (
Package.swift)
Automatic Detection
The CLI automatically:
- Detects project type (Xcode vs SPM)
- Extracts package names from
Package.swift when available
- Generates appropriate package manifests
- Adapts behavior across all commands (
dev, deploy, generate server)
Automatic Dependency Analysis
The CLI uses SwiftSyntax to intelligently analyze actor dependencies:
What it analyzes:
- Actor method signatures (parameters and return types)
- Transitive dependencies (e.g.,
PlayerInfo → GameStatus)
- Complex types: generics (
Array<T>), optionals (T?), nested types
- Only types actually used by actors (symbol-scoped analysis)
What it filters out:
- Standard library types (
String, Int, UUID, etc.)
- Unrelated types in the same file as dependencies
- Files that actors don't depend on
Result: Only 1-5 files typically copied vs. entire app
Cascade Prevention
The CLI prevents copying your entire codebase:
- Symbol-level analysis: Only analyzes types actually used by actors
- Smart filtering: Doesn't cascade through unrelated dependencies
- 20-60x improvement over naive file-level analysis
Example: If your actor uses PlayerInfo from Models.swift, but Models.swift also contains UnrelatedType, the CLI won't cascade to UnrelatedType's dependencies.
Works Everywhere
Xcode support works across all commands:
trebuchet dev
trebuchet generate server --output ./my-server
trebuchet deploy --provider aws
Installation
Using Mint (Recommended)
mint install briannadoubt/Trebuchet
Build from Source
git clone https://github.com/briannadoubt/Trebuchet.git
cd Trebuchet
swift build -c release --product trebuchet
cp .build/release/trebuchet /usr/local/bin/
Verify Installation
trebuchet --version
Commands
trebuchet init
Initialize a new Trebuchet project configuration.
trebuchet init --name my-project --provider aws
Options:
--name (required): Project name
--provider: Cloud provider (aws, fly)
--region: Default deployment region
--output: Output file path (default: trebuchet.yaml)
Example:
trebuchet init --name game-server --provider aws --region us-east-1
Creates trebuchet.yaml:
name: game-server
version: "1"
defaults:
provider: aws
region: us-east-1
memory: 512
timeout: 30
actors: {}
state:
type: dynamodb
discovery:
type: cloudmap
trebuchet deploy
Deploy actors to the cloud.
trebuchet deploy --provider aws --region us-east-1
Options:
--provider: Cloud provider (aws, fly)
--region: Deployment region
--environment: Environment name (production, staging, etc.)
--dry-run: Preview deployment without making changes
--verbose: Show detailed output
--config: Path to config file (default: trebuchet.yaml)
Examples:
trebuchet deploy --provider aws --region us-east-1
trebuchet deploy --provider fly --region iad
trebuchet deploy --dry-run --verbose
trebuchet deploy --environment staging
trebuchet deploy --config custom.yaml
Output:
Discovering actors...
✓ GameRoom (Sources/Actors/GameRoom.swift)
✓ Lobby (Sources/Actors/Lobby.swift)
Building for Lambda (arm64)...
Building executable...
Packaging bootstrap...
✓ Package built (14.2 MB)
Deploying to AWS...
Creating Lambda function...
✓ Lambda: arn:aws:lambda:us-east-1:123:function:game-server
Creating API Gateway...
✓ API Gateway: https://abc123.execute-api.us-east-1.amazonaws.com
Creating DynamoDB table...
✓ DynamoDB: game-server-actor-state
Creating CloudMap namespace...
✓ CloudMap: game-server namespace
Deployment complete!
Endpoint: https://abc123.execute-api.us-east-1.amazonaws.com
trebuchet status
Check the status of deployed actors.
trebuchet status
Options:
--verbose: Show detailed information
--provider: Filter by provider
--config: Path to config file
Example:
trebuchet status --verbose
Output:
Project: game-server
Provider: aws
Region: us-east-1
Actors:
GameRoom
Status: Active
Memory: 1024 MB
Timeout: 60s
Last Update: 2026-01-27 10:30:00 UTC
Invocations (24h): 1,234
Lobby
Status: Active
Memory: 256 MB
Timeout: 30s
Last Update: 2026-01-27 10:30:00 UTC
Invocations (24h): 567
Infrastructure:
Lambda: arn:aws:lambda:us-east-1:123:function:game-server
API Gateway: https://abc123.execute-api.us-east-1.amazonaws.com
DynamoDB: game-server-actor-state
CloudMap: game-server
trebuchet undeploy
Remove deployed infrastructure.
trebuchet undeploy
Options:
--provider: Cloud provider
--region: Deployment region
--force: Skip confirmation prompt
--config: Path to config file
Example:
trebuchet undeploy --force
Output:
⚠️ This will delete all infrastructure and data!
Removing infrastructure...
✓ Lambda function deleted
✓ API Gateway deleted
✓ DynamoDB table deleted
✓ CloudMap namespace deleted
Undeployment complete.
trebuchet dev
Run actors locally for development.
trebuchet dev --port 8080
Options:
--port / -p: HTTP server port (default: 8080)
--host / -h: Host to bind to (default: localhost)
--verbose / -v: Enable verbose build output
Examples:
trebuchet dev
trebuchet dev --port 3000 --host 0.0.0.0
trebuchet dev --verbose
What it does:
- Discovers all
@Trebuchet actors in your project
- Builds your project with
swift build (skipped for Xcode projects)
- Analyzes actor dependencies and copies only required files
- Generates a local development runner in
.trebuchet/
- Starts an HTTP server using
CloudGateway.development()
- Exposes actors at
/invoke endpoint
- Provides health check at
/health endpoint
Note: For Xcode projects, the CLI skips swift build since Xcode handles compilation. The dev server uses the generated package in .trebuchet/ instead.
Output:
Starting local development server...
Found actors:
• GameRoom
• Lobby
Building project...
✓ Build succeeded
Generating development server...
✓ Runner generated
Starting server on localhost:8080...
Starting local development server...
✓ Exposed: GameRoom
✓ Exposed: Lobby
Server running on http://localhost:8080
Health check: http://localhost:8080/health
Invocation endpoint: http://localhost:8080/invoke
Press Ctrl+C to stop
trebuchet generate
Generate deployment artifacts.
trebuchet generate server
Generate a standalone server package from your actors.
trebuchet generate server --output ./my-server
Options:
--output: Output directory for generated server (default: .trebuchet/server)
--config: Path to trebuchet.yaml
--verbose / -v: Enable verbose output
--force: Force regeneration even if server exists
Examples:
trebuchet generate server
trebuchet generate server --output ./deploy/server
trebuchet generate server --force --verbose
What it does:
- Discovers all
@Trebuchet actors
- Generates a standalone Swift package
- Creates Package.swift with dependencies
- Generates main.swift with actor bootstrapping
- Ready to deploy or run independently
Output:
Loading configuration...
Discovering actors...
✓ GameRoom
✓ Lobby
Generating server package...
✓ Package manifest created
✓ Bootstrap code generated
✓ Server configured
✓ Server package generated at .trebuchet/server
To deploy:
trebuchet deploy
To run locally:
cd .trebuchet/server
swift run
Configuration File (trebuchet.yaml)
Basic Structure
name: my-project
version: "1"
defaults:
provider: aws
region: us-east-1
memory: 512
timeout: 30
actors: {}
environments: {}
state: {}
discovery: {}
Actor Configuration
actors:
GameRoom:
memory: 1024
timeout: 60
stateful: true
isolated: true
environment:
LOG_LEVEL: debug
MAX_PLAYERS: "10"
Lobby:
memory: 256
timeout: 30
Environment Configuration
environments:
production:
region: us-west-2
memory: 2048
environment:
LOG_LEVEL: warn
ENABLE_METRICS: "true"
staging:
region: us-east-1
memory: 512
environment:
LOG_LEVEL: debug
State Configuration
state:
type: dynamodb
tableName: custom-table-name
Supported types:
dynamodb: AWS DynamoDB (for AWS deployments)
postgresql or postgres: PostgreSQL database (for Fly.io or custom deployments)
memory: In-memory (development only)
Discovery Configuration
discovery:
type: cloudmap
namespace: my-namespace
Supported types:
cloudmap: AWS Cloud Map
memory: In-memory (development only)
WebSocket Configuration
websocket:
enabled: true
stage: production
routes:
- $connect
- $disconnect
- $default
connections:
type: dynamodb
table: my-app-connections
Actor Discovery
The CLI automatically discovers actors in your codebase:
@Trebuchet
distributed actor GameRoom {
distributed func join(player: Player) -> RoomState
}
The CLI scans:
Sources/ directory
- All
.swift files
- Actors marked with
@Trebuchet
- Actor annotations in comments
Build Process
When deploying to AWS Lambda, the CLI:
- Detects project type (Xcode vs SPM)
- Discovers actors using SwiftSyntax
- Analyzes dependencies to identify required types
- Copies actor files and dependencies (1-5 files typically)
- Generates bootstrap code for Lambda handler
- Builds for ARM64 using Docker
- Packages binary with swift-lambda-runtime
- Generates Terraform for infrastructure
- Applies infrastructure changes
- Uploads Lambda package
Dependency Analysis Performance
- Analysis time: 50-100ms for typical projects
- Cascade prevention: Avoids copying 200+ unnecessary files in worst case
- File copying: Only 1-5 files typically copied vs entire app
Docker Build
The CLI uses Docker to cross-compile for Lambda ARM64:
FROM swift:latest
RUN swift build -c release --arch arm64
Terraform Integration
The CLI generates Terraform configuration in .trebuchet/terraform/:
.trebuchet/
└── terraform/
├── main.tf
├── variables.tf
├── outputs.tf
└── lambda.zip
Customizing Terraform
You can customize the generated Terraform:
cd .trebuchet/terraform
terraform plan -var="lambda_memory=2048"
terraform apply
Using Existing Terraform
Skip CLI-generated Terraform and use your own:
trebuchet deploy --skip-terraform
Common Workflows
Initial Setup
trebuchet init --name my-project --provider aws
vi trebuchet.yaml
trebuchet dev --port 8080
trebuchet deploy --environment staging
trebuchet deploy --environment production
Iterative Development
trebuchet dev --port 8080
trebuchet deploy --environment staging
trebuchet status --environment staging
trebuchet deploy --environment production
Debugging Deployment Issues
trebuchet deploy --dry-run --verbose
trebuchet status --verbose
cat .trebuchet/terraform/main.tf
cd .trebuchet/terraform
terraform plan
terraform apply
Environment Variables
The CLI respects these environment variables:
AWS_ACCESS_KEY_ID: AWS access key
AWS_SECRET_ACCESS_KEY: AWS secret key
AWS_REGION: Default AWS region
AWS_PROFILE: AWS credentials profile
TREBUCHET_CONFIG: Path to config file
Exit Codes
0: Success
1: General error
2: Configuration error
3: Build error
4: Deployment error
5: Connection error
Troubleshooting
Actor Discovery Fails
Problem: CLI doesn't find actors
Solutions:
- Ensure actors are marked with
@Trebuchet
- Check actors are in
Sources/ directory
- Verify Swift files are valid syntax
- Use
--verbose flag to see discovery details
Build Fails
Problem: Docker build fails
Solutions:
- Ensure Docker is running
- Check Docker has sufficient memory (4GB+)
- Verify internet connection for package downloads
- Use
--verbose to see full build output
Deployment Fails
Problem: Terraform apply fails
Solutions:
- Check AWS credentials are valid
- Verify IAM permissions
- Check region is correct
- Review
.trebuchet/terraform/ for errors
- Use
trebuchet deploy --dry-run first
Connection Timeout
Problem: CLI can't connect to AWS
Solutions:
- Verify internet connection
- Check AWS credentials
- Try different region
- Check firewall settings
See Also
- Cloud deployment guide for deployment concepts
- AWS Lambda guide for AWS-specific deployment
- Configuration reference for trebuchet.yaml options