Skip to main content

chunk_your_tools/
runtime_config.rs

1//! Score thresholds and default policy strings; override from the host app via `configure`.
2
3use std::sync::{OnceLock, RwLock};
4
5/// Runtime defaults for retrieve scoring and policy fallbacks.
6#[derive(Clone, Debug, PartialEq)]
7pub struct RuntimeConfig {
8    pub decomposed_score: f64,
9    pub enum_score: f64,
10    pub rerank_score: f64,
11    pub empty_optional_fallback_k: usize,
12    pub default_system_policy: String,
13    pub default_mcp_policy: String,
14}
15
16impl Default for RuntimeConfig {
17    fn default() -> Self {
18        Self {
19            decomposed_score: 0.5,
20            enum_score: 0.2,
21            rerank_score: 0.003,
22            empty_optional_fallback_k: 3,
23            default_system_policy: "prune_optional".to_string(),
24            default_mcp_policy: "prune_all".to_string(),
25        }
26    }
27}
28
29fn config_lock() -> &'static RwLock<RuntimeConfig> {
30    static CONFIG: OnceLock<RwLock<RuntimeConfig>> = OnceLock::new();
31    CONFIG.get_or_init(|| RwLock::new(RuntimeConfig::default()))
32}
33
34pub fn configure(cfg: RuntimeConfig) {
35    *config_lock()
36        .write()
37        .unwrap_or_else(std::sync::PoisonError::into_inner) = cfg;
38}
39
40#[must_use]
41pub fn snapshot() -> RuntimeConfig {
42    config_lock()
43        .read()
44        .unwrap_or_else(std::sync::PoisonError::into_inner)
45        .clone()
46}
47
48#[must_use]
49pub fn decomposed_score() -> f64 {
50    snapshot().decomposed_score
51}
52
53#[must_use]
54pub fn enum_score() -> f64 {
55    snapshot().enum_score
56}
57
58#[must_use]
59pub fn rerank_score() -> f64 {
60    snapshot().rerank_score
61}
62
63#[must_use]
64pub fn empty_optional_fallback_k() -> usize {
65    snapshot().empty_optional_fallback_k
66}
67
68#[must_use]
69pub fn default_system_policy() -> String {
70    snapshot().default_system_policy
71}
72
73#[must_use]
74pub fn default_mcp_policy() -> String {
75    snapshot().default_mcp_policy
76}