remem-ai 0.5.145

Local-first coding agent memory for Claude Code and OpenAI Codex
Documentation
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
use std::collections::BTreeMap;
use std::sync::{Arc, Mutex};

use serde::{ser::SerializeStruct, Deserialize, Serialize};

#[derive(Clone, Copy, Default)]
pub struct DbState;

#[derive(Clone, Default)]
pub(super) struct StatusCache {
    pub(super) entry: Arc<Mutex<Option<StatusCacheEntry>>>,
}

#[derive(Clone)]
pub(super) struct StatusCacheEntry {
    pub(super) generated_at_epoch: i64,
    pub(super) payload: serde_json::Value,
}

#[derive(Deserialize, Default)]
pub(super) struct StatusParams {
    pub refresh: Option<bool>,
}

#[derive(Deserialize)]
pub(super) struct SearchParams {
    pub query: Option<String>,
    pub project: Option<String>,
    #[serde(rename = "type")]
    pub memory_type: Option<String>,
    pub limit: Option<i64>,
    pub offset: Option<i64>,
    pub include_stale: Option<bool>,
    pub include_suppressed: Option<bool>,
    pub branch: Option<String>,
    pub multi_hop: Option<bool>,
    pub explain: Option<bool>,
}

#[derive(Serialize)]
pub(super) struct SearchResponse {
    pub data: Vec<MemoryItem>,
    pub meta: Meta,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub multi_hop: Option<MultiHopInfo>,
    /// Raw archive hits attached as fallback when curated memories are sparse.
    /// Only present when the underlying service returned non-empty raw_hits.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub raw_hits: Vec<RawHitItem>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub raw_hits_error: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub explain: Option<crate::retrieval::search::SearchExplain>,
}

#[derive(Serialize)]
pub(super) struct RawHitItem {
    pub id: i64,
    pub session_id: String,
    pub project: String,
    pub role: String,
    pub preview: String,
    pub source: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch: Option<String>,
    pub created_at_epoch: i64,
}

#[derive(Serialize)]
pub(super) struct MultiHopInfo {
    pub hops: u8,
    pub entities_discovered: Vec<String>,
}

#[derive(Serialize)]
pub(super) struct MemoryItem {
    pub id: i64,
    pub title: String,
    pub content: String,
    pub memory_type: String,
    pub project: String,
    pub scope: String,
    pub status: String,
    pub staleness: crate::memory::MemoryStalenessLabel,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub topic_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch: Option<String>,
    pub created_at_epoch: i64,
    pub updated_at_epoch: i64,
}

#[derive(Serialize)]
pub(super) struct Meta {
    pub count: usize,
    pub has_more: bool,
    pub limit: i64,
    pub offset: i64,
}

#[derive(Serialize)]
pub(super) struct ErrorResponse {
    pub error: ErrorDetail,
}

#[derive(Serialize)]
pub(super) struct ErrorDetail {
    pub code: String,
    pub message: String,
}

#[derive(Serialize)]
pub(super) struct CapabilitiesResponse {
    pub version: &'static str,
    pub schema_version: i64,
    pub api_version: u16,
    pub features: CapabilitiesFeatures,
    pub endpoints: BTreeMap<&'static str, &'static str>,
}

#[derive(Serialize)]
pub(super) struct CapabilitiesFeatures {
    pub health: bool,
    pub status: bool,
    pub stats: bool,
    pub search: bool,
    pub search_explain: bool,
    pub memory_list: bool,
    pub memory_detail: bool,
    pub save_memory: bool,
    pub candidate_rows: bool,
    pub candidate_review: bool,
    pub graph: bool,
    pub user_recall: bool,
    pub user_recall_usage_policy: bool,
}

#[derive(Serialize)]
pub(super) struct HealthResponse {
    pub ok: bool,
    pub version: &'static str,
    pub api_version: u16,
    pub schema_version: i64,
}

#[derive(Deserialize)]
pub(super) struct SaveMemoryRequest {
    pub text: String,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub project: Option<String>,
    #[serde(default)]
    pub session_id: Option<String>,
    #[serde(default)]
    pub host: Option<String>,
    #[serde(default)]
    pub topic_key: Option<String>,
    #[serde(default)]
    pub memory_type: Option<String>,
    #[serde(default)]
    pub files: Option<Vec<String>>,
    #[serde(default)]
    pub scope: Option<String>,
    #[serde(default)]
    pub reference_time_epoch: Option<i64>,
    #[serde(default)]
    pub created_at_epoch: Option<i64>,
    #[serde(default)]
    pub branch: Option<String>,
    #[serde(default)]
    pub local_path: Option<String>,
    #[serde(default)]
    pub local_copy_enabled: Option<bool>,
    #[serde(default)]
    pub claim_enabled: Option<bool>,
    #[serde(default)]
    pub claim_source: Option<String>,
}

#[derive(Deserialize)]
pub(super) struct UserRecallRequest {
    pub query: String,
    #[serde(default)]
    pub project: Option<String>,
    #[serde(default)]
    pub cwd: Option<String>,
    #[serde(default)]
    pub task_intent: Option<String>,
    #[serde(default)]
    pub current_files: Vec<String>,
    #[serde(default)]
    pub host: Option<String>,
    #[serde(default)]
    pub owner_scope: Option<String>,
    #[serde(default)]
    pub owner_key: Option<String>,
    #[serde(default)]
    pub state_keys: Vec<String>,
    #[serde(default)]
    pub include_sensitive: bool,
    #[serde(default)]
    pub include_suppressed: bool,
    #[serde(default)]
    pub limit: Option<i64>,
    #[serde(default)]
    pub budget_chars: Option<usize>,
}

