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/// Auto-compact once the fully-enriched request reaches this percentage
25/// of the model's known context window.
26pub const COMPACTION_AUTO_THRESHOLD_PERCENT: u8 = 85;
27/// Default number of recent user turns preserved verbatim after compaction.
28pub const COMPACTION_TAIL_TURNS: usize = 2;
29/// Maximum estimated tokens to preserve as the recent tail.
30pub const COMPACTION_TAIL_TOKEN_BUDGET: usize = 8_000;
31/// Maximum characters of old tool output included in the summarization prompt.
32pub const COMPACTION_TOOL_OUTPUT_MAX_CHARS: usize = 2_000;
33/// Maximum tokens requested from the compaction summarizer.
34pub const COMPACTION_SUMMARY_MAX_TOKENS: usize = 8_000;
35/// Maximum estimated input tokens sent to the summarizer.
36pub const COMPACTION_SUMMARIZER_INPUT_TOKEN_BUDGET: usize = 64_000;
37/// Minimum response reserve when deciding whether the next request fits.
38pub const COMPACTION_MIN_RESPONSE_RESERVE_TOKENS: usize = 4_000;
39/// Maximum response reserve when deciding whether the next request fits.
40pub const COMPACTION_MAX_RESPONSE_RESERVE_TOKENS: usize = 20_000;
41
42// Web Content
43/// Maximum characters to keep when truncating fetched web content
44pub const WEB_CONTENT_MAX_CHARS: usize = 5_000;
45
46/// Aggregate cap on the formatted output of `execute_web_searches`.
47/// Per-result content is already truncated to `WEB_CONTENT_MAX_CHARS`, so
48/// at the default 5 results this caps the total at ~25 KB plus headers and
49/// the sources block. The aggregate cap protects against many-results-of-
50/// medium-size cases where individual truncation alone isn't enough.
51pub const WEB_SEARCH_AGGREGATE_MAX_CHARS: usize = 30_000;
52
53/// Maximum characters allowed in the streaming response buffer.
54/// Prevents unbounded memory growth from runaway model responses.
55pub const MAX_RESPONSE_CHARS: usize = 400_000;
56
57// UI Cache
58/// Maximum entries in the markdown parse cache before eviction
59pub const MARKDOWN_CACHE_MAX_ENTRIES: usize = 200;
60
61// Computer Use
62/// Maximum width for screenshots sent to models (pixels)
63pub const SCREENSHOT_MAX_WIDTH: u32 = 1280;
64
65// Computer-use timing — empirically tuned for typical desktop response.
66// Slow systems (high-load WMs, remote X displays) may need higher values;
67// the right place to make these tunable later is via env vars on
68// `app::Config`, alongside the rest of the configurable surface.
69/// Delay after `xdotool windowactivate --sync` so the window manager has
70/// time to actually move focus before the next action.
71pub const WINDOW_FOCUS_DELAY_MS: u64 = 200;
72/// Delay after a click for the window manager to process focus + UI update,
73/// before we take the auto-screenshot the model uses to decide its next move.
74pub const POST_CLICK_DELAY_MS: u64 = 500;
75/// Delay after typing for the target application to settle (validate input,
76/// re-render) before the auto-screenshot.
77pub const POST_TYPE_DELAY_MS: u64 = 500;
78/// Delay after a key press / shortcut for the target app to react before
79/// the auto-screenshot.
80pub const POST_KEY_DELAY_MS: u64 = 500;
81/// Delay between simulated keystrokes when typing text. The previous
82/// 12ms default lost characters on slow Electron / web targets; 25ms
83/// is a safer default that still types ~40 chars/sec.
84pub const TYPE_KEY_DELAY_MS: u64 = 25;
85/// Maximum scroll wheel ticks in a single `scroll` call. Clamps the
86/// model's `amount` parameter so a runaway model can't request a
87/// million ticks (would exceed `ARG_MAX` building xdotool argv).
88pub const MAX_SCROLL_AMOUNT: i32 = 100;
89/// Capacity of the per-screenshot metadata ring buffer in
90/// `computer_use`. Each call to `screenshot` registers metadata under
91/// a new id; older entries are LRU-evicted past this cap. Sized to
92/// cover any realistic agentic loop without unbounded growth.
93pub const SCREENSHOT_REGISTRY_CAPACITY: usize = 16;
94/// Maximum number of screenshot images retained in the per-call
95/// message history sent to the model. Older messages keep their text
96/// content (with a placeholder noting where the image was elided) so
97/// the model knows what was dropped from context.
98pub const MAX_RETAINED_SCREENSHOTS: usize = 3;
99
100// MERMAID.md project instructions (Step 5h)
101/// Maximum bytes loaded from MERMAID.md before truncation. ~10k
102/// tokens at 4 chars/token. Files larger than this likely have
103/// repository-wide notes that don't all need to live in the system
104/// prompt; truncate with a marker so the user knows.
105pub const MAX_INSTRUCTIONS_BYTES: usize = 40_000;
106/// Marker appended to MERMAID.md content when the file exceeds the
107/// byte cap. The model sees this so it knows context was elided.
108pub const INSTRUCTIONS_TRUNCATION_MARKER: &str =
109 "\n\n[MERMAID.md truncated — exceeds 10k token cap]";