@rcs-lang/cli
Section titled “@rcs-lang/cli”Command-line interface for compiling RCL (Rich Communication Language) files into JavaScript modules and JSON configurations. Provides a simple way to compile .rcl files from the command line with multiple output formats and helpful development features.
Installation
Section titled “Installation”Global Installation
Section titled “Global Installation”bun add -g @rcs-lang/cli# ornpm install -g @rcs-lang/cliLocal Installation
Section titled “Local Installation”bun add --dev @rcs-lang/cli# ornpm install --save-dev @rcs-lang/cliQuick Start
Section titled “Quick Start”# Compile a single filercl compile agent.rcl
# Compile with specific output directoryrcl compile agent.rcl --output dist/
# Compile multiple filesrcl compile src/**/*.rcl
# Watch for changes and recompilercl compile agent.rcl --watchAvailable Commands
Section titled “Available Commands”compile - Compile RCL Files
Section titled “compile - Compile RCL Files”Compile RCL files to JavaScript and JSON.
rcl compile <input> [options]Options:
-o, --output <dir>- Output directory (default: same as input)-f, --format <format>- Output format:json,js, orboth(default:both)--no-pretty- Disable pretty printing for JSON-w, --watch- Watch files for changes and recompile-c, --config <path>- Path to rcl.config.json
Examples:
# Basic compilationrcl compile coffee-shop.rcl
# Specify output directoryrcl compile agent.rcl --output dist/
# JSON output onlyrcl compile agent.rcl --format json
# Watch mode for developmentrcl compile src/**/*.rcl --watch --output dist/parse - Parse and Output AST
Section titled “parse - Parse and Output AST”Parse RCL files and output the Abstract Syntax Tree (useful for debugging).
rcl parse <input> [output] [options]Options:
--no-pretty- Disable pretty printing for JSON--exclude <fields>- Comma-separated list of fields to exclude from AST--only <fields>- Comma-separated list of fields to keep in AST
Examples:
# Parse and output to stdoutrcl parse agent.rcl
# Parse and save to filercl parse agent.rcl ast.json
# Exclude location informationrcl parse agent.rcl --exclude location,source
# Only show structurercl parse agent.rcl --only type,sections,bodydiagram - Generate Flow Diagrams
Section titled “diagram - Generate Flow Diagrams”Generate visual diagrams from RCL flow definitions.
rcl diagram <input> [options]Options:
-o, --output <file>- Output file path-t, --type <type>- Diagram type:d2ormermaid(default:d2)--no-error-paths- Hide error/invalid option paths--no-separate-invalid- Use shared InvalidOption state instead of local ones
Examples:
# Generate D2 diagramrcl diagram coffee-shop.rcl
# Generate Mermaid diagramrcl diagram coffee-shop.rcl --type mermaid
# Custom output locationrcl diagram agent.rcl --output diagrams/agent-flow.d2init - Initialize Project
Section titled “init - Initialize Project”Initialize a new RCL project with configuration file.
rcl initCreates an rcl.config.json file in the current directory with default settings.
Output Formats
Section titled “Output Formats”The CLI generates multiple output formats:
JSON Output
Section titled “JSON Output”Structured data representation suitable for runtime interpretation:
{ "agent": { "name": "CoffeeShop", "displayName": "Coffee Shop Agent" }, "flows": { "OrderFlow": { "start": "Welcome", "states": { "Welcome": { "transitions": [...] } } } }, "messages": { "Welcome": { "type": "text", "text": "Hello! How can I help you today?" } }}JavaScript Output
Section titled “JavaScript Output”ES6 module with convenient exports:
// Generated from coffee-shop.rclexport const agent = { name: "CoffeeShop", displayName: "Coffee Shop Agent"};
export const messages = { Welcome: { type: "text", text: "Hello! How can I help you today!" }};
export const flows = { OrderFlow: { start: "Welcome", states: { ... } }};
// Convenience exportexport default { agent, messages, flows};Diagram Formats
Section titled “Diagram Formats”D2 Diagrams:
# Coffee Shop Agent FlowWelcome -> ChooseSize: "order coffee"Welcome -> ShowMenu: "view menu"ChooseSize -> ChooseDrink: "small" | "medium" | "large"Mermaid Diagrams:
graph TD Welcome --> ChooseSize Welcome --> ShowMenu ChooseSize --> ChooseDrinkConfiguration
Section titled “Configuration”Create an rcl.config.json file in your project root:
{ "outDir": "./dist", "compilerOptions": { "generateSourceMap": true, "preserveComments": false, "strict": true, "module": "esm", "emit": { "json": true, "javascript": true, "declarations": true } }, "include": ["**/*.rcl"], "exclude": ["node_modules", "**/*.test.rcl"]}Configuration Options:
outDir- Output directory for compiled filescompilerOptions.generateSourceMap- Generate source maps for debuggingcompilerOptions.strict- Enable strict validation modecompilerOptions.emit- Control which output formats to generateinclude- Glob patterns for files to includeexclude- Glob patterns for files to exclude
Error Handling
Section titled “Error Handling”The CLI provides detailed error messages with source locations:
Error in coffee-shop.rcl: Line 15, Column 8: Missing required 'displayName' in agent definition
13 | agent CoffeeShop 14 | # Missing displayName here> 15 | flow OrderFlow | ^ 16 | start: WelcomeExit Codes
Section titled “Exit Codes”The CLI uses specific exit codes for different error types:
0- Success1- Compilation/syntax errors2- Semantic/validation errors3- File not found4- Write permission error64- Invalid command usage70- Internal error
Integration with Build Tools
Section titled “Integration with Build Tools”npm Scripts
Section titled “npm Scripts”Add RCL compilation to your build process:
{ "scripts": { "build:rcl": "rcl compile src/**/*.rcl --output dist/", "watch:rcl": "rcl compile src/**/*.rcl --output dist/ --watch", "validate:rcl": "rcl parse src/**/*.rcl", "diagram:rcl": "rcl diagram src/main.rcl --output docs/flow.d2" }}CI/CD Integration
Section titled “CI/CD Integration”# GitHub Actions example- name: Compile RCL files run: | bun add -g @rcs-lang/cli rcl compile src/**/*.rcl --output dist/
- name: Validate RCL syntax run: rcl parse src/**/*.rcl --exclude location,sourceWatch Mode
Section titled “Watch Mode”For development, use watch mode to automatically recompile when files change:
rcl compile src/**/*.rcl --watch --output dist/This will:
- Watch all
.rclfiles in thesrc/directory - Automatically recompile when files change
- Output compiled files to
dist/ - Show compilation status and errors
Programmatic Usage
Section titled “Programmatic Usage”You can also use the CLI programmatically in Node.js:
import { compileRCL, parseRCL, generateDiagram } from '@rcs-lang/cli';
// Compile a fileconst compileResult = await compileRCL('agent.rcl', { output: 'dist/', format: 'both', pretty: true});
// Parse a fileconst parseResult = await parseRCL('agent.rcl', { output: 'ast.json', pretty: true, exclude: ['location']});
// Generate diagramawait generateDiagram('agent.rcl', { output: 'flow.d2', type: 'd2', errorPaths: false});Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”File not found:
❌ Error: Input file not found: agent.rcl- Check the file path is correct
- Ensure the file exists and has
.rclextension
Permission errors:
❌ Error: Failed to write output: permission denied- Check write permissions on the output directory
- Try running with appropriate permissions
Java required for development: If you're building from source, Java 17+ is required for ANTLR grammar generation.
Getting Help
Section titled “Getting Help”# Show all available commandsrcl --help
# Show help for specific commandrcl compile --helprcl parse --helprcl diagram --helpExamples
Section titled “Examples”Basic Agent Compilation
Section titled “Basic Agent Compilation”Input file coffee-shop.rcl:
agent CoffeeShop displayName: "Coffee Shop Agent"
flow OrderFlow start: Welcome
on Welcome match @userInput "order coffee" -> ChooseSize "view menu" -> ShowMenu
messages Messages text Welcome "Hello! How can I help you today?" text ShowMenu "Here's our menu: ..."Compile:
rcl compile coffee-shop.rclGenerates:
coffee-shop.json- Runtime configurationcoffee-shop.js- JavaScript module
Batch Processing
Section titled “Batch Processing”# Compile all RCL files in src/rcl compile src/**/*.rcl --output dist/
# Generate diagrams for all agentsfor file in src/*.rcl; do rcl diagram "$file" --output "docs/$(basename "$file" .rcl).d2"doneDevelopment Workflow
Section titled “Development Workflow”# Terminal 1: Watch and compilercl compile src/**/*.rcl --watch --output dist/
# Terminal 2: Watch and generate diagramsrcl diagram src/main.rcl --watch --output docs/flow.d2
# Terminal 3: Your development servernpm run devAPI Reference
Section titled “API Reference”For detailed programmatic API documentation, see: