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