AI-Powered CLI
Use AI commands in the ObjectQL CLI
The ObjectQL CLI provides AI-powered commands to generate and validate applications using natural language.
Overview
The objectql ai command provides interactive and automated application generation with built-in validation and testing.
Prerequisites
Set your OpenAI API key as an environment variable:
Commands
Interactive Mode (Default)
The easiest way to build applications - just type:
This starts an interactive conversational session where you can:
- Describe what you want to build in natural language
- Request changes and improvements iteratively
- Get suggestions for next steps
- See files generated in real-time
Example Session:
Specify Output Directory:
One-Shot Generation
Generate a complete application from a single description without interaction:
Options:
-d, --description <text>- Application description (required)-o, --output <path>- Output directory (default:./src)-t, --type <type>- Generation type:basic,complete, orcustom(default:custom)
Generation Types:
basic- Minimal metadata (objects only)complete- Full metadata (objects, forms, views, actions, hooks, tests)custom- AI decides based on description (recommended)
Examples:
What Gets Generated:
For a complete application, you get:
-
Metadata Files (YAML)
*.object.yml- Data entities*.validation.yml- Validation rules*.permission.yml- Access control*.workflow.yml- Automation*.data.yml- Seed data
-
TypeScript Implementation Files
*.action.ts- Custom business operations*.hook.ts- Lifecycle triggers (beforeCreate, afterUpdate, etc.)
-
Test Files
*.test.ts- Jest tests for business logic
Validation
Validate existing metadata files with AI-powered analysis:
Options:
<path>- Path to metadata directory (required)--fix- Automatically fix issues where possible-v, --verbose- Show detailed validation output
What Gets Checked:
- ✅ YAML syntax
- ✅ ObjectQL specification compliance
- ✅ Business logic consistency
- ✅ Data model best practices
- ✅ Security considerations
- ✅ Performance implications
- ✅ Field type correctness
- ✅ Relationship integrity
Example:
Chat Assistant
Get help and guidance about ObjectQL concepts:
With Initial Prompt:
Example Session:
Complete Workflow Example
Here's a complete workflow from generation to deployment:
Tips & Best Practices
Writing Good Descriptions
Good:
Not as good:
Tips:
- Be specific about entities and relationships
- Mention key features and business rules
- Include any special requirements (e.g., "with approval workflow")
- Specify important fields or attributes
Interactive vs One-Shot
Use Interactive Mode when:
- Building a new application from scratch
- Exploring different design options
- Need to make iterative refinements
- Want AI guidance and suggestions
Use One-Shot Generation when:
- You have a clear, detailed requirements document
- Building a simple, well-defined system
- Automating app generation in scripts
- Need quick prototypes
Validation Workflow
Always validate generated files:
Environment Variables
OPENAI_API_KEY- Your OpenAI API key (required)OPENAI_MODEL- Model to use (optional, default:gpt-4)OPENAI_TEMPERATURE- Generation temperature 0-1 (optional, default:0.7)
Fallback Behavior
Without an API key, the CLI will:
- ✅ Still perform basic YAML syntax validation
- ❌ Cannot generate applications
- ❌ Cannot perform AI-powered deep validation
- ❌ Chat assistant unavailable
Next Steps
- Read Programmatic API to use AI agent in your code
- Check Generating Apps for advanced prompting techniques
- See Building Apps to use ObjectQL in AI applications