Skip to main content

deepstrike_core/memory/
working.rs

1use std::collections::HashMap;
2
3use compact_str::CompactString;
4
5use crate::context::dashboard::Dashboard;
6use crate::types::signal::RuntimeSignal;
7
8/// Working memory: ephemeral state for the current run.
9#[derive(Debug, Default)]
10pub struct WorkingMemory {
11    pub pending_signals: Vec<RuntimeSignal>,
12    pub tool_cache: HashMap<CompactString, CompactString>,
13    pub scratch: HashMap<String, serde_json::Value>,
14    /// Structured dashboard state shared with context layer.
15    pub dashboard: Dashboard,
16}
17
18impl WorkingMemory {
19    pub fn new() -> Self {
20        Self::default()
21    }
22
23    pub fn cache_tool_result(&mut self, call_id: CompactString, result: CompactString) {
24        self.tool_cache.insert(call_id, result);
25    }
26
27    pub fn get_cached(&self, call_id: &str) -> Option<&CompactString> {
28        self.tool_cache.get(call_id)
29    }
30
31    pub fn add_signal(&mut self, signal: RuntimeSignal) {
32        self.pending_signals.push(signal);
33    }
34
35    pub fn drain_signals(&mut self) -> Vec<RuntimeSignal> {
36        std::mem::take(&mut self.pending_signals)
37    }
38
39    pub fn clear(&mut self) {
40        self.pending_signals.clear();
41        self.tool_cache.clear();
42        self.scratch.clear();
43    }
44}