Skip to main content

vtcode_core/tools/
constants.rs

1//! Shared constants for tool operations to eliminate duplication
2//!
3//! This module provides common constants used across multiple tool implementations
4//! to reduce code duplication and ensure consistency.
5
6/// Standard error patterns used for error detection across tools
7/// These patterns are used in grep operations and error analysis
8pub const ERROR_DETECTION_PATTERNS: &[&str] = &[
9    "error",
10    "failed",
11    "exception",
12    "permission denied",
13    "not found",
14    "no such file",
15    "cannot",
16    "could not",
17    "panic",
18    "crash",
19    "unhandled",
20    "fatal",
21    "timeout",
22    "connection refused",
23    "access denied",
24    "stack trace",
25    "traceback",
26    "abort",
27    "terminate",
28];
29
30/// Network-related error patterns for more specific error detection
31pub const NETWORK_ERROR_PATTERNS: &[&str] = &[
32    "connection",
33    "timeout",
34    "network",
35    "http",
36    "ssl",
37    "tls",
38    "dns",
39    "proxy",
40];
41
42/// Memory and resource error patterns
43pub const RESOURCE_ERROR_PATTERNS: &[&str] = &[
44    "memory",
45    "oom",
46    "out of",
47    "resource",
48    "too large",
49    "disk full",
50    "quota exceeded",
51];
52
53/// Git-specific error patterns
54pub const GIT_ERROR_PATTERNS: &[&str] = &[
55    "git error",
56    "git fatal",
57    "merge conflict",
58    "rebase conflict",
59    "detached HEAD",
60];
61
62/// Command execution error patterns
63pub const COMMAND_ERROR_PATTERNS: &[&str] = &[
64    "command not found",
65    "command failed",
66    "exit code",
67    "permission denied",
68    "no such file or directory",
69];
70
71/// File system error patterns
72pub const FILESYSTEM_ERROR_PATTERNS: &[&str] = &[
73    "file not found",
74    "no such file",
75    "directory not found",
76    "permission denied",
77    "read-only file system",
78    "disk quota exceeded",
79];
80
81/// Default capacity hints for common collections
82pub const DEFAULT_VEC_CAPACITY: usize = 32;
83pub const DEFAULT_HASHMAP_CAPACITY: usize = 16;
84pub const DEFAULT_STRING_CAPACITY: usize = 256;
85
86/// Context optimization constants following AGENTS.md guidelines
87pub const MAX_SEARCH_RESULTS: usize = 5;
88pub const MAX_LIST_ITEMS_SUMMARY: usize = 5;
89pub const OVERFLOW_INDICATOR_PREFIX: &str = "[+]";
90pub const OVERFLOW_INDICATOR_SUFFIX: &str = "more items]";
91
92/// Common tool operation limits
93pub const MAX_FILE_SIZE_FOR_PROCESSING: usize = 100 * 1024 * 1024; // 100MB
94pub const MAX_CONTEXT_LINES: usize = 20;
95pub const MAX_OUTPUT_TOKENS: usize = 4000;
96
97/// Reusable empty JSON object schema `{"type": "object"}` for tool parameter definitions.
98/// Used by tools that accept no parameters or only optional parameters.
99pub fn empty_object_schema() -> serde_json::Value {
100    serde_json::json!({"type": "object"})
101}