mermaid_cli/constants.rs
1//! Constants module to avoid magic numbers in the codebase
2
3// Network Configuration
4pub const DEFAULT_OLLAMA_PORT: u16 = 11434;
5
6// Timeouts
7pub const COMMAND_TIMEOUT_SECS: u64 = 30;
8pub const COMMAND_MAX_TIMEOUT_SECS: u64 = 300;
9
10// UI Configuration
11pub const UI_POLL_INTERVAL_MS: u64 = 50;
12pub const UI_MOUSE_SCROLL_LINES: u16 = 3;
13pub const UI_ERROR_LOG_MAX_SIZE: usize = 50;
14
15// Default Model Configuration
16pub const DEFAULT_TEMPERATURE: f32 = 0.7;
17pub const DEFAULT_MAX_TOKENS: usize = 4096;
18
19// Context Management
20/// Maximum context tokens for managed message history
21pub const MAX_CONTEXT_TOKENS: usize = 75_000;
22/// Tokens reserved for the model's response within the context window
23pub const CONTEXT_RESERVE_TOKENS: usize = 4_000;
24
25// Web Content
26/// Maximum characters to keep when truncating fetched web content
27pub const WEB_CONTENT_MAX_CHARS: usize = 5_000;
28
29/// Aggregate cap on the formatted output of `execute_web_searches`.
30/// Per-result content is already truncated to `WEB_CONTENT_MAX_CHARS`, so
31/// at the default 5 results this caps the total at ~25 KB plus headers and
32/// the sources block. The aggregate cap protects against many-results-of-
33/// medium-size cases where individual truncation alone isn't enough.
34pub const WEB_SEARCH_AGGREGATE_MAX_CHARS: usize = 30_000;
35
36/// Maximum characters allowed in the streaming response buffer.
37/// Prevents unbounded memory growth from runaway model responses.
38pub const MAX_RESPONSE_CHARS: usize = 400_000;
39
40// UI Cache
41/// Maximum entries in the markdown parse cache before eviction
42pub const MARKDOWN_CACHE_MAX_ENTRIES: usize = 200;
43
44// Subagent Configuration
45/// Maximum number of concurrent subagents that can be spawned by a single parent call
46pub const MAX_CONCURRENT_AGENTS: usize = 10;
47
48// Computer Use
49/// Maximum width for screenshots sent to models (pixels)
50pub const SCREENSHOT_MAX_WIDTH: u32 = 1280;
51
52// Computer-use timing — empirically tuned for typical desktop response.
53// Slow systems (high-load WMs, remote X displays) may need higher values;
54// the right place to make these tunable later is via env vars on
55// `app::Config`, alongside the rest of the configurable surface.
56/// Delay after `xdotool windowactivate --sync` so the window manager has
57/// time to actually move focus before the next action.
58pub const WINDOW_FOCUS_DELAY_MS: u64 = 200;
59/// Delay after a click for the window manager to process focus + UI update,
60/// before we take the auto-screenshot the model uses to decide its next move.
61pub const POST_CLICK_DELAY_MS: u64 = 500;
62/// Delay after typing for the target application to settle (validate input,
63/// re-render) before the auto-screenshot.
64pub const POST_TYPE_DELAY_MS: u64 = 500;
65/// Delay after a key press / shortcut for the target app to react before
66/// the auto-screenshot.
67pub const POST_KEY_DELAY_MS: u64 = 500;
68/// Delay between simulated keystrokes when typing text. The previous
69/// 12ms default lost characters on slow Electron / web targets; 25ms
70/// is a safer default that still types ~40 chars/sec.
71pub const TYPE_KEY_DELAY_MS: u64 = 25;
72/// Maximum scroll wheel ticks in a single `scroll` call. Clamps the
73/// model's `amount` parameter so a runaway model can't request a
74/// million ticks (would exceed `ARG_MAX` building xdotool argv).
75pub const MAX_SCROLL_AMOUNT: i32 = 100;
76/// Capacity of the per-screenshot metadata ring buffer in
77/// `computer_use`. Each call to `screenshot` registers metadata under
78/// a new id; older entries are LRU-evicted past this cap. Sized to
79/// cover any realistic agentic loop without unbounded growth.
80pub const SCREENSHOT_REGISTRY_CAPACITY: usize = 16;
81/// Maximum number of screenshot images retained in the per-call
82/// message history sent to the model. Older messages keep their text
83/// content (with a placeholder noting where the image was elided) so
84/// the model knows what was dropped from context.
85pub const MAX_RETAINED_SCREENSHOTS: usize = 3;
86
87// MERMAID.md project instructions (Step 5h)
88/// Maximum bytes loaded from MERMAID.md before truncation. ~10k
89/// tokens at 4 chars/token. Files larger than this likely have
90/// repository-wide notes that don't all need to live in the system
91/// prompt; truncate with a marker so the user knows.
92pub const MAX_INSTRUCTIONS_BYTES: usize = 40_000;
93/// Marker appended to MERMAID.md content when the file exceeds the
94/// byte cap. The model sees this so it knows context was elided.
95pub const INSTRUCTIONS_TRUNCATION_MARKER: &str =
96 "\n\n[MERMAID.md truncated — exceeds 10k token cap]";