mnemo-engine 0.8.0__tar.gz → 0.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/PKG-INFO +1 -1
  2. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/Cargo.lock +2 -2
  3. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/Cargo.toml +1 -1
  4. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/open.rs +41 -1
  5. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/recall.rs +0 -38
  6. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/bin/mnemo.rs +26 -5
  7. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/lib.rs +2 -2
  8. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/mcp.rs +24 -3
  9. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/memory.rs +34 -0
  10. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/store.rs +37 -8
  11. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/cli_smoke.rs +99 -0
  12. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/integration.rs +92 -2
  13. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/Cargo.lock +2 -2
  14. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/Cargo.toml +1 -1
  15. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/src/lib.rs +27 -7
  16. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/test_mnemo.py +52 -0
  17. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/pyproject.toml +1 -1
  18. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/README.md +0 -0
  19. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/.gitignore +0 -0
  20. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/README.md +0 -0
  21. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/cache.rs +0 -0
  22. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/corpus.rs +0 -0
  23. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/embed_overhead.rs +0 -0
  24. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/benches/write.rs +0 -0
  25. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/deny.toml +0 -0
  26. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  27. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/ann_diagnose.rs +0 -0
  28. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/ann_recall_grid.rs +0 -0
  29. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
  30. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/embedder_server.py +0 -0
  31. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/file_size_breakdown.rs +0 -0
  32. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/quickstart.rs +0 -0
  33. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/ranking_v2.rs +0 -0
  34. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/examples/session.rs +0 -0
  35. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/cache.rs +0 -0
  36. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/crypto.rs +0 -0
  37. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/embed.rs +0 -0
  38. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/embed_cmd.rs +0 -0
  39. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/error.rs +0 -0
  40. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/format.rs +0 -0
  41. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/index.rs +0 -0
  42. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/pager.rs +0 -0
  43. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/result_cache.rs +0 -0
  44. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/session.rs +0 -0
  45. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/src/wal.rs +0 -0
  46. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/dur1_torn_header.rs +0 -0
  47. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
  48. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/proptest_store.proptest-regressions +0 -0
  49. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/proptest_store.rs +0 -0
  50. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
  51. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/.gitignore +0 -0
  52. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/mnemo-python/README.md +0 -0
  53. {mnemo_engine-0.8.0 → mnemo_engine-0.8.1}/python/mnemo_engine/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mnemo-engine
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -610,7 +610,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
610
610
 
611
611
  [[package]]
612
612
  name = "mnemo-engine"
