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
// SPDX-License-Identifier: Apache-2.0
//! `/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:
//! - the session playbook (distilled strategies/pitfalls/facts)
//! - currently active stigmergy scents
//! - efficacy trends (bounce rate, 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 playbook: Vec<serde_json::Value> = lean_ctx::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> = lean_ctx::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!({
"playbook": playbook,
"scents": scents,
"efficacy": lean_ctx::core::efficacy::report_json(),
});
Some((
"200 OK",
"application/json",
serde_json::to_string(&body).unwrap_or_else(|_| "{}".to_string()),
))
}