#[derive(Serialize)]
pub(super) struct SaveMemoryResponse {
    pub id: i64,
    pub status: String,
    pub memory_type: String,
    pub project: String,
    pub scope: String,
    pub topic_key: Option<String>,
    pub branch: Option<String>,
    pub operation: String,
    pub created_at_epoch: i64,
    pub reference_time_epoch: i64,
    pub updated_at_epoch: i64,
    pub upserted: bool,
    pub local_copy: LocalCopyResponse,
    pub local_status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub local_path: Option<String>,
    pub claim_status: String,
    pub claim_id: Option<i64>,
    pub claim_error: Option<String>,
    pub next_step: SaveMemoryNextStepResponse,
}

#[derive(Serialize)]
pub(super) struct LocalCopyResponse {
    pub status: String,
    pub path: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
}

#[derive(Serialize)]
pub(super) struct SaveMemoryNextStepResponse {
    pub tool: String,
    pub ids: Vec<i64>,
    pub source: String,
    pub reason: String,
}

#[derive(Deserialize)]
pub(super) struct ShowParams {
    pub id: i64,
    pub include_suppressed: Option<bool>,
}

#[derive(Deserialize)]
pub(super) struct MemoryDetailParams {
    pub include_suppressed: Option<bool>,
}
// ===== remem-web 只读端点类型 =====

#[derive(Deserialize)]
pub(super) struct ListParams {
    pub project: Option<String>,
    #[serde(rename = "type")]
    pub memory_type: Option<String>,
    pub scope: Option<String>,
    pub status: Option<String>,
    pub branch: Option<String>,
    pub q: Option<String>,
    pub include_suppressed: Option<bool>,
    pub limit: Option<i64>,
    pub offset: Option<i64>,
}

pub(super) struct ListMeta {
    pub count: usize,
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
}

impl Serialize for ListMeta {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let count = i64::try_from(self.count).unwrap_or(i64::MAX);
        let consumed = self.offset.saturating_add(count);
        let has_more = consumed < self.total;
        let next_offset = has_more.then_some(consumed);

        let mut state = serializer.serialize_struct("ListMeta", 6)?;
        state.serialize_field("count", &self.count)?;
        state.serialize_field("total", &self.total)?;
        state.serialize_field("limit", &self.limit)?;
        state.serialize_field("offset", &self.offset)?;
        state.serialize_field("has_more", &has_more)?;
        state.serialize_field("next_offset", &next_offset)?;
        state.end()
    }
}

#[derive(Serialize)]
pub(super) struct ListResponse<T: Serialize> {
    pub data: Vec<T>,
    pub meta: ListMeta,
}

#[derive(Deserialize)]
pub(super) struct CandidateParams {
    pub project: Option<String>,
    pub status: Option<String>,
    pub limit: Option<i64>,
    pub offset: Option<i64>,
}

#[derive(Serialize)]
pub(super) struct CandidateItem {
    pub id: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub project: Option<String>,
    pub memory_type: String,
    pub text: String,
    pub scope: String,
    pub confidence: f64,
    pub risk_class: String,
    pub review_status: String,
    pub evidence_count: i64,
    pub created_at_epoch: i64,
}

#[derive(Deserialize)]
pub(super) struct CandidateEditRequest {
    #[serde(default)]
    pub scope: Option<String>,
    #[serde(default, rename = "memory_type")]
    pub memory_type: Option<String>,
    #[serde(default)]
    pub topic_key: Option<String>,
    #[serde(default)]
    pub text: Option<String>,
}

#[derive(Serialize)]
pub(super) struct CandidateReviewResponse {
    pub candidate_id: i64,
    pub status: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory_id: Option<i64>,
}

#[derive(Deserialize)]
pub(super) struct GraphParams {
    pub project: Option<String>,
    pub include_suppressed: Option<bool>,
    pub limit: Option<i64>,
}

#[derive(Serialize)]
pub(super) struct GraphNodeItem {
    pub id: i64,
    pub name: String,
    pub entity_type: Option<String>,
    pub mention_count: i64,
    pub mems: Vec<i64>,
}

#[derive(Serialize)]
pub(super) struct GraphEdgeItem {
    pub a: i64,
    pub b: i64,
    pub w: i64,
}

#[derive(Serialize)]
pub(super) struct GraphResponse {
    pub nodes: Vec<GraphNodeItem>,
    pub edges: Vec<GraphEdgeItem>,
}

#[derive(Serialize)]
pub(super) struct MemoryEdgeItem {
    pub id: i64,
    pub edge_type: String,
    pub from_memory_id: Option<i64>,
    pub to_memory_id: Option<i64>,
    pub confidence: Option<f64>,
}

#[derive(Serialize)]
pub(super) struct MemoryDetailResponse {
    #[serde(flatten)]
    pub memory: MemoryItem,
    pub entities: Vec<String>,
    pub edges: Vec<MemoryEdgeItem>,
}

#[derive(Serialize)]
pub(super) struct TypeCount {
    pub memory_type: String,
    pub count: i64,
}

#[derive(Serialize)]
pub(super) struct StatsResponse {
    pub active_memories: i64,
    pub total_memories: i64,
    pub pending_candidates: i64,
    pub captured_events: i64,
    pub pending_extraction_tasks: i64,
    pub ai_calls: i64,
    pub ai_cost_usd: f64,
    pub ai_total_tokens: i64,
    pub type_distribution: Vec<TypeCount>,
}