|
| 1 | +# AI-Powered CLI |
| 2 | + |
| 3 | +The ObjectQL CLI provides AI-powered commands to generate and validate applications using natural language. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The `objectql ai` command provides interactive and automated application generation with built-in validation and testing. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Set your OpenAI API key as an environment variable: |
| 12 | + |
| 13 | +```bash |
| 14 | +export OPENAI_API_KEY=sk-your-api-key-here |
| 15 | +``` |
| 16 | + |
| 17 | +## Commands |
| 18 | + |
| 19 | +### Interactive Mode (Default) |
| 20 | + |
| 21 | +The easiest way to build applications - just type: |
| 22 | + |
| 23 | +```bash |
| 24 | +objectql ai |
| 25 | +``` |
| 26 | + |
| 27 | +This starts an interactive conversational session where you can: |
| 28 | +- Describe what you want to build in natural language |
| 29 | +- Request changes and improvements iteratively |
| 30 | +- Get suggestions for next steps |
| 31 | +- See files generated in real-time |
| 32 | + |
| 33 | +**Example Session:** |
| 34 | + |
| 35 | +``` |
| 36 | +$ objectql ai |
| 37 | +💬 ObjectQL AI Assistant |
| 38 | +
|
| 39 | +What would you like to build today? |
| 40 | +> A blog system with posts, comments, and categories |
| 41 | +
|
| 42 | +Great! I'll create a blog system for you... |
| 43 | +✓ Generated: post.object.yml |
| 44 | +✓ Generated: comment.object.yml |
| 45 | +✓ Generated: category.object.yml |
| 46 | +✓ Generated: post.hook.ts |
| 47 | +✓ Generated: post.test.ts |
| 48 | +
|
| 49 | +What would you like to add or modify? |
| 50 | +> Add tags to posts |
| 51 | +
|
| 52 | +Adding tag support... |
| 53 | +✓ Generated: tag.object.yml |
| 54 | +✓ Updated: post.object.yml |
| 55 | +
|
| 56 | +Type "done" to finish, or continue refining your app. |
| 57 | +> done |
| 58 | +
|
| 59 | +📁 Application saved to ./src |
| 60 | +``` |
| 61 | + |
| 62 | +**Specify Output Directory:** |
| 63 | + |
| 64 | +```bash |
| 65 | +objectql ai ./my-app |
| 66 | +``` |
| 67 | + |
| 68 | +### One-Shot Generation |
| 69 | + |
| 70 | +Generate a complete application from a single description without interaction: |
| 71 | + |
| 72 | +```bash |
| 73 | +objectql ai generate -d "A CRM system with customers, contacts, and opportunities" -o ./src |
| 74 | +``` |
| 75 | + |
| 76 | +**Options:** |
| 77 | +- `-d, --description <text>` - Application description (required) |
| 78 | +- `-o, --output <path>` - Output directory (default: `./src`) |
| 79 | +- `-t, --type <type>` - Generation type: `basic`, `complete`, or `custom` (default: `custom`) |
| 80 | + |
| 81 | +**Generation Types:** |
| 82 | + |
| 83 | +- `basic` - Minimal metadata (objects only) |
| 84 | +- `complete` - Full metadata (objects, forms, views, actions, hooks, tests) |
| 85 | +- `custom` - AI decides based on description (recommended) |
| 86 | + |
| 87 | +**Examples:** |
| 88 | + |
| 89 | +```bash |
| 90 | +# Generate complete CRM |
| 91 | +objectql ai generate \ |
| 92 | + -d "Customer relationship management with sales pipeline" \ |
| 93 | + -t complete \ |
| 94 | + -o ./crm |
| 95 | + |
| 96 | +# Generate simple inventory tracker |
| 97 | +objectql ai generate \ |
| 98 | + -d "Track products with quantities and locations" \ |
| 99 | + -t basic |
| 100 | + |
| 101 | +# Let AI decide what's needed |
| 102 | +objectql ai generate \ |
| 103 | + -d "E-commerce platform with products, orders, and payments" |
| 104 | +``` |
| 105 | + |
| 106 | +**What Gets Generated:** |
| 107 | + |
| 108 | +For a `complete` application, you get: |
| 109 | + |
| 110 | +1. **Metadata Files (YAML)** |
| 111 | + - `*.object.yml` - Data entities |
| 112 | + - `*.validation.yml` - Validation rules |
| 113 | + - `*.form.yml` - Data entry forms |
| 114 | + - `*.view.yml` - List views |
| 115 | + - `*.page.yml` - UI pages |
| 116 | + - `*.menu.yml` - Navigation |
| 117 | + - `*.permission.yml` - Access control |
| 118 | + |
| 119 | +2. **TypeScript Implementation Files** |
| 120 | + - `*.action.ts` - Custom business operations |
| 121 | + - `*.hook.ts` - Lifecycle triggers (beforeCreate, afterUpdate, etc.) |
| 122 | + |
| 123 | +3. **Test Files** |
| 124 | + - `*.test.ts` - Jest tests for business logic |
| 125 | + |
| 126 | +### Validation |
| 127 | + |
| 128 | +Validate existing metadata files with AI-powered analysis: |
| 129 | + |
| 130 | +```bash |
| 131 | +objectql ai validate ./src |
| 132 | +``` |
| 133 | + |
| 134 | +**Options:** |
| 135 | +- `<path>` - Path to metadata directory (required) |
| 136 | +- `--fix` - Automatically fix issues where possible |
| 137 | +- `-v, --verbose` - Show detailed validation output |
| 138 | + |
| 139 | +**What Gets Checked:** |
| 140 | +- ✅ YAML syntax |
| 141 | +- ✅ ObjectQL specification compliance |
| 142 | +- ✅ Business logic consistency |
| 143 | +- ✅ Data model best practices |
| 144 | +- ✅ Security considerations |
| 145 | +- ✅ Performance implications |
| 146 | +- ✅ Field type correctness |
| 147 | +- ✅ Relationship integrity |
| 148 | + |
| 149 | +**Example:** |
| 150 | + |
| 151 | +```bash |
| 152 | +$ objectql ai validate ./src -v |
| 153 | + |
| 154 | +🔍 Validating metadata files... |
| 155 | + |
| 156 | +✓ user.object.yml - Valid |
| 157 | +⚠ order.object.yml - 2 warnings |
| 158 | + - Line 15: Consider adding index on 'customer_id' field for query performance |
| 159 | + - Line 23: 'total' field should use 'currency' type instead of 'number' |
| 160 | + |
| 161 | +❌ product.object.yml - 1 error |
| 162 | + - Line 10: Invalid field type 'string', use 'text' instead |
| 163 | + |
| 164 | +📊 Summary: |
| 165 | + Files checked: 3 |
| 166 | + Errors: 1 |
| 167 | + Warnings: 2 |
| 168 | + Info: 0 |
| 169 | +``` |
| 170 | + |
| 171 | +### Chat Assistant |
| 172 | + |
| 173 | +Get help and guidance about ObjectQL concepts: |
| 174 | + |
| 175 | +```bash |
| 176 | +objectql ai chat |
| 177 | +``` |
| 178 | + |
| 179 | +**With Initial Prompt:** |
| 180 | + |
| 181 | +```bash |
| 182 | +objectql ai chat -p "How do I create a lookup relationship?" |
| 183 | +``` |
| 184 | + |
| 185 | +**Example Session:** |
| 186 | + |
| 187 | +``` |
| 188 | +$ objectql ai chat |
| 189 | +🤖 ObjectQL AI Assistant |
| 190 | +
|
| 191 | +Ask me anything about ObjectQL! |
| 192 | +> How do I add email validation to a field? |
| 193 | +
|
| 194 | +You can add email validation in several ways: |
| 195 | +
|
| 196 | +1. Use the built-in 'email' field type: |
| 197 | + fields: |
| 198 | + email: |
| 199 | + type: email |
| 200 | + required: true |
| 201 | +
|
| 202 | +2. Or add validation rules: |
| 203 | + fields: |
| 204 | + contact_email: |
| 205 | + type: text |
| 206 | + validation: |
| 207 | + format: email |
| 208 | + |
| 209 | +> What about custom validation logic? |
| 210 | +
|
| 211 | +For custom validation, use a validation hook... |
| 212 | +``` |
| 213 | + |
| 214 | +## Complete Workflow Example |
| 215 | + |
| 216 | +Here's a complete workflow from generation to deployment: |
| 217 | + |
| 218 | +```bash |
| 219 | +# 1. Set API key |
| 220 | +export OPENAI_API_KEY=sk-your-key |
| 221 | + |
| 222 | +# 2. Generate application (interactive) |
| 223 | +objectql ai |
| 224 | +> A project management system with tasks, projects, and teams |
| 225 | +> done |
| 226 | + |
| 227 | +# 3. Validate generated files |
| 228 | +objectql ai validate ./src -v |
| 229 | + |
| 230 | +# 4. Fix any issues |
| 231 | +objectql ai validate ./src --fix |
| 232 | + |
| 233 | +# 5. Test the application |
| 234 | +objectql serve |
| 235 | + |
| 236 | +# 6. Get help if needed |
| 237 | +objectql ai chat -p "How do I add user authentication?" |
| 238 | +``` |
| 239 | + |
| 240 | +## Tips & Best Practices |
| 241 | + |
| 242 | +### Writing Good Descriptions |
| 243 | + |
| 244 | +**Good:** |
| 245 | +```bash |
| 246 | +objectql ai generate -d "Inventory management with products, warehouses, stock movements, and reorder points. Include barcode scanning support and low stock alerts." |
| 247 | +``` |
| 248 | + |
| 249 | +**Not as good:** |
| 250 | +```bash |
| 251 | +objectql ai generate -d "inventory app" |
| 252 | +``` |
| 253 | + |
| 254 | +**Tips:** |
| 255 | +- Be specific about entities and relationships |
| 256 | +- Mention key features and business rules |
| 257 | +- Include any special requirements (e.g., "with approval workflow") |
| 258 | +- Specify important fields or attributes |
| 259 | + |
| 260 | +### Interactive vs One-Shot |
| 261 | + |
| 262 | +Use **Interactive Mode** when: |
| 263 | +- Building a new application from scratch |
| 264 | +- Exploring different design options |
| 265 | +- Need to make iterative refinements |
| 266 | +- Want AI guidance and suggestions |
| 267 | + |
| 268 | +Use **One-Shot Generation** when: |
| 269 | +- You have a clear, detailed requirements document |
| 270 | +- Building a simple, well-defined system |
| 271 | +- Automating app generation in scripts |
| 272 | +- Need quick prototypes |
| 273 | + |
| 274 | +### Validation Workflow |
| 275 | + |
| 276 | +Always validate generated files: |
| 277 | + |
| 278 | +```bash |
| 279 | +# After generation |
| 280 | +objectql ai generate -d "..." -o ./src |
| 281 | + |
| 282 | +# Validate |
| 283 | +objectql ai validate ./src -v |
| 284 | + |
| 285 | +# Auto-fix common issues |
| 286 | +objectql ai validate ./src --fix |
| 287 | + |
| 288 | +# Manually review any remaining issues |
| 289 | +``` |
| 290 | + |
| 291 | +## Environment Variables |
| 292 | + |
| 293 | +- `OPENAI_API_KEY` - Your OpenAI API key (required) |
| 294 | +- `OPENAI_MODEL` - Model to use (optional, default: `gpt-4`) |
| 295 | +- `OPENAI_TEMPERATURE` - Generation temperature 0-1 (optional, default: `0.7`) |
| 296 | + |
| 297 | +## Fallback Behavior |
| 298 | + |
| 299 | +Without an API key, the CLI will: |
| 300 | +- ✅ Still perform basic YAML syntax validation |
| 301 | +- ❌ Cannot generate applications |
| 302 | +- ❌ Cannot perform AI-powered deep validation |
| 303 | +- ❌ Chat assistant unavailable |
| 304 | + |
| 305 | +```bash |
| 306 | +# This still works without API key: |
| 307 | +objectql ai validate ./src # Basic YAML syntax check only |
| 308 | +``` |
| 309 | + |
| 310 | +## Next Steps |
| 311 | + |
| 312 | +- Read [Programmatic API](/ai/programmatic-api) to use AI agent in your code |
| 313 | +- Check [Generating Apps](/ai/generating-apps) for advanced prompting techniques |
| 314 | +- See [Building Apps](/ai/building-apps) to use ObjectQL in AI applications |
0 commit comments