Skip to main content

_diffctx/config/
mode.rs

1use crate::config::env_overrides::read_env_usize;
2
3pub struct ModeConfig {
4    pub bm25_top_k_primary: usize,
5    pub bm25_top_k_off: usize,
6    pub ego_depth_default: usize,
7    pub ego_depth_extended: usize,
8}
9
10impl Default for ModeConfig {
11    fn default() -> Self {
12        Self {
13            bm25_top_k_primary: 1,
14            bm25_top_k_off: 0,
15            ego_depth_default: 1,
16            ego_depth_extended: 2,
17        }
18    }
19}
20
21// Returns a fresh `ModeConfig` snapshot, reading every env override on
22// each call. Symmetric with `selection()`/`rescue()` in `config/selection.rs`
23// — needed because in-process reuse loops (e.g. `pool_eval_all_cells` for
24// a depth or budget sweep) mutate the env per cell, and a `Lazy` static
25// would freeze the values at first access.
26//
27// `DIFFCTX_OP_GRAPH_DEPTH` overrides the graph traversal radius used by
28// any scoring mode that walks the typed dependency graph (currently EGO;
29// other modes that consume a depth parameter will read the same knob).
30// The framework abstracts scoring as a pluggable signal, so the depth
31// control is named after the underlying graph operation, not the mode.
32//
33// Used by the L sweep to run depth in {0, 1, 2, 3, 4} from the same
34// binary without rebuilding. At depth 0 the EGO instantiation reduces
35// to seed-only relevance (rel_scores carries cores at score 1.0, every
36// non-core fragment is filtered before selection); the post-passes
37// (coherence + rescue + changed-files) still run, so depth=0 measures
38// "framework without graph propagation in scoring", not "trivial diff
39// baseline".
40pub fn mode() -> ModeConfig {
41    ModeConfig {
42        ego_depth_extended: read_env_usize("DIFFCTX_OP_GRAPH_DEPTH", 2),
43        // Breadth of the lexical discovery channel into the candidate
44        // universe. Shipped 1 = one BM25 file total; measured on dcbench, 79%
45        // of nontrivial gold never enters the universe while most of it shares
46        // 3+ path tokens with the diff. Env-gated for the universe ablation
47        // (#130); unset, behaviour is byte-identical.
48        bm25_top_k_primary: read_env_usize("DIFFCTX_BM25_DISCOVERY_TOP_K", 1),
49        ..ModeConfig::default()
50    }
51}