1#![cfg_attr(
2 not(test),
3 allow(
4 clippy::large_futures,
5 reason = "Core async orchestration intentionally keeps some large stateful futures together."
6 )
7)]
8#![allow(
10 clippy::expect_used,
11 clippy::panic,
12 clippy::unnecessary_safety_comment,
13 clippy::unreachable,
14 clippy::unwrap_used,
15 missing_docs,
16 reason = "Core exposes compatibility and feature-gated surfaces whose documentation is maintained in project guides."
17)]
18#![expect(
19 unused_results,
20 clippy::let_underscore_must_use,
21 clippy::indexing_slicing,
22 clippy::string_slice,
23 clippy::cast_possible_truncation,
24 clippy::cast_possible_wrap,
25 reason = "Core runtime code intentionally maintains side-effect-only caches, validated text offsets, and protocol-sized counters across feature-gated paths."
26)]
27#![recursion_limit = "256"]
28pub mod a2a; pub mod acp;
154#[cfg(feature = "anthropic-api")]
155pub mod anthropic_api; pub mod audit;
157pub mod auth; pub mod cache; pub mod cli;
160pub mod code;
161pub mod command_safety; pub mod commands;
163pub mod compaction;
164pub mod components; pub mod config;
166pub mod constants;
167pub mod context; pub mod copilot {
170 pub use vtcode_llm::copilot::*;
171}
172pub mod core;
173pub mod diagnostics;
174pub mod dotfile_protection; pub mod error; pub mod exec;
177pub mod exec_policy; pub use components::delegate_components;
180pub use exec_policy::command_validation as execpolicy;
181pub mod gemini; pub mod git; pub mod git_info; pub mod hooks;
185pub mod http_client;
186mod id_newtype;
187pub mod instructions;
188pub mod llm;
189pub mod loop_memory; pub mod loop_state; pub mod marketplace;
192pub mod mcp;
193pub mod memory; pub mod metrics;
195pub mod models;
196pub mod models_manager; pub mod notifications;
198pub mod open_responses {
200 pub use vtcode_llm::open_responses::*;
201}
202pub mod permissions;
203pub mod persistent_memory;
204pub mod planning; pub mod plugins;
206pub mod pods;
207pub mod primary_agent;
208pub mod project_doc;
209pub mod prompts;
210pub mod retry;
211mod retry_after;
212pub mod review;
213pub mod safety;
214pub mod sandboxing; pub mod scheduler;
216pub mod security;
217pub mod session;
218pub mod shutdown;
219pub mod skills;
220pub mod subagents;
221pub mod telemetry;
222pub mod terminal_setup;
223pub mod tool_policy;
224pub mod tools;
225pub mod trace; pub mod turn_metadata; pub mod types;
228pub mod ui;
229pub mod utils;
230mod zsh_exec_bridge;
231
232pub use vtcode_commons::errors::*;
234pub use vtcode_commons::{ctx_err, file_err};
235
236pub use cli::args::{Cli, Commands};
239pub use code::code_completion::{CompletionEngine, CompletionSuggestion};
240pub use commands::stats::handle_stats_command;
241pub use config::types::{
242 AnalysisDepth, CapabilityLevel, OutputFormat, PerformanceMetrics, ReasoningEffortLevel, SessionInfo,
243};
244pub use config::{
245 AgentClientProtocolConfig, AgentClientProtocolTransport, AgentClientProtocolZedConfig,
246 AgentClientProtocolZedToolsConfig, AgentConfig, PluginRuntimeConfig, PluginTrustLevel, ToolProfile, VTCodeConfig,
247 WorkspaceTrustLevel,
248};
249pub use core::agent::core::Agent;
250pub use core::agent::runner::AgentRunner;
251pub use core::agent::task::{
252 ContextItem as RunnerContextItem, Task as RunnerTask, TaskOutcome as RunnerTaskOutcome,
253 TaskResults as RunnerTaskResults,
254};
255pub use core::memory_pool::{MemoryPool, global_pool};
256pub use core::performance_profiler::{BenchmarkResults, BenchmarkUtils, PerformanceProfiler};
257pub use core::threads::{
258 SubmissionId, ThreadBootstrap, ThreadEventRecord, ThreadId, ThreadManager, ThreadRuntimeHandle, ThreadSnapshot,
259 build_thread_archive_metadata, loaded_skills_from_session_listing, messages_from_session_listing,
260};
261pub use primary_agent::{
262 ActivePrimaryAgent, ActivePrimaryAgentSpecIdentity, ActivePrimaryAgentState, PrimaryAgentResolutionError,
263 active_primary_agent_permissions, apply_primary_agent_prompt_context, apply_primary_agent_tool_policy,
264 build_primary_agent_hook_config, build_primary_agent_runtime_config, evaluate_active_primary_agent_permissions,
265 resolve_discovered_primary_agent, resolve_primary_agent,
266};
267pub use subagents::{
268 SendInputRequest as SubagentSendInputRequest, SpawnAgentRequest as SubagentSpawnRequest,
269 SpawnBackgroundSubprocessRequest as SubagentSpawnBackgroundSubprocessRequest, SubagentController,
270 SubagentControllerConfig, SubagentInputItem, SubagentStatus, SubagentStatusEntry, VerificationResult,
271};
272pub use vtcode_bash_runner::BashRunner;
273
274pub use core::prompt_caching::{CacheStats, PromptCache, PromptCacheConfig, PromptOptimizer};
275pub use core::timeout_detector::TimeoutDetector;
276pub use diagnostics::{
277 DiagnosticReport, HealthSample, LabeledAction, PredictiveMonitor, RecoveryAction, RecoveryPlaybook,
278};
279pub use dotfile_protection::{
280 AccessType as DotfileAccessType, AuditEntry as DotfileAuditEntry, AuditLog as DotfileAuditLog,
281 AuditOutcome as DotfileAuditOutcome, BackupManager as DotfileBackupManager, DotfileBackup, DotfileGuardian,
282 ProtectionDecision, ProtectionViolation, get_global_guardian, init_global_guardian, is_protected_dotfile,
283};
284pub use error::{
285 ConfigGuidance, ErrorCategory as VtCodeErrorCategory, ErrorCode as VtCodeErrorCode, MisconfigurationKind,
286 Result as VtCodeResult, VtCodeError,
287};
288pub use exec::events::{
289 AgentMessageItem, CommandExecutionItem, CommandExecutionStatus, ContextResetEvent, ContextResetTrigger,
290 EVENT_SCHEMA_VERSION, ErrorItem, FileChangeItem, FileUpdateChange, ItemCompletedEvent, ItemStartedEvent,
291 ItemUpdatedEvent, McpToolCallItem, McpToolCallStatus, PatchApplyStatus, PatchChangeKind, PlanApprovalDecision,
292 PlanApprovalRequestedEvent, PlanApprovalResolvedEvent, PlanDeltaEvent, PlanItem, ReasoningItem, ThreadEvent,
293 ThreadItem, ThreadItemDetails, ThreadStartedEvent, ToolCallStatus, ToolInvocationItem, ToolOutputItem,
294 TurnCompletedEvent, TurnFailedEvent, TurnStartedEvent, Usage, VersionedThreadEvent, WebSearchItem,
295};
296pub use exec::{CodeExecutor, ExecutionConfig, ExecutionResult, Language};
297pub use llm::providers::gemini::wire::{Content, FunctionDeclaration, Part};
298pub use llm::{AnyClient, make_client};
299pub use mcp::{
300 tool_discovery::{DetailLevel, ToolDiscovery, ToolDiscoveryResult},
301 validate_mcp_config,
302};
303pub use memory::{MemoryMonitor, MemoryPressure, MemoryReport, RssCheckpoint};
304pub use models_manager::{
305 ModelFamily, ModelPreset, ModelsCache, ModelsManager, builtin_model_presets, model_family::find_family_for_model,
306};
307pub use notifications::{
308 NotificationConfig, NotificationEvent, NotificationManager, apply_global_notification_config,
309 apply_global_notification_config_from_vtcode, get_global_notification_manager, init_global_notification_manager,
310 init_global_notification_manager_with_config, notify_command_failure, notify_error, notify_human_in_the_loop,
311 notify_tool_failure, notify_tool_success, send_global_notification,
312};
313pub use pods::*;
314pub use prompts::SystemPromptReport;
315pub use prompts::{generate_lightweight_instruction, generate_specialized_instruction, measure_system_prompt_size};
316pub use retry::{RetryDecision, RetryPolicy, RetryPolicyCoreExt};
317pub use security::{IntegrityTag, PayloadEnvelope, ZeroTrustContext};
318pub use telemetry::{TelemetryEvent, TelemetryPipeline};
319pub use zsh_exec_bridge::maybe_run_zsh_exec_wrapper_mode;
320
321pub use open_responses::{
323 ContentPart, CustomItem, DualEventEmitter, FunctionCallItem, FunctionCallOutputItem, IncompleteDetails,
324 IncompleteReason, InputTokensDetails, ItemStatus, MessageItem, MessageRole, OpenResponseError,
325 OpenResponseErrorCode, OpenResponseErrorType, OpenResponsesCallback, OpenResponsesIntegration,
326 OpenResponsesProvider, OpenUsage, OutputItem, OutputItemId, OutputTokensDetails,
327 ReasoningItem as OpenReasoningItem, Response as OpenResponse, ResponseBuilder, ResponseId, ResponseStatus,
328 ResponseStreamEvent, StreamEventEmitter, ToOpenResponse, VecStreamEmitter, generate_item_id, generate_response_id,
329};
330
331pub use tool_policy::{ToolPolicy, ToolPolicyManager};
332
333pub use exec_policy::{
335 AskForApproval, Decision, ExecApprovalRequirement, ExecPolicyAmendment, ExecPolicyConfig, ExecPolicyManager,
336 Policy, PolicyEvaluation, PolicyParser, PrefixRule, RuleMatch, SharedExecPolicyManager,
337};
338pub use sandboxing::{
339 CommandSpec as SandboxCommandSpec, ExecEnv as SandboxExecEnv, ExecExpiration,
340 SandboxManager as CodexSandboxManager, SandboxPermissions as CodexSandboxPermissions,
341 SandboxPolicy as CodexSandboxPolicy, SandboxType, WritableRoot,
342};
343
344pub use tools::grep_file::GrepSearchManager;
345pub use tools::registry::{
346 McpBridge, PtySessionControl, SharedRegistry, ToolCatalog, ToolGroup, ToolMetrics, ToolRegistryApi, ToolResilience,
347 ToolSecurity, tool_groups,
348};
349pub use tools::{ToolRegistration, ToolRegistry};
350pub use ui::diff_renderer::{DiffRenderer, DiffRendererOptions};
351pub use utils::dot_config::{
352 CacheConfig, DotConfig, DotManager, LifecycleHookApprovalRecord, ProviderConfigs, UiConfig, UserPreferences,
353 WorkspaceTrustRecord, WorkspaceTrustStore, initialize_dot_folder, load_lifecycle_hook_approval, load_user_config,
354 load_workspace_trust_level, save_user_config, update_lifecycle_hook_approval, update_model_preference,
355 update_theme_preference, update_workspace_trust,
356};
357pub use utils::vtcodegitignore::initialize_vtcode_gitignore;
358pub use vtcode_indexer::SimpleIndexer;
359pub use vtcode_indexer::markdown_store::{
360 MarkdownStorage, ProjectData, ProjectStorage, SimpleCache, SimpleKVStorage, SimpleProjectManager,
361};
362
363#[cfg(test)]
364mod memory_tests;
365
366#[cfg(test)]
367mod memory_integration_tests;
368
369#[cfg(test)]
370mod config_verification_tests;
371
372#[cfg(test)]
373mod tests {
374 use super::*;
375
376 use tempfile::TempDir;
377
378 struct CwdGuard {
379 previous: std::path::PathBuf,
380 }
381
382 impl CwdGuard {
383 fn new() -> Self {
384 let previous = std::env::current_dir().expect("current dir");
385 Self { previous }
386 }
387 }
388
389 impl Drop for CwdGuard {
390 fn drop(&mut self) {
391 let _ = std::env::set_current_dir(&self.previous);
392 }
393 }
394
395 #[tokio::test]
396 async fn test_library_exports() {
397 let _cache = PromptCache::new().await;
399 }
400
401 #[test]
402 fn test_module_structure() {
403 }
406
407 #[test]
408 fn test_version_consistency() {
409 }
412
413 #[tokio::test]
414 async fn test_tool_registry_integration() {
415 let temp_dir = TempDir::new().expect("Failed to create temp dir");
416 let _cwd_guard = CwdGuard::new();
417 std::env::set_current_dir(&temp_dir).expect("Failed to change dir");
418
419 let registry = ToolRegistry::new(temp_dir.path().to_path_buf()).await;
420 registry.initialize_async().await.expect("Failed to init registry");
421
422 let list_args = serde_json::json!({
424 "path": "."
425 });
426
427 let result = registry.list_files(list_args).await;
428 assert!(result.is_ok());
429
430 let response: serde_json::Value = result.expect("Failed to execute list_files");
431 assert!(response.is_object() || response.is_array());
432 }
433
434 #[tokio::test]
435 async fn test_pty_basic_command() {
436 let temp_dir = TempDir::new().expect("Failed to create temp dir");
437 let workspace = temp_dir.path().to_path_buf();
438 let registry = ToolRegistry::new(workspace.clone()).await;
439 registry.initialize_async().await.expect("Failed to init registry");
440
441 let args = serde_json::json!({
443 "command": "echo",
444 "args": ["Hello, PTY!"]
445 });
446
447 let result = registry.execute_tool("run_pty_cmd", args).await;
448 assert!(result.is_ok());
449 let response: serde_json::Value = result.expect("Failed to run PTY");
450 assert_eq!(response["is_exited"], true);
451 assert_eq!(response["exit_code"], 0);
452 assert!(response["output"].is_string());
453 }
454
455 #[tokio::test]
456 async fn test_pty_session_management() {
457 let temp_dir = TempDir::new().expect("Failed to create temp dir");
458 let workspace = temp_dir.path().to_path_buf();
459 std::fs::write(workspace.join("vtcode.toml"), "[workspace]\nuse_root_config = true\n")
460 .expect("write isolated workspace config");
461 let registry = ToolRegistry::new(workspace.clone()).await;
462 registry.initialize_async().await.expect("Failed to init registry");
463
464 let args = serde_json::json!({
466 "command": "cat",
467 "yield_time_ms": 10
468 });
469
470 let result = registry.execute_tool("create_pty_session", args).await;
471 assert!(result.is_ok());
472 let response: serde_json::Value = result.expect("Failed to create PTY session");
473 assert_eq!(response["success"], true);
474 assert_eq!(response["is_exited"], false);
475 let session_id = response["session_id"]
476 .as_str()
477 .expect("create_pty_session should return a session id")
478 .to_string();
479 assert!(!session_id.is_empty());
480
481 let args = serde_json::json!({});
483 let result = registry.execute_tool("list_pty_sessions", args).await;
484 assert!(result.is_ok());
485 let response: serde_json::Value = result.expect("Failed to list PTY sessions");
486 assert!(response.is_object() || response.is_array());
487
488 let args = serde_json::json!({
490 "session_id": session_id.clone()
491 });
492
493 let result = registry.execute_tool("close_pty_session", args).await;
494 assert!(result.is_ok());
495 let response: serde_json::Value = result.expect("Failed to close PTY session");
496 assert_eq!(response["success"], true);
497 assert_eq!(response["session_id"], session_id);
498 }
499}