remem-ai 0.6.50

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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
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::SearchExplainDetails>,
}

#[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,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<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 memory_archive: bool,
    pub memory_restore: bool,
    pub memory_delete: bool,
    pub candidate_rows: bool,
    pub candidate_filters: bool,
    pub candidate_review: bool,
    pub candidate_detail: bool,
    pub candidate_evidence: bool,
    pub candidate_review_safe: bool,
    pub observations: bool,
    pub sessions: bool,
    pub workstreams: bool,
    pub events: bool,
    pub tasks: 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>,
    #[serde(default)]
    pub acknowledge_pattern: 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>,
    #[serde(rename = "type")]
    pub memory_type: Option<String>,
    pub block_reason: Option<String>,
    pub topic_key: Option<String>,
    pub contains: Option<String>,
    pub min_confidence: Option<f64>,
    pub older_than_days: Option<i64>,
    pub limit: Option<i64>,
    pub offset: Option<i64>,
}

#[derive(Deserialize)]
pub(super) struct BlockedParams {
    pub project: Option<String>,
}

#[derive(Serialize)]
pub(super) struct BlockedReasonItem {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
    pub pending: i64,
    pub example_ids: Vec<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(Deserialize, Default)]
pub(super) struct CandidateApproveRequest {
    #[serde(default)]
    pub acknowledge_pattern: 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(Serialize)]
pub(super) struct CandidateDetailResponse {
    pub data: CandidateDetailItem,
    pub evidence: Vec<CandidateEvidenceItem>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub provenance: Option<CandidateDreamProvenance>,
    pub decision: CandidateReviewDecision,
}

#[derive(Serialize)]
pub(super) struct CandidateDreamProvenance {
    pub kind: &'static str,
    pub review_token: Option<String>,
    pub authorized_supersede_ids: Vec<i64>,
    pub artifacts: Vec<CandidateDreamArtifact>,
}

#[derive(Serialize)]
pub(super) struct CandidateDreamArtifact {
    pub artifact_id: i64,
    pub version: i64,
    pub project: String,
    pub cluster_signature: String,
    pub member_ids: Vec<i64>,
    pub decision_kind: String,
    pub decision_ids: Vec<i64>,
    pub decision_payload_sha256: String,
    pub intended_superseded_ids: Vec<i64>,
    pub generated_topic_key: Option<String>,
    pub generated_memory_type: Option<String>,
    pub generated_title: Option<String>,
    pub generated_content: Option<String>,
    pub generated_field: String,
    pub pattern_id: String,
    pub pattern_version: i64,
    pub source_operation: String,
    pub source_trust_class: String,
    pub occurrence_count: i64,
    pub created_at_epoch: i64,
    pub updated_at_epoch: i64,
}

#[derive(Serialize)]
pub(super) struct CandidateDetailItem {
    pub id: i64,
    pub project: Option<String>,
    pub scope: String,
    pub memory_type: String,
    pub topic_key: String,
    pub text: String,
    pub source_kind: Option<String>,
    pub source_project: Option<String>,
    pub target_project: Option<String>,
    pub owner_scope: Option<String>,
    pub owner_key: Option<String>,
    pub topic_domain: Option<String>,
    pub routing_confidence: Option<f64>,
    pub routing_reason: Option<String>,
    pub context_class: Option<String>,
    pub confidence: f64,
    pub risk_class: String,
    pub review_status: String,
    pub auto_promote_block_reason: Option<String>,
    pub source_trust_class: String,
    pub quarantine_pattern_id: Option<String>,
    pub quarantine_pattern_version: Option<i64>,
    pub version: i64,
    pub created_at_epoch: i64,
    pub updated_at_epoch: i64,
}

#[derive(Serialize)]
pub(super) struct CandidateEvidenceItem {
    pub source_kind: &'static str,
    pub source_id: i64,
    pub event_type: Option<String>,
    pub role: Option<String>,
    pub tool_name: Option<String>,
    pub created_at_epoch: Option<i64>,
    pub summary: String,
    pub preview: String,
    pub provenance_status: String,
    pub redacted: bool,
}

#[derive(Serialize)]
pub(super) struct CandidateReviewDecision {
    pub can_review: bool,
    pub blocked_reasons: Vec<String>,
    pub actions: CandidateReviewActionDecisions,
}

#[derive(Serialize)]
pub(super) struct CandidateReviewActionDecisions {
    pub approve: CandidateReviewActionDecision,
    pub reject: CandidateReviewActionDecision,
    pub edit: CandidateReviewActionDecision,
}

#[derive(Serialize)]
pub(super) struct CandidateReviewActionDecision {
    pub allowed: bool,
    pub blocked_reasons: Vec<String>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct CandidateSafeApproveRequest {
    pub reason: String,
    pub expected_version: i64,
    pub idempotency_key: String,
    #[serde(default)]
    pub acknowledge_pattern: Option<String>,
    #[serde(default)]
    pub acknowledge_dream_review_token: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct CandidateSafeRejectRequest {
    pub reason: String,
    pub expected_version: i64,
    pub idempotency_key: String,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct CandidateSafeEditRequest {
    pub reason: String,
    pub expected_version: i64,
    pub idempotency_key: String,
    #[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(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(super) struct CandidateSafeReviewResponse {
    pub response_schema_version: i64,
    pub operation_id: String,
    pub audit_id: i64,
    pub candidate_id: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory_id: Option<i64>,
    pub action: String,
    pub before_status: String,
    pub after_status: String,
    pub version: i64,
    pub occurred_at_epoch: i64,
    pub replayed: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub(super) struct MemorySafeGovernanceRequest {
    pub reason: String,
    pub expected_version: i64,
    pub idempotency_key: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(super) struct MemorySafeGovernanceResponse {
    pub response_schema_version: i64,
    pub operation_id: String,
    pub audit_id: i64,
    pub memory_id: i64,
    pub action: String,
    pub before_status: String,
    pub after_status: String,
    pub version: i64,
    pub occurred_at_epoch: i64,
    pub replayed: bool,
}

#[derive(Serialize)]
pub(super) struct SafeMutationErrorResponse {
    pub error: SafeMutationErrorDetail,
}

#[derive(Serialize)]
pub(super) struct SafeMutationErrorDetail {
    pub code: String,
    pub message: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub operation_id: Option<String>,
}

#[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>,
}