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// Tool execution limits
58/// Maximum bytes of combined stdout/stderr captured from a single
59/// `execute_command` invocation. Past this the capture stops and a
60/// truncation marker is appended — prevents a chatty or newline-less
61/// command (`cat /dev/urandom`, `yes`) from exhausting memory.
62pub const MAX_TOOL_OUTPUT_BYTES: usize = 256 * 1024;
63/// Upper bound on the number of parallel tool calls a single streaming model
64/// response may accumulate. A delta whose `index` exceeds this is dropped
65/// rather than used to grow an allocation proportional to an untrusted
66/// integer (guards against a crafted stream OOM-ing the daemon).
67pub const MAX_TOOL_CALLS: usize = 256;
68
69// UI Cache
70/// Maximum entries in the markdown parse cache before eviction
71pub const MARKDOWN_CACHE_MAX_ENTRIES: usize = 200;
72
73// Computer Use
74/// Maximum width for screenshots sent to models (pixels)
75pub const SCREENSHOT_MAX_WIDTH: u32 = 1280;
76
77// Computer-use timing — empirically tuned for typical GUI response.
78// Slow systems (high-load WMs, remote X displays) may need higher values;
79// the right place to make these tunable later is via env vars on
80// `app::Config`, alongside the rest of the configurable surface.
81/// Delay after `xdotool windowactivate --sync` so the window manager has
82/// time to actually move focus before the next action.
83pub const WINDOW_FOCUS_DELAY_MS: u64 = 200;
84/// Delay after a click for the window manager to process focus + UI update,
85/// before we take the auto-screenshot the model uses to decide its next move.
86pub const POST_CLICK_DELAY_MS: u64 = 500;
87/// Delay after typing for the target application to settle (validate input,
88/// re-render) before the auto-screenshot.
89pub const POST_TYPE_DELAY_MS: u64 = 500;
90/// Delay after a key press / shortcut for the target app to react before
91/// the auto-screenshot.
92pub const POST_KEY_DELAY_MS: u64 = 500;
93/// Delay between simulated keystrokes when typing text. The previous
94/// 12ms default lost characters on slow Electron / web targets; 25ms
95/// is a safer default that still types ~40 chars/sec.
96pub const TYPE_KEY_DELAY_MS: u64 = 25;
97/// Maximum scroll wheel ticks in a single `scroll` call. Clamps the
98/// model's `amount` parameter so a runaway model can't request a
99/// million ticks (would exceed `ARG_MAX` building xdotool argv).
100pub const MAX_SCROLL_AMOUNT: i32 = 100;
101/// Capacity of the per-screenshot metadata ring buffer in
102/// `computer_use`. Each call to `screenshot` registers metadata under
103/// a new id; older entries are LRU-evicted past this cap. Sized to
104/// cover any realistic agentic loop without unbounded growth.
105pub const SCREENSHOT_REGISTRY_CAPACITY: usize = 16;
106/// Maximum number of screenshot images retained in the per-call
107/// message history sent to the model. Older messages keep their text
108/// content (with a placeholder noting where the image was elided) so
109/// the model knows what was dropped from context.
110pub const MAX_RETAINED_SCREENSHOTS: usize = 3;
111
112// Project instructions (Step 5h)
113/// Maximum bytes loaded from project instruction files before truncation. ~10k
114/// tokens at 4 chars/token. Files larger than this likely have
115/// repository-wide notes that don't all need to live in the system
116/// prompt; truncate with a marker so the user knows.
117pub const MAX_INSTRUCTIONS_BYTES: usize = 40_000;
118/// Marker appended to project-instruction content when it exceeds the
119/// byte cap. The model sees this so it knows context was elided.
120pub const INSTRUCTIONS_TRUNCATION_MARKER: &str =
121 "\n\n[Project instructions truncated - exceeds 10k token cap]";