mnemo-engine 0.9.0__tar.gz → 0.9.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.
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/PKG-INFO +2 -1
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/README.md +1 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/Cargo.lock +2 -2
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/Cargo.toml +6 -1
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/README.md +9 -1
- mnemo_engine-0.9.1/mnemo/benches/thread.rs +162 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/bin/mnemo.rs +28 -49
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/lib.rs +2 -2
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/mcp.rs +51 -22
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/memory.rs +55 -2
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/store.rs +526 -317
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/cli_smoke.rs +216 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/integration.rs +385 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/proptest_store.rs +235 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/Cargo.lock +2 -2
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/Cargo.toml +1 -1
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/README.md +1 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/src/lib.rs +28 -18
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/test_mnemo.py +83 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/pyproject.toml +1 -1
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/.gitignore +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/cache.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/corpus.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/embed_overhead.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/open.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/recall.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/benches/write.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/deny.toml +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/ann_diagnose.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/ann_recall_grid.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/embedder_server.py +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/file_size_breakdown.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/open_rss.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/quickstart.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/ranking_v2.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/examples/session.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/cache.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/crypto.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/embed.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/embed_cmd.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/error.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/format.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/index.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/pager.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/result_cache.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/session.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/transcript.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/src/wal.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/dur1_torn_header.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/proptest_store.proptest-regressions +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.1}/mnemo-python/.gitignore +0 -0
- {mnemo_engine-0.9.0 → mnemo_engine-0.9.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.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -167,6 +167,7 @@ its own agent.
|
|
|
167
167
|
| `search(query, top_k=10)` | Exact nearest-neighbour search |
|
|
168
168
|
| `get(id)` / `delete(id)` | Fetch / soft-delete by id |
|
|
169
169
|
| `about()` | Self-describing onboarding briefing — memories tagged `metadata.area="onboarding"`, manifest first |
|
|
170
|
+
| `about_essence()` | The project essence render for the briefing (markdown), or `None` when the file has none |
|
|
170
171
|
| `insert_default_manifest()` | Insert the canonical scaffold manifest (same one `mnemo init` adds); returns its id |
|
|
171
172
|
| `session(agent_id)` | Begin a conversation `Session` |
|
|
172
173
|
| `flush()` / `close()` | Persist pending changes |
|
|
@@ -153,6 +153,7 @@ its own agent.
|
|
|
153
153
|
| `search(query, top_k=10)` | Exact nearest-neighbour search |
|
|
154
154
|
| `get(id)` / `delete(id)` | Fetch / soft-delete by id |
|
|
155
155
|
| `about()` | Self-describing onboarding briefing — memories tagged `metadata.area="onboarding"`, manifest first |
|
|
156
|
+
| `about_essence()` | The project essence render for the briefing (markdown), or `None` when the file has none |
|
|
156
157
|
| `insert_default_manifest()` | Insert the canonical scaffold manifest (same one `mnemo init` adds); returns its id |
|
|
157
158
|
| `session(agent_id)` | Begin a conversation `Session` |
|
|
158
159
|
| `flush()` / `close()` | Persist pending changes |
|
|
@@ -644,7 +644,7 @@ dependencies = [
|
|
|
644
644
|
|
|
645
645
|
[[package]]
|
|
646
646
|
name = "mnemo-engine"
|
|
647
|
-
version = "0.9.
|
|
647
|
+
version = "0.9.1"
|
|
648
648
|
dependencies = [
|
|
649
649
|
"aes-gcm",
|
|
650
650
|
"argon2",
|
|
@@ -669,7 +669,7 @@ dependencies = [
|
|
|
669
669
|
|
|
670
670
|
[[package]]
|
|
671
671
|
name = "mnemo-node"
|
|
672
|
-
version = "0.9.
|
|
672
|
+
version = "0.9.1"
|
|
673
673
|
dependencies = [
|
|
674
674
|
"mnemo-engine",
|
|
675
675
|
"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.9.
|
|
13
|
+
version = "0.9.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
|
|
@@ -148,6 +148,11 @@ name = "embed_overhead"
|
|
|
148
148
|
harness = false
|
|
149
149
|
required-features = ["benches"]
|
|
150
150
|
|
|
151
|
+
[[bench]]
|
|
152
|
+
name = "thread"
|
|
153
|
+
harness = false
|
|
154
|
+
required-features = ["benches"]
|
|
155
|
+
|
|
151
156
|
[features]
|
|
152
157
|
# When enabled, exposes crash-injection hooks used by the Phase 1.3
|
|
153
158
|
# proptest under `mnemo_engine::__failpoints::*`. Always enabled during
|
|
@@ -695,9 +695,17 @@ knowledge. The `about` command surfaces that introduction:
|
|
|
695
695
|
cargo run --bin mnemo -- about agent.mnemo
|
|
696
696
|
# Prints a one-line stats header, then every memory tagged
|
|
697
697
|
# metadata.area = "onboarding" sorted with the canonical manifest first,
|
|
698
|
-
# then by importance descending,
|
|
698
|
+
# then by importance descending, then the project essence (if any),
|
|
699
|
+
# ending with a quick-start footer.
|
|
699
700
|
```
|
|
700
701
|
|
|
702
|
+
Since v0.9.1 the briefing also carries the file's **project essence**: the
|
|
703
|
+
render of its project-scope essence items (conventions, lasting decisions,
|
|
704
|
+
open items), at the default 6 KB budget, after the manifest and onboarding
|
|
705
|
+
memories. `Mnemo::about_essence()` returns it (`None` when there is none),
|
|
706
|
+
`mnemo about --format json` adds it as `"essence"`, and the MCP `about` tool
|
|
707
|
+
appends it as a final `{"kind": "essence", "render": …}` element.
|
|
708
|
+
|
|
701
709
|
The convention is two metadata keys on ordinary memories — no new schema, no
|
|
702
710
|
extra file:
|
|
703
711
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
//! Phase 12.7d speed benches for the thread layers.
|
|
2
|
+
//!
|
|
3
|
+
//! Three entries, all with a trivial in-process embedder (a canned
|
|
4
|
+
//! 384-dim vector), so they measure the engine's cost rather than a
|
|
5
|
+
//! model's:
|
|
6
|
+
//!
|
|
7
|
+
//! 1. `thread/ingest_1000_turns`: `ingest_thread` of 1,000 ~200-byte
|
|
8
|
+
//! turns into an empty thread, plus the flush. Throughput is reported
|
|
9
|
+
//! in turns per second.
|
|
10
|
+
//! 2. `thread/essence_render_1000_items`: `essence(thread, 6144)` over a
|
|
11
|
+
//! thread holding 1,000 essence items (700 section items across the
|
|
12
|
+
//! seven sections, 300 timeline entries).
|
|
13
|
+
//! 3. `thread/about_with_essence_1000_items`: the full `about` briefing,
|
|
14
|
+
//! `about()` plus `about_essence()`, on a file with a manifest and
|
|
15
|
+
//! 1,000 project-scope essence items.
|
|
16
|
+
|
|
17
|
+
use std::hint::black_box;
|
|
18
|
+
|
|
19
|
+
use criterion::{criterion_group, criterion_main, BatchSize, Criterion, Throughput};
|
|
20
|
+
use mnemo_engine::{
|
|
21
|
+
Embedder, EmbedderIdentity, EssenceScope, EssenceSection, Memory, Mnemo, Result, ThreadTurn,
|
|
22
|
+
};
|
|
23
|
+
use tempfile::TempDir;
|
|
24
|
+
|
|
25
|
+
#[path = "corpus.rs"]
|
|
26
|
+
mod corpus;
|
|
27
|
+
use corpus::{fast_kdf_cfg, gen_clustered_vectors, DIMENSIONS, PASSPHRASE};
|
|
28
|
+
|
|
29
|
+
const ITEMS: usize = 1_000;
|
|
30
|
+
const TURNS: usize = 1_000;
|
|
31
|
+
|
|
32
|
+
struct CannedEmbedder {
|
|
33
|
+
vector: Vec<f32>,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
impl Embedder for CannedEmbedder {
|
|
37
|
+
fn identity(&self) -> EmbedderIdentity {
|
|
38
|
+
EmbedderIdentity {
|
|
39
|
+
name: "bench-canned-embedder".into(),
|
|
40
|
+
dimensions: self.vector.len(),
|
|
41
|
+
normalize: true,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>> {
|
|
46
|
+
Ok(texts.iter().map(|_| self.vector.clone()).collect())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn canned_vector() -> Vec<f32> {
|
|
51
|
+
gen_clustered_vectors(1, DIMENSIONS, 1, 0x7E8D_0001)
|
|
52
|
+
.into_iter()
|
|
53
|
+
.next()
|
|
54
|
+
.unwrap()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fn make_db(td: &TempDir) -> Mnemo {
|
|
58
|
+
let path = td.path().join("thread-bench.mnemo");
|
|
59
|
+
let mut db = Mnemo::create(&path, PASSPHRASE, fast_kdf_cfg(DIMENSIONS)).expect("create");
|
|
60
|
+
db.remember(Memory::scaffold_manifest(DIMENSIONS))
|
|
61
|
+
.expect("manifest");
|
|
62
|
+
db.set_embedder(CannedEmbedder {
|
|
63
|
+
vector: canned_vector(),
|
|
64
|
+
})
|
|
65
|
+
.expect("set_embedder");
|
|
66
|
+
db
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const SECTIONS: [EssenceSection; 7] = [
|
|
70
|
+
EssenceSection::Intent,
|
|
71
|
+
EssenceSection::Conventions,
|
|
72
|
+
EssenceSection::Decisions,
|
|
73
|
+
EssenceSection::State,
|
|
74
|
+
EssenceSection::Open,
|
|
75
|
+
EssenceSection::Next,
|
|
76
|
+
EssenceSection::Lessons,
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
/// Fill `scope` with `ITEMS` essence items: 70% section items spread
|
|
80
|
+
/// over the seven sections, 30% timeline entries.
|
|
81
|
+
fn fill_essence(db: &mut Mnemo, scope: &EssenceScope) {
|
|
82
|
+
for i in 0..ITEMS {
|
|
83
|
+
if i % 10 < 7 {
|
|
84
|
+
let section = SECTIONS[i % SECTIONS.len()];
|
|
85
|
+
let text =
|
|
86
|
+
format!("item {i:04}: a one-line essence entry of typical length for a bench");
|
|
87
|
+
db.essence_add(scope.clone(), section, &text, None)
|
|
88
|
+
.expect("essence_add");
|
|
89
|
+
} else {
|
|
90
|
+
let text =
|
|
91
|
+
format!("milestone {i:04}: shipped a thing, measured it, and wrote down why");
|
|
92
|
+
db.essence_append_timeline(scope.clone(), &text, None)
|
|
93
|
+
.expect("essence_append_timeline");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
db.flush().expect("flush");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn bench_ingest(c: &mut Criterion) {
|
|
100
|
+
let turns: Vec<ThreadTurn> = (0..TURNS)
|
|
101
|
+
.map(|i| ThreadTurn {
|
|
102
|
+
turn_id: format!("turn-{i:05}"),
|
|
103
|
+
role: if i % 2 == 0 { "user" } else { "assistant" }.into(),
|
|
104
|
+
content: format!("turn {i:05}: {}", "lorem ipsum dolor sit amet ".repeat(7)),
|
|
105
|
+
timestamp: Some(1_700_000_000 + i as i64),
|
|
106
|
+
})
|
|
107
|
+
.collect();
|
|
108
|
+
|
|
109
|
+
let mut group = c.benchmark_group("thread");
|
|
110
|
+
group.sample_size(10);
|
|
111
|
+
group.throughput(Throughput::Elements(TURNS as u64));
|
|
112
|
+
group.bench_function("ingest_1000_turns", |b| {
|
|
113
|
+
b.iter_batched(
|
|
114
|
+
|| {
|
|
115
|
+
let td = TempDir::new().expect("tempdir");
|
|
116
|
+
let db = make_db(&td);
|
|
117
|
+
(td, db)
|
|
118
|
+
},
|
|
119
|
+
|(_td, mut db)| {
|
|
120
|
+
let report = db.ingest_thread("bench", &turns).expect("ingest");
|
|
121
|
+
db.flush().expect("flush");
|
|
122
|
+
black_box(report);
|
|
123
|
+
},
|
|
124
|
+
BatchSize::PerIteration,
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
group.finish();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fn bench_render(c: &mut Criterion) {
|
|
131
|
+
let td = TempDir::new().expect("tempdir");
|
|
132
|
+
let mut db = make_db(&td);
|
|
133
|
+
let scope = EssenceScope::Thread("bench".into());
|
|
134
|
+
fill_essence(&mut db, &scope);
|
|
135
|
+
|
|
136
|
+
let mut group = c.benchmark_group("thread");
|
|
137
|
+
group.sample_size(20);
|
|
138
|
+
group.bench_function("essence_render_1000_items", |b| {
|
|
139
|
+
b.iter(|| black_box(db.essence(scope.clone(), 6144).expect("render")));
|
|
140
|
+
});
|
|
141
|
+
group.finish();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fn bench_about(c: &mut Criterion) {
|
|
145
|
+
let td = TempDir::new().expect("tempdir");
|
|
146
|
+
let mut db = make_db(&td);
|
|
147
|
+
fill_essence(&mut db, &EssenceScope::Project);
|
|
148
|
+
|
|
149
|
+
let mut group = c.benchmark_group("thread");
|
|
150
|
+
group.sample_size(20);
|
|
151
|
+
group.bench_function("about_with_essence_1000_items", |b| {
|
|
152
|
+
b.iter(|| {
|
|
153
|
+
let records = db.about().expect("about");
|
|
154
|
+
let essence = db.about_essence().expect("about_essence");
|
|
155
|
+
black_box((records, essence))
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
group.finish();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
criterion_group!(thread_benches, bench_ingest, bench_render, bench_about);
|
|
162
|
+
criterion_main!(thread_benches);
|
|
@@ -1523,6 +1523,21 @@ fn run() -> std::result::Result<(), String> {
|
|
|
1523
1523
|
let stats = db.stats().map_err(fmt)?;
|
|
1524
1524
|
let snapshots = db.snapshots().len();
|
|
1525
1525
|
let mut entries = db.about().map_err(fmt)?;
|
|
1526
|
+
// 12.7d: the project essence follows the manifest and the
|
|
1527
|
+
// onboarding memories (skipped with --manifest-only).
|
|
1528
|
+
let essence = if manifest_only {
|
|
1529
|
+
None
|
|
1530
|
+
} else {
|
|
1531
|
+
db.about_essence().map_err(fmt)?
|
|
1532
|
+
};
|
|
1533
|
+
let print_essence = || {
|
|
1534
|
+
if let Some(render) = &essence {
|
|
1535
|
+
println!();
|
|
1536
|
+
println!("## Project essence");
|
|
1537
|
+
println!();
|
|
1538
|
+
print!("{render}");
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1526
1541
|
if manifest_only {
|
|
1527
1542
|
entries.retain(|m| {
|
|
1528
1543
|
m.metadata
|
|
@@ -1556,6 +1571,7 @@ fn run() -> std::result::Result<(), String> {
|
|
|
1556
1571
|
.iter()
|
|
1557
1572
|
.map(|m| memory_to_json(m, false))
|
|
1558
1573
|
.collect::<Vec<_>>(),
|
|
1574
|
+
"essence": essence.as_deref(),
|
|
1559
1575
|
});
|
|
1560
1576
|
println!(
|
|
1561
1577
|
"{}",
|
|
@@ -1591,6 +1607,7 @@ fn run() -> std::result::Result<(), String> {
|
|
|
1591
1607
|
" metadata = {{\"area\": \"onboarding\", \"topic\": \"manifest\"}}"
|
|
1592
1608
|
);
|
|
1593
1609
|
println!("that introduces the project, embedder, and conventions.");
|
|
1610
|
+
print_essence();
|
|
1594
1611
|
} else {
|
|
1595
1612
|
println!();
|
|
1596
1613
|
println!(
|
|
@@ -1626,6 +1643,7 @@ fn run() -> std::result::Result<(), String> {
|
|
|
1626
1643
|
println!("### {head}");
|
|
1627
1644
|
println!("{}", m.content);
|
|
1628
1645
|
}
|
|
1646
|
+
print_essence();
|
|
1629
1647
|
println!();
|
|
1630
1648
|
println!("## Quick start");
|
|
1631
1649
|
println!(
|
|
@@ -2260,10 +2278,7 @@ fn fmt(e: mnemo_engine::MnemoError) -> String {
|
|
|
2260
2278
|
/// into its own function because the three subcommands share nothing
|
|
2261
2279
|
/// with the top-level dispatch beyond passphrase resolution.
|
|
2262
2280
|
fn handle_thread_cmd(cmd: ThreadCmd) -> std::result::Result<(), String> {
|
|
2263
|
-
use mnemo_engine::{
|
|
2264
|
-
read_transcript, EmbedCmd, EmbedderIdentity, TranscriptFormat, MNEMO_META_LENGTH,
|
|
2265
|
-
MNEMO_META_ROLE, MNEMO_META_SHA256, MNEMO_META_TURN_ID,
|
|
2266
|
-
};
|
|
2281
|
+
use mnemo_engine::{read_transcript, EmbedCmd, EmbedderIdentity, TranscriptFormat};
|
|
2267
2282
|
use std::io::{Read, Write};
|
|
2268
2283
|
match cmd {
|
|
2269
2284
|
ThreadCmd::Ingest {
|
|
@@ -2324,50 +2339,14 @@ fn handle_thread_cmd(cmd: ThreadCmd) -> std::result::Result<(), String> {
|
|
|
2324
2339
|
} => {
|
|
2325
2340
|
let pp = passphrase(&pp)?;
|
|
2326
2341
|
let mut db = Mnemo::open_read_only(&path, &pp).map_err(fmt)?;
|
|
2327
|
-
|
|
2328
|
-
//
|
|
2329
|
-
//
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
// Group multi-part turns by `_mnemo.turn_id`.
|
|
2336
|
-
use std::collections::BTreeMap;
|
|
2337
|
-
let mut grouped: BTreeMap<String, Vec<&mnemo_engine::Memory>> = BTreeMap::new();
|
|
2338
|
-
for m in &records {
|
|
2339
|
-
let tid = m
|
|
2340
|
-
.metadata
|
|
2341
|
-
.get(MNEMO_META_TURN_ID)
|
|
2342
|
-
.and_then(|v| v.as_str())
|
|
2343
|
-
.unwrap_or("");
|
|
2344
|
-
grouped.entry(tid.to_string()).or_default().push(m);
|
|
2345
|
-
}
|
|
2346
|
-
for (tid, parts) in &grouped {
|
|
2347
|
-
let mut combined = String::new();
|
|
2348
|
-
for p in parts {
|
|
2349
|
-
combined.push_str(&p.content);
|
|
2350
|
-
}
|
|
2351
|
-
let first = parts.first().expect("group has at least one record");
|
|
2352
|
-
let role = first
|
|
2353
|
-
.metadata
|
|
2354
|
-
.get(MNEMO_META_ROLE)
|
|
2355
|
-
.and_then(|v| v.as_str())
|
|
2356
|
-
.unwrap_or("");
|
|
2357
|
-
let mut obj = serde_json::json!({
|
|
2358
|
-
"turn_id": tid,
|
|
2359
|
-
"role": role,
|
|
2360
|
-
"content": combined,
|
|
2361
|
-
"timestamp": first.created_at,
|
|
2362
|
-
});
|
|
2363
|
-
if let Some(sha) = first.metadata.get(MNEMO_META_SHA256) {
|
|
2364
|
-
obj["sha256"] = sha.clone();
|
|
2365
|
-
}
|
|
2366
|
-
if let Some(len) = first.metadata.get(MNEMO_META_LENGTH) {
|
|
2367
|
-
obj["original_length"] = len.clone();
|
|
2368
|
-
}
|
|
2369
|
-
lines.push(serde_json::to_string(&obj).unwrap_or_else(|_| "{}".into()));
|
|
2370
|
-
}
|
|
2342
|
+
// 12.7d: the shared ingest-shape export (seq order, chunks
|
|
2343
|
+
// joined), so the JSONL matches Python and MCP `thread_export`
|
|
2344
|
+
// and re-ingests cleanly.
|
|
2345
|
+
let turns = db.thread_export_turns(&thread).map_err(fmt)?;
|
|
2346
|
+
let lines: Vec<String> = turns
|
|
2347
|
+
.iter()
|
|
2348
|
+
.map(|t| serde_json::to_string(&t.to_json()).unwrap_or_else(|_| "{}".into()))
|
|
2349
|
+
.collect();
|
|
2371
2350
|
let body = lines.join("\n") + "\n";
|
|
2372
2351
|
match output {
|
|
2373
2352
|
Some(p) => {
|
|
@@ -2377,7 +2356,7 @@ fn handle_thread_cmd(cmd: ThreadCmd) -> std::result::Result<(), String> {
|
|
|
2377
2356
|
.map_err(|e| format!("writing {p}: {e}"))?;
|
|
2378
2357
|
println!(
|
|
2379
2358
|
"exported {} turn(s) from thread '{thread}' to {p}",
|
|
2380
|
-
|
|
2359
|
+
turns.len()
|
|
2381
2360
|
);
|
|
2382
2361
|
}
|
|
2383
2362
|
None => {
|
|
@@ -72,8 +72,8 @@ pub use error::{MnemoError, Result};
|
|
|
72
72
|
pub use index::{IndexConfig, IndexInfo};
|
|
73
73
|
pub use memory::{
|
|
74
74
|
status as essence_status, CommitBatch, CommitReport, EssenceOp, EssenceOpKind, EssenceScope,
|
|
75
|
-
EssenceSection, Filter, FilterTerm, IngestReport, KeyScope, KeyedMemory, Memory,
|
|
76
|
-
MemoryType, Metric, Scope, ScoreWeights, ThreadTurn, TurnPolicy, WriteOutcome,
|
|
75
|
+
EssenceSection, ExportedTurn, Filter, FilterTerm, IngestReport, KeyScope, KeyedMemory, Memory,
|
|
76
|
+
MemoryPatch, MemoryType, Metric, Scope, ScoreWeights, ThreadTurn, TurnPolicy, WriteOutcome,
|
|
77
77
|
CONTINUATION_TIMELINE_ENTRIES, ESSENCE_DEFAULT_RENDER_BYTES, ESSENCE_SECTION_MAX_BYTES,
|
|
78
78
|
ESSENCE_TIMELINE_MAX_BYTES, ESSENCE_TRANSITIONS, FINDING_TRANSITIONS, MNEMO_META_CONTINUES,
|
|
79
79
|
MNEMO_META_INVALID_AT, MNEMO_META_KEY, MNEMO_META_KIND, MNEMO_META_KIND_ESSENCE,
|
|
@@ -309,7 +309,7 @@ fn tools_list() -> Value {
|
|
|
309
309
|
"tools": [
|
|
310
310
|
{
|
|
311
311
|
"name": "about",
|
|
312
|
-
"description": "Read-only briefing for this .mnemo file: manifest scaffold plus any memories tagged as onboarding. Run this first to learn how the file expects to be used.",
|
|
312
|
+
"description": "Read-only briefing for this .mnemo file: manifest scaffold plus any memories tagged as onboarding, then the project essence (conventions, decisions, open items) as a final `{kind: \"essence\", render}` element when the file has one. Run this first to learn how the file expects to be used.",
|
|
313
313
|
"inputSchema": {
|
|
314
314
|
"type": "object",
|
|
315
315
|
"properties": {},
|
|
@@ -391,7 +391,7 @@ fn tools_list() -> Value {
|
|
|
391
391
|
},
|
|
392
392
|
{
|
|
393
393
|
"name": "commit_deltas",
|
|
394
|
-
"description": "
|
|
394
|
+
"description": "Atomic batch write: facts, essence ops and thread archive turns in one call. Every item is checked before anything is written, so an invalid item writes nothing; one flush on success. Facts may omit `vector`: the server embeds every fact `content`, essence text and turn in one batched call with its embedder (`--embed-cmd` or builtin). Use at a session end to save a burst of updates in one round trip. `turn_policy` defaults to `archive`; `expire_after` takes a TTL in seconds; `drop` discards turns. Returns a counts summary.",
|
|
395
395
|
"inputSchema": {
|
|
396
396
|
"type": "object",
|
|
397
397
|
"properties": {
|
|
@@ -403,7 +403,7 @@ fn tools_list() -> Value {
|
|
|
403
403
|
"properties": {
|
|
404
404
|
"content": { "type": "string" },
|
|
405
405
|
"memory_type": { "type": "string", "enum": ["episodic", "semantic", "procedural", "working"] },
|
|
406
|
-
"vector": { "type": "array", "items": { "type": "number" } },
|
|
406
|
+
"vector": { "type": "array", "items": { "type": "number" }, "description": "Optional. Omit it to have the server embed `content`." },
|
|
407
407
|
"importance": { "type": "number", "minimum": 0, "maximum": 1 },
|
|
408
408
|
"agent_id": { "type": "string" },
|
|
409
409
|
"session_id": { "type": "string" },
|
|
@@ -463,6 +463,18 @@ fn tools_list() -> Value {
|
|
|
463
463
|
"additionalProperties": false
|
|
464
464
|
}
|
|
465
465
|
},
|
|
466
|
+
{
|
|
467
|
+
"name": "thread_export",
|
|
468
|
+
"description": "Return a thread's archive in the ingest shape: `[{turn_id, role, content, timestamp}]` in order, one entry per turn (long turns' chunks joined), plus `sha256` and `original_length` on a truncated tool result. Feeding it back to ingest for the same thread adds nothing.",
|
|
469
|
+
"inputSchema": {
|
|
470
|
+
"type": "object",
|
|
471
|
+
"required": ["thread"],
|
|
472
|
+
"properties": {
|
|
473
|
+
"thread": { "type": "string", "description": "Thread id to export." }
|
|
474
|
+
},
|
|
475
|
+
"additionalProperties": false
|
|
476
|
+
}
|
|
477
|
+
},
|
|
466
478
|
{
|
|
467
479
|
"name": "history",
|
|
468
480
|
"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.",
|
|
@@ -641,6 +653,7 @@ fn tools_call(db: &mut Mnemo, params: &Value) -> std::result::Result<Value, RpcE
|
|
|
641
653
|
"update" => tool_update(db, args)?,
|
|
642
654
|
"history" => tool_history(db, args)?,
|
|
643
655
|
"thread_ingest" => tool_thread_ingest(db, args)?,
|
|
656
|
+
"thread_export" => tool_thread_export(db, args)?,
|
|
644
657
|
"thread_start" => tool_thread_start(db, args)?,
|
|
645
658
|
"commit_deltas" => tool_commit_deltas(db, args)?,
|
|
646
659
|
"essence" => tool_essence(db, args)?,
|
|
@@ -707,10 +720,25 @@ fn mnemo_err(e: MnemoError) -> RpcError {
|
|
|
707
720
|
|
|
708
721
|
fn tool_about(db: &mut Mnemo) -> std::result::Result<String, RpcError> {
|
|
709
722
|
let mems = db.about().map_err(mnemo_err)?;
|
|
710
|
-
let arr: Vec<Value> = mems.iter().map(memory_to_json).collect();
|
|
723
|
+
let mut arr: Vec<Value> = mems.iter().map(memory_to_json).collect();
|
|
724
|
+
// Phase 12.7d: the project essence follows the manifest and the
|
|
725
|
+
// onboarding memories, as one tagged element.
|
|
726
|
+
if let Some(render) = db.about_essence().map_err(mnemo_err)? {
|
|
727
|
+
arr.push(json!({ "kind": "essence", "scope": "project", "render": render }));
|
|
728
|
+
}
|
|
711
729
|
Ok(serde_json::to_string_pretty(&arr).unwrap_or_else(|_| "[]".into()))
|
|
712
730
|
}
|
|
713
731
|
|
|
732
|
+
fn tool_thread_export(db: &mut Mnemo, args: &Value) -> std::result::Result<String, RpcError> {
|
|
733
|
+
let thread = args
|
|
734
|
+
.get("thread")
|
|
735
|
+
.and_then(|v| v.as_str())
|
|
736
|
+
.ok_or_else(|| RpcError::new(INVALID_PARAMS, "thread_export: missing 'thread'"))?;
|
|
737
|
+
let turns = db.thread_export_turns(thread).map_err(mnemo_err)?;
|
|
738
|
+
let arr: Vec<Value> = turns.iter().map(|t| t.to_json()).collect();
|
|
739
|
+
Ok(Value::Array(arr).to_string())
|
|
740
|
+
}
|
|
741
|
+
|
|
714
742
|
fn tool_remember(db: &mut Mnemo, args: &Value) -> std::result::Result<String, RpcError> {
|
|
715
743
|
let content = args
|
|
716
744
|
.get("content")
|
|
@@ -942,24 +970,25 @@ fn tool_commit_deltas(db: &mut Mnemo, args: &Value) -> std::result::Result<Strin
|
|
|
942
970
|
format!("commit_deltas: facts[{i}] unknown memory_type '{mtype_str}'"),
|
|
943
971
|
)
|
|
944
972
|
})?;
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
973
|
+
// 12.7d: `vector` is optional. Without one the engine embeds
|
|
974
|
+
// `content` with the server's embedder, batched with the rest
|
|
975
|
+
// of the call.
|
|
976
|
+
let vector = match obj.get("vector") {
|
|
977
|
+
None | Some(Value::Null) => Vec::new(),
|
|
978
|
+
Some(v) => v
|
|
979
|
+
.as_array()
|
|
980
|
+
.and_then(|a| {
|
|
981
|
+
a.iter()
|
|
982
|
+
.map(|x| x.as_f64().map(|f| f as f32))
|
|
983
|
+
.collect::<Option<Vec<f32>>>()
|
|
984
|
+
})
|
|
985
|
+
.ok_or_else(|| {
|
|
986
|
+
RpcError::new(
|
|
987
|
+
INVALID_PARAMS,
|
|
988
|
+
format!("commit_deltas: facts[{i}] vector must be an array of numbers"),
|
|
989
|
+
)
|
|
990
|
+
})?,
|
|
991
|
+
};
|
|
963
992
|
let mut mem = Memory::new(content, mtype, vector);
|
|
964
993
|
if let Some(a) = obj.get("agent_id").and_then(|v| v.as_str()) {
|
|
965
994
|
mem = mem.with_agent(a);
|
|
@@ -489,7 +489,9 @@ pub enum EssenceScope {
|
|
|
489
489
|
/// thread's render only.
|
|
490
490
|
Thread(String),
|
|
491
491
|
/// Shared across every thread in the file. Shows up in every
|
|
492
|
-
/// thread's render, and in the `about
|
|
492
|
+
/// thread's render, and in the `about` briefing: the CLI and MCP
|
|
493
|
+
/// `about` append the project render after the manifest, from
|
|
494
|
+
/// `Mnemo::about_essence()` (12.7d).
|
|
493
495
|
Project,
|
|
494
496
|
}
|
|
495
497
|
|
|
@@ -616,7 +618,9 @@ pub struct EssenceOp {
|
|
|
616
618
|
/// One keyed fact inside a [`CommitBatch`] (Phase 12.7c).
|
|
617
619
|
#[derive(Debug, Clone)]
|
|
618
620
|
pub struct KeyedMemory {
|
|
619
|
-
/// The memory to store.
|
|
621
|
+
/// The memory to store. An **empty `vector`** means "embed
|
|
622
|
+
/// `content` with the registered embedder" (12.7d): every such fact
|
|
623
|
+
/// in a batch is embedded together in one `Embedder::embed` call.
|
|
620
624
|
pub memory: Memory,
|
|
621
625
|
/// Optional 12.1 upsert key.
|
|
622
626
|
pub key: Option<String>,
|
|
@@ -735,6 +739,55 @@ pub struct ThreadTurn {
|
|
|
735
739
|
pub timestamp: Option<i64>,
|
|
736
740
|
}
|
|
737
741
|
|
|
742
|
+
/// One turn of a thread's archive in the **ingest shape** (Phase 12.7d),
|
|
743
|
+
/// as returned by [`crate::Mnemo::thread_export_turns`] and by Python
|
|
744
|
+
/// `db.thread_export`, MCP `thread_export` and `mnemo thread export`.
|
|
745
|
+
///
|
|
746
|
+
/// Turns come back in `_mnemo.seq` order, one entry per source turn: the
|
|
747
|
+
/// 8 KB chunks of a long turn are joined back into one `content`, so
|
|
748
|
+
/// feeding the list to `ingest_thread` (same thread: every turn is
|
|
749
|
+
/// skipped; a new thread: the turns are re-chunked identically) round
|
|
750
|
+
/// trips. A tool result that was truncated at 16 KB carries `sha256` and
|
|
751
|
+
/// `original_length` of the original content.
|
|
752
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
753
|
+
pub struct ExportedTurn {
|
|
754
|
+
/// Source `turn_id` (`_mnemo.turn_id`).
|
|
755
|
+
pub turn_id: String,
|
|
756
|
+
/// Author role (`_mnemo.role`).
|
|
757
|
+
pub role: String,
|
|
758
|
+
/// Stored text, with chunks joined in `_mnemo.part` order.
|
|
759
|
+
pub content: String,
|
|
760
|
+
/// The turn's timestamp (unix seconds; the record's `created_at`).
|
|
761
|
+
pub timestamp: i64,
|
|
762
|
+
/// Hex SHA-256 of the original content, set only for a truncated
|
|
763
|
+
/// tool result.
|
|
764
|
+
pub sha256: Option<String>,
|
|
765
|
+
/// Byte length of the original content, set only for a truncated
|
|
766
|
+
/// tool result.
|
|
767
|
+
pub original_length: Option<u64>,
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
impl ExportedTurn {
|
|
771
|
+
/// The JSON object shared by the MCP tool and the CLI JSONL export:
|
|
772
|
+
/// `{turn_id, role, content, timestamp}` plus `sha256` and
|
|
773
|
+
/// `original_length` when the turn was truncated.
|
|
774
|
+
pub fn to_json(&self) -> serde_json::Value {
|
|
775
|
+
let mut obj = serde_json::json!({
|
|
776
|
+
"turn_id": self.turn_id,
|
|
777
|
+
"role": self.role,
|
|
778
|
+
"content": self.content,
|
|
779
|
+
"timestamp": self.timestamp,
|
|
780
|
+
});
|
|
781
|
+
if let Some(sha) = &self.sha256 {
|
|
782
|
+
obj["sha256"] = serde_json::Value::String(sha.clone());
|
|
783
|
+
}
|
|
784
|
+
if let Some(len) = self.original_length {
|
|
785
|
+
obj["original_length"] = serde_json::Value::Number(len.into());
|
|
786
|
+
}
|
|
787
|
+
obj
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
738
791
|
/// Result of one [`crate::Mnemo::ingest_thread`] call (Phase 12.7a).
|
|
739
792
|
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
|
740
793
|
pub struct IngestReport {
|