Skip to main content

vct_core/
lib.rs

1//! Library crate behind the `vibe_coding_tracker` / `vct` CLI.
2//!
3//! The crate scans on-disk session logs written by eight AI coding assistants:
4//! JSONL logs from Claude Code, OpenAI Codex, GitHub Copilot CLI, and Gemini
5//! CLI; `signals.json` plus sibling `updates.jsonl` from Grok CLI; SQLite data
6//! from OpenCode and Cursor; and usage-only SQLite data from Hermes. It exposes
7//! two views:
8//!
9//! - **usage** — per-model token counts and LiteLLM-priced cost
10//! - **analysis** — complete per-session data plus compact per-model
11//!   file-operation and tool-call metrics
12//!
13//! # Pipeline
14//!
15//! Raw bytes flow through a two-stage pipeline. [`session`] owns the
16//! "local session data → typed [`CodeAnalysis`]" boundary (provider detection plus a
17//! parser per provider); [`analysis`] and [`usage`] then aggregate those
18//! typed records. The `vct-tui` crate renders the result as an interactive
19//! TUI, a static table, plain text, or JSON, and the `vct-cli` binary wires
20//! the clap surface to both. Both downstream views consume the same parsed
21//! shape, so file parsing lives only in [`session`]. This crate holds no
22//! terminal dependency, so a future GUI backend can reuse it directly.
23//!
24//! Supporting modules: [`pricing`] (LiteLLM price lookup with a daily
25//! on-disk cache), [`cache`] (LRU file cache keyed by mtime), [`update`]
26//! (self-replace from the matching GitHub release asset), [`utils`]
27//! (path resolution and the glibc allocator tuning), and [`constants`]
28//! (capacity and buffer sizing).
29
30pub mod analysis;
31pub mod cache;
32pub mod config;
33pub mod constants;
34pub mod logging;
35pub mod models;
36pub mod pricing;
37pub mod quota;
38pub mod scan;
39pub mod session;
40pub mod summary_cache;
41pub mod update;
42pub mod usage;
43pub mod utils;
44
45pub use models::*;
46pub use session::parser::{parse_session_file_to_value, parse_session_file_typed};
47pub use usage::aggregator::{UsageData, aggregate_usage_from_home, aggregate_usage_from_paths};
48// Curated surface for non-CLI consumers (e.g. a future GUI backend): the
49// serializable priced-usage payload, the compact analysis summary, and the
50// shared scan diagnostics.
51pub use analysis::{AnalysisData, project_code_analysis};
52pub use scan::{ScanDiagnostics, ScanFailure};
53pub use usage::{PricedUsageRow, price_usage_data};
54
55/// Full build version: latest git tag plus commits-since and short SHA
56/// (with a `-dirty` suffix when the worktree is modified), generated by
57/// `build.rs`. Falls back to the `Cargo.toml` version outside a git tree.
58pub const VERSION: &str = env!("BUILD_VERSION");
59/// Crate name from `Cargo.toml` (`vct-core`).
60pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");
61/// Crate description from `Cargo.toml`.
62pub const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
63/// `rustc` version string captured at build time by `build.rs`.
64pub const RUST_VERSION: &str = env!("BUILD_RUST_VERSION");
65/// `cargo` version string captured at build time by `build.rs`.
66pub const CARGO_VERSION: &str = env!("BUILD_CARGO_VERSION");
67
68/// Snapshots the build version, Rust toolchain, and Cargo version into a
69/// [`VersionInfo`].
70///
71/// Reads the compile-time [`VERSION`], [`RUST_VERSION`], and
72/// [`CARGO_VERSION`] constants; this is what backs the `vct version`
73/// subcommand.
74///
75/// # Examples
76///
77/// ```
78/// let info = vct_core::get_version_info();
79/// assert_eq!(info.version, vct_core::VERSION);
80/// ```
81pub fn get_version_info() -> VersionInfo {
82    VersionInfo {
83        version: VERSION.to_string(),
84        rust_version: RUST_VERSION.to_string(),
85        cargo_version: CARGO_VERSION.to_string(),
86    }
87}
88
89/// Build metadata reported by the `vct version` subcommand.
90///
91/// Construct via [`get_version_info`]; the fields mirror the [`VERSION`],
92/// [`RUST_VERSION`], and [`CARGO_VERSION`] constants. Serializes to JSON
93/// for the `--json` output mode.
94#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
95pub struct VersionInfo {
96    /// Full build version (see [`VERSION`]).
97    pub version: String,
98    /// `rustc` version the binary was built with.
99    pub rust_version: String,
100    /// `cargo` version the binary was built with.
101    pub cargo_version: String,
102}