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
//! `/api/learning` — adaptive-learning state for the dashboard (#548).
//!
//! Surfaces what the learning layers (#538–#544) have actually learned, plus
//! the efficacy evidence (#549) that the adaptation works:
//! - learned compression-threshold deltas per extension
//! - LITM placement calibration per client profile
//! - the session playbook (distilled strategies/pitfalls/facts)
//! - currently active stigmergy scents
//! - efficacy trends (bounce rate, placement hits, prevented duplicate work)
pub(super) fn handle(
path: &str,
_query_str: &str,
method: &str,
_body: &str,
) -> Option<(&'static str, &'static str, String)> {
if path != "/api/learning" || !method.eq_ignore_ascii_case("GET") {
return None;
}
let thresholds: Vec<serde_json::Value> = crate::core::threshold_learning::snapshot()
.into_iter()
.map(|(ext, d)| {
serde_json::json!({
"extension": ext,
"delta_entropy": d.delta_entropy,
"samples": d.samples,
// Positive delta -> compresses more aggressively; negative ->
// backs off because bounces/edit-failures were observed.
"direction": if d.delta_entropy > 0.0 { "more_compression" }
else if d.delta_entropy < 0.0 { "less_compression" }
else { "neutral" },
})
})
.collect();
let litm: Vec<serde_json::Value> = crate::core::litm_calibration::snapshot()
.into_iter()
.map(|(profile, s, share)| {
serde_json::json!({
"profile": profile,
"begin_hits": s.begin_hits,
"begin_misses": s.begin_misses,
"end_hits": s.end_hits,
"end_misses": s.end_misses,
"begin_share": share,
})
})
.collect();
let playbook: Vec<serde_json::Value> = crate::core::session::SessionState::load_latest()
.map(|state| {
let turn = state.stats.total_tool_calls;
state
.playbook
.entries
.iter()
.map(|e| {
serde_json::json!({
"id": e.id,
"kind": e.kind.as_str(),
"content": e.content,
"helpful_votes": e.helpful_votes,
"harmful_votes": e.harmful_votes,
"age_turns": turn.saturating_sub(e.created_turn),
})
})
.collect()
})
.unwrap_or_default();
let scents: Vec<serde_json::Value> = crate::core::scent_field::active_scents()
.into_iter()
.map(|(s, eff)| {
serde_json::json!({
"kind": s.kind.as_str(),
"target": s.target,
"agent_id": s.agent_id,
"effective_intensity": eff,
"deposited_at": s.deposited_at,
})
})
.collect();
let body = serde_json::json!({
"thresholds": thresholds,
"litm": litm,
"playbook": playbook,
"scents": scents,
"efficacy": crate::core::efficacy::report_json(),
});
Some((
"200 OK",
"application/json",
serde_json::to_string(&body).unwrap_or_else(|_| "{}".to_string()),
))
}