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 http;
42pub mod image;
43pub mod interjection;
44pub mod interner;
45pub mod json_extract;
46pub mod line_framing;
47pub mod llm;
48pub mod lr_map;
49pub mod memory;
50pub mod message_metadata;
51pub mod message_timestamp;
52pub mod misconfiguration;
53pub mod modal_hints;
54pub mod model_family;
55pub mod paths;
56pub mod preview;
57pub mod program_status;
58pub mod project;
59pub mod provider;
60pub mod reasoning;
61pub mod reference;
62pub mod retry;
63pub mod runtime_diagnostics;
64pub mod sanitizer;
65pub mod search;
66pub mod serde_helpers;
67pub mod slug;
68#[doc(hidden)]
69pub mod startup_trace;
70pub mod stop_hints;
71pub mod styling;
72pub mod task_guard;
73pub mod telemetry;
74pub mod terminal_detection;
75pub mod text_fence;
76pub mod thread_safety;
77pub mod tokens;
78pub mod tool_types;
79pub mod trace_flush;
80pub mod ui_protocol;
81pub mod unicode;
82pub mod utils;
83pub mod validation;
84pub mod vtcode_paths;
85pub mod vtcodegitignore;
86pub mod walk;
87pub mod workspace_snapshot;
88pub use colors::{blend_colors, color_from_hex, contrasting_color, is_light_color, style};
89pub use editor::{
90    EditorPoint, EditorTarget, normalize_editor_hash_fragment, parse_editor_target, resolve_editor_path,
91    resolve_editor_target,
92};
93pub use error_category::{
94    BackoffStrategy, ErrorCategory, Retryability, classify_anyhow_error, classify_error_message,
95    is_context_capacity_error, is_context_capacity_message, is_retryable_llm_error_message,
96};
97pub use errors::{DisplayErrorFormatter, ErrorFormatter, ErrorReporter, MultiErrors, NoopErrorReporter};
98pub(crate) use interjection::{
99    EventQueue, FormattedInterjection, InterjectionBuffer, LARGE_PROMPT_THRESHOLD, PendingInterjection,
100    drain_formatted, format_interjection, user_query,
101};
102pub use interner::{StringId, StringInterner};
103pub use misconfiguration::{
104    ConfigGuidance, MisconfigurationKind, detect_misconfiguration, detect_misconfiguration_in_anyhow,
105    detect_misconfiguration_in_llm_error, is_misconfiguration,
106};
107pub use modal_hints::{
108    APPROVAL_NAVIGATE_CANCEL, APPROVAL_NAVIGATE_DENY, APPROVAL_NAVIGATE_STOP, choose_handling_line, truncate_modal_text,
109};
110pub use paths::{
111    PathExt, PathResolver, PathScope, StrPathExt, WorkspacePaths, canonicalize, canonicalize_async,
112    file_name_from_path, is_safe_relative_path, normalize_ascii_identifier, resolve_workspace_path,
113    safe_archive_relative_path, validate_no_escaping_symlink_ancestors, workspace_relative_display,
114};
115pub use project::{ProjectOverview, build_project_overview};
116pub use reference::{MemoryErrorReporter, MemoryTelemetry, StaticWorkspacePaths};
117pub use stop_hints::{STOP_HINT_COMPACT, STOP_HINT_INLINE, with_stop_hint};
118pub use styling::{ColorPalette, DiffColorPalette, render_styled};
119pub use task_guard::TaskGuard;
120pub use telemetry::{NoopTelemetry, TelemetrySink};
121pub use tokens::{estimate_tokens, format_token_count, truncate_to_tokens};
122pub use unicode::{UNICODE_MONITOR, UnicodeMonitor, UnicodeValidationContext};
123pub use validation::{EmptyCollectionError, NonEmptySlice, NonEmptyString, NonEmptyVec};
124pub use vtcode_paths::{
125    MigrationEntry, MigrationFailure, MigrationReport, MigrationSkip, MigrationSkipReason, VtCodePaths,
126};
127
128// Re-export key thread safety primitives.
129pub(crate) use thread_safety::RelaxedAtomic;
130
131/// Canonical runtime diagnostic sanitization.
132pub mod diagnostics;