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