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_headlines;
81pub mod tool_intent;
82pub mod tool_types;
83pub mod trace_flush;
84pub mod tracker_title;
85pub mod tty;
86pub mod ui_protocol;
87pub mod unicode;
88pub mod utf8_stream;
89pub mod utils;
90pub mod validation;
91pub mod vtcode_paths;
92pub mod vtcodegitignore;
93pub mod walk;
94pub mod workspace_snapshot;
95pub use colors::{blend_colors, color_from_hex, contrasting_color, is_light_color, style};
96pub use editor::{
97    EditorPoint, EditorTarget, normalize_editor_hash_fragment, parse_editor_target, resolve_editor_path,
98    resolve_editor_target,
99};
100pub use error_category::{
101    BackoffStrategy, ErrorCategory, Retryability, classify_anyhow_error, classify_error_message,
102    is_context_capacity_error, is_context_capacity_message, is_retryable_llm_error_message,
103};
104pub use errors::{DisplayErrorFormatter, ErrorFormatter, ErrorReporter, MultiErrors, NoopErrorReporter};
105pub(crate) use interjection::{
106    EventQueue, FormattedInterjection, InterjectionBuffer, LARGE_PROMPT_THRESHOLD, PendingInterjection,
107    drain_formatted, format_interjection, user_query,
108};
109pub use interner::{StringId, StringInterner};
110pub use misconfiguration::{
111    ConfigGuidance, MisconfigurationKind, detect_misconfiguration, detect_misconfiguration_in_anyhow,
112    detect_misconfiguration_in_llm_error, is_misconfiguration,
113};
114pub use modal_hints::{
115    APPROVAL_NAVIGATE_CANCEL, APPROVAL_NAVIGATE_DENY, APPROVAL_NAVIGATE_STOP, choose_handling_line, truncate_modal_text,
116};
117pub use paths::{
118    PathExt, PathResolver, PathScope, StrPathExt, WorkspacePathDisplay, WorkspacePaths, canonicalize,
119    canonicalize_async, file_name_from_path, is_safe_relative_path, normalize_ascii_identifier, resolve_workspace_path,
120    safe_archive_relative_path, validate_no_escaping_symlink_ancestors, workspace_relative_display,
121    workspace_relative_slash,
122};
123pub use project::{ProjectOverview, build_project_overview};
124pub use reference::{MemoryErrorReporter, MemoryTelemetry, StaticWorkspacePaths};
125pub use stop_hints::{STOP_HINT_COMPACT, STOP_HINT_INLINE, with_stop_hint};
126pub use styling::{ColorPalette, DiffColorPalette, render_styled};
127pub use task_guard::TaskGuard;
128pub use telemetry::{NoopTelemetry, TelemetrySink};
129pub use tokens::{
130    CHARS_PER_TOKEN, estimate_tokens, format_token_count, heuristic_tokens_from_byte_len,
131    heuristic_tokens_from_byte_len_u64, truncate_to_tokens,
132};
133pub use unicode::{UNICODE_MONITOR, UnicodeMonitor, UnicodeValidationContext};
134pub use utf8_stream::Utf8StreamDecoder;
135pub use validation::{EmptyCollectionError, NonEmptySlice, NonEmptyString, NonEmptyVec};
136pub use vtcode_paths::{
137    MigrationEntry, MigrationFailure, MigrationReport, MigrationSkip, MigrationSkipReason, VtCodePaths,
138};
139
140// Re-export key thread safety primitives.
141pub(crate) use thread_safety::RelaxedAtomic;
142
143/// Canonical runtime diagnostic sanitization.
144pub mod diagnostics;