@agentlang/cli 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,690 @@
1
+ # Agentlang CLI
2
+
3
+ > A powerful command-line interface for building, running, and managing
4
+ > Agentlang applications
5
+
6
+ [![npm version](https://img.shields.io/npm/v/agentlangcli.svg)](https://www.npmjs.com/package/agentlangcli)
7
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg)](https://nodejs.org)
8
+ [![License](https://img.shields.io/badge/License-Sustainable%20Use-blue.svg)](LICENSE)
9
+
10
+ Agentlang is a programming language designed for building agent-based
11
+ applications with built-in support for entities, events, and relationships. This
12
+ CLI provides a complete toolkit for developing, testing, and deploying Agentlang
13
+ applications.
14
+
15
+ ## Table of Contents
16
+
17
+ - [Features](#features)
18
+ - [Installation](#installation)
19
+ - [Quick Start](#quick-start)
20
+ - [Commands](#commands)
21
+ - [init](#init)
22
+ - [run](#run)
23
+ - [repl](#repl)
24
+ - [doc](#doc)
25
+ - [parseAndValidate](#parseandvalidate)
26
+ - [ui-gen](#ui-gen)
27
+ - [Configuration](#configuration)
28
+ - [Examples](#examples)
29
+ - [License](#license)
30
+
31
+ ## Features
32
+
33
+ - **🚀 Project Initialization** - Scaffold new Agentlang applications with
34
+ proper structure
35
+ - **▶️ Runtime Execution** - Run Agentlang programs with full runtime support
36
+ - **🔄 Interactive REPL** - Test and debug with hot-reloading support
37
+ - **✅ Validation** - Parse and validate Agentlang code for syntax and semantic
38
+ correctness
39
+ - **📚 API Documentation** - Auto-generate OpenAPI/Swagger docs from your
40
+ modules
41
+ - **🎨 UI Generation** - Generate complete React + TypeScript + Vite apps using
42
+ Claude AI
43
+
44
+ ## Installation
45
+
46
+ ### Prerequisites
47
+
48
+ - Node.js 20.0.0 or higher
49
+ - npm, pnpm, or yarn
50
+
51
+ ### Global Installation
52
+
53
+ ```bash
54
+ npm install -g agentlangcli
55
+ ```
56
+
57
+ ### Local Installation
58
+
59
+ ```bash
60
+ npm install agentlangcli
61
+ ```
62
+
63
+ ### Using pnpm
64
+
65
+ ```bash
66
+ pnpm install -g agentlangcli
67
+ ```
68
+
69
+ After installation, the `agent` command will be available globally.
70
+
71
+ ## Quick Start
72
+
73
+ ```bash
74
+ # 1. Initialize a new Agentlang application
75
+ agent init MyApp
76
+
77
+ # 2. Navigate to your project
78
+ cd MyApp
79
+
80
+ # 3. Add your application logic to src/core.al
81
+ # (Edit src/core.al with your entities, events, and relationships)
82
+
83
+ # 4. Run your application
84
+ agent run
85
+
86
+ # 5. Start interactive REPL with hot-reload
87
+ agent repl --watch
88
+
89
+ # 6. Generate API documentation
90
+ agent doc --outputHtml docs/api.html
91
+ ```
92
+
93
+ ## Commands
94
+
95
+ ### init
96
+
97
+ Initialize a new Agentlang application with the necessary project structure.
98
+
99
+ ```bash
100
+ agent init <appname>
101
+ ```
102
+
103
+ **Arguments:**
104
+
105
+ - `<appname>` - Name of the application to initialize (required)
106
+
107
+ **What it creates:**
108
+
109
+ - `package.json` with your app name and version 0.0.1
110
+ - `config.al` for application configuration
111
+ - `src/core.al` with your application module
112
+
113
+ **Examples:**
114
+
115
+ ```bash
116
+ # Initialize a car dealership application
117
+ agent init CarDealership
118
+
119
+ # Initialize an e-commerce app
120
+ agent init MyShop
121
+
122
+ # Initialize with PascalCase for multi-word names
123
+ agent init InventoryManagement
124
+ ```
125
+
126
+ **Behavior:** The command intelligently checks if a directory is already
127
+ initialized by looking for existing `package.json` or `.al` files (excluding
128
+ `config.al`). If found, it skips initialization to prevent overwriting your
129
+ work.
130
+
131
+ ---
132
+
133
+ ### run
134
+
135
+ Load and execute an Agentlang module with full runtime support.
136
+
137
+ ```bash
138
+ agent run [file]
139
+ ```
140
+
141
+ **Arguments:**
142
+
143
+ - `[file]` - Path to Agentlang source file or directory (default: current
144
+ directory)
145
+
146
+ **Options:**
147
+
148
+ - `-c, --config <file>` - Path to configuration file
149
+
150
+ **Examples:**
151
+
152
+ ```bash
153
+ # Run module in current directory
154
+ agent run
155
+
156
+ # Run specific module file
157
+ agent run ./my-app/main.al
158
+
159
+ # Run with custom configuration
160
+ agent run ./my-app -c config.json
161
+
162
+ # Run module from specific directory
163
+ agent run ~/projects/erp-system
164
+ ```
165
+
166
+ **What it does:** Loads and executes your Agentlang module, starting the runtime
167
+ environment and initializing all configured services, databases, and
168
+ integrations. The application will start an HTTP server (default port: 8080)
169
+ exposing REST APIs for your entities and workflows.
170
+
171
+ ---
172
+
173
+ ### repl
174
+
175
+ Start an interactive Read-Eval-Print Loop environment for testing and debugging.
176
+
177
+ ```bash
178
+ agent repl [directory]
179
+ ```
180
+
181
+ **Arguments:**
182
+
183
+ - `[directory]` - Application directory (default: current directory)
184
+
185
+ **Options:**
186
+
187
+ - `-w, --watch` - Watch for file changes and reload automatically
188
+ - `-q, --quiet` - Suppress startup messages
189
+
190
+ **Examples:**
191
+
192
+ ```bash
193
+ # Start REPL in current directory
194
+ agent repl
195
+
196
+ # Start REPL in specific directory
197
+ agent repl ./my-app
198
+
199
+ # Start with file watching enabled
200
+ agent repl --watch
201
+
202
+ # Start in quiet mode
203
+ agent repl --quiet
204
+
205
+ # Combine options for development workflow
206
+ agent repl . --watch
207
+ ```
208
+
209
+ **Features:**
210
+
211
+ - Execute Agentlang expressions in real-time
212
+ - Test entity operations and workflows
213
+ - Hot reload with `--watch` flag for rapid development
214
+ - Access all loaded entities and functions
215
+
216
+ ---
217
+
218
+ ### doc
219
+
220
+ Generate API documentation in OpenAPI/Swagger format.
221
+
222
+ ```bash
223
+ agent doc [file]
224
+ ```
225
+
226
+ **Arguments:**
227
+
228
+ - `[file]` - Path to Agentlang source file or directory (default: current
229
+ directory)
230
+
231
+ **Options:**
232
+
233
+ - `-h, --outputHtml <file>` - Generate HTML documentation
234
+ - `-p, --outputPostman <file>` - Generate Postman collection
235
+
236
+ **Examples:**
237
+
238
+ ```bash
239
+ # Generate OpenAPI spec (outputs to console)
240
+ agent doc
241
+
242
+ # Generate HTML documentation
243
+ agent doc --outputHtml api-docs.html
244
+
245
+ # Generate Postman collection
246
+ agent doc --outputPostman collection.json
247
+
248
+ # Generate both HTML and Postman
249
+ agent doc -h docs.html -p collection.json
250
+
251
+ # Generate docs for specific module
252
+ agent doc ./my-api -h api.html
253
+ ```
254
+
255
+ **Generated Endpoints:**
256
+
257
+ For each entity in your module:
258
+
259
+ - `POST /api/{module}/{entity}` - Create entity
260
+ - `GET /api/{module}/{entity}` - List entities
261
+ - `PUT /api/{module}/{entity}/{id}` - Update entity
262
+ - `DELETE /api/{module}/{entity}/{id}` - Delete entity
263
+
264
+ For relationships:
265
+
266
+ - `POST /api/{module}/{entity}/{relationship}/{relatedEntity}` - Create related
267
+ entity
268
+ - `GET /api/{module}/{entity}/{relationship}/{relatedEntity}` - List related
269
+ entities
270
+ - `PUT /api/{module}/{entity}/{relationship}/{relatedEntity}/{id}` - Update
271
+ related entity
272
+ - `DELETE /api/{module}/{entity}/{relationship}/{relatedEntity}/{id}` - Delete
273
+ related entity
274
+
275
+ ---
276
+
277
+ ### parseAndValidate
278
+
279
+ Parse and validate Agentlang source code for syntax and semantic correctness.
280
+
281
+ ```bash
282
+ agent parseAndValidate <file>
283
+ ```
284
+
285
+ **Arguments:**
286
+
287
+ - `<file>` - Path to Agentlang source file (required)
288
+
289
+ **Options:**
290
+
291
+ - `-d, --destination <dir>` - Output directory for generated files
292
+
293
+ **Examples:**
294
+
295
+ ```bash
296
+ # Validate a source file
297
+ agent parseAndValidate ./src/main.al
298
+
299
+ # Parse and validate with output directory
300
+ agent parseAndValidate main.al -d ./out
301
+
302
+ # Validate in CI/CD pipeline
303
+ agent parseAndValidate app.al && npm run deploy
304
+ ```
305
+
306
+ **Use Cases:**
307
+
308
+ - Pre-deployment validation
309
+ - CI/CD pipeline integration
310
+ - Syntax checking during development
311
+
312
+ ---
313
+
314
+ ### ui-gen
315
+
316
+ Generate a complete React + TypeScript + Vite application from a UI
317
+ specification using Claude AI.
318
+
319
+ ```bash
320
+ agent ui-gen [spec-file]
321
+ ```
322
+
323
+ **Arguments:**
324
+
325
+ - `[spec-file]` - Path to ui-spec.json (auto-detects if omitted)
326
+
327
+ **Options:**
328
+
329
+ - `-d, --directory <dir>` - Target directory (default: current directory)
330
+ - `-k, --api-key <key>` - Anthropic API key (or set `ANTHROPIC_API_KEY` env var)
331
+ - `-p, --push` - Automatically commit and push changes to git
332
+ - `-m, --message <text>` - User message for incremental updates
333
+
334
+ **API Key Setup:**
335
+
336
+ You can provide the Anthropic API key in two ways:
337
+
338
+ 1. **Environment variable (recommended):**
339
+
340
+ ```bash
341
+ export ANTHROPIC_API_KEY=sk-ant-...
342
+ agent ui-gen
343
+ ```
344
+
345
+ 2. **Command flag:**
346
+
347
+ ```bash
348
+ agent ui-gen --api-key sk-ant-...
349
+ ```
350
+
351
+ Get your API key at: https://console.anthropic.com
352
+
353
+ **Examples:**
354
+
355
+ ```bash
356
+ # Basic usage - auto-detect spec file
357
+ agent ui-gen
358
+
359
+ # Use specific spec file
360
+ agent ui-gen ui-spec.json
361
+
362
+ # Generate with custom directory
363
+ agent ui-gen -d ./my-project
364
+
365
+ # With API key and git push
366
+ agent ui-gen ui-spec.json -k sk-ant-... -p
367
+
368
+ # Incremental update with user message
369
+ agent ui-gen -m "Add dark mode support"
370
+
371
+ # Update and push to git
372
+ agent ui-gen -m "Fix login form validation" -p
373
+ ```
374
+
375
+ **Generation Modes:**
376
+
377
+ The UI generator intelligently selects the appropriate mode:
378
+
379
+ - **Fresh Generation** - No existing `ui/` directory → generates complete
380
+ application
381
+ - **Incremental Update** - Existing `ui/` directory → adds missing files based
382
+ on spec
383
+ - **User-Directed Update** - Using `-m` flag → makes targeted changes per
384
+ instructions
385
+
386
+ **Generated Application Features:**
387
+
388
+ - React 18+ with TypeScript
389
+ - Vite for fast development and builds
390
+ - Authentication (login, signup, forgot password)
391
+ - Entity CRUD operations with forms and validation
392
+ - Dashboard with charts and statistics
393
+ - Relationship management between entities
394
+ - Workflow/event execution
395
+ - Responsive, mobile-friendly design
396
+ - Mock data mode for testing without backend
397
+ - Environment-based configuration
398
+
399
+ **UI Spec Format:**
400
+
401
+ The generator expects a JSON file with the following structure:
402
+
403
+ ```json
404
+ {
405
+ "appInfo": {
406
+ "name": "my-app",
407
+ "title": "My Application",
408
+ "description": "Application description"
409
+ },
410
+ "entities": [
411
+ {
412
+ "name": "Customer",
413
+ "displayName": "Customers",
414
+ "fields": [
415
+ {
416
+ "name": "name",
417
+ "type": "string",
418
+ "required": true
419
+ },
420
+ {
421
+ "name": "email",
422
+ "type": "string",
423
+ "required": true
424
+ }
425
+ ]
426
+ }
427
+ ],
428
+ "relationships": [],
429
+ "workflows": [],
430
+ "navigation": {
431
+ "groups": []
432
+ }
433
+ }
434
+ ```
435
+
436
+ **Authentication Endpoints:**
437
+
438
+ The generated application uses the following endpoints:
439
+
440
+ - `POST /agentlang_auth/login` - User login
441
+ - `POST /agentlang_auth/signUp` - User registration
442
+ - `POST /agentlang_auth/forgotPassword` - Password recovery
443
+
444
+ **Environment Configuration:**
445
+
446
+ Generated `.env` file:
447
+
448
+ ```env
449
+ VITE_BACKEND_URL=http://localhost:8080/
450
+ VITE_USE_MOCK_DATA=true
451
+ ```
452
+
453
+ By default, mock data mode is enabled for immediate testing. Set
454
+ `VITE_USE_MOCK_DATA=false` when your backend is ready.
455
+
456
+ ---
457
+
458
+ ## Configuration
459
+
460
+ The CLI supports configuration through a `config.al` or custom configuration
461
+ file.
462
+
463
+ ### Basic Configuration
464
+
465
+ ```javascript
466
+ // config.al or app.config.js
467
+ {
468
+ "service": {
469
+ "port": 8080
470
+ },
471
+ "store": {
472
+ "type": "sqlite",
473
+ "dbname": "myapp.db"
474
+ }
475
+ }
476
+ ```
477
+
478
+ ### Database Options
479
+
480
+ #### SQLite (Default)
481
+
482
+ ```javascript
483
+ {
484
+ "store": {
485
+ "type": "sqlite",
486
+ "dbname": "myapp.db" // optional, defaults to in-memory
487
+ }
488
+ }
489
+ ```
490
+
491
+ #### PostgreSQL
492
+
493
+ ```javascript
494
+ {
495
+ "store": {
496
+ "type": "postgres",
497
+ "host": "localhost",
498
+ "username": "postgres",
499
+ "password": "postgres",
500
+ "dbname": "myapp",
501
+ "port": 5432
502
+ }
503
+ }
504
+ ```
505
+
506
+ ### Advanced Configuration
507
+
508
+ ```javascript
509
+ {
510
+ "service": {
511
+ "port": 8080
512
+ },
513
+ "store": {
514
+ "type": "postgres",
515
+ "host": "localhost",
516
+ "username": "postgres",
517
+ "password": "postgres",
518
+ "dbname": "myapp",
519
+ "port": 5432
520
+ },
521
+ "graphql": {
522
+ "enabled": true
523
+ },
524
+ "rbacEnabled": true,
525
+ "auditTrail": {
526
+ "enabled": true
527
+ },
528
+ "authentication": {
529
+ "enabled": true
530
+ }
531
+ }
532
+ ```
533
+
534
+ ## Examples
535
+
536
+ ### Simple Agentlang Module
537
+
538
+ ```agentlang
539
+ module UserManagement {
540
+ entity User {
541
+ id: UUID
542
+ name: String
543
+ email: String
544
+ createdAt: DateTime
545
+ }
546
+
547
+ event UserCreated {
548
+ userId: UUID
549
+ timestamp: DateTime
550
+ }
551
+ }
552
+ ```
553
+
554
+ ### Complete Development Workflow
555
+
556
+ ```bash
557
+ # 1. Initialize a new Agentlang application
558
+ mkdir my-project && cd my-project
559
+ agent init MyApp
560
+
561
+ # 2. Navigate into the project
562
+ cd MyApp
563
+
564
+ # 3. Add your application logic to src/core.al
565
+ # (Edit src/core.al with your entities and logic)
566
+
567
+ # 4. Test interactively with REPL
568
+ agent repl --watch
569
+
570
+ # 5. Run your Agentlang application
571
+ agent run
572
+
573
+ # 6. Generate API documentation
574
+ agent doc -h ./docs/api.html
575
+
576
+ # 7. Generate UI from specification
577
+ export ANTHROPIC_API_KEY=sk-ant-...
578
+ agent ui-gen ui-spec.json -p
579
+
580
+ # 8. Navigate to generated UI and test
581
+ cd ui
582
+ npm install
583
+ npm run dev
584
+
585
+ # 9. Make iterative updates to UI
586
+ cd ..
587
+ agent ui-gen -m "Add export to CSV feature"
588
+ ```
589
+
590
+ ### CI/CD Integration
591
+
592
+ ```bash
593
+ # In your CI/CD pipeline
594
+ agent parseAndValidate src/main.al
595
+ if [ $? -eq 0 ]; then
596
+ echo "Validation successful"
597
+ agent run src/main.al
598
+ else
599
+ echo "Validation failed"
600
+ exit 1
601
+ fi
602
+ ```
603
+
604
+ ### E-Commerce Example
605
+
606
+ ```bash
607
+ # Initialize e-commerce app
608
+ mkdir online-store && cd online-store
609
+ agent init OnlineStore
610
+ cd OnlineStore
611
+
612
+ # Start REPL with hot-reload for development
613
+ agent repl --watch
614
+
615
+ # In another terminal, run the application
616
+ agent run
617
+
618
+ # Generate API docs
619
+ agent doc -h docs/api-docs.html -p docs/postman-collection.json
620
+
621
+ # Generate UI
622
+ agent ui-gen ui-spec.json --push
623
+ ```
624
+
625
+ ## File Extensions
626
+
627
+ The CLI supports Agentlang files with the following extensions:
628
+
629
+ - `.al` (recommended)
630
+ - `.agentlang`
631
+
632
+ ## Error Handling
633
+
634
+ The CLI provides clear error messages for common issues:
635
+
636
+ - **Configuration Errors** - Invalid configuration files or missing required
637
+ fields
638
+ - **Parse Errors** - Syntax errors in Agentlang code with line numbers
639
+ - **Validation Errors** - Semantic errors in Agentlang modules
640
+ - **Runtime Errors** - Errors during program execution with stack traces
641
+
642
+ ## Development
643
+
644
+ ### Building from Source
645
+
646
+ ```bash
647
+ git clone https://github.com/agentlang/agentlang-cli.git
648
+ cd agentlang-cli
649
+ npm install
650
+ npm run build
651
+ ```
652
+
653
+ ### Running in Development Mode
654
+
655
+ ```bash
656
+ npm run dev
657
+ ```
658
+
659
+ ### Running Tests
660
+
661
+ ```bash
662
+ npm test
663
+ ```
664
+
665
+ ## Contributing
666
+
667
+ Contributions are welcome! Please feel free to submit a Pull Request.
668
+
669
+ 1. Fork the repository
670
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
671
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
672
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
673
+ 5. Open a Pull Request
674
+
675
+ ## Support
676
+
677
+ - **Documentation**:
678
+ [GitHub Repository](https://github.com/agentlang/agentlang-cli)
679
+ - **Issues**: [GitHub Issues](https://github.com/agentlang/agentlang-cli/issues)
680
+ - **Discussions**:
681
+ [GitHub Discussions](https://github.com/agentlang/agentlang-cli/discussions)
682
+
683
+ ## License
684
+
685
+ This project is licensed under the [Sustainable Use License](LICENSE) - see the
686
+ LICENSE file for details.
687
+
688
+ ---
689
+
690
+ **Made with ❤️ by the Agentlang Team**
package/bin/cli.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ import main from '../out/main.js';
4
+ main();