schema-validator 0.1.1

CLI tool that validates cuenv schemas against JSON Schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# cuenv

**A modern application build toolchain with typed environments and CUE-powered task orchestration**

[![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![Build Status](https://github.com/cuenv/cuenv/workflows/CI/badge.svg)](https://github.com/cuenv/cuenv/actions)
[![Crates.io](https://img.shields.io/crates/v/cuenv)](https://crates.io/crates/cuenv)

> **Status**: Alpha - Core evaluation engine complete, CLI and task runner in active development

---

## Overview

cuenv is a next-generation build toolchain that brings type safety and powerful configuration management to application development. Built around CUE's constraint-based type system, cuenv provides a unified solution for environment management, task orchestration, and secure secret handling.

Unlike traditional build tools, cuenv leverages CUE's ability to compose and validate configuration across directory hierarchies, making it particularly well-suited for monorepos and complex project structures. With integrated Nix support, security isolation, and extensible secret management, cuenv provides a complete development environment solution.

**Perfect for:**

- Monorepos requiring consistent environment management
- Teams needing type-safe configuration
- Projects with complex build dependencies
- Security-conscious development workflows

---

## Features

| Feature                      | Status         | Description                                           |
| ---------------------------- | -------------- | ----------------------------------------------------- |
| ✅ **CUE Evaluation Engine** | Complete       | Fast, reliable CUE evaluation with Rust performance   |
| 🚧 **CLI Interface**         | In Development | Task execution and environment management             |
| 🚧 **Typed Environments**    | In Development | Compose environment constraints from CUE modules      |
| 🚧 **Task Orchestration**    | In Development | Parallel/sequential execution with smart dependencies |
| 🚧 **Nix Integration**       | In Development | Automatic software provisioning via Nix flakes        |
| 🚧 **Secret Management**     | In Development | Extensible resolvers for 1Password, AWS, GCP, etc.    |
| 📋 **Security Isolation**    | Planned        | Linux namespaces, landlock, eBPF integration          |
| 🚧 **Shell Integration**     | In Development | Smart hooks for bash, fish, zsh, nushell              |
| 🚧 **Dev Tool Integration**  | In Development | Seamless Nix flake and Flox compatibility             |

**Legend:** ✅ Complete • 🚧 In Development • 📋 Planned

---

## Quick Start

### Installation 🚧

```bash
# Install cuenv
cargo install cuenv

# Initialize in your project
cuenv init

# Setup shell integration
cuenv shell setup
```

### Basic Configuration

Create an `env.cue` file in your project root:

```cue
package cuenv

import "github.com/cuenv/cuenv/schema"

schema.#Cuenv

// Environment variables with type constraints
env: {
    NODE_ENV: "development" | "staging" | "production"
    PORT:     >0 & <65536 & *3000
    DEBUG:    bool | *false

    // Environment-specific overrides
    environment: production: {
        NODE_ENV: "production"
        DEBUG:    false
    }
}

// Task definitions
tasks: {
    build: {
        description: "Build the application"
        command:     "npm"
        args:        ["run", "build"]
        inputs:      ["src/**/*", "package.json"]
        outputs:     ["dist/**/*"]
    }

    test: {
        description: "Run tests in parallel"
        unit: {
            command: "npm"
            args:    ["run", "test:unit"]
            inputs:  ["src/**/*.test.js"]
        }
        integration: {
            command: "npm"
            args:    ["run", "test:integration"]
            inputs:  ["tests/**/*"]
        }
    }
}
```

### Running Tasks 🚧

```bash
# List available tasks
cuenv task

# Run a specific task
cuenv task build

# Run with specific environment
cuenv --env production task build

# Execute with loaded environment
cuenv exec npm start
```

---

## Core Concepts

### Typed Environments 🚧

cuenv uses CUE's constraint system to provide type-safe environment management:

```cue
import (
    "github.com/myorg/postgres/schema"
    "github.com/myorg/redis/schema"
)

// Compose environment constraints from multiple modules
env: postgres.#Config & redis.#Config & {
    DATABASE_URL: string & =~"^postgresql://"
    REDIS_URL:    string & =~"^redis://"
    API_KEY:      #Secret & {
        resolver: #OnePasswordRef & {
            ref: "op://api-keys/production/key"
        }
    }
}
```

### Task Orchestration 🚧

Control execution flow with CUE's structure:

```cue
tasks: {
    // Array structure = sequential execution
    deploy: {
        description: "Deploy application"
        tasks: [
            {command: "docker", args: ["build", "-t", "myapp", "."]},
            {command: "docker", args: ["push", "myapp"]},
            {command: "kubectl", args: ["apply", "-f", "k8s/"]}
        ]
    }

    // Object structure = parallel execution
    test: {
        description: "Run all tests"
        unit:        {command: "npm", args: ["run", "test:unit"]}
        integration: {command: "npm", args: ["run", "test:e2e"]}
        lint:        {command: "npm", args: ["run", "lint"]}
    }
}
```

### Secret Management 🚧

Extensible secret resolution with multiple providers:

```cue
#OnePasswordRef: #Secret & {
    ref: string
    resolver: #ExecResolver & {
        command: "op"
        args: ["read", ref]
    }
}

#AWSSecretRef: #Secret & {
    region: string
    name:   string
    resolver: #ExecResolver & {
        command: "aws"
        args: ["secretsmanager", "get-secret-value",
               "--region", region, "--secret-id", name,
               "--query", "SecretString", "--output", "text"]
    }
}

env: {
    DB_PASSWORD: #OnePasswordRef & {
        ref: "op://vault/database/password"
    }
    API_KEY: #AWSSecretRef & {
        region: "us-west-2"
        name:   "prod-api-key"
    }
}
```

### Shell Integration 🚧

Automatic environment loading with shell hooks:

```cue
hooks: {
    onEnter: [
        // Load Nix environment
        schema.#NixFlake & {preload: true},

        // Custom initialization
        {
            command: "echo"
            args: ["Entering cuenv environment..."]
        }
    ]

    onExit: [
        {
            command: "echo"
            args: ["Goodbye!"]
        }
    ]
}
```

---

## CLI Reference 🚧

### Commands

```bash
# Task management
cuenv task                           # List all tasks
cuenv task build                     # Run build task
cuenv task test.unit                 # Run specific subtask
cuenv task --parallel build test    # Run multiple tasks

# Environment management
cuenv env                            # Show current environment
cuenv env --environment production  # Switch to production
cuenv exec -- npm start             # Execute with loaded env

# Project setup
cuenv init                           # Create initial env.cue
cuenv discover                       # Find all CUE packages
cuenv shell setup                    # Configure shell integration

# Development
cuenv cache clear                    # Clear task cache
cuenv --audit task build            # Run in audit mode
cuenv --trace-output task deploy     # Enable tracing
```

### Global Options

| Option             | Description                                   |
| ------------------ | --------------------------------------------- |
| `--env, -e`        | Environment to use (dev, staging, production) |
| `--cache`          | Cache mode (off, read, read-write, write)     |
| `--capability, -c` | Enable specific capabilities                  |
| `--audit`          | Run in audit mode for security analysis       |
| `--output-format`  | Output format (tui, spinner, simple, tree)    |

---

## Advanced Usage

### Monorepo Configuration 🚧

cuenv excels at managing complex monorepo environments:

```
myproject/
├── env.cue              # Root configuration
├── services/
│   ├── api/
│   │   └── env.cue      # API-specific config
│   └── frontend/
│       └── env.cue      # Frontend-specific config
└── shared/
    └── postgres.cue     # Shared schemas
```

**Root `env.cue`:**

```cue
package cuenv

// Global environment
env: {
    PROJECT_NAME: "myproject"
    LOG_LEVEL:    "info" | "debug" | "error" | *"info"
}

// Workspace tasks
tasks: {
    "build-all": {
        description: "Build all services"
        tasks: [
            {command: "cuenv", args: ["task", "build"], dir: "services/api"},
            {command: "cuenv", args: ["task", "build"], dir: "services/frontend"}
        ]
    }
}
```

### CI/CD Integration 🚧

```yaml
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: cachix/install-nix-action@v22
      - run: curl -fsSL https://cuenv.sh/install | sh
      - run: cuenv task ci.quality # Run quality checks
      - run: cuenv task ci.test # Run all tests
      - run: cuenv task ci.build # Build artifacts
```

### Custom Secret Resolvers 🚧

Extend cuenv with your own secret providers:

```cue
#HashiCorpVaultRef: #Secret & {
    vault_addr: string
    path:       string
    field:      string
    resolver: #ExecResolver & {
        command: "vault"
        args: ["kv", "get", "-address=\(vault_addr)",
               "-field=\(field)", path]
    }
}

env: {
    SECRET_KEY: #HashiCorpVaultRef & {
        vault_addr: "https://vault.company.com"
        path:       "secret/myapp"
        field:      "api_key"
    }
}
```

---

## Architecture

### CUE Evaluation Engine ✅

The core of cuenv is `cuengine`, a high-performance CUE evaluation engine written in Rust with Go FFI integration:

- **Performance**: Native Rust performance with optimized caching
- **Memory Safety**: Zero-copy string handling and safe FFI boundaries
- **Reliability**: Comprehensive error handling and recovery
- **Extensibility**: Plugin architecture for custom functions

### Caching Strategy ✅

Intelligent caching system for fast repeated evaluations:

- **Input Tracking**: File modification time and content hashing
- **Dependency Resolution**: Automatic cache invalidation
- **LRU Eviction**: Memory-efficient cache management
- **Configurable TTL**: Flexible expiration policies

### Security Model 📋

Multi-layered security approach (planned):

- **Linux Namespaces**: Process, network, and filesystem isolation
- **Landlock**: Fine-grained filesystem access control
- **eBPF Integration**: System call monitoring and filtering
- **Capability System**: Principle of least privilege
- **Audit Logging**: Comprehensive security event tracking

---

## Comparison

| Feature                | cuenv              | Make       | Bazel          | Taskfile   | direnv           |
| ---------------------- | ------------------ | ---------- | -------------- | ---------- | ---------------- |
| Type Safety            | ✅ CUE constraints | ❌         | ✅ BUILD files | ❌         | ❌               |
| Monorepo Support       | ✅ Native          | ⚠️ Basic   | ✅ Excellent   | ⚠️ Basic   | ⚠️ Per-directory |
| Environment Management | ✅ Typed + Secrets | ❌         | ❌             | ❌         | ✅ Basic         |
| Task Dependencies      | ✅ Smart           | ✅         | ✅ Advanced    | ✅ Basic   | ❌               |
| Parallel Execution     | ✅                 | ⚠️ -j flag | ✅             | ⚠️ Limited | ❌               |
| Caching                | ✅ Content-aware   | ❌         | ✅ Advanced    | ❌         | ❌               |
| Security Isolation     | 📋 Planned         | ❌         | ✅ Sandboxing  | ❌         | ❌               |
| Shell Integration      | 🚧                 | ❌         | ❌             | ❌         | ✅               |

---

## Project Status

### Current Phase: Alpha

**Production Ready:**

- ✅ CUE evaluation engine with comprehensive test suite
- ✅ FFI bridge between Rust and Go
- ✅ Caching and retry mechanisms
- ✅ Input validation and error handling

**In Active Development:**

- 🚧 CLI interface and task runner
- 🚧 Shell integration and hooks
- 🚧 Secret management framework
- 🚧 Nix integration layer

**Planned Features:**

- 📋 Security isolation (namespaces, landlock)
- 📋 Web UI and monitoring
- 📋 SaaS offering for teams
- 📋 IDE integrations

### Roadmap

**Q1 2025:** Complete CLI, basic task execution, shell integration  
**Q2 2025:** Secret management, Nix integration, beta release  
**Q3 2025:** Security features, performance optimizations  
**Q4 2025:** SaaS platform, enterprise features

---

## Contributing

We welcome contributions! cuenv is licensed under AGPL-3.0, ensuring it remains open source.

### Development Setup

```bash
# Clone the repository
git clone https://github.com/cuenv/cuenv
cd cuenv

# Install Nix (recommended)
curl -L https://nixos.org/nix/install | sh

# Enter development environment
nix develop
# or with direnv: direnv allow

# Run tests
cargo test

# Check code quality
treefmt && cargo clippy
```

### Architecture Overview

```
cuenv/
├── crates/
│   ├── cuengine/           # Core CUE evaluation engine
│   │   ├── src/
│   │   ├── bridge.go       # Go FFI bridge
│   │   └── tests/
│   ├── cuenv-core/         # Shared types and utilities
│   └── cuenv-cli/          # CLI interface (upcoming)
├── examples/               # CUE configuration examples
└── docs/                   # Documentation
```

### Testing

- Unit tests: `cargo test`
- Integration tests: `cargo test --test integration_tests`
- Example validation: `cargo test --test examples`
- Coverage: `cargo llvm-cov`

---

## License

Licensed under the [GNU Affero General Public License v3.0](LICENSE).

**Why AGPL?** We believe in keeping cuenv open source while building a sustainable business. The AGPL ensures that any modifications or hosted services using cuenv remain open source, benefiting the entire community.

---

## Links

- **Documentation**: [docs.cuenv.sh]https://docs.cuenv.sh 🚧
- **Original POC**: [github.com/rawkode/cuenv]https://github.com/rawkode/cuenv
- **CUE Language**: [cuelang.org]https://cuelang.org
- **Discussion**: [GitHub Discussions]https://github.com/cuenv/cuenv/discussions

---

_Built in 🏴 󠁧󠁢󠁳󠁣󠁴󠁿w for the open source community_