Skip to main content

vane_core/
lib.rs

1//! Foundation types, traits, `FlowGraph` IR, and compilation pipeline for vane.
2//!
3//! See `spec/crates/core.md`, `spec/flow-model.md`, `spec/crates/engine.md`.
4
5pub mod body;
6pub use body::*;
7pub mod compile;
8pub use compile::compile;
9pub mod config;
10pub use config::{Env, EnvReader, LoadedConfig, ProcessEnv, load, scan_rules_dir};
11pub mod conn_context;
12pub use conn_context::*;
13pub mod error;
14pub use error::*;
15pub mod fetch;
16pub use fetch::*;
17pub mod flow_ctx;
18pub use flow_ctx::*;
19pub mod flow_log;
20pub use flow_log::*;
21pub mod ir;
22pub use ir::*;
23pub mod l4;
24pub use l4::*;
25pub mod metadata;
26pub use metadata::*;
27pub mod middleware;
28pub use middleware::*;
29pub mod wasm_runtime;
30pub use wasm_runtime::*;
31pub mod phase;
32pub mod predicate;
33pub use predicate::*;
34pub mod protocol_detect;
35pub use protocol_detect::*;
36pub mod preset;
37pub use preset::{PresetInvocation, RuleEntry, expand_invocation};
38pub mod rule;
39
40pub mod meta {
41	pub const DESCRIPTION: &str = "A compact programmable proxy engine";
42	pub const COPYRIGHT: &str = "Copyright (C) 2025 Canmi <t@canmi.icu>";
43	pub const HOMEPAGE: &str = "https://vane.canmi.app";
44	pub const REPOSITORY: &str = "https://github.com/canmi21/vane";
45	pub const LICENSE: &str = "MIT";
46	pub const LICENSE_URL: &str = "https://opensource.org/licenses/MIT";
47}
48
49pub mod version {
50	use owo_colors::{OwoColorize, Stream, Style};
51
52	use super::meta::{COPYRIGHT, DESCRIPTION, HOMEPAGE, LICENSE_URL, REPOSITORY};
53
54	/// Compile-time and runtime information about a vane binary.
55	///
56	/// Constructed by each binary from its own `build.rs`-emitted env vars
57	/// and `cfg!(feature = ...)` introspection. See [`spec/crates/daemon.md`
58	/// § _Crypto provider_](../../../spec/crates/daemon.md) and the
59	/// per-binary `build.rs` files for the full contract.
60	pub struct BuildInfo {
61		pub version: &'static str,
62		pub commit: &'static str,
63		pub build_date: &'static str,
64		pub rustc: &'static str,
65		pub cargo: &'static str,
66		pub features: &'static [&'static str],
67		pub protocols: &'static [&'static str],
68	}
69
70	/// Print the shared build banner used by both `vane -v` and
71	/// `vaned -v`. Goes straight to stdout. ANSI colour escapes are
72	/// emitted only when stdout is detected as a TTY (via owo-colors'
73	/// `Stream::Stdout` check), so `vane -v | cat` still produces flat
74	/// ASCII.
75	///
76	/// Palette (kept consistent with `vane`'s clap help output):
77	/// - **Vane** brand → yellow + bold
78	/// - section labels (`Built:`, `Rust:`, `Homepage:` …) → cyan + bold
79	/// - MIT-licence prose lead-in (the two lines that introduce the
80	///   warranty disclaimer) → green, mirroring the placeholder
81	///   colour from clap help so the disclaimer block reads as a
82	///   single styled paragraph
83	/// - `ABSOLUTELY NO WARRANTY` substring → red + bold
84	/// - everything else (description, version values, copyright,
85	///   URL values) → plain
86	///
87	/// Layout (uncoloured shape):
88	/// ```text
89	///
90	///   Vane — A compact programmable proxy engine
91	///
92	///   Built:      <version> (<commit> <date>)
93	///   Rust:       <rustc-version-line>
94	///   Cargo:      <cargo-version-line>
95	///   Features:   ...                              (vaned only)
96	///   Protocols:  ...                              (vaned only)
97	///
98	///   Copyright (C) 2025 Canmi <t@canmi.icu>
99	///
100	///   Released under the MIT License without restriction.
101	///   This software comes with ABSOLUTELY NO WARRANTY.
102	///
103	///   Homepage:   https://vane.canmi.app
104	///   Source:     https://github.com/canmi21/vane
105	///   License:    https://opensource.org/licenses/MIT
106	///
107	/// ```
108	pub fn print_banner(info: &BuildInfo) {
109		const WIDTH: usize = 12;
110		const INDENT: &str = "  ";
111
112		let brand_bold = Style::new().yellow().bold();
113		let brand = Style::new().yellow();
114		let prose = Style::new().cyan();
115		let email = Style::new().green();
116		let warning = Style::new().red().bold();
117
118		println!();
119		println!(
120			"{INDENT}{} — {DESCRIPTION}",
121			"Vane".if_supports_color(Stream::Stdout, |t| t.style(brand_bold)),
122		);
123		println!();
124
125		print_label(
126			"Built:",
127			&format!("{} ({} {})", info.version, info.commit, info.build_date),
128			WIDTH,
129			INDENT,
130		);
131		print_label("Rust:", info.rustc, WIDTH, INDENT);
132		print_label("Cargo:", info.cargo, WIDTH, INDENT);
133		if !info.features.is_empty() {
134			print_label("Features:", &info.features.join(", "), WIDTH, INDENT);
135		}
136		if !info.protocols.is_empty() {
137			print_label("Protocols:", &info.protocols.join(", "), WIDTH, INDENT);
138		}
139
140		println!();
141		// Split COPYRIGHT into three styled spans:
142		//   "Copyright"          → yellow (matches the brand tone, no bold)
143		//   " (C) 2025 Canmi "   → cyan, currently — second pass may flip
144		//                          this to plain depending on review
145		//   "<t@canmi.icu>"      → green, mirrors the prose accent
146		let (copyright_word, rest) = COPYRIGHT.split_at("Copyright".len());
147		let (middle, email_addr) = match rest.find('<') {
148			Some(i) => rest.split_at(i),
149			None => (rest, ""),
150		};
151		println!(
152			"{INDENT}{}{}{}",
153			copyright_word.if_supports_color(Stream::Stdout, |t| t.style(brand)),
154			middle.if_supports_color(Stream::Stdout, |t| t.style(prose)),
155			email_addr.if_supports_color(Stream::Stdout, |t| t.style(email)),
156		);
157		println!();
158		// Each licence line keeps prose plain and styles only the
159		// noun phrase that carries the meaning — cyan for the licence
160		// reference, red-bold for the warranty disclaimer.
161		println!(
162			"{INDENT}Released under the {} without restriction.",
163			"MIT License".if_supports_color(Stream::Stdout, |t| t.style(prose)),
164		);
165		println!(
166			"{INDENT}This software comes with {}.",
167			"ABSOLUTELY NO WARRANTY".if_supports_color(Stream::Stdout, |t| t.style(warning)),
168		);
169		println!();
170
171		print_label("Homepage:", HOMEPAGE, WIDTH, INDENT);
172		print_label("Source:", REPOSITORY, WIDTH, INDENT);
173		print_label("License:", LICENSE_URL, WIDTH, INDENT);
174		println!();
175	}
176
177	fn print_label(label: &str, value: &str, width: usize, indent: &str) {
178		let label_style = Style::new().cyan().bold();
179		let padded = format!("{label:<width$}");
180		let label_styled = padded.if_supports_color(Stream::Stdout, |t| t.style(label_style));
181		println!("{indent}{label_styled}{value}");
182	}
183}