1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Centralized hard limits for the crate.
//!
//! These constants define the operational boundaries for keys, namespaces,
//! values, configuration fields and storage parsing.
//!
//! Keeping limits in one place makes them:
//!
//! - easy to audit
//! - easy to test
//! - harder to accidentally drift across modules
//! - explicit for security review
//!
//! These values are intentionally conservative for v1. They can be revisited
//! later, but they should not change casually because they affect:
//!
//! - validation behavior
//! - parser hardening
//! - denial-of-service resistance
//! - storage compatibility expectations
/// Maximum number of bytes allowed in a key.
///
/// Keys should remain short, human-readable and namespace-oriented.
pub const MAX_KEY_LEN: usize = 512;
/// Minimum number of bytes required for a key.
pub const MIN_KEY_LEN: usize = 1;
/// Maximum number of bytes allowed in a single key segment.
///
/// Example segments:
///
/// - `agent`
/// - `claude`
/// - `current_task`
pub const MAX_KEY_SEGMENT_LEN: usize = 128;
/// Minimum number of bytes required for a key segment.
pub const MIN_KEY_SEGMENT_LEN: usize = 1;
/// Maximum number of namespace segments allowed in a key or namespace.
///
/// This protects against deeply nested path-like structures that are difficult
/// to reason about and may be abused for oversized inputs.
pub const MAX_SEGMENT_COUNT: usize = 32;
/// Maximum number of bytes allowed in a namespace.
pub const MAX_NAMESPACE_LEN: usize = 384;
/// Minimum number of bytes required for a namespace.
pub const MIN_NAMESPACE_LEN: usize = 1;
/// Maximum number of bytes allowed in a project name.
///
/// Project names should remain short enough to display clearly and map
/// comfortably into namespaces and filesystem suggestions.
pub const MAX_PROJECT_NAME_LEN: usize = 128;
/// Minimum number of bytes required for a project name.
pub const MIN_PROJECT_NAME_LEN: usize = 1;
/// Maximum number of bytes allowed in a value.
///
/// This is intentionally bounded in v1 to avoid unbounded memory growth and to
/// keep the local store focused on agent state rather than arbitrary document
/// storage.
pub const MAX_VALUE_LEN: usize = 64 * 1024; // 64 KiB
/// Minimum number of bytes required for a value.
///
/// Empty values are allowed in v1 because explicit emptiness can be meaningful
/// in agent workflows.
pub const MIN_VALUE_LEN: usize = 0;
/// Maximum number of bytes allowed in a single serialized line of the storage file.
///
/// This limit protects the parser from unbounded line growth.
pub const MAX_STORE_LINE_LEN: usize = 128 * 1024; // 128 KiB
/// Maximum number of entries allowed in a single in-memory map instance.
///
/// This is a safety boundary, not a promise that every deployment should aim
/// for this scale.
pub const MAX_ENTRY_COUNT: usize = 1_000_000;
/// Maximum number of bytes allowed in a fully resolved store path string.
///
/// This is a policy limit to catch unreasonable inputs early.
pub const MAX_STORE_PATH_LEN: usize = 4096;
/// Maximum number of bytes allowed in a config file payload.
///
/// The config format is intentionally small; anything significantly larger is
/// likely malformed or a misuse of the file.
pub const MAX_CONFIG_FILE_LEN: usize = 64 * 1024; // 64 KiB
/// Default initial capacity for a newly created in-memory map.
///
/// This should be large enough to avoid immediate resizing for small projects
/// without wasting excessive memory.
pub const DEFAULT_MAP_CAPACITY: usize = 64;
/// Minimum valid capacity for the in-memory map.
///
/// Internal map code may round capacities upward depending on its design.
pub const MIN_MAP_CAPACITY: usize = 16;
/// Maximum load factor before the in-memory map should resize.
///
/// The map implementation may use this threshold to balance memory overhead and
/// lookup performance.
pub const MAX_LOAD_FACTOR: f64 = 0.70;
/// Maximum number of bytes allowed in a storage format version field once rendered.
///
/// This is mainly useful for parser hardening and defensive checks.
pub const MAX_VERSION_FIELD_LEN: usize = 16;
/// Maximum number of bytes allowed in a file name used for the primary store.
///
/// This does not replace filesystem rules; it is a crate-level sanity limit.
pub const MAX_STORE_FILE_NAME_LEN: usize = 255;
/// Returns `true` if the provided length is within the inclusive range.
///
/// This helper keeps validation sites a little cleaner.
pub const