@semiont/cli 0.1.0-build.2

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,497 @@
1
+ # Semiont CLI
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@semiont/cli.svg)](https://www.npmjs.com/package/@semiont/cli)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@semiont/cli.svg)](https://www.npmjs.com/package/@semiont/cli)
5
+ [![License](https://img.shields.io/npm/l/@semiont/cli.svg)](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
6
+
7
+ The unified command-line interface for managing Semiont environments and services with platform-aware operations.
8
+
9
+ ## Overview
10
+
11
+ The Semiont CLI provides a consistent interface for managing services across different environments and platforms through five core concepts:
12
+
13
+ ### Core Concepts
14
+
15
+ 1. **Environment** - The primary configuration context (dev, staging, production)
16
+ 2. **Service** - Business entities managed by the CLI (backend, frontend, database)
17
+ 3. **Service Type** - High-level service categories declared by services (frontend, backend, database, filesystem, worker, mcp, etc.)
18
+ 4. **Command** - Operations you can perform (start, stop, check, deploy)
19
+ 5. **Platform Type** - Infrastructure targets where services run (posix, container, aws, external, mock)
20
+
21
+ ### Key Capabilities
22
+
23
+ - **Environment-Driven Configuration**: All operations require an environment context
24
+ - **Service Management**: start, stop, restart, check services based on environment
25
+ - **Infrastructure Operations**: provision, configure, backup across platforms
26
+ - **Development Workflows**: publish, update, test with platform awareness
27
+ - **Safety Features**: comprehensive `--dry-run` support for all operations
28
+
29
+ ## Quick Links
30
+
31
+ - [**Architecture Overview**](./docs/ARCHITECTURE.md) - Understanding the CLI architecture and core concepts
32
+ - [**Managing Environments**](./docs/ADDING_ENVIRONMENTS.md) - Guide for configuring and managing environments
33
+ - [**Adding New Commands**](./docs/ADDING_COMMANDS.md) - Step-by-step guide for adding new CLI commands
34
+ - [**Adding New Platforms**](./docs/ADDING_PLATFORMS.md) - Guide for implementing new platform strategies
35
+ - [**Adding New Services**](./docs/ADDING_SERVICES.md) - Guide for adding new service implementations
36
+ - [**Adding New Service Types**](./docs/ADDING_SERVICE_TYPES.md) - Guide for adding new service type categories
37
+
38
+ ## Installation
39
+
40
+ Install globally from npm:
41
+
42
+ ```bash
43
+ # Latest stable release
44
+ npm install -g @semiont/cli
45
+
46
+ # Or latest development build
47
+ npm install -g @semiont/cli@dev
48
+
49
+ # After installation, the 'semiont' command is available globally
50
+ semiont --help
51
+ ```
52
+
53
+ Or install from source:
54
+
55
+ ```bash
56
+ # From the CLI directory
57
+ cd apps/cli
58
+ npm run build # Build the CLI
59
+ npm link # Install globally
60
+ ```
61
+
62
+ ## Common Options
63
+
64
+ All commands support these common options:
65
+
66
+ - **Environment** (required): `--environment <env>` or via `SEMIONT_ENV` - Target environment
67
+ - **Service Selection**: `-s, --service <service>` - Target specific service(s) (default: "all")
68
+ - **Safety**: `--dry-run` - Preview changes without applying (comprehensive support)
69
+ - **Output**: `-v, --verbose` - Show detailed output and debug information
70
+ - **Help**: `-h, --help` - Show help for the command
71
+
72
+ ### Environment Configuration (Required)
73
+
74
+ Every command requires an environment to be specified:
75
+
76
+ ```bash
77
+ # Via command-line flag (highest priority)
78
+ semiont start backend --environment production
79
+
80
+ # Via environment variable
81
+ export SEMIONT_ENV=staging
82
+ semiont start backend
83
+
84
+ # Error if neither is provided
85
+ semiont start backend
86
+ # Error: Environment is required. Specify --environment flag or set SEMIONT_ENV
87
+ ```
88
+
89
+ ### Dry-Run Support
90
+
91
+ All commands have comprehensive `--dry-run` support with two levels:
92
+
93
+ 1. **Overview Level**: Shows which services would be affected
94
+ 2. **Detail Level**: Shows specific actions that would be taken for each service
95
+
96
+ ```bash
97
+ # Example dry-run output
98
+ $ semiont start production --dry-run
99
+ ℹ️ Starting services in production environment
100
+ ℹ️ [DRY RUN] Would start the following services:
101
+ - frontend (aws)
102
+ - backend (aws)
103
+ - database (aws)
104
+ - filesystem (aws)
105
+ ```
106
+
107
+ ### Service Selection
108
+
109
+ Flexible service targeting:
110
+ - `all` - All services in the environment (default)
111
+ - `frontend` - Frontend web application
112
+ - `backend` - Backend API service
113
+ - `database` - PostgreSQL database
114
+ - `graph` - Graph database (Neo4j/Neptune)
115
+ - `event-store` - Event Store (immutable event log)
116
+ - `projection` - Projection Store (materialized views)
117
+ - `filesystem` - File storage service
118
+ - `inference` - AI/ML inference service
119
+ - `mcp` - Model Context Protocol server
120
+ - Service combinations and patterns (future extension)
121
+
122
+ ### Environment-Driven Architecture
123
+
124
+ Environments are the foundation of configuration:
125
+ - **Define which services exist** in each deployment context
126
+ - **Specify platform assignments** for each service (posix, container, aws)
127
+ - **Configure service settings** (ports, environment variables, resources)
128
+ - **No special environment names** - all environments are treated equally
129
+ - **Required for all operations** via `--environment` or `SEMIONT_ENV`
130
+
131
+ ## Architecture
132
+
133
+ The CLI follows a unified architecture built on five core concepts:
134
+
135
+ ```
136
+ Environment (configuration context)
137
+ ↓ defines
138
+ Services (what exists)
139
+ ↓ declare their
140
+ Service Type (what they are: frontend, backend, database, etc.)
141
+ ↓ deployed to
142
+ Platform (where they run: aws, container, posix, etc.)
143
+ ↓ operated via
144
+ Commands (what you can do)
145
+ ```
146
+
147
+ See [Architecture Overview](./docs/ARCHITECTURE.md) for detailed information.
148
+
149
+ ### Directory Structure
150
+
151
+ ```
152
+ environments/ # Environment configurations (primary config)
153
+ ├── dev.json # Development environment
154
+ ├── staging.json # Staging environment
155
+ └── production.json # Production environment
156
+
157
+ src/
158
+ ├── cli.ts # CLI entry point
159
+ ├── core/ # Core execution engine
160
+ │ ├── multi-service-executor.ts # Multi-service command execution
161
+ │ ├── command-descriptor.ts # Command configuration
162
+ │ ├── command-result.ts # Unified result type
163
+ │ ├── platform.ts # Abstract Platform class
164
+ │ ├── service-interface.ts # Service contracts
165
+ │ ├── service-types.ts # Service type definitions
166
+ │ ├── service-cli-behaviors.ts # CLI behavior capabilities
167
+ │ ├── service-command-capabilities.ts # Command support declarations
168
+ │ └── handlers/ # Handler management
169
+ │ ├── registry.ts # Handler registration
170
+ │ └── types.ts # Handler types
171
+ ├── commands/ # Command implementations
172
+ │ ├── start.ts # Start services
173
+ │ ├── stop.ts # Stop services
174
+ │ ├── check.ts # Health checks
175
+ │ └── ... # Other commands
176
+ ├── services/ # Service implementations
177
+ │ ├── base-service.ts # Base service class
178
+ │ └── ... # Service implementations
179
+ ├── platforms/ # Platform implementations
180
+ │ ├── posix/handlers/ # POSIX system handlers
181
+ │ ├── container/handlers/ # Docker/Podman handlers
182
+ │ ├── aws/handlers/ # AWS service handlers
183
+ │ └── ... # Other platforms
184
+ ├── lib/ # Shared utilities
185
+ └── docs/ # Documentation
186
+ ├── ARCHITECTURE.md # Architecture & concepts
187
+ ├── ADDING_ENVIRONMENTS.md # Environment guide
188
+ ├── ADDING_COMMANDS.md # Commands guide
189
+ ├── ADDING_PLATFORMS.md # Platforms guide
190
+ ├── ADDING_SERVICES.md # Services guide
191
+ └── ADDING_SERVICE_TYPES.md # Service types guide
192
+ ```
193
+
194
+ ### Environment Configuration
195
+
196
+ Environments are JSON files that define:
197
+ - Which services exist
198
+ - Platform assignments for each service
199
+ - Service-specific configuration
200
+ - Platform settings (AWS regions, Docker registries, etc.)
201
+
202
+ #### Example Environment File (environments/staging.json)
203
+
204
+ ```json
205
+ {
206
+ "platform": {
207
+ "default": "container"
208
+ },
209
+ "services": {
210
+ "backend": {
211
+ "platform": "container",
212
+ "image": "myorg/backend:staging",
213
+ "port": 3000,
214
+ "env": {
215
+ "NODE_ENV": "staging"
216
+ }
217
+ },
218
+ "database": {
219
+ "platform": "aws",
220
+ "instanceClass": "db.t3.medium"
221
+ }
222
+ }
223
+ }
224
+ ```
225
+
226
+ #### Environment Resolution
227
+
228
+ The CLI determines the environment using:
229
+
230
+ 1. **Command-line flag** (`--environment`) - highest priority
231
+ 2. **Environment variable** (`SEMIONT_ENV`) - fallback
232
+ 3. **Error** - if neither is provided
233
+
234
+ ```bash
235
+ # Via flag
236
+ semiont start backend --environment production
237
+
238
+ # Via environment variable
239
+ export SEMIONT_ENV=staging
240
+ semiont start backend
241
+
242
+ # Error if neither
243
+ semiont start backend
244
+ # Error: Environment is required
245
+ ```
246
+
247
+ ## Service Types and Capabilities
248
+
249
+ Services declare their type and capabilities through annotations in their requirements:
250
+
251
+ ### Service Types
252
+ Each service declares what it is (not where it runs):
253
+ - **frontend** - User-facing web applications
254
+ - **backend** - API servers and application logic
255
+ - **database** - Data persistence layers
256
+ - **filesystem** - File storage and management
257
+ - **worker** - Background job processors
258
+ - **mcp** - Model Context Protocol services
259
+ - **inference** - AI/ML model serving
260
+ - **generic** - General-purpose services
261
+
262
+ ### Service Capabilities
263
+ Services can declare special behaviors and command support:
264
+ - **CLI behaviors** - Output suppression, process lifecycle, interactive mode
265
+ - **Command support** - Which commands the service supports (publish, update, backup, etc.)
266
+
267
+ ## Platform Support
268
+
269
+ Platforms determine where services run, configured per environment:
270
+
271
+ - **POSIX** (`posix`): Services running as local OS processes
272
+ - **Container** (`container`): Services in Docker/Podman containers
273
+ - **AWS** (`aws`): Services on AWS infrastructure
274
+ - Maps service types to AWS services (frontend → S3+CloudFront, backend → ECS, database → RDS)
275
+ - **External** (`external`): Third-party or existing services
276
+ - **Mock** (`mock`): Simulated services for testing
277
+
278
+ Each service's platform is specified in the environment configuration file.
279
+
280
+ ## Key Design Principles
281
+
282
+ 1. **Environment-First Configuration** - All configuration flows from environment files
283
+ 2. **Unified Execution Pattern** - All commands use MultiServiceExecutor for consistency
284
+ 3. **Handler-Based Architecture** - Platform-specific logic in self-contained handlers
285
+ 4. **Service Requirements Pattern** - Services declare needs, platforms provide resources
286
+ 5. **Comprehensive Dry-Run Support** - All commands support `--dry-run` with detailed previews
287
+ 6. **Type Safety** - Full TypeScript and Zod validation throughout
288
+ 7. **No Special Environment Names** - All environments treated equally
289
+ 8. **Extensible Architecture** - Easy to add new services, platforms, handlers, and commands
290
+
291
+ ## Command Overview
292
+
293
+ All commands follow a consistent pattern and support common options like `--dry-run`, `--verbose`, and service selection. Commands automatically adapt their behavior based on the platform configuration of each service.
294
+
295
+ For detailed instructions on adding new commands, see the [Adding Commands Guide](./docs/ADDING_COMMANDS.md).
296
+
297
+ ### Available Commands
298
+
299
+ **Service Management**
300
+ - `start` - Start services
301
+ - `stop` - Stop services
302
+ - `restart` - Restart services
303
+ - `check` - Health check services
304
+ - `watch` - Monitor services with live dashboard
305
+
306
+ **Infrastructure & Configuration**
307
+ - `provision` - Provision infrastructure resources
308
+ - `configure` - Manage configuration and secrets
309
+ - `backup` - Create service backups
310
+ - `restore` - Restore from backups
311
+
312
+ **Development & Deployment**
313
+ - `publish` - Build and publish artifacts (creates new versions, does not deploy)
314
+ - `update` - Deploy new versions to running services (deploys what publish created)
315
+ - `test` - Run test suites
316
+ - `exec` - Execute commands in service context
317
+ - `init` - Initialize new Semiont project
318
+
319
+ Each command automatically detects the platform for each service and executes the appropriate implementation. See the documentation links above for detailed guides on extending the CLI.
320
+
321
+ ### Publish and Update Workflow
322
+
323
+ The `publish` and `update` commands work together to deploy new versions:
324
+
325
+ **Publish** - Prepares artifacts for deployment:
326
+ - Builds applications and Docker images
327
+ - Pushes images to registries (ECR, Docker Hub, etc.)
328
+ - Creates new task definitions (for ECS) or deployment manifests
329
+ - Does NOT deploy to running services
330
+ - Respects `imageTagStrategy` configuration (mutable vs immutable tags)
331
+
332
+ **Update** - Deploys prepared artifacts:
333
+ - Checks for newer versions created by `publish`
334
+ - Updates running services to use new versions
335
+ - For mutable tags (`:latest`), can force redeployment to pull updated images
336
+ - Monitors deployment progress and reports success/failure
337
+
338
+ **Typical workflow:**
339
+ ```bash
340
+ # 1. Build and publish new version
341
+ semiont publish --service frontend --environment production
342
+
343
+ # 2. Deploy the new version
344
+ semiont update --service frontend --environment production
345
+ ```
346
+
347
+ For services using immutable tags (e.g., git hashes), `update` will only deploy if a newer version exists. For mutable tags (e.g., `:latest`), `update` can force a redeployment even without version changes.
348
+
349
+ ## MCP (Model Context Protocol) Server
350
+
351
+ The Semiont CLI includes built-in support for MCP, allowing AI assistants to interact with Semiont APIs.
352
+
353
+ ### MCP Setup
354
+
355
+ MCP requires one-time OAuth provisioning per environment:
356
+
357
+ ```bash
358
+ # Provision MCP for production environment
359
+ semiont provision --service mcp --environment production
360
+
361
+ # This will:
362
+ # 1. Open your browser for OAuth authentication
363
+ # 2. Store refresh token in ~/.config/semiont/mcp-auth-production.json
364
+ # 3. Display AI application configuration
365
+ ```
366
+
367
+ ### Starting MCP Server
368
+
369
+ After provisioning, the MCP server can be started:
370
+
371
+ ```bash
372
+ # Start MCP server for production
373
+ semiont start --service mcp --environment production
374
+
375
+ # Or with environment variable
376
+ SEMIONT_ENV=production semiont start --service mcp
377
+ ```
378
+
379
+ ### AI Application Configuration
380
+
381
+ After provisioning, add this configuration to your AI application:
382
+
383
+ ```json
384
+ {
385
+ "semiont": {
386
+ "command": "semiont",
387
+ "args": ["start", "--service", "mcp"],
388
+ "env": {
389
+ "SEMIONT_ROOT": "/path/to/semiont",
390
+ "SEMIONT_ENV": "production"
391
+ }
392
+ }
393
+ }
394
+ ```
395
+
396
+ ### Available MCP Tools
397
+
398
+ The MCP server currently provides:
399
+ - `semiont_hello` - Get a personalized greeting from Semiont API
400
+
401
+ Future capabilities will include graph retrieval for GraphRAG-like systems.
402
+
403
+ ### Authentication Flow
404
+
405
+ 1. **Initial Setup**: Browser-based OAuth during `provision` command
406
+ 2. **Refresh Tokens**: Stored locally, valid for 30 days
407
+ 3. **Access Tokens**: Automatically refreshed on startup, valid for 1 hour
408
+ 4. **Unattended Operation**: No user interaction required after initial setup
409
+
410
+ ### Troubleshooting MCP
411
+
412
+ - **Authentication Failed**: Re-run `semiont provision --service mcp --environment <env>`
413
+ - **Token Expired**: Refresh tokens expire after 30 days, re-provision if needed
414
+ - **Server Won't Start**: Check that the environment was provisioned first
415
+
416
+ ## Development
417
+
418
+ ### Building
419
+
420
+ ```bash
421
+ npm run build # Build the CLI
422
+ npm run watch # Watch mode for development
423
+ npm test # Run tests
424
+ ```
425
+
426
+ ### Testing
427
+
428
+ The CLI has comprehensive test coverage:
429
+
430
+ ```bash
431
+ npm test # Run all tests
432
+ npm run test:unit # Unit tests only
433
+ npm run test:integration # Integration tests
434
+ npm run test:coverage # Generate coverage report
435
+ ```
436
+
437
+ ### Code Style
438
+
439
+ The project uses ESLint and Prettier:
440
+
441
+ ```bash
442
+ npm run lint # Check code style
443
+ npm run lint:fix # Auto-fix issues
444
+ npm run format # Format code with Prettier
445
+ ```
446
+
447
+ ## Troubleshooting
448
+
449
+ ### Common Issues
450
+
451
+ **Service won't start**
452
+ - Check if port is already in use: `lsof -i :PORT`
453
+ - Verify environment configuration exists
454
+ - Check service logs with `semiont watch`
455
+
456
+ **AWS commands fail**
457
+ - Ensure AWS credentials are configured: `aws configure`
458
+ - Check AWS region matches environment config
459
+ - Verify IAM permissions for ECS/RDS operations
460
+
461
+ **Container commands fail**
462
+ - Verify Docker/Podman is installed and running
463
+ - Check container runtime detection: `docker version` or `podman version`
464
+ - Ensure user has permissions for container operations
465
+
466
+ **MCP server issues**
467
+ - Re-provision if authentication fails
468
+ - Check refresh token hasn't expired (30 days)
469
+ - Verify environment was provisioned before starting
470
+
471
+ ## Contributing
472
+
473
+ We welcome contributions! Please see our contributing guidelines for:
474
+
475
+ - Code style and standards
476
+ - Testing requirements
477
+ - Documentation updates
478
+ - Pull request process
479
+
480
+ ### Adding New Features
481
+
482
+ 1. **Environments**: See [Managing Environments Guide](./docs/ADDING_ENVIRONMENTS.md)
483
+ 2. **Commands**: See [Adding Commands Guide](./docs/ADDING_COMMANDS.md)
484
+ 3. **Services**: See [Adding Services Guide](./docs/ADDING_SERVICES.md)
485
+ 4. **Platforms**: See [Adding Platforms Guide](./docs/ADDING_PLATFORMS.md)
486
+
487
+ ### Development Workflow
488
+
489
+ 1. Fork the repository
490
+ 2. Create a feature branch
491
+ 3. Make your changes with tests
492
+ 4. Update documentation
493
+ 5. Submit a pull request
494
+
495
+ ## License
496
+
497
+ This project is licensed under the Apache License 2.0 - see the LICENSE file for details.