|
1 | | -# FACET Compiler (Rust) |
| 1 | +# FACET Compiler (`facet-fct`) |
2 | 2 |
|
3 | 3 | [](https://github.com/rokoss21/facet-compiler/actions/workflows/ci.yml) |
4 | 4 | [](https://github.com/rokoss21/facet-compiler/actions/workflows/release.yml) |
5 | 5 | [](https://github.com/rokoss21/facet-compiler/releases) |
6 | | -[](./FACET-v2.1.3-Production-Language-Specification.md) |
| 6 | +[](./FACET-v2.1.3-Production-Language-Specification.md) |
7 | 7 | [](https://www.rust-lang.org/) |
8 | 8 | [](./LICENSE-MIT) |
9 | 9 |
|
10 | | -Deterministic compiler/runtime for **FACET v2.1.3** — a contract-first language for reliable AI request construction. |
| 10 | +Deterministic compiler and execution layer for **FACET v2.1.3**. |
11 | 11 |
|
12 | | -FACET Compiler turns `.facet` programs into validated, reproducible canonical payloads with strict typing, deterministic execution, policy guard enforcement, and provenance artifacts. |
| 12 | +`facet-fct` compiles `.facet` contracts into canonical, policy-aware AI request context with explicit failure semantics (`F*` codes), deterministic ordering, and bounded execution behavior. |
13 | 13 |
|
14 | | -## Why FACET Compiler |
| 14 | +## What You Get |
15 | 15 |
|
16 | | -Most AI stacks fail at the contract boundary: schemas drift, tool calls are weakly enforced, context packing is ad hoc, and behavior differs across runs/providers. |
| 16 | +- Deterministic pipeline: normalization -> resolution -> type check -> compute -> layout -> render |
| 17 | +- Strict type and placement checks (FTS) |
| 18 | +- Policy and guard fail-closed behavior (`F454`, `F455`) |
| 19 | +- Canonical JSON output + stable document and policy hashes |
| 20 | +- Spec-oriented examples and conformance suites in CI |
17 | 21 |
|
18 | | -FACET Compiler addresses this by enforcing the contract **before generation**: |
| 22 | +## Quick Start (2 Minutes) |
19 | 23 |
|
20 | | -- deterministic phases (resolution -> type check -> compute -> layout -> render) |
21 | | -- strict FTS typing and placement rules |
22 | | -- fail-closed policy/guard model (`F454`, `F455`) |
23 | | -- canonical JSON with stable hashes for replay/audit |
24 | | -- deterministic context budget behavior (Token Box Model) |
| 24 | +### 1) Build the compiler |
25 | 25 |
|
26 | | -## What This Repository Is |
| 26 | +```bash |
| 27 | +cargo build --release --bin facet-fct |
| 28 | +./target/release/facet-fct --version |
| 29 | +# fct 0.1.2 |
| 30 | +``` |
| 31 | + |
| 32 | +### 2) Create a minimal contract |
| 33 | + |
| 34 | +```facet |
| 35 | +@meta |
| 36 | + name: "hello" |
27 | 37 |
|
28 | | -This repository is the **Rust reference compiler implementation** for FACET v2.1.3. |
| 38 | +@context |
| 39 | + budget: 32000 |
29 | 40 |
|
30 | | -- Language target: FACET v2.1.3 REC-PROD |
31 | | -- Binary: `facet-fct` (`fct --version`) |
32 | | -- Conformance tracker: [`docs/14-v2.1.3-migration-checklist.md`](./docs/14-v2.1.3-migration-checklist.md) |
33 | | -- Canonical spec in this repo: [`FACET-v2.1.3-Production-Language-Specification.md`](./FACET-v2.1.3-Production-Language-Specification.md) |
| 41 | +@vars |
| 42 | + query: @input(type="string") |
34 | 43 |
|
35 | | -## Quick Start |
| 44 | +@system |
| 45 | + content: "You are a helpful assistant." |
| 46 | +
|
| 47 | +@user |
| 48 | + content: $query |
| 49 | +``` |
| 50 | + |
| 51 | +Save as `hello.facet` and create runtime input: |
| 52 | + |
| 53 | +```json |
| 54 | +{ "query": "Hello FACET" } |
| 55 | +``` |
36 | 56 |
|
37 | | -### 1) Build |
| 57 | +Save as `hello.input.json`. |
| 58 | + |
| 59 | +### 3) Validate and run |
38 | 60 |
|
39 | 61 | ```bash |
40 | | -cargo build --release --bin facet-fct |
41 | | -./target/release/facet-fct --version |
| 62 | +./target/release/facet-fct build --input hello.facet |
| 63 | +./target/release/facet-fct run --input hello.facet --runtime-input hello.input.json --exec --format pretty |
42 | 64 | ``` |
43 | 65 |
|
44 | | -### 2) Validate a `.facet` file (Phases 1-2) |
| 66 | +## Installation |
| 67 | + |
| 68 | +### Option A: Download release binary |
| 69 | + |
| 70 | +From [Releases](https://github.com/rokoss21/facet-compiler/releases/latest): |
| 71 | + |
| 72 | +- Linux: `facet-fct-linux-x86_64.tar.gz` |
| 73 | +- macOS (Intel): `facet-fct-macos-x86_64.tar.gz` |
| 74 | +- Windows: `facet-fct-windows-x86_64.zip` |
| 75 | + |
| 76 | +Example (Linux/macOS): |
45 | 77 |
|
46 | 78 | ```bash |
47 | | -./target/release/facet-fct build --input examples/spec/01_minimal.facet |
| 79 | +tar -xzf facet-fct-*.tar.gz |
| 80 | +chmod +x facet-fct |
| 81 | +./facet-fct --version |
48 | 82 | ``` |
49 | 83 |
|
50 | | -### 3) Run full pipeline (Phases 1-5) |
| 84 | +### Option B: Install from local source with Cargo |
51 | 85 |
|
52 | 86 | ```bash |
53 | | -./target/release/facet-fct run --input examples/spec/01_minimal.facet --exec --format pretty |
| 87 | +cargo install --path . --bin facet-fct |
| 88 | +facet-fct --version |
54 | 89 | ``` |
55 | 90 |
|
56 | | -### 4) Run deterministic suites used in CI/release gates |
| 91 | +### Option C: Build from source |
57 | 92 |
|
58 | 93 | ```bash |
59 | | -./scripts/smoke_examples_spec.sh ./target/release/facet-fct |
60 | | -./scripts/spec_matrix_examples.sh ./target/release/facet-fct |
| 94 | +git clone https://github.com/rokoss21/facet-compiler |
| 95 | +cd facet-compiler |
| 96 | +cargo build --release --bin facet-fct |
61 | 97 | ``` |
62 | 98 |
|
63 | | -## CLI Overview |
| 99 | +## CLI Cheatsheet |
64 | 100 |
|
65 | 101 | ```bash |
66 | | -# Global help |
67 | | -./target/release/facet-fct --help |
| 102 | +# Parse + resolve + type check |
| 103 | +facet-fct build --input file.facet |
68 | 104 |
|
69 | | -# Build: parse + resolve + validate |
70 | | -./target/release/facet-fct build --input file.facet |
| 105 | +# Full execution (default mode: --exec) |
| 106 | +facet-fct run --input file.facet --exec |
| 107 | +facet-fct run --input file.facet --pure |
71 | 108 |
|
72 | | -# Run: full execution pipeline |
73 | | -./target/release/facet-fct run --input file.facet --exec |
74 | | -./target/release/facet-fct run --input file.facet --pure |
| 109 | +# Provide runtime @input values |
| 110 | +facet-fct run --input file.facet --runtime-input input.json --exec |
75 | 111 |
|
76 | | -# Test: execute @test blocks |
77 | | -./target/release/facet-fct test --input file.facet --exec |
| 112 | +# Run @test blocks |
| 113 | +facet-fct test --input file.facet --exec |
78 | 114 |
|
79 | | -# Inspect: dump compiler internals |
80 | | -./target/release/facet-fct inspect --input file.facet \ |
| 115 | +# Dump internals |
| 116 | +facet-fct inspect --input file.facet \ |
81 | 117 | --ast ast.json --dag dag.json --layout layout.json --policy policy.json |
82 | | -``` |
83 | | - |
84 | | -Runtime inputs for `@input(...)`: |
85 | 118 |
|
86 | | -```bash |
87 | | -./target/release/facet-fct run \ |
88 | | - --input examples/spec/03_input_runtime.facet \ |
89 | | - --runtime-input examples/spec/03_input_runtime.input.json \ |
90 | | - --exec |
| 119 | +# Help |
| 120 | +facet-fct --help |
| 121 | +facet-fct run --help |
91 | 122 | ``` |
92 | 123 |
|
93 | | -## Architecture (Compiler Pipeline) |
| 124 | +## Docs Map |
94 | 125 |
|
95 | | -| Phase | Purpose | |
96 | | -| --- | --- | |
97 | | -| Phase 1 | Normalize, parse, resolve `@import`, deterministic merge | |
98 | | -| Phase 2 | Type checking, semantic validation, policy schema validation | |
99 | | -| Phase 3 | Reactive compute (R-DAG), lens execution, input materialization | |
100 | | -| Phase 4 | Deterministic context packing (Token Box Model) | |
101 | | -| Phase 5 | Canonical JSON render + execution provenance emission | |
| 126 | +- Documentation portal: [rokoss21.github.io/facet-compiler](https://rokoss21.github.io/facet-compiler/) |
| 127 | +- Quick Start: [docs/01-quickstart.md](./docs/01-quickstart.md) |
| 128 | +- Execution Model: [docs/15-execution-model.md](./docs/15-execution-model.md) |
| 129 | +- Production Failure Scenario: [docs/16-production-scenario.md](./docs/16-production-scenario.md) |
| 130 | +- Integration Guide: [docs/18-integration-guide.md](./docs/18-integration-guide.md) |
| 131 | +- Spec-conformance checklist: [docs/14-v2.1.3-migration-checklist.md](./docs/14-v2.1.3-migration-checklist.md) |
| 132 | +- Language specification: [FACET-v2.1.3-Production-Language-Specification.md](./FACET-v2.1.3-Production-Language-Specification.md) |
102 | 133 |
|
103 | | -## Ecosystem and Methodology |
| 134 | +## Common Workflows |
104 | 135 |
|
105 | | -FACET Compiler is part of a broader engineering model around deterministic AI systems and measurable delivery: |
| 136 | +### Validate contracts in CI |
106 | 137 |
|
107 | | -- **FACET Standard**: language/specification source of truth |
108 | | - [github.com/rokoss21/facet-standard](https://github.com/rokoss21/facet-standard) |
109 | | -- **IOSM Specification**: methodology for controlled improvement cycles |
110 | | - [github.com/rokoss21/IOSM](https://github.com/rokoss21/IOSM) |
111 | | -- **IOSM CLI Runtime**: terminal execution runtime implementing IOSM |
112 | | - [github.com/rokoss21/iosm-cli](https://github.com/rokoss21/iosm-cli) |
113 | | - |
114 | | -How they connect conceptually: |
115 | | - |
116 | | -- FACET defines the **deterministic contract layer** for AI behavior. |
117 | | -- IOSM defines the **engineering methodology** (Improve -> Optimize -> Shrink -> Modularize) for iterative system quality improvement with artifacts/metrics. |
118 | | -- iosm-cli operationalizes IOSM as a runtime for real repositories. |
| 138 | +```bash |
| 139 | +facet-fct build --input examples/spec/01_minimal.facet |
| 140 | +``` |
119 | 141 |
|
120 | | -Together they align language contracts, execution control, and process governance. |
| 142 | +### Run deterministic example suites |
121 | 143 |
|
122 | | -## Quality Gates |
| 144 | +```bash |
| 145 | +./scripts/smoke_examples_spec.sh ./target/release/facet-fct |
| 146 | +./scripts/spec_matrix_examples.sh ./target/release/facet-fct |
| 147 | +``` |
123 | 148 |
|
124 | | -Recommended local gate: |
| 149 | +### Local quality gate |
125 | 150 |
|
126 | 151 | ```bash |
127 | 152 | cargo fmt --all -- --check |
128 | 153 | cargo clippy --all-targets --all-features -- -D warnings |
129 | 154 | cargo test -q --workspace |
130 | 155 | ``` |
131 | 156 |
|
132 | | -Release tag gate (`v*`) includes: |
| 157 | +## Integration Pattern (Brownfield) |
133 | 158 |
|
134 | | -- workspace tests |
135 | | -- spec smoke/matrix runs |
136 | | -- compliance report artifact generation |
| 159 | +Minimal-risk adoption path: |
137 | 160 |
|
138 | | -## Project Layout |
| 161 | +1. Keep your current provider SDK and business logic. |
| 162 | +2. Replace prompt assembly with `facet-fct run`. |
| 163 | +3. Keep strict response schema validation in host code. |
| 164 | +4. Add bounded retry/fallback policy in host runtime. |
139 | 165 |
|
140 | | -- `src/commands/*` — CLI commands (`build`, `run`, `test`, `inspect`, `codegen`) |
141 | | -- `crates/fct-parser` — parser + normalization |
142 | | -- `crates/fct-resolver` — import resolution + deterministic merge |
143 | | -- `crates/fct-validator` — Phase 2 semantic/type/policy validation |
144 | | -- `crates/fct-engine` — Phase 3/4 runtime + guard-aware compute |
145 | | -- `crates/fct-render` — canonical payload/provenance render |
146 | | -- `crates/fct-std` — standard lens registry/library |
147 | | -- `docs/` — documentation and migration evidence |
148 | | -- `examples/spec/` — ordered spec-conformance examples |
| 166 | +Detailed guide: [docs/18-integration-guide.md](./docs/18-integration-guide.md) |
| 167 | + |
| 168 | +## Project Scope |
| 169 | + |
| 170 | +FACET **does** guarantee deterministic contract compilation/execution boundaries. |
| 171 | + |
| 172 | +FACET **does not** guarantee deterministic model generation output or correctness of external APIs. |
| 173 | + |
| 174 | +## Repository Structure |
| 175 | + |
| 176 | +- `src/commands/*` - CLI commands (`build`, `run`, `test`, `inspect`, `codegen`) |
| 177 | +- `crates/fct-parser` - parser and normalization |
| 178 | +- `crates/fct-resolver` - import resolution and deterministic merge |
| 179 | +- `crates/fct-validator` - type/semantic/policy checks |
| 180 | +- `crates/fct-engine` - compute/layout and guard-aware runtime behavior |
| 181 | +- `crates/fct-render` - canonical JSON and provenance output |
| 182 | +- `crates/fct-std` - standard lens registry |
| 183 | +- `docs/` - documentation and conformance evidence |
| 184 | +- `examples/spec/` - ordered specification scenarios |
| 185 | + |
| 186 | +## Ecosystem |
| 187 | + |
| 188 | +- FACET Standard: [github.com/rokoss21/facet-standard](https://github.com/rokoss21/facet-standard) |
| 189 | +- IOSM Methodology: [github.com/rokoss21/IOSM](https://github.com/rokoss21/IOSM) |
| 190 | +- IOSM CLI: [github.com/rokoss21/iosm-cli](https://github.com/rokoss21/iosm-cli) |
| 191 | + |
| 192 | +## Contributing |
| 193 | + |
| 194 | +- Contribution guide: [CONTRIBUTING.md](./CONTRIBUTING.md) |
| 195 | +- Issues: [github.com/rokoss21/facet-compiler/issues](https://github.com/rokoss21/facet-compiler/issues) |
149 | 196 |
|
150 | 197 | ## Author |
151 | 198 |
|
152 | 199 | **Emil Rokossovskiy** |
153 | 200 |
|
| 201 | +- GitHub: [github.com/rokoss21](https://github.com/rokoss21) |
| 202 | +- Email: [ecsiar@gmail.com](mailto:ecsiar@gmail.com) |
| 203 | +- Site: [facetcore.dev](https://facetcore.dev/) |
| 204 | + |
154 | 205 | ## License |
155 | 206 |
|
156 | 207 | Dual-licensed under [MIT](./LICENSE-MIT) or [Apache-2.0](./LICENSE-APACHE). |
0 commit comments