Skip to main content

vtcode_commons/
lib.rs

1#![allow(
2    missing_docs,
3    clippy::expect_used,
4    dead_code,
5    unused_imports,
6    reason = "Intentional compatibility, platform, or test-only suppression."
7)]
8//! Shared primitives and helper types reused across VT Code crates.
9//!
10//! This crate provides the foundational building blocks that both the core
11//! agent library (`vtcode-core`) and the terminal UI (`vtcode-ui`) depend on.
12//! Modules include ANSI processing, diff rendering, file traversal, color
13//! policy, error classification, and shared protocol types.
14//!
15//! Items live here (rather than `vtcode-ui`) when they are consumed by
16//! `vtcode-core` or the main binary -- keeping the dependency direction clean.
17//!
18//! See `docs/modules/vtcode_commons_reference.md` for ready-to-use adapters.
19
20pub mod ansi;
21pub mod ansi_capabilities;
22pub mod ansi_codes;
23pub mod async_utils;
24pub mod at_pattern;
25pub mod cgp;
26pub mod color256_theme;
27pub mod color_policy;
28pub mod colors;
29pub mod diff;
30pub mod diff_paths;
31pub mod diff_preview;
32pub mod diff_theme;
33pub mod editor;
34pub mod env_lock;
35pub mod error_category;
36pub mod errors;
37pub mod exclusions;
38pub mod file_input;
39pub mod formatting;
40pub mod fs;
41pub mod history_scope;
42pub mod http;
43pub mod image;
44pub mod interjection;
45pub mod interner;
46pub mod json_extract;
47pub mod line_framing;
48pub mod llm;
49pub mod lr_map;
50pub mod memory;
51pub mod message_metadata;
52pub mod message_timestamp;
53pub mod misconfiguration;
54pub mod modal_hints;
55pub mod model_family;
56pub mod paths;
57pub mod preview;
58pub mod program_status;
59pub mod project;
60pub mod prompt_history;
61pub mod provider;
62pub mod reasoning;
63pub mod reference;
64pub mod retry;
65pub mod runtime_diagnostics;
66pub mod sanitizer;
67pub mod search;
68pub mod serde_helpers;
69pub mod slug;
70#[doc(hidden)]
71pub mod startup_trace;
72pub mod stop_hints;
73pub mod styling;
74pub mod task_guard;
75pub mod telemetry;
76pub mod terminal_detection;
77pub mod text_fence;
78pub mod thread_safety;
79pub mod tokens;
80pub mod tool_types;
81pub mod trace_flush;
82pub mod tracker_title;
83pub mod tty;
84pub mod ui_protocol;
85pub mod unicode;
86pub mod utf8_stream;
87pub mod utils;
88pub mod validation;
89pub mod vtcode_paths;
90pub mod vtcodegitignore;
91pub mod walk;
92pub mod workspace_snapshot;
93pub use colors::{blend_colors, color_from_hex, contrasting_color, is_light_color, style};
94pub use editor::{
95    EditorPoint, EditorTarget, normalize_editor_hash_fragment, parse_editor_target, resolve_editor_path,
96    resolve_editor_target,
97};
98pub use error_category::{
99    BackoffStrategy, ErrorCategory, Retryability, classify_anyhow_error, classify_error_message,
100    is_context_capacity_error, is_context_capacity_message, is_retryable_llm_error_message,
101};
102pub use errors::{DisplayErrorFormatter, ErrorFormatter, ErrorReporter, MultiErrors, NoopErrorReporter};
103pub(crate) use interjection::{
104    EventQueue, FormattedInterjection, InterjectionBuffer, LARGE_PROMPT_THRESHOLD, PendingInterjection,
105    drain_formatted, format_interjection, user_query,
106};
107pub use interner::{StringId, StringInterner};
108pub use misconfiguration::{
109    ConfigGuidance, MisconfigurationKind, detect_misconfiguration, detect_misconfiguration_in_anyhow,
110    detect_misconfiguration_in_llm_error, is_misconfiguration,
111};
112pub use modal_hints::{
113    APPROVAL_NAVIGATE_CANCEL, APPROVAL_NAVIGATE_DENY, APPROVAL_NAVIGATE_STOP, choose_handling_line, truncate_modal_text,
114};
115pub use paths::{
116    PathExt, PathResolver, PathScope, StrPathExt, WorkspacePathDisplay, WorkspacePaths, canonicalize,
117    canonicalize_async, file_name_from_path, is_safe_relative_path, normalize_ascii_identifier, resolve_workspace_path,
118    safe_archive_relative_path, validate_no_escaping_symlink_ancestors, workspace_relative_display,
119    workspace_relative_slash,
120};
121pub use project::{ProjectOverview, build_project_overview};
122pub use reference::{MemoryErrorReporter, MemoryTelemetry, StaticWorkspacePaths};
123pub use stop_hints::{STOP_HINT_COMPACT, STOP_HINT_INLINE, with_stop_hint};
124pub use styling::{ColorPalette, DiffColorPalette, render_styled};
125pub use task_guard::TaskGuard;
126pub use telemetry::{NoopTelemetry, TelemetrySink};
127pub use tokens::{
128    CHARS_PER_TOKEN, estimate_tokens, format_token_count, heuristic_tokens_from_byte_len,
129    heuristic_tokens_from_byte_len_u64, truncate_to_tokens,
130};
131pub use unicode::{UNICODE_MONITOR, UnicodeMonitor, UnicodeValidationContext};
132pub use utf8_stream::Utf8StreamDecoder;
133pub use validation::{EmptyCollectionError, NonEmptySlice, NonEmptyString, NonEmptyVec};
134pub use vtcode_paths::{
135    MigrationEntry, MigrationFailure, MigrationReport, MigrationSkip, MigrationSkipReason, VtCodePaths,
136};
137
138// Re-export key thread safety primitives.
139pub(crate) use thread_safety::RelaxedAtomic;
140
141/// Canonical runtime diagnostic sanitization.
142pub mod diagnostics;