vc-cli 0.1.0

Command-line interface for Visual Compiler
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
# Visual Compiler

**Deterministic compiler for AI‑generated visual content**  
*Webtoon • Manga • Visual Novel • Storyboard*

[![CI](https://github.com/NightSky199714/visual_compiler/actions/workflows/ci.yml/badge.svg)](https://github.com/NightSky199714/visual_compiler/actions/workflows/ci.yml)
[![crates.io](https://img.shields.io/crates/v/vc-cli.svg)](https://crates.io/crates/vc-cli)
[![docs.rs](https://docs.rs/vc-cli/badge.svg)](https://docs.rs/vc-cli)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue)](https://github.com/NightSky199714/visual_compiler#license)
[![MSRV](https://img.shields.io/badge/rust-1.75+-blue)](https://www.rust-lang.org/)

---

## Table of Contents

- [Description]#-description
- [Core Principles]#-core-principles
- [Who Is This For?]#-who-is-this-for
- [Why Visual Compiler?]#-why-visual-compiler
- [Features]#-features
- [Project Status]#-project-status
- [Architecture]#-architecture-overview
- [Workspace Crates]#-workspace-crates--dependencies
- [Compatibility Matrix]#-compatibility-matrix
- [Installation]#-installation
- [Quick Start]#-quick-start
- [Example Configuration]#-example-configuration
- [Example Output]#-example-output
- [Library Usage]#-library-usage
- [Roadmap]#-roadmap
- [Design Goals]#-design-goals
- [Non‑Goals]#-non-goals
- [FAQ]#-faq
- [MSRV]#-msrv
- [Versioning Policy]#-versioning-policy
- [Documentation]#-documentation
- [Contributing]#-contributing
- [License]#-license

---

## 📖 Description

**Visual Compiler** is a deterministic, modular compiler pipeline for transforming structured narrative data into **prompts** for AI image generation models (SDXL, ComfyUI, Flux, etc.).

It ensures that the **same input always produces the same output**—enabling reproducible asset generation, version control of visual assets, and seamless integration with game engines, animation pipelines, and VFX workflows.

---

## Core Principles

- **Deterministic by default** – Same input → same output, always
- **Reproducible builds** – Golden tests, content‑addressable IDs
- **Backend agnostic** – Runtime supports multiple backends via registry
- **Library first** – Use as a binary or integrate as a Rust library
- **Test driven** – Extensive unit, integration, golden, and E2E testing
- **Content addressable** – `snap_<hash>` deduplication and auditability

---

## 🎯 Who Is This For?

| Audience | Use Case |
| :------- | :------- |
| **Game Developers** | Generate consistent character assets across frames |
| **Visual Novel Engines** | Maintain character appearance across scenes |
| **Asset Pipelines** | Version-controlled, reproducible image generation |
| **AI Workflow Automation** | Batch processing with deterministic outputs |
| **Research** | Reproducible experiments in AI image generation |

---

## 🧠 Why Visual Compiler?

| Problem | Solution |
| :------ | :------- |
| AI image generation is non‑deterministic | Deterministic hash‑based pipeline |
| Prompt engineering is messy | Structured semantic IR (`PromptCore`) |
| Integration with different backends is painful | Pluggable runtime backend registry |
| No versioning for generated assets | Content‑addressable IDs (`snap_<hash>`) |
| Hard to reproduce old results | Replay‑first design with golden tests |

---

## ✨ Features

| Feature | Description |
| :------ | :---------- |
| **Deterministic Pipeline** | SHA‑256 hashing, canonical JSON, Merkle root |
| **Semantic IR** | `PromptCore` – structured prompt representation, not plain text |
| **Pluggable Backends** | Dummy, SDXL, ComfyUI, Python, and extensible registry |
| **Content‑Addressable IDs** | `snap_<hash>` – deduplication and auditability built‑in |
| **Configuration‑Driven** | TOML profiles for runtime backend selection |
| **Golden Tests** | Snapshot, archive, bundle, prompt hashing regression tests |
| **CLI & Library** | Use as a binary or integrate as a Rust library |

---

## 📊 Project Status

| Aspect | Status |
| :----- | :----- |
| Public API | ✅ Frozen for `v0.1.0` |
| crates.io Readiness | ✅ Ready |
| Release Candidate | ✅ Ready |
| Documentation | ✅ Ready |
| CI/CD | ✅ Ready |

**Current version:** `v0.1.0`

---

## 🏛️ Architecture (Overview)
┌───────────────┐
│ Snapshot │ ← Structured narrative input (story, assets, characters)
│ (Core) │
└───────┬───────┘
│
▼
┌───────────────┐
│ Resolver │ ← Deterministic resolution: Snapshot → Bundle
└───────┬───────┘
│
▼
┌───────────────┐
│ Bundle │ ← Visual asset bundle (character, appearance, descriptors)
│ (Core) │
└───────┬───────┘
│
▼
┌───────────────┐
│ Prompt │ ← Semantic IR (PromptCore) – compiler boundary
│ (Core) │
└───────┬───────┘
│
▼
┌───────────────┐
│ Adapter │ ← SDXL, Flux, etc. → plain text prompt
│ (SDXL) │
└───────┬───────┘
│
▼
┌───────────────┐
│ Compiler │ ← Canonical JSON artifact (compiler_output.json)
│ Output │
└───────┬───────┘
│
▼
┌───────────────┐
│ Runtime │ ← Backend registry, BuildContext, Runner
│ (Backend) │
└───────┬───────┘
│
▼
┌───────────────┐
│ Renderer │ ← Dummy, Python, ComfyUI, etc.
│ (Image) │
└───────────────┘


---

## 📦 Workspace Crates & Dependencies

### High‑Level Dependency Path
vc-cli
│
▼
vc-runtime
│
▼
vc-output
│
▼
vc-prompt
│
▼
vc-resolver
│
▼
vc-bundle
│
▼
vc-snapshot


*Note: This is a high‑level dependency path. Additional crates like `vc-shared`, `vc-types`, and `vc-archive` are used throughout the workspace.*

### Crate Overview

| Crate | Crates.io Name | Description |
| :---- | :------------- | :---------- |
| `vc-shared` | `vc-shared` | Canonical JSON, SHA‑256, Merkle root utilities |
| `vc-bundle` | `vc-bundle` | `VisualBundleCore` + deterministic hashing |
| `vc-prompt` | `vc-prompt` | `PromptCore` semantic IR + compilation |
| `vc-snapshot` | `vc-snapshot` | `SnapshotCore` + deterministic hashing |
| `vc-archive` | `vc-archive` | Archive manifest + deterministic hashing |
| `vc-resolver` | `vc-resolver` | Deterministic Snapshot → Bundle resolution |
| `vc-types` | `vc-types` | Domain types: `AdapterKind`, `CompilerVersion`, etc. |
| `vc-output` | `vc-output` | Compiler output artifact (`CompilerOutput`) |
| `vc-adapter-sdxl` | `vc-adapter-sdxl` | SDXL prompt adapter |
| `vc-runtime` | `vc-runtime` | Runtime backend registry, config, BuildContext, runner |
| `vc-cli` | `vc-cli` | Command‑line interface (binary `vc`) |

---

## 💻 Compatibility Matrix

| Item | Version / Support |
| :--- | :---------------- |
| **Rust** | 1.75+ |
| **Edition** | 2021 |
| **Windows** | ✅ Tested |
| **Linux** | ✅ Tested |
| **macOS** | ✅ Tested |

---

## 🔧 Installation

### From crates.io (binary)

```bash
cargo install vc-cli

From source
git clone https://github.com/NightSky199714/visual_compiler.git
cd visual_compiler
cargo build --release --workspace

As a library
Add to your Cargo.toml:

[dependencies]
vc-shared = "0.1.0"
vc-prompt = "0.1.0"
vc-runtime = "0.1.0"
# ... etc.
🚀 Quick Start
1. Generate compiler output (demo)
vc demo --out build/
This creates:

build/compiler_output.json – canonical artifact

build/prompt.txt – rendered prompt text

2. Run with a backend
Create config.toml:

[global]

[profiles.default]
backend_name = "dummy"

[backends.dummy]
enabled = true
options = { kind = "dummy", options = {} }
Run:

vc run --input build/ --out run/ --config config.toml --profile default
Output:

run/runtime.json – runtime result metadata

run/image.png – generated image (placeholder for dummy backend)

📄 Example Configuration
Dummy Backend (for testing)

[backends.dummy]
enabled = true
options = { kind = "dummy", options = {} }
Python Backend
toml
[backends.python]
enabled = true
options = {
  kind = "python",
  options = {
    script_path = "scripts/fake_renderer.py",
    python_path = "python3"
  }
}
ComfyUI Backend
toml
[backends.comfy]
enabled = true
options = {
  kind = "comfy",
  options = {
    base_url = "http://127.0.0.1:8188",
    timeout_secs = 30,
    poll_timeout_secs = 300,
    poll_interval_ms = 500,
    workflow_template_path = "fixtures/comfy/workflow_base.json"
  }
}

📊 Example Output
compiler_output.json (excerpt)

{
  "schema_version": 1,
  "prompt": {
    "character": {
      "descriptors": ["hero", "adventurer", "sword"]
    }
  },
  "metadata": {
    "compiler_version": "0.1.0",
    "adapter": "Sdxl",
    "snapshot_hash": "abc123...",
    "bundle_hash": "def456...",
    "prompt_hash": "789abc..."
  }
}
runtime.json (excerpt)

{
  "status": "Success",
  "backend": "Sdxl",
  "image_path": "run/image.png",
  "image_hash": "hash123...",
  "seed": 42,
  "width": 1024,
  "height": 1024,
  "steps": 30,
  "cfg": 7.0
}

📚 Library Usage

use vc_shared::hashing::sha256;
use vc_prompt::{PromptCore, CharacterVisual};
use vc_runtime::{load_config, run_backend, RuntimeInput};

fn main() -> anyhow::Result<()> {
    // 1. Load compiler output
    let input = RuntimeInput { vc_output: /* CompilerOutput */ };
    
    // 2. Load config
    let config = load_config("config.toml")?;
    
    // 3. Run backend
    let result = run_backend(&config, "default", &input, "run/")?;
    
    // 4. Use result
    println!("Image: {:?}", result.image_path);
    Ok(())
}
🛣️ Roadmap
Upcoming Features
Additional Adapters – Flux, SD3, Kandinsky

Plugin API – Backend extensibility for third‑party renderers

Performance Improvements – Caching, parallelism, faster hashing

Developer Experience – Better diagnostics and error messages

See ROADMAP.md for the complete roadmap.

🎯 Design Goals
Goal	Description
Deterministic	Same input → same output, always
Modular	Each crate has a single, clear responsibility
Backend‑Agnostic	Runtime supports multiple backends via registry
Reproducible	Golden tests, content‑addressable IDs
Configurable	TOML profiles and runtime overrides
Observable	Clear error messages, logging, and diagnostics

🚫 Non‑Goals
Not an image generation model itself (uses existing backends)

Not a UI tool (focused on CLI and library usage)

Not a real‑time renderer (batch/offline oriented)

Not a web service (though can be wrapped as one)

❓ FAQ
Q: Does this generate images?
No. It compiles prompts and delegates rendering to a backend (Dummy, Python, ComfyUI, etc.).

Q: Does it require Python?
Only if you use the Python‑based renderer. The core pipeline and Dummy/SDXL backends are pure Rust.

Q: Can I use ComfyUI?
Yes. The ComfyUI backend is fully supported with workflow templating.

Q: Is it production‑ready?
The core pipeline is stable and tested. The API is frozen for v0.1.0. Some features (like advanced backends) are still evolving.

Q: What about determinism?
The entire pipeline—from Snapshot to Runtime—is built around SHA‑256 hashing and canonical JSON. Golden tests ensure regression‑free behavior.

🔒 MSRV
The Minimum Supported Rust Version (MSRV) is 1.75.

The MSRV is guaranteed for all releases within the same minor version. Changes to the MSRV are considered a minor-version change and will be documented in the changelog.

🔒 Versioning Policy
We follow Semantic Versioning (SemVer) for all published crates.
Version	Policy
v0.1.x	No intentional breaking changes. Bug fixes and minor additions only.
v0.2.x	Breaking changes allowed, but documented in CHANGELOG.md with migration guides.
v1.0.0	Full stability guarantee. API frozen.
See API_STABILITY.md for detailed stability guarantees.

📚 Documentation
Document	Description
README.md	This document
ROADMAP.md	Development roadmap
CHANGELOG.md	Release notes
CONTRIBUTING.md	Contribution guide
CODE_OF_CONDUCT.md	Code of conduct
SECURITY.md	Security policy
RELEASE.md	Release process
SUPPORTED_BACKENDS.md	Supported backends
API_STABILITY.md	API stability guarantees
ARCHITECTURE.md	Architecture overview
RUNTIME.md	Runtime documentation

🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for:

Development setup

Build & test commands

Commit conventions

Pull request guidelines

Quick Contribution Steps

# Clone & build
git clone https://github.com/NightSky199714/visual_compiler.git
cd visual_compiler
cargo build --workspace

# Run tests
cargo test --workspace

# Run linter
cargo clippy --workspace --all-features -- -D warnings

# Generate docs
cargo doc --workspace --no-deps

🔏 License
Licensed under either of:

MIT License

Apache License, Version 2.0

at your option.

🙏 Acknowledgements
Built with ❤️ using:

Rust

Serde

Tokio

Clap

Image

ComfyUI

Visual Compiler – Deterministic pipeline for the AI‑powered visual future. 🚀