613
- version = "0.8.0"
613
+ version = "0.8.1"
614
614
  dependencies = [
615
615
  "aes-gcm",
616
616
  "argon2",
@@ -634,7 +634,7 @@ dependencies = [
634
634
 
635
635
  [[package]]
636
636
  name = "mnemo-node"
637
- version = "0.8.0"
637
+ version = "0.8.1"
638
638
  dependencies = [
639
639
  "mnemo-engine",
640
640
  "napi",
@@ -10,7 +10,7 @@
10
10
  # The CLI binary name stays `mnemo`, so users still invoke `mnemo` on
11
11
  # the command line after `cargo install mnemo-engine`.
12
12
  name = "mnemo-engine"
13
- version = "0.8.0"
13
+ version = "0.8.1"
14
14
  edition = "2021"
15
15
  rust-version = "1.75"
16
16
  # `benches/corpus.rs` is a shared helper module pulled into real benches
@@ -29,7 +29,10 @@ use mnemo_engine::{Memory, MemoryType, Mnemo};
29
29
 
30
30
  #[path = "corpus.rs"]
31
31
  mod corpus;
32
- use corpus::{fast_kdf_cfg, gen_clustered_vectors, secure_kdf_cfg, DIMENSIONS, PASSPHRASE};
32
+ use corpus::{
33
+ fast_kdf_cfg, gen_clustered_vectors, secure_kdf_cfg, setup_cached_corpus, DIMENSIONS,
34
+ PASSPHRASE,
35
+ };
33
36
 
34
37
  const OPEN_CORPUS_SIZE: usize = 100;
35
38
 
@@ -103,9 +106,46 @@ fn bench_open_latency_secure_kdf(c: &mut Criterion) {
103
106
  group.finish();
104
107
  }
105
108
 
109
+ /// Phase 12.1.1 lane-A DISPATCH remeasure (v0.8.1): open latency on an
110
+ /// **indexed** 10K-memory file with fast KDF. This isolates the
111
+ /// non-KDF cost dominated by catalog + ANN-index load. Pairs with the
112
+ /// 100K variant below so the README's "open ~15 ms" line can be
113
+ /// replaced with numbers that reflect what agents actually pay.
114
+ fn bench_open_latency_indexed_10k(c: &mut Criterion) {
115
+ let cached = setup_cached_corpus(10_000, DIMENSIONS);
116
+ let mut group = c.benchmark_group("open");
117
+ group.sample_size(30);
118
+ group.bench_function("open_latency_indexed_10k", |b| {
119
+ b.iter(|| {
120
+ let db = Mnemo::open(&cached, PASSPHRASE).expect("open");
121
+ black_box(db);
122
+ });
123
+ });
124
+ group.finish();
125
+ }
126
+
127
+ /// Phase 12.1.1 lane-A DISPATCH remeasure (v0.8.1): open latency on an
128
+ /// **indexed** 100K-memory file with fast KDF. This is the number
129
+ /// Planner-A called out as "~115 ms in my sandbox" that doesn't
130
+ /// regress v0.7.0 → v0.8.0 but needs its own README mention.
131
+ fn bench_open_latency_indexed_100k(c: &mut Criterion) {
132
+ let cached = setup_cached_corpus(100_000, DIMENSIONS);
133
+ let mut group = c.benchmark_group("open");
134
+ group.sample_size(20);
135
+ group.bench_function("open_latency_indexed_100k", |b| {
136
+ b.iter(|| {
137
+ let db = Mnemo::open(&cached, PASSPHRASE).expect("open");
138
+ black_box(db);
139
+ });
140
+ });
141
+ group.finish();
142
+ }
143
+
106
144
  criterion_group!(
107
145
  open_benches,
108
146
  bench_open_latency_fast_kdf,
109
147
  bench_open_latency_secure_kdf,
148
+ bench_open_latency_indexed_10k,
149
+ bench_open_latency_indexed_100k,
110
150
  );
111
151
  criterion_main!(open_benches);
@@ -112,48 +112,10 @@ fn bench_recall_1m(c: &mut Criterion) {
112
112
  bench_recall_pair(c, 1_000_000, "1m", 10);
113
113
  }
114
114
 
115
- /// Phase 12.1 lane-A REVIEW remeasure: first recall on a *fresh*
116
- /// `Mnemo` handle. Opens the cached 100K corpus, issues a single
117
- /// recall, closes the handle — repeated per Criterion iteration. The
118
- /// pre-v0.8.0 code called `ensure_key_caches()` inside recall itself,
119
- /// which decrypted every live record on the first call — roughly 1 s
120
- /// at 100K with hardware AES. Post-fix, the first recall only decrypts
121
- /// the ANN shortlist plus whatever the widen / exact-scan loop needs
122
- /// (typically a few hundred records), so this cell should sit near
123
- /// the pure per-query cost of `ivfpq_recall_100k`.
124
- fn bench_first_recall_fresh_handle_100k(c: &mut Criterion) {
125
- use mnemo_engine::{RecallRequest, ScoreWeights};
126
- let cached = setup_cached_corpus(100_000, DIMENSIONS);
127
- let queries = gen_clustered_vectors(DIMENSIONS, 20, 0xDEAD_BEEF, 100);
128
- let mut group = c.benchmark_group("ivfpq_first_recall_fresh_handle_100k");
129
- group.sample_size(20);
130
- group.bench_function("first_recall", |b| {
131
- let mut i = 0usize;
132
- b.iter(|| {
133
- // Open a *fresh* handle every iteration so the key-cache
134
- // lazy init (removed in v0.8.0) and page-cache are cold.
135
- // Use `open_corpus_with_index` so the IVF+PQ path is live;
136
- // the "fresh handle" invariant we want to measure is the
137
- // one that pre-v0.8.0 would have paid for key-cache init
138
- // on every first recall.
139
- let mut db = open_corpus_with_index(&cached);
140
- let q = &queries[i % queries.len()];
141
- i += 1;
142
- let req = RecallRequest::new(q.clone())
143
- .top_k(10)
144
- .track_access(false)
145
- .weights(ScoreWeights::default());
146
- let _ = black_box(db.recall(&req).unwrap());
147
- });
148
- });
149
- group.finish();
150
- }
151
-
152
115
  criterion_group!(
153
116
  recall_benches,
154
117
  bench_recall_10k,
155
118
  bench_recall_100k,
156
119
  bench_recall_1m,
157
- bench_first_recall_fresh_handle_100k,
158
120
  );
159
121
  criterion_main!(recall_benches);
@@ -422,7 +422,10 @@ enum Command {
422
422
  },
423
423
  /// Walk the full chain for a keyed slot (Phase 12.1), newest first.
424
424
  /// Entry 0 is the live record (or empty if the slot is empty);
425
- /// subsequent entries are the superseded history.
425
+ /// subsequent entries are the superseded history. Slot resolution
426
+ /// matches `mnemo remember --key`: without `--agent` or `--shared`,
427
+ /// walks the default agent's private slot (v0.8.1 bugfix); pass
428
+ /// `--shared` for the shared slot.
426
429
  History {
427
430
  /// Path to the `.mnemo` file.
428
431
  path: String,
@@ -430,10 +433,15 @@ enum Command {
430
433
  /// `remember_keyed`).
431
434
  #[arg(long)]
432
435
  key: String,
433
- /// Query the private slot for this agent. Omit for the shared
434
- /// slot (one per file).
435
- #[arg(long)]
436
+ /// Query the private slot for this agent. Omit for the default
437
+ /// agent's private slot (pre-v0.8.1 this flag was required for
438
+ /// a working chain; it's now optional).
439
+ #[arg(long, conflicts_with = "shared")]
436
440
  agent: Option<String>,
441
+ /// Query the shared slot (one per file across every agent)
442
+ /// instead of a private slot. Mutually exclusive with `--agent`.
443
+ #[arg(long, conflicts_with = "agent")]
444
+ shared: bool,
437
445
  /// Output format.
438
446
  #[arg(long, value_enum, default_value_t = OutputFormat::Table)]
439
447
  format: OutputFormat,
@@ -1753,12 +1761,25 @@ fn run() -> std::result::Result<(), String> {
1753
1761
  path,
1754
1762
  key,
1755
1763
  agent,
1764
+ shared,
1756
1765
  format,
1757
1766
  passphrase: pp,
1758
1767
  } => {
1768
+ use mnemo_engine::KeyScope;
1759
1769
  let pp = passphrase(&pp)?;
1760
1770
  let mut db = Mnemo::open_read_only(&path, &pp).map_err(fmt)?;
1761
- let chain = db.history(&key, agent.as_deref()).map_err(fmt)?;
1771
+ // v0.8.1 bugfix: default slot matches keyed remember with
1772
+ // the same arguments. No `--shared`, no `--agent` → default
1773
+ // agent's private slot.
1774
+ let scope = if shared {
1775
+ KeyScope::Shared
1776
+ } else {
1777
+ match agent {
1778
+ Some(a) => KeyScope::Private(a),
1779
+ None => KeyScope::private_default(),
1780
+ }
1781
+ };
1782
+ let chain = db.history_in(&key, scope).map_err(fmt)?;
1762
1783
  match format {
1763
1784
  OutputFormat::Table => {
1764
1785
  if chain.is_empty() {
@@ -70,8 +70,8 @@ pub use embed_cmd::{EmbedCmd, DEFAULT_EMBED_TIMEOUT};
70
70
  pub use error::{MnemoError, Result};
71
71
  pub use index::{IndexConfig, IndexInfo};
72
72
  pub use memory::{
73
- Filter, FilterTerm, Memory, MemoryPatch, MemoryType, Metric, Scope, ScoreWeights, WriteOutcome,
74
- MNEMO_META_INVALID_AT, MNEMO_META_KEY, MNEMO_META_NS, MNEMO_META_SUPERSEDED_BY,
73
+ Filter, FilterTerm, KeyScope, Memory, MemoryPatch, MemoryType, Metric, Scope, ScoreWeights,
74
+ WriteOutcome, MNEMO_META_INVALID_AT, MNEMO_META_KEY, MNEMO_META_NS, MNEMO_META_SUPERSEDED_BY,
75
75
  MNEMO_META_SUPERSEDES, MNEMO_META_UPDATED_AT,
76
76
  };
77
77
  pub use result_cache::{
@@ -359,13 +359,14 @@ fn tools_list() -> Value {
359
359
  },
360
360
  {
361
361
  "name": "history",
362
- "description": "Walk the full chain for a keyed slot (Phase 12.1), newest first. Entry 0 is the live record (or empty if the slot is empty); subsequent entries are the superseded history. Use `agent` for a private-scope slot; omit for the shared slot.",
362
+ "description": "Walk the full chain for a keyed slot (Phase 12.1), newest first. Entry 0 is the live record (or empty if the slot is empty); subsequent entries are the superseded history. Slot resolution matches keyed `remember`: with no `agent` and `shared=false`, walks the default agent's private slot (v0.8.1 bugfix — pre-v0.8.1 this walked the shared slot by accident and returned empty for the common case). Pass `shared: true` for the shared slot; `agent` + `shared=true` is rejected.",
363
363
  "inputSchema": {
364
364
  "type": "object",
365
365
  "required": ["key"],
366
366
  "properties": {
367
367
  "key": { "type": "string" },
368
- "agent": { "type": "string" }
368
+ "agent": { "type": "string", "description": "Query the private slot for this agent. Mutually exclusive with `shared`." },
369
+ "shared": { "type": "boolean", "default": false, "description": "Query the shared slot (one per file). Mutually exclusive with `agent`." }
369
370
  },
370
371
  "additionalProperties": false
371
372
  }
@@ -781,12 +782,32 @@ fn tool_update(db: &mut Mnemo, args: &Value) -> std::result::Result<String, RpcE
781
782
  }
782
783
 
783
784
  fn tool_history(db: &mut Mnemo, args: &Value) -> std::result::Result<String, RpcError> {
785
+ use crate::KeyScope;
784
786
  let key = args
785
787
  .get("key")
786
788
  .and_then(|v| v.as_str())
787
789
  .ok_or_else(|| RpcError::new(INVALID_PARAMS, "history: missing 'key'"))?;
788
790
  let agent = args.get("agent").and_then(|v| v.as_str());
789
- let chain = db.history(key, agent).map_err(mnemo_err)?;
791
+ let shared = args
792
+ .get("shared")
793
+ .and_then(|v| v.as_bool())
794
+ .unwrap_or(false);
795
+ if shared && agent.is_some() {
796
+ return Err(RpcError::new(
797
+ INVALID_PARAMS,
798
+ "history: 'agent' and 'shared' are mutually exclusive",
799
+ ));
800
+ }
801
+ // v0.8.1 bugfix (lane A): match keyed `remember` slot resolution.
802
+ let scope = if shared {
803
+ KeyScope::Shared
804
+ } else {
805
+ match agent {
806
+ Some(a) => KeyScope::Private(a.to_string()),
807
+ None => KeyScope::private_default(),
808
+ }
809
+ };
810
+ let chain = db.history_in(key, scope).map_err(mnemo_err)?;
790
811
  let out: Vec<Value> = chain
791
812
  .iter()
792
813
  .enumerate()
@@ -302,6 +302,40 @@ pub struct MemoryPatch {
302
302
  pub ttl_secs: Option<Option<i64>>,
303
303
  }
304
304
 
305
+ /// Scope selector for a keyed slot (Phase 12.1.1). A keyed
306
+ /// `remember`'s slot is always identified by `(scope_owner, key)`:
307
+ /// `Private(agent_id)` slots are per-agent, `Shared` slots are per-file.
308
+ /// `history_in(key, scope)` uses the same selector so the lookup matches
309
+ /// the write exactly.
310
+ ///
311
+ /// The convenience [`crate::Mnemo::history`] is equivalent to
312
+ /// `history_in(key, KeyScope::Private(agent.unwrap_or("default")))` —
313
+ /// i.e. `history(key, None)` resolves to the default agent's private
314
+ /// slot, matching the `remember(…, agent_id=None, scope=Private, key=K)`
315
+ /// write path. Use [`crate::Mnemo::history_in`] with
316
+ /// [`KeyScope::Shared`] when you need the shared slot.
317
+ #[derive(Debug, Clone, PartialEq, Eq, Hash)]
318
+ pub enum KeyScope {
319
+ /// Per-agent slot. The agent id is the one carried on `Memory.agent_id`
320
+ /// at write time; `remember` with no explicit agent uses `"default"`.
321
+ Private(String),
322
+ /// Per-file slot shared across every agent.
323
+ Shared,
324
+ }
325
+
326
+ impl KeyScope {
327
+ /// Default agent id used when `Memory::new(...)` is called without
328
+ /// `.with_agent(...)` — same `"default"` the [`Memory::new`]
329
+ /// constructor seeds into `Memory.agent_id`.
330
+ pub const DEFAULT_AGENT: &'static str = "default";
331
+
332
+ /// Build the private slot for the default agent. Shorthand for
333
+ /// `KeyScope::Private(KeyScope::DEFAULT_AGENT.to_string())`.
334
+ pub fn private_default() -> Self {
335
+ KeyScope::Private(Self::DEFAULT_AGENT.to_string())
336
+ }
337
+ }
338
+
305
339
  /// Outcome of a 12.1 write operation (`remember` with `key`, or `update`).
306
340
  ///
307
341
  /// Plain `remember` without a key always returns a ULID, not a
@@ -37,9 +37,9 @@ use crate::error::{MnemoError, Result};
37
37
  use crate::format::{Header, FLAG_ENCRYPTED, PAGE_SIZE, PAYLOAD, VERSION, WRAPPED_DEK_LEN};
38
38
  use crate::index::{IndexConfig, IndexInfo, IvfPqIndex};
39
39
  use crate::memory::{
40
- self, Filter, Memory, MemoryPatch, MemoryType, Metric, Scope, ScoreWeights, WriteOutcome,
41
- MNEMO_META_INVALID_AT, MNEMO_META_KEY, MNEMO_META_SUPERSEDED_BY, MNEMO_META_SUPERSEDES,
42
- MNEMO_META_UPDATED_AT,
40
+ self, Filter, KeyScope, Memory, MemoryPatch, MemoryType, Metric, Scope, ScoreWeights,
41
+ WriteOutcome, MNEMO_META_INVALID_AT, MNEMO_META_KEY, MNEMO_META_SUPERSEDED_BY,
42
+ MNEMO_META_SUPERSEDES, MNEMO_META_UPDATED_AT,
43
43
  };
44
44
  use crate::pager::Pager;
45
45
  use crate::result_cache::{
@@ -2081,16 +2081,45 @@ impl Mnemo {
2081
2081
  /// the slot is empty, in which case the vector is empty); subsequent
2082
2082
  /// entries are the superseded history in reverse-supersession order.
2083
2083
  ///
2084
- /// `agent_id = Some(a)` queries the private slot for that agent;
2085
- /// `agent_id = None` queries the shared slot.
2084
+ /// **Slot resolution (v0.8.1 bugfix, lane A).** The lookup slot
2085
+ /// matches a keyed `remember` with the same arguments, so the
2086
+ /// obvious `history(key, None)` walks the private slot of the
2087
+ /// default agent — the same slot
2088
+ /// `remember_keyed(Memory::new(...), key)` writes to when the
2089
+ /// caller omits an explicit `agent_id` / `scope`. Pre-v0.8.1
2090
+ /// `agent_id = None` incorrectly looked up the shared slot and
2091
+ /// returned an empty chain for the common case; the old behavior
2092
+ /// is still reachable via `history_in(key, KeyScope::Shared)`.
2093
+ ///
2094
+ /// * `agent_id = Some(a)` → private slot for that agent.
2095
+ /// * `agent_id = None` → private slot for the default agent (same
2096
+ /// as [`KeyScope::private_default`]).
2097
+ ///
2098
+ /// Use [`Mnemo::history_in`] with [`KeyScope::Shared`] for the
2099
+ /// shared slot.
2086
2100
  pub fn history(&mut self, key: &str, agent_id: Option<&str>) -> Result<Vec<Memory>> {
2101
+ let scope = match agent_id {
2102
+ Some(a) => KeyScope::Private(a.to_string()),
2103
+ None => KeyScope::private_default(),
2104
+ };
2105
+ self.history_in(key, scope)
2106
+ }
2107
+
2108
+ /// Walk the full chain for a keyed slot identified by an explicit
2109
+ /// [`KeyScope`]. Returns the same shape as [`Mnemo::history`] —
2110
+ /// live record first, then the superseded chain newest-first.
2111
+ ///
2112
+ /// Use this when you need the **shared** slot (`KeyScope::Shared`),
2113
+ /// which `history(key, None)` no longer reaches as of v0.8.1.
2114
+ pub fn history_in(&mut self, key: &str, scope: KeyScope) -> Result<Vec<Memory>> {
2087
2115
  self.ensure_key_caches()?;
2088
2116
  let slot = crate::store::KeySlot {
2089
- scope_owner: agent_id.map(|a| a.to_string()),
2117
+ scope_owner: match scope {
2118
+ KeyScope::Private(a) => Some(a),
2119
+ KeyScope::Shared => None,
2120
+ },
2090
2121
  key: key.to_string(),
2091
2122
  };
2092
- // Start from the live id (if any) in the slot; walk backwards via
2093
- // `_mnemo.supersedes`.
2094
2123
  let live_id = self.key_index.as_ref().and_then(|k| k.get(&slot).copied());
2095
2124
  let mut out = Vec::new();
2096
2125
  let mut cursor = live_id;
@@ -1711,3 +1711,102 @@ fn recall_tracking_flushes_access_count_to_disk() {
1711
1711
  // before the second open completes.
1712
1712
  drop(dir);
1713
1713
  }
1714
+
1715
+ #[test]
1716
+ fn cli_history_defaults_to_private_slot_after_keyed_remember() {
1717
+ // v0.8.1 bugfix: `mnemo history <file> --key K` with no --agent /
1718
+ // --shared must walk the default agent's private slot — the same
1719
+ // slot `mnemo remember --key K` writes to when neither flag is set.
1720
+ use mnemo_engine::Memory;
1721
+ let dir = tempdir().unwrap();
1722
+ let path = dir.path().join("cli-hist.mnemo");
1723
+ let pp = "hist-pw";
1724
+
1725
+ // Seed with two keyed writes under the default agent's private
1726
+ // slot, via the library (the CLI's remember path with --key would
1727
+ // work too but needs a Python embedder; the library write hits the
1728
+ // same `remember_keyed` code path).
1729
+ {
1730
+ let mut db = Mnemo::create(&path, pp, fast_cfg(4)).unwrap();
1731
+ db.remember_keyed(
1732
+ Memory::new("v1", MemoryType::Semantic, vec![1.0, 0.0, 0.0, 0.0]),
1733
+ "release",
1734
+ )
1735
+ .unwrap();
1736
+ db.remember_keyed(
1737
+ Memory::new("v2", MemoryType::Semantic, vec![0.0, 1.0, 0.0, 0.0]),
1738
+ "release",
1739
+ )
1740
+ .unwrap();
1741
+ db.flush().unwrap();
1742
+ }
1743
+
1744
+ // Default (no --agent, no --shared) → private default-agent chain.
1745
+ let (status, stdout, _stderr) =
1746
+ run_cli(&["history", path.to_str().unwrap(), "--key", "release"], pp);
1747
+ assert!(status.success());
1748
+ // Two chain entries ("live …" + "superseded …"); both contents
1749
+ // land on the same line as their state marker.
1750
+ let lines: Vec<&str> = stdout.lines().filter(|l| !l.is_empty()).collect();
1751
+ assert_eq!(
1752
+ lines.len(),
1753
+ 2,
1754
+ "default --key history should return 2 entries (live + 1 superseded); got {stdout}"
1755
+ );
1756
+ assert!(
1757
+ lines[0].contains("live"),
1758
+ "entry 0 must be live, got {}",
1759
+ lines[0]
1760
+ );
1761
+ assert!(
1762
+ lines[0].contains("v2"),
1763
+ "live entry should be v2, got {}",
1764
+ lines[0]
1765
+ );
1766
+ assert!(lines[1].contains("superseded"));
1767
+ assert!(lines[1].contains("v1"));
1768
+
1769
+ // --shared should return an empty chain (no shared writes).
1770
+ let (status2, stdout2, _stderr2) = run_cli(
1771
+ &[
1772
+ "history",
1773
+ path.to_str().unwrap(),
1774
+ "--key",
1775
+ "release",
1776
+ "--shared",
1777
+ ],
1778
+ pp,
1779
+ );
1780
+ assert!(status2.success());
1781
+ assert!(
1782
+ stdout2.contains("no history"),
1783
+ "no shared writes → 'no history' message; got {stdout2}"
1784
+ );
1785
+ }
1786
+
1787
+ #[test]
1788
+ fn cli_history_rejects_agent_with_shared() {
1789
+ let (_dir, path, pp, _) = seed_db();
1790
+ let (status, _stdout, stderr) = run_cli(
1791
+ &[
1792
+ "history",
1793
+ path.to_str().unwrap(),
1794
+ "--key",
1795
+ "k",
1796
+ "--agent",
1797
+ "alice",
1798
+ "--shared",
1799
+ ],
1800
+ pp,
1801
+ );
1802
+ assert!(
1803
+ !status.success(),
1804
+ "clap should reject --agent with --shared"
1805
+ );
1806
+ assert!(
1807
+ stderr.contains("cannot be used with")
1808
+ || stderr.contains("conflicts")
1809
+ || (stderr.contains("--agent") && stderr.contains("--shared")),
1810
+ "expected a clap 'conflicts' message, got: {stderr}"
1811
+ );
1812
+ }
@@ -5,7 +5,7 @@
5
5
  //! (secure) parameters.
6
6
 
7
7
  use mnemo_engine::{
8
- CacheBudget, CacheFlushPolicy, CachePutOpts, Filter, KdfParams, Memory, MemoryPatch,
8
+ CacheBudget, CacheFlushPolicy, CachePutOpts, Filter, KdfParams, KeyScope, Memory, MemoryPatch,
9
9
  MemoryType, Metric, Mnemo, MnemoConfig, RecallRequest, Scope, ScoreWeights,
10
10
  SemanticCachePutOpts, Turn, WriteOutcome, DEFAULT_SEMANTIC_THRESHOLD, MNEMO_META_INVALID_AT,
11
11
  MNEMO_META_KEY, MNEMO_META_SUPERSEDED_BY, MNEMO_META_SUPERSEDES,
@@ -2884,7 +2884,12 @@ fn history_walks_the_supersession_chain_newest_first() {
2884
2884
  let (id2, _) = db.remember_keyed(make("v2", 1), "status").unwrap();
2885
2885
  let (id3, _) = db.remember_keyed(make("v3", 2), "status").unwrap();
2886
2886
 
2887
- let chain = db.history("status", None).unwrap();
2887
+ // v0.8.1 bugfix: these writes used `Scope::Shared`, so the chain
2888
+ // lives in the shared slot, not the default-agent private slot.
2889
+ // `history(key, None)` now walks the private slot (matching keyed
2890
+ // `remember` default), so use `history_in(key, KeyScope::Shared)`
2891
+ // for the shared chain.
2892
+ let chain = db.history_in("status", KeyScope::Shared).unwrap();
2888
2893
  assert_eq!(chain.len(), 3, "history should include live + 2 superseded");
2889
2894
  assert_eq!(chain[0].id, id3, "entry 0 is the live record");
2890
2895
  assert_eq!(chain[1].id, id2);
@@ -3432,3 +3437,88 @@ fn recall_wrapper_still_returns_hits_vec() {
3432
3437
  assert!(!hits.is_empty());
3433
3438
  assert!(hits.len() <= 3);
3434
3439
  }
3440
+
3441
+ // ===========================================================================
3442
+ // Phase 12.1.1 (v0.8.1): history slot resolution — default to the private
3443
+ // slot of the default agent, with KeyScope::Shared as an explicit opt-in.
3444
+ // ===========================================================================
3445
+
3446
+ #[test]
3447
+ fn history_default_slot_matches_remember_default_slot() {
3448
+ // v0.8.1 bugfix (lane A): `remember(key=K)` with no explicit agent
3449
+ // writes to the default agent's private slot; `history(K)` with no
3450
+ // arguments must now walk that same slot (pre-v0.8.1 it walked the
3451
+ // shared slot by accident and returned []).
3452
+ let dir = tempdir().unwrap();
3453
+ let path = dir.path().join("hist-default.mnemo");
3454
+ let mut db = Mnemo::create(&path, "pw", fast_cfg(4)).unwrap();
3455
+ let (_id1, _) = db
3456
+ .remember_keyed(
3457
+ Memory::new("v1", MemoryType::Semantic, vec4(1.0, 0.0, 0.0, 0.0)).with_importance(0.5),
3458
+ "release",
3459
+ )
3460
+ .unwrap();
3461
+ let (_id2, _) = db
3462
+ .remember_keyed(
3463
+ Memory::new("v2", MemoryType::Semantic, vec4(0.0, 1.0, 0.0, 0.0)).with_importance(0.5),
3464
+ "release",
3465
+ )
3466
+ .unwrap();
3467
+
3468
+ // The obvious call: no agent, no shared → must walk the default
3469
+ // agent's private chain (live + 1 superseded = 2 entries).
3470
+ let chain = db.history("release", None).unwrap();
3471
+ assert_eq!(
3472
+ chain.len(),
3473
+ 2,
3474
+ "history(key, None) should walk the default-agent private chain, not the shared slot"
3475
+ );
3476
+ assert_eq!(chain[0].content, "v2", "entry 0 is the live record");
3477
+ assert_eq!(chain[1].content, "v1");
3478
+ }
3479
+
3480
+ #[test]
3481
+ fn history_in_shared_and_private_are_separate_chains() {
3482
+ let dir = tempdir().unwrap();
3483
+ let path = dir.path().join("hist-sep.mnemo");
3484
+ let mut db = Mnemo::create(&path, "pw", fast_cfg(4)).unwrap();
3485
+
3486
+ // Two keyed slots under the same key string "pref":
3487
+ // * default-agent private slot
3488
+ // * shared slot
3489
+ // They must not alias.
3490
+ db.remember_keyed(
3491
+ Memory::new("priv-v1", MemoryType::Semantic, vec4(1.0, 0.0, 0.0, 0.0)),
3492
+ "pref",
3493
+ )
3494
+ .unwrap();
3495
+ db.remember_keyed(
3496
+ Memory::new("priv-v2", MemoryType::Semantic, vec4(1.0, 0.0, 0.0, 0.0)),
3497
+ "pref",
3498
+ )
3499
+ .unwrap();
3500
+ db.remember_keyed(
3501
+ Memory::new("shared-v1", MemoryType::Semantic, vec4(0.0, 1.0, 0.0, 0.0))
3502
+ .with_scope(Scope::Shared),
3503
+ "pref",
3504
+ )
3505
+ .unwrap();
3506
+
3507
+ let private = db.history("pref", None).unwrap();
3508
+ assert_eq!(private.len(), 2, "default-agent private chain = 2");
3509
+ assert_eq!(private[0].content, "priv-v2");
3510
+ assert_eq!(private[1].content, "priv-v1");
3511
+
3512
+ let shared = db.history_in("pref", KeyScope::Shared).unwrap();
3513
+ assert_eq!(shared.len(), 1, "shared chain = 1 (no supersession)");
3514
+ assert_eq!(shared[0].content, "shared-v1");
3515
+
3516
+ // Named-agent lookup must also be independent.
3517
+ let alice = db
3518
+ .history_in("pref", KeyScope::Private("alice".into()))
3519
+ .unwrap();
3520
+ assert!(
3521
+ alice.is_empty(),
3522
+ "no 'alice' write → empty chain, not aliased to default or shared"
3523
+ );
3524
+ }
@@ -409,7 +409,7 @@ dependencies = [
409
409
 
410
410
  [[package]]
411
411
  name = "mnemo-engine"
412
- version = "0.8.0"
412
+ version = "0.8.1"
413
413
  dependencies = [
414
414
  "aes-gcm",
415
415
  "argon2",
@@ -430,7 +430,7 @@ dependencies = [
430
430
 
431
431
  [[package]]
432
432
  name = "mnemo-python"
433
- version = "0.8.0"
433
+ version = "0.8.1"
434
434
  dependencies = [
435
435
  "mnemo-engine",
436
436
  "pyo3",
@@ -4,7 +4,7 @@
4
4
  # fields below are still useful for `cargo publish --dry-run` to lint
5
5
  # cleanly and for `cargo doc` to render coherently.
6
6
  name = "mnemo-python"
7
- version = "0.8.0"
7
+ version = "0.8.1"
8
8
  edition = "2021"
9
9
  rust-version = "1.75"
10
10
  description = "Python (PyO3) bindings for the Mnemo encrypted agent-memory engine; built by maturin into the mnemo-engine wheel on PyPI"
@@ -685,19 +685,39 @@ impl Mnemo {
685
685
  /// Phase 12.1: walk the full chain for a keyed slot, newest first.
686
686
  /// Entry 0 is the live record (or an empty list if the slot is
687
687
  /// empty); subsequent entries are the superseded history.
688
- /// `agent_id=None` queries the shared slot; a string queries the
689
- /// private slot for that agent.
690
- #[pyo3(signature = (key, *, agent_id=None))]
688
+ ///
689
+ /// Slot resolution (v0.8.1 bugfix): matches keyed `remember` with
690
+ /// the same arguments.
691
+ ///
692
+ /// * `agent_id=None, shared=False` → default agent's private slot
693
+ /// (same slot `remember(key=K)` writes to when `agent_id` is
694
+ /// omitted).
695
+ /// * `agent_id="alice"` → alice's private slot.
696
+ /// * `shared=True` → shared slot. Mutually exclusive with
697
+ /// `agent_id`.
698
+ #[pyo3(signature = (key, *, agent_id=None, shared=false))]
691
699
  fn history(
692
700
  &mut self,
693
701
  py: Python<'_>,
694
702
  key: &str,
695
703
  agent_id: Option<String>,
704
+ shared: bool,
696
705
  ) -> PyResult<PyObject> {
697
- let chain = self
698
- .core_mut()?
699
- .history(key, agent_id.as_deref())
700
- .map_err(to_py)?;
706
+ use mnemo_core::KeyScope;
707
+ if shared && agent_id.is_some() {
708
+ return Err(PyValueError::new_err(
709
+ "history: 'agent_id' and 'shared' are mutually exclusive",
710
+ ));
711
+ }
712
+ let scope = if shared {
713
+ KeyScope::Shared
714
+ } else {
715
+ match agent_id {
716
+ Some(a) => KeyScope::Private(a),
717
+ None => KeyScope::private_default(),
718
+ }
719
+ };
720
+ let chain = self.core_mut()?.history_in(key, scope).map_err(to_py)?;
701
721
  let list = PyList::empty_bound(py);
702
722
  for (i, m) in chain.iter().enumerate() {
703
723
  let d_obj = memory_to_dict(py, m)?;
@@ -845,6 +845,57 @@ def test_rebuild_index_reclusters_under_current_defaults():
845
845
  print("ok db.rebuild_index() runs + persists")
846
846
 
847
847
 
848
+ def test_history_default_slot_matches_remember_default_slot():
849
+ """v0.8.1 bugfix (lane A): `remember(key=K)` with no explicit
850
+ agent writes to the default agent's private slot; `history(K)`
851
+ with no arguments must walk that same slot — pre-v0.8.1 it
852
+ walked the shared slot by accident and returned []."""
853
+ import tempfile, os
854
+ with tempfile.TemporaryDirectory() as tmp:
855
+ path = os.path.join(tmp, "hist.mnemo")
856
+ db = mnemo.open(path, "pw", dimensions=4)
857
+ try:
858
+ r1 = db.remember(
859
+ "v1", "semantic", [1.0, 0.0, 0.0, 0.0], key="release"
860
+ )
861
+ r2 = db.remember(
862
+ "v2", "semantic", [0.0, 1.0, 0.0, 0.0], key="release"
863
+ )
864
+ assert isinstance(r1, dict) and r1["outcome"] == "added"
865
+ assert isinstance(r2, dict) and r2["outcome"] == "superseded"
866
+
867
+ # The common-case call: no agent_id, no shared.
868
+ chain = db.history("release")
869
+ assert len(chain) == 2, (
870
+ f"history('release') should return the private chain "
871
+ f"(2 entries); got {len(chain)}"
872
+ )
873
+ assert chain[0]["content"] == "v2"
874
+ assert chain[0]["state"] == "live"
875
+ assert chain[1]["content"] == "v1"
876
+ assert chain[1]["state"] == "superseded"
877
+
878
+ # Shared slot is empty (we only wrote private).
879
+ shared = db.history("release", shared=True)
880
+ assert shared == [], f"shared slot should be empty, got {shared}"
881
+
882
+ # Named-agent lookup is also independent.
883
+ alice = db.history("release", agent_id="alice")
884
+ assert alice == [], f"'alice' slot should be empty, got {alice}"
885
+
886
+ # `shared=True` with `agent_id=...` is rejected.
887
+ try:
888
+ db.history("release", agent_id="alice", shared=True)
889
+ except ValueError as e:
890
+ assert "mutually exclusive" in str(e)
891
+ else:
892
+ raise AssertionError("expected ValueError on shared+agent_id")
893
+ finally:
894
+ db.close()
895
+
896
+ print("ok history default slot matches remember default slot (v0.8.1 bugfix)")
897
+
898
+
848
899
  if __name__ == "__main__":
849
900
  print(f"mnemo {mnemo.__version__}")
850
901
  test_create_remember_recall()
@@ -876,4 +927,5 @@ if __name__ == "__main__":
876
927
  test_recall_accepts_n_probe_n_rerank_overrides()
877
928
  test_rebuild_index_reclusters_under_current_defaults()
878
929
  test_mnemo_alias_is_as_import_only_and_wheel_ships_no_mnemo_package()
930
+ test_history_default_slot_matches_remember_default_slot()
879
931
  print("\nall Python binding tests passed")
@@ -15,7 +15,7 @@ build-backend = "maturin"
15
15
  # sites unchanged). See the "Breaking: import name" section in
16
16
  # CHANGELOG.md for the full migration.
17
17
  name = "mnemo-engine"
18
- version = "0.8.0"
18
+ version = "0.8.1"
19
19
  description = "Encrypted, portable agent-memory engine — Python bindings"
20
20
  readme = "README.md"
21
21
  requires-python = ">=3.8"
File without changes