mnemo-engine 0.17.1__tar.gz → 0.17.2__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.17.1 → mnemo_engine-0.17.2}/PKG-INFO +1 -1
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/Cargo.lock +3 -3
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/Cargo.toml +1 -1
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/README.md +7 -3
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/guide/guide.md +4 -3
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/hook.rs +39 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/onboard.rs +3 -2
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo.rs +23 -5
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/builtin.rs +222 -17
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/mcp/context.rs +12 -4
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/mcp.rs +19 -3
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/memory.rs +4 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/coordination.rs +109 -4
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/records.rs +7 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/Cargo.lock +2 -2
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/Cargo.toml +1 -1
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/pyproject.toml +1 -1
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/README.md +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/.gitignore +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/benches/corpus.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/build.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/deny.toml +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/ann_diagnose.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/ann_recall_grid.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/candle_hard.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/embedder_server.py +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/file_size_breakdown.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/open_rss.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/quickstart.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/ranking_v2.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/session.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/shared_bench.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/examples/thread_profile.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/export.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/inspect.html +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/inspect.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/mcp_install.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/bin/mnemo/project.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/cache.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/crypto.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/embed.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/embed_cmd.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/error.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/format.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/freelist.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/guide.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/ident.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/index.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/keys/display.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/keys/mod.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/keys/os_store.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/keys/recovery.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/keyslot.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/lib.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/pager.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/redact.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/result_cache.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/session.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/call.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/fscheck.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/lock.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/mod.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/presence.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/shared/sidecar.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/ann.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/cache_api.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/continuation.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/crud.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/essence.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/flush.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/header_graft_tests.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/hooks.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/keyed.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/load.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/maintenance.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/mod.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/open.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/recall.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/shared.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/snapshots.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/store/threads.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/text.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/transcript.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/veccol.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo/src/wal.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/.gitignore +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/README.md +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/src/lib.rs +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/mnemo-python/test_mnemo.py +0 -0
- {mnemo_engine-0.17.1 → mnemo_engine-0.17.2}/python/mnemo_engine/__init__.py +0 -0
|
@@ -1520,7 +1520,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
|
1520
1520
|
|
|
1521
1521
|
[[package]]
|
|
1522
1522
|
name = "mnemo-engine"
|
|
1523
|
-
version = "0.17.
|
|
1523
|
+
version = "0.17.2"
|
|
1524
1524
|
dependencies = [
|
|
1525
1525
|
"aes-gcm",
|
|
1526
1526
|
"apple-native-keyring-store",
|
|
@@ -1561,7 +1561,7 @@ dependencies = [
|
|
|
1561
1561
|
|
|
1562
1562
|
[[package]]
|
|
1563
1563
|
name = "mnemo-node"
|
|
1564
|
-
version = "0.17.
|
|
1564
|
+
version = "0.17.2"
|
|
1565
1565
|
dependencies = [
|
|
1566
1566
|
"mnemo-engine",
|
|
1567
1567
|
"napi",
|
|
@@ -1571,7 +1571,7 @@ dependencies = [
|
|
|
1571
1571
|
|
|
1572
1572
|
[[package]]
|
|
1573
1573
|
name = "mnemo-uniffi"
|
|
1574
|
-
version = "0.17.
|
|
1574
|
+
version = "0.17.2"
|
|
1575
1575
|
dependencies = [
|
|
1576
1576
|
"mnemo-engine",
|
|
1577
1577
|
"serde_json",
|
|
@@ -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.17.
|
|
13
|
+
version = "0.17.2"
|
|
14
14
|
edition = "2021"
|
|
15
15
|
rust-version = "1.94"
|
|
16
16
|
# `benches/corpus.rs` is a shared helper module pulled into real benches
|
|
@@ -107,8 +107,9 @@ which would leak into shell history and process listings). Tools exposed:
|
|
|
107
107
|
`MNEMO_ROLE`; `visibility` for private ones), `task` (the shared work queue: `next`, `update`, `add`,
|
|
108
108
|
`list`, `get`) and `claim` (`take`, `renew`, `release`, `check`, `who`). A
|
|
109
109
|
`serve --mcp --shared` with `MNEMO_AGENT` holds that agent's presence lock
|
|
110
|
-
in the sidecar directory for its life,
|
|
111
|
-
|
|
110
|
+
in the sidecar directory for its life, and since v0.17.2 writes its
|
|
111
|
+
presence record at start, so `who` sees it alive before its first call; it
|
|
112
|
+
never holds the brain's lock between calls. Since v0.17, `recall` and `about` take `visibility` (private records only when asked), and `about` with `stale: true` lists the stale records. Every mutation flushes before
|
|
112
113
|
returning.
|
|
113
114
|
|
|
114
115
|
With no `--embed-cmd`, the server embeds `text` with the built-in embedder
|
|
@@ -139,7 +140,7 @@ On `initialize`, the server sends the guide's card as its `instructions`
|
|
|
139
140
|
|
|
140
141
|
| Resource | What it holds | Limit |
|
|
141
142
|
|---|---|---|
|
|
142
|
-
| `mnemo://about` | The card, then the brain's briefing (the manifest and onboarding memories) and the project essence | 8,000 bytes |
|
|
143
|
+
| `mnemo://about` | The card, then the counts (as `mnemo about`'s header, since v0.17.2), the brain's briefing (the manifest and onboarding memories) and the project essence | 8,000 bytes |
|
|
143
144
|
| `mnemo://recent` | The 20 most recently written memories, newest first, a line each | 6,000 bytes |
|
|
144
145
|
| `mnemo://guide` | The whole guide | Its size |
|
|
145
146
|
| `mnemo://key/{key}` (a template) | A key's live value, then its earlier versions | 4,000 bytes |
|
|
@@ -391,6 +392,9 @@ mnemo cache purge agent.mnemo --ns llm --expired
|
|
|
391
392
|
mnemo cache delete agent.mnemo --ns llm --key prompt-42
|
|
392
393
|
```
|
|
393
394
|
|
|
395
|
+
Since v0.17.2 the path may be left out in a git repository, as with `get`:
|
|
396
|
+
`mnemo cache get --ns llm --key prompt-42` uses this project's brain.
|
|
397
|
+
|
|
394
398
|
**MCP:** `mnemo serve --mcp` exposes `cache_put`, `cache_get`,
|
|
395
399
|
`cache_stats`, `cache_put_semantic`, and `cache_get_semantic` as
|
|
396
400
|
tools (Phase 10.4) — any MCP-compatible agent can drive the cache
|
|
@@ -378,11 +378,12 @@ of one.
|
|
|
378
378
|
|
|
379
379
|
- **Every turn:** the `user-prompt` hook adds a short line when something
|
|
380
380
|
is new for you (a message, a task ready for your role, a claim of yours
|
|
381
|
-
about to lapse
|
|
382
|
-
call, at most once a
|
|
381
|
+
about to lapse, a task you added that's `ready` for your `done`), and
|
|
382
|
+
nothing otherwise. Cursor runs it after a tool call, at most once a
|
|
383
|
+
minute.
|
|
383
384
|
- **When a turn ends,** with `onboard --wake stop`: the Stop hook keeps
|
|
384
385
|
you going for a pre-approved task for your role or a message to you by
|
|
385
|
-
name
|
|
386
|
+
name, never for a task that waits for your `done`. It's off by default.
|
|
386
387
|
- **In Claude Code, wake a peer yourself:** after you post or add a task,
|
|
387
388
|
send the session a short pointer with Claude Code's `SendMessage` ("new
|
|
388
389
|
work in your inbox"). The inbox is the record, and the message is only
|
|
@@ -692,6 +692,27 @@ fn your_work(db: &mut Mnemo) -> String {
|
|
|
692
692
|
}
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
|
+
// READY-NOTICE: tasks it created that wait for its `done`.
|
|
696
|
+
if let Some(a) = &agent {
|
|
697
|
+
if let Ok(ts) = db.tasks(Some(mnemo_engine::task_status::READY), None) {
|
|
698
|
+
let mine: Vec<String> = ts
|
|
699
|
+
.iter()
|
|
700
|
+
.filter(|t| &t.creator == a)
|
|
701
|
+
.map(|t| format!("- {}: {}", esc(&t.slug), esc(&t.title)))
|
|
702
|
+
.collect();
|
|
703
|
+
if !mine.is_empty() {
|
|
704
|
+
sections.push((
|
|
705
|
+
format!(
|
|
706
|
+
"{} of your tasks {} for your done (call `task` with `list`, then \
|
|
707
|
+
`update --status done`):",
|
|
708
|
+
mine.len(),
|
|
709
|
+
plural(mine.len(), "waits", "wait")
|
|
710
|
+
),
|
|
711
|
+
mine,
|
|
712
|
+
));
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
695
716
|
// Its own tasks' claims about to lapse.
|
|
696
717
|
if let Some(a) = &agent {
|
|
697
718
|
if let Ok(claims) = db.claims() {
|
|
@@ -1002,6 +1023,13 @@ pub fn turn_text(work: &mnemo_engine::NewWork, now: i64) -> String {
|
|
|
1002
1023
|
"claims lapsing soon",
|
|
1003
1024
|
));
|
|
1004
1025
|
}
|
|
1026
|
+
if !work.ready_for_done.is_empty() {
|
|
1027
|
+
counts.push(n(
|
|
1028
|
+
work.ready_for_done.len(),
|
|
1029
|
+
"task ready for your `done`",
|
|
1030
|
+
"tasks ready for your `done`",
|
|
1031
|
+
));
|
|
1032
|
+
}
|
|
1005
1033
|
// What to call, for only what the counts hold (ONBOARD-UX).
|
|
1006
1034
|
let mut calls = Vec::new();
|
|
1007
1035
|
let it = |k: usize, one: &'static str, many: &'static str| if k == 1 { one } else { many };
|
|
@@ -1023,6 +1051,10 @@ pub fn turn_text(work: &mnemo_engine::NewWork, now: i64) -> String {
|
|
|
1023
1051
|
it(work.lapsing.len(), "its claim", "their claims")
|
|
1024
1052
|
));
|
|
1025
1053
|
}
|
|
1054
|
+
// READY-NOTICE: fixed text; the slugs are items, after the framing.
|
|
1055
|
+
if !work.ready_for_done.is_empty() {
|
|
1056
|
+
calls.push("Call `task` with `list`, then `update --status done`.".to_string());
|
|
1057
|
+
}
|
|
1026
1058
|
let head = format!(
|
|
1027
1059
|
"mnemo: new for you: {}. {}\n{}",
|
|
1028
1060
|
counts.join(", "),
|
|
@@ -1033,6 +1065,13 @@ pub fn turn_text(work: &mnemo_engine::NewWork, now: i64) -> String {
|
|
|
1033
1065
|
for t in &work.tasks {
|
|
1034
1066
|
items.push(format!("- task {}: {}", esc(&t.slug), esc(&t.title)));
|
|
1035
1067
|
}
|
|
1068
|
+
for t in &work.ready_for_done {
|
|
1069
|
+
items.push(format!(
|
|
1070
|
+
"- ready for your done: {}: {}",
|
|
1071
|
+
esc(&t.slug),
|
|
1072
|
+
esc(&t.title)
|
|
1073
|
+
));
|
|
1074
|
+
}
|
|
1036
1075
|
for c in &work.lapsing {
|
|
1037
1076
|
items.push(format!(
|
|
1038
1077
|
"- your claim {} lapses in {} min",
|
|
@@ -1780,7 +1780,8 @@ fn summary_tty(
|
|
|
1780
1780
|
}
|
|
1781
1781
|
}
|
|
1782
1782
|
println!();
|
|
1783
|
-
|
|
1783
|
+
// TTY-BACKTICKS: plain text on a terminal, no Markdown.
|
|
1784
|
+
println!("The guide for agents: mnemo onboard --guide");
|
|
1784
1785
|
}
|
|
1785
1786
|
|
|
1786
1787
|
/// A step as a sentence: a capital first, a full stop last.
|
|
@@ -2109,7 +2110,7 @@ fn run_person(v: &View, o: &Opts, changes: usize) -> Result<(), String> {
|
|
|
2109
2110
|
println!();
|
|
2110
2111
|
if o.print || !interactive() {
|
|
2111
2112
|
println!(
|
|
2112
|
-
"Nothing was written; run
|
|
2113
|
+
"Nothing was written; run mnemo onboard{} --yes to write it.",
|
|
2113
2114
|
if o.undo { " --undo" } else { "" }
|
|
2114
2115
|
);
|
|
2115
2116
|
if o.print {
|
|
@@ -91,6 +91,14 @@ fn brain_arg(cmd: &mut Command) -> Option<&mut String> {
|
|
|
91
91
|
| Command::Mcp {
|
|
92
92
|
cmd: McpCmd::Install { path, .. },
|
|
93
93
|
}
|
|
94
|
+
| Command::Cache {
|
|
95
|
+
op:
|
|
96
|
+
CacheOp::Get { path, .. }
|
|
97
|
+
| CacheOp::Put { path, .. }
|
|
98
|
+
| CacheOp::Delete { path, .. }
|
|
99
|
+
| CacheOp::Stats { path, .. }
|
|
100
|
+
| CacheOp::Purge { path, .. },
|
|
101
|
+
}
|
|
94
102
|
| Command::Thread {
|
|
95
103
|
cmd:
|
|
96
104
|
ThreadCmd::Ingest { path, .. }
|
|
@@ -1756,7 +1764,9 @@ enum CacheOp {
|
|
|
1756
1764
|
/// Look up a key; prints the value to stdout on hit, non-zero
|
|
1757
1765
|
/// exit on miss.
|
|
1758
1766
|
Get {
|
|
1759
|
-
/// Path to the `.mnemo` file.
|
|
1767
|
+
/// Path to the `.mnemo` file. Leave it out for this project's brain
|
|
1768
|
+
/// (v0.17.2), as with `get`.
|
|
1769
|
+
#[arg(default_value = "", hide_default_value = true)]
|
|
1760
1770
|
path: String,
|
|
1761
1771
|
/// Cache namespace.
|
|
1762
1772
|
#[arg(long)]
|
|
@@ -1770,7 +1780,9 @@ enum CacheOp {
|
|
|
1770
1780
|
/// Insert or overwrite an entry. Either `--value <string>` (UTF-8)
|
|
1771
1781
|
/// or `--file <path>` (raw bytes) must be provided.
|
|
1772
1782
|
Put {
|
|
1773
|
-
/// Path to the `.mnemo` file.
|
|
1783
|
+
/// Path to the `.mnemo` file. Leave it out for this project's brain
|
|
1784
|
+
/// (v0.17.2), as with `get`.
|
|
1785
|
+
#[arg(default_value = "", hide_default_value = true)]
|
|
1774
1786
|
path: String,
|
|
1775
1787
|
#[arg(long)]
|
|
1776
1788
|
ns: String,
|
|
@@ -1794,7 +1806,9 @@ enum CacheOp {
|
|
|
1794
1806
|
},
|
|
1795
1807
|
/// Tombstone an entry. Space reclaimed by `mnemo compact`.
|
|
1796
1808
|
Delete {
|
|
1797
|
-
/// Path to the `.mnemo` file.
|
|
1809
|
+
/// Path to the `.mnemo` file. Leave it out for this project's brain
|
|
1810
|
+
/// (v0.17.2), as with `get`.
|
|
1811
|
+
#[arg(default_value = "", hide_default_value = true)]
|
|
1798
1812
|
path: String,
|
|
1799
1813
|
#[arg(long)]
|
|
1800
1814
|
ns: String,
|
|
@@ -1806,7 +1820,9 @@ enum CacheOp {
|
|
|
1806
1820
|
/// Print cache statistics as JSON. `--ns` restricts to one
|
|
1807
1821
|
/// namespace; without it the whole cache is summarized.
|
|
1808
1822
|
Stats {
|
|
1809
|
-
/// Path to the `.mnemo` file.
|
|
1823
|
+
/// Path to the `.mnemo` file. Leave it out for this project's brain
|
|
1824
|
+
/// (v0.17.2), as with `get`.
|
|
1825
|
+
#[arg(default_value = "", hide_default_value = true)]
|
|
1810
1826
|
path: String,
|
|
1811
1827
|
#[arg(long)]
|
|
1812
1828
|
ns: Option<String>,
|
|
@@ -1817,7 +1833,9 @@ enum CacheOp {
|
|
|
1817
1833
|
/// `--expired` restricts to TTL-expired entries only; otherwise
|
|
1818
1834
|
/// every live entry in the scope is tombstoned.
|
|
1819
1835
|
Purge {
|
|
1820
|
-
/// Path to the `.mnemo` file.
|
|
1836
|
+
/// Path to the `.mnemo` file. Leave it out for this project's brain
|
|
1837
|
+
/// (v0.17.2), as with `get`.
|
|
1838
|
+
#[arg(default_value = "", hide_default_value = true)]
|
|
1821
1839
|
path: String,
|
|
1822
1840
|
#[arg(long)]
|
|
1823
1841
|
ns: Option<String>,
|
|
@@ -304,10 +304,96 @@ fn remove_stale_parts(dir: &Path) {
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/// MODEL-RETRY (v0.17.2): the waits before the second and third tries of a
|
|
308
|
+
/// download that failed in a way that may pass.
|
|
309
|
+
const RETRY_BACKOFF: [std::time::Duration; 2] = [
|
|
310
|
+
std::time::Duration::from_secs(1),
|
|
311
|
+
std::time::Duration::from_secs(4),
|
|
312
|
+
];
|
|
313
|
+
|
|
307
314
|
/// Download `url` to `dest`, through a temporary file beside it that
|
|
308
|
-
/// replaces `dest` only once its size and SHA-256 match.
|
|
315
|
+
/// replaces `dest` only once its size and SHA-256 match. A reset
|
|
316
|
+
/// connection, a timeout, a body cut short or a 5xx is tried twice more,
|
|
317
|
+
/// with a line on stderr each time; a 4xx, a refused connection, a size or
|
|
318
|
+
/// SHA-256 that doesn't match, or a local write error isn't.
|
|
309
319
|
pub(crate) fn fetch(url: &str, dest: &Path, sha256: &str, size: u64) -> Result<()> {
|
|
320
|
+
fetch_with(url, dest, sha256, size, &RETRY_BACKOFF, &mut |m| {
|
|
321
|
+
eprintln!("{m}")
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/// [`fetch`] with its waits and its notice given (the tests' short ones).
|
|
326
|
+
fn fetch_with(
|
|
327
|
+
url: &str,
|
|
328
|
+
dest: &Path,
|
|
329
|
+
sha256: &str,
|
|
330
|
+
size: u64,
|
|
331
|
+
backoff: &[std::time::Duration],
|
|
332
|
+
notice: &mut dyn FnMut(&str),
|
|
333
|
+
) -> Result<()> {
|
|
334
|
+
let name = dest
|
|
335
|
+
.file_name()
|
|
336
|
+
.and_then(|n| n.to_str())
|
|
337
|
+
.unwrap_or("model file");
|
|
338
|
+
let tries = backoff.len() + 1;
|
|
339
|
+
let mut attempt = 1;
|
|
340
|
+
loop {
|
|
341
|
+
match fetch_once(url, dest, sha256, size) {
|
|
342
|
+
Ok(()) => return Ok(()),
|
|
343
|
+
Err(Attempt { error, retry }) => {
|
|
344
|
+
let Some(wait) = backoff.get(attempt - 1).filter(|_| retry) else {
|
|
345
|
+
return Err(error);
|
|
346
|
+
};
|
|
347
|
+
notice(&format!(
|
|
348
|
+
"mnemo: {error}; trying {name} again in {} s ({} of {tries})",
|
|
349
|
+
wait.as_secs_f32(),
|
|
350
|
+
attempt + 1
|
|
351
|
+
));
|
|
352
|
+
std::thread::sleep(*wait);
|
|
353
|
+
attempt += 1;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/// One download's failure, and whether another try may pass.
|
|
360
|
+
struct Attempt {
|
|
361
|
+
error: MnemoError,
|
|
362
|
+
retry: bool,
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/// Whether a request error may pass on another try: a timeout, a reset
|
|
366
|
+
/// or cut connection, or a 5xx. Not a refused connection, an unknown host,
|
|
367
|
+
/// or a 4xx.
|
|
368
|
+
fn may_pass(e: &ureq::Error) -> bool {
|
|
369
|
+
match e {
|
|
370
|
+
ureq::Error::StatusCode(code) => *code >= 500,
|
|
371
|
+
ureq::Error::Timeout(_) | ureq::Error::BodyStalled => true,
|
|
372
|
+
ureq::Error::Io(io) => cut_short(io),
|
|
373
|
+
_ => false,
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/// An I/O error from a connection that was reset, cut or timed out.
|
|
378
|
+
fn cut_short(e: &std::io::Error) -> bool {
|
|
379
|
+
use std::io::ErrorKind::*;
|
|
380
|
+
matches!(
|
|
381
|
+
e.kind(),
|
|
382
|
+
ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut | UnexpectedEof | Interrupted
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/// One try of [`fetch`].
|
|
387
|
+
fn fetch_once(url: &str, dest: &Path, sha256: &str, size: u64) -> std::result::Result<(), Attempt> {
|
|
310
388
|
let fail = |what: String| MnemoError::Invalid(format!("the built-in embedder's {what}"));
|
|
389
|
+
let last = |what: String| Attempt {
|
|
390
|
+
error: fail(what),
|
|
391
|
+
retry: false,
|
|
392
|
+
};
|
|
393
|
+
let again = |what: String| Attempt {
|
|
394
|
+
error: fail(what),
|
|
395
|
+
retry: true,
|
|
396
|
+
};
|
|
311
397
|
let name = dest
|
|
312
398
|
.file_name()
|
|
313
399
|
.and_then(|n| n.to_str())
|
|
@@ -318,10 +404,10 @@ pub(crate) fn fetch(url: &str, dest: &Path, sha256: &str, size: u64) -> Result<(
|
|
|
318
404
|
.user_agent(concat!("mnemo/", env!("CARGO_PKG_VERSION")))
|
|
319
405
|
.build()
|
|
320
406
|
.into();
|
|
321
|
-
let mut resp = agent
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
407
|
+
let mut resp = agent.get(url).call().map_err(|e| Attempt {
|
|
408
|
+
retry: may_pass(&e),
|
|
409
|
+
error: fail(format!("download of {name} failed ({url}): {e}")),
|
|
410
|
+
})?;
|
|
325
411
|
let tmp = dest.with_file_name(format!("{name}.{}.part", std::process::id()));
|
|
326
412
|
let result = (|| {
|
|
327
413
|
// `create_new`: never through a link, or over another writer's file.
|
|
@@ -329,7 +415,7 @@ pub(crate) fn fetch(url: &str, dest: &Path, sha256: &str, size: u64) -> Result<(
|
|
|
329
415
|
.write(true)
|
|
330
416
|
.create_new(true)
|
|
331
417
|
.open(&tmp)
|
|
332
|
-
.map_err(|e|
|
|
418
|
+
.map_err(|e| last(format!("download can't write {}: {e}", tmp.display())))?;
|
|
333
419
|
// One byte over the size is enough to tell a too-long body.
|
|
334
420
|
let mut body = resp.body_mut().with_config().limit(size + 1).reader();
|
|
335
421
|
let mut hasher = Sha256::new();
|
|
@@ -341,40 +427,47 @@ pub(crate) fn fetch(url: &str, dest: &Path, sha256: &str, size: u64) -> Result<(
|
|
|
341
427
|
Ok(n) => n,
|
|
342
428
|
Err(e) => {
|
|
343
429
|
// ureq reports the limit as an error: the body is too long.
|
|
344
|
-
|
|
345
|
-
|
|
430
|
+
let over = e
|
|
431
|
+
.get_ref()
|
|
432
|
+
.and_then(|i| i.downcast_ref::<ureq::Error>())
|
|
433
|
+
.is_some_and(|u| matches!(u, ureq::Error::BodyExceedsLimit(_)));
|
|
434
|
+
if over {
|
|
435
|
+
return Err(last(format!(
|
|
346
436
|
"{name} is larger than the {size} bytes pinned"
|
|
347
437
|
)));
|
|
348
438
|
}
|
|
349
|
-
|
|
439
|
+
// Cut off mid-body: a reset or a stall.
|
|
440
|
+
return Err(again(format!("download of {name} failed: {e}")));
|
|
350
441
|
}
|
|
351
442
|
};
|
|
352
443
|
got += n as u64;
|
|
353
444
|
if got > size {
|
|
354
|
-
return Err(
|
|
445
|
+
return Err(last(format!(
|
|
355
446
|
"{name} is larger than the {size} bytes pinned"
|
|
356
447
|
)));
|
|
357
448
|
}
|
|
358
449
|
hasher.update(&buf[..n]);
|
|
359
450
|
out.write_all(&buf[..n])
|
|
360
|
-
.map_err(|e|
|
|
451
|
+
.map_err(|e| last(format!("download can't write {}: {e}", tmp.display())))?;
|
|
361
452
|
}
|
|
362
453
|
if got != size {
|
|
363
|
-
|
|
454
|
+
// Shorter than pinned: the connection closed early.
|
|
455
|
+
return Err(again(format!(
|
|
364
456
|
"{name} is {got} bytes, not the {size} pinned (an interrupted download?)"
|
|
365
457
|
)));
|
|
366
458
|
}
|
|
367
459
|
let digest = hex(&hasher.finalize());
|
|
368
460
|
if digest != sha256 {
|
|
369
|
-
|
|
461
|
+
// Never tried again: the file served isn't the one pinned.
|
|
462
|
+
return Err(last(format!(
|
|
370
463
|
"{name} doesn't match its pinned SHA-256 (got {digest}); nothing was installed"
|
|
371
464
|
)));
|
|
372
465
|
}
|
|
373
466
|
out.sync_all()
|
|
374
|
-
.map_err(|e|
|
|
467
|
+
.map_err(|e| last(format!("download can't write {}: {e}", tmp.display())))?;
|
|
375
468
|
drop(out);
|
|
376
469
|
std::fs::rename(&tmp, dest)
|
|
377
|
-
.map_err(|e|
|
|
470
|
+
.map_err(|e| last(format!("download can't move {name} into place: {e}")))
|
|
378
471
|
})();
|
|
379
472
|
if result.is_err() {
|
|
380
473
|
let _ = std::fs::remove_file(&tmp);
|
|
@@ -635,22 +728,134 @@ mod tests {
|
|
|
635
728
|
assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 1);
|
|
636
729
|
|
|
637
730
|
// Too short and too long.
|
|
638
|
-
|
|
731
|
+
// One try each (MODEL-RETRY retries a short body; this serves once).
|
|
732
|
+
let e = fetch_with(
|
|
639
733
|
&serve_once(body.clone()),
|
|
640
734
|
&dest,
|
|
641
735
|
&sha,
|
|
642
736
|
body.len() as u64 + 5,
|
|
737
|
+
&[],
|
|
738
|
+
&mut |_| {},
|
|
643
739
|
)
|
|
644
740
|
.unwrap_err()
|
|
645
741
|
.to_string();
|
|
646
742
|
assert!(e.contains("not the"), "{e}");
|
|
647
|
-
let e =
|
|
743
|
+
let e = fetch_with(&serve_once(body.clone()), &dest, &sha, 4, &[], &mut |_| {})
|
|
648
744
|
.unwrap_err()
|
|
649
745
|
.to_string();
|
|
650
746
|
assert!(e.contains("larger than"), "{e}");
|
|
651
747
|
assert_eq!(std::fs::read_dir(dir.path()).unwrap().count(), 1);
|
|
652
748
|
}
|
|
653
749
|
|
|
750
|
+
/// What the scripted server answers to one connection.
|
|
751
|
+
#[derive(Clone, Copy)]
|
|
752
|
+
enum Reply {
|
|
753
|
+
/// The headers and half the body, then the connection closes.
|
|
754
|
+
Cut,
|
|
755
|
+
/// The whole body.
|
|
756
|
+
Full,
|
|
757
|
+
/// A status with no body.
|
|
758
|
+
Status(u16),
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/// Answer each connection with the next reply (the last one again when
|
|
762
|
+
/// they run out); returns the URL and a count of the requests.
|
|
763
|
+
fn serve_script(
|
|
764
|
+
replies: Vec<Reply>,
|
|
765
|
+
body: Vec<u8>,
|
|
766
|
+
) -> (String, std::sync::Arc<std::sync::atomic::AtomicUsize>) {
|
|
767
|
+
use std::sync::atomic::Ordering;
|
|
768
|
+
let l = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
769
|
+
let addr = l.local_addr().unwrap();
|
|
770
|
+
let count = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
|
771
|
+
let served = count.clone();
|
|
772
|
+
std::thread::spawn(move || {
|
|
773
|
+
for s in l.incoming() {
|
|
774
|
+
let Ok(mut s) = s else { continue };
|
|
775
|
+
let mut r = std::io::BufReader::new(s.try_clone().unwrap());
|
|
776
|
+
let mut line = String::new();
|
|
777
|
+
while r.read_line(&mut line).unwrap_or(0) > 0 && line != "\r\n" {
|
|
778
|
+
line.clear();
|
|
779
|
+
}
|
|
780
|
+
let i = served.fetch_add(1, Ordering::SeqCst);
|
|
781
|
+
let reply = *replies.get(i).or(replies.last()).unwrap();
|
|
782
|
+
let head = |code: u16, len: usize| {
|
|
783
|
+
format!(
|
|
784
|
+
"HTTP/1.1 {code} X\r\nContent-Length: {len}\r\nConnection: close\r\n\r\n"
|
|
785
|
+
)
|
|
786
|
+
};
|
|
787
|
+
let _ = match reply {
|
|
788
|
+
Reply::Cut => s
|
|
789
|
+
.write_all(head(200, body.len()).as_bytes())
|
|
790
|
+
.and_then(|_| s.write_all(&body[..body.len() / 2])),
|
|
791
|
+
Reply::Full => s
|
|
792
|
+
.write_all(head(200, body.len()).as_bytes())
|
|
793
|
+
.and_then(|_| s.write_all(&body)),
|
|
794
|
+
Reply::Status(code) => s.write_all(head(code, 0).as_bytes()),
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
(format!("http://{addr}/f"), count)
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/// MODEL-RETRY: a download cut short is tried again, and a 5xx twice
|
|
802
|
+
/// more, each with a notice; a 4xx and a SHA-256 mismatch aren't, and
|
|
803
|
+
/// the last error is the one a single try gives.
|
|
804
|
+
#[test]
|
|
805
|
+
fn a_download_retries_only_what_may_pass() {
|
|
806
|
+
use std::sync::atomic::Ordering;
|
|
807
|
+
let fast = [std::time::Duration::from_millis(10); 2];
|
|
808
|
+
let body = b"{\"hidden_size\": 384, \"layers\": 6}".to_vec();
|
|
809
|
+
let sha = hex(&Sha256::digest(&body));
|
|
810
|
+
let n = body.len() as u64;
|
|
811
|
+
let run = |replies: Vec<Reply>, sha: &str, backoff: &[std::time::Duration]| {
|
|
812
|
+
let dir = tempfile::tempdir().unwrap();
|
|
813
|
+
let dest = dir.path().join("config.json");
|
|
814
|
+
let (url, count) = serve_script(replies, body.clone());
|
|
815
|
+
let mut notices = Vec::new();
|
|
816
|
+
let r = fetch_with(&url, &dest, sha, n, backoff, &mut |m| {
|
|
817
|
+
notices.push(m.to_string())
|
|
818
|
+
});
|
|
819
|
+
let installed = std::fs::read(&dest).ok();
|
|
820
|
+
(r, count.load(Ordering::SeqCst), notices, installed)
|
|
821
|
+
};
|
|
822
|
+
// Cut short, then whole: installed on the second try.
|
|
823
|
+
let (r, count, notices, installed) = run(vec![Reply::Cut, Reply::Full], &sha, &fast);
|
|
824
|
+
assert!(r.is_ok(), "{r:?}");
|
|
825
|
+
assert_eq!((count, installed.as_deref()), (2, Some(&body[..])));
|
|
826
|
+
assert_eq!(notices.len(), 1, "{notices:?}");
|
|
827
|
+
assert!(
|
|
828
|
+
notices[0].contains("trying config.json again") && notices[0].contains("(2 of 3)"),
|
|
829
|
+
"{notices:?}"
|
|
830
|
+
);
|
|
831
|
+
// Three 503s: three tries, two notices, and today's error.
|
|
832
|
+
let (r, count, notices, installed) = run(vec![Reply::Status(503)], &sha, &fast);
|
|
833
|
+
let (once, one, _, _) = run(vec![Reply::Status(503)], &sha, &[]);
|
|
834
|
+
assert_eq!((count, notices.len(), installed), (3, 2, None));
|
|
835
|
+
assert_eq!(one, 1);
|
|
836
|
+
let (r, once) = (r.unwrap_err().to_string(), once.unwrap_err().to_string());
|
|
837
|
+
assert!(r.contains("503"), "{r}");
|
|
838
|
+
assert_eq!(
|
|
839
|
+
r.replace(&r[r.find("http://").unwrap()..r.find("/f").unwrap()], ""),
|
|
840
|
+
once.replace(
|
|
841
|
+
&once[once.find("http://").unwrap()..once.find("/f").unwrap()],
|
|
842
|
+
""
|
|
843
|
+
)
|
|
844
|
+
);
|
|
845
|
+
// A 404: once, no notice.
|
|
846
|
+
let (r, count, notices, _) = run(vec![Reply::Status(404)], &sha, &fast);
|
|
847
|
+
assert!(r.unwrap_err().to_string().contains("404"));
|
|
848
|
+
assert_eq!((count, notices.len()), (1, 0));
|
|
849
|
+
// A SHA-256 mismatch: once, nothing installed.
|
|
850
|
+
let wrong = "0".repeat(64);
|
|
851
|
+
let (r, count, notices, installed) = run(vec![Reply::Full], &wrong, &fast);
|
|
852
|
+
assert!(r
|
|
853
|
+
.unwrap_err()
|
|
854
|
+
.to_string()
|
|
855
|
+
.contains("doesn't match its pinned SHA-256"));
|
|
856
|
+
assert_eq!((count, notices.len(), installed), (1, 0, None));
|
|
857
|
+
}
|
|
858
|
+
|
|
654
859
|
#[test]
|
|
655
860
|
fn an_unreachable_server_is_an_error_not_a_hang() {
|
|
656
861
|
let l = TcpListener::bind("127.0.0.1:0").unwrap();
|
|
@@ -188,13 +188,21 @@ pub(super) fn resources_read(
|
|
|
188
188
|
Ok(json!({ "contents": [ { "uri": uri, "mimeType": MD, "text": text } ] }))
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
/// `mnemo://about`: the card, the framing line, the
|
|
192
|
-
///
|
|
191
|
+
/// `mnemo://about`: the card, the framing line, the counts (as `mnemo
|
|
192
|
+
/// about`'s header, v0.17.2), the onboarding memories (the manifest first)
|
|
193
|
+
/// and the project essence.
|
|
193
194
|
pub(super) fn about_text(m: &mut Mnemo) -> std::result::Result<String, RpcError> {
|
|
195
|
+
let memories = m.stats().map_err(mnemo_err)?.memories;
|
|
196
|
+
let c = m.kind_counts();
|
|
194
197
|
let mut out = format!(
|
|
195
|
-
"{}\n\n{}\n\n## About this brain\n
|
|
198
|
+
"{}\n\n{}\n\n## About this brain\n\n{memories} memories: {} facts, {} turns, {} essence, \
|
|
199
|
+
{} coordination\n",
|
|
196
200
|
guide::card(),
|
|
197
|
-
guide::FRAMING
|
|
201
|
+
guide::FRAMING,
|
|
202
|
+
c.facts,
|
|
203
|
+
c.turns,
|
|
204
|
+
c.essence,
|
|
205
|
+
c.coordination
|
|
198
206
|
);
|
|
199
207
|
let mems = m.about().map_err(mnemo_err)?;
|
|
200
208
|
if mems.is_empty() {
|
|
@@ -774,9 +774,11 @@ fn tool_claim(db: &mut Mnemo, args: &Value) -> std::result::Result<String, RpcEr
|
|
|
774
774
|
json!({
|
|
775
775
|
"agent": p.agent, "role": p.role, "tool": p.tool,
|
|
776
776
|
"last_active": p.last_active,
|
|
777
|
+
// WHO-SHAPE (v0.17.2): the CLI's strings, which
|
|
778
|
+
// say what a boolean can't.
|
|
777
779
|
"alive": match p.alive {
|
|
778
|
-
crate::Alive::Yes => json!(
|
|
779
|
-
crate::Alive::No => json!(
|
|
780
|
+
crate::Alive::Yes => json!("yes"),
|
|
781
|
+
crate::Alive::No => json!("no"),
|
|
780
782
|
crate::Alive::Unknown => json!("unknown"),
|
|
781
783
|
},
|
|
782
784
|
"claims": p.claims,
|
|
@@ -958,7 +960,21 @@ fn serve_inner<R: Read, W: Write>(
|
|
|
958
960
|
// lapse early once it's gone. It never touches the brain's lock.
|
|
959
961
|
if let Some(a) = &named {
|
|
960
962
|
match s.hold_presence() {
|
|
961
|
-
Ok(()) =>
|
|
963
|
+
Ok(()) => {
|
|
964
|
+
eprintln!("mnemo mcp: holding {a}'s presence lock");
|
|
965
|
+
// PRESENCE-AT-START (v0.17.2): the presence record,
|
|
966
|
+
// with the lock flag, written once now in one short
|
|
967
|
+
// write window, so `who` sees this session alive
|
|
968
|
+
// before its first write. Never a failed start.
|
|
969
|
+
let role = SERVER_ROLE.with(|r| r.borrow().clone());
|
|
970
|
+
match s.write(|db| db.touch_presence(role.as_deref(), Some("mcp"))) {
|
|
971
|
+
Ok(_) => eprintln!("mnemo mcp: {a} is present (tool mcp)"),
|
|
972
|
+
Err(e) => eprintln!(
|
|
973
|
+
"mnemo mcp: note: {a}'s presence wasn't written at start ({e}); \
|
|
974
|
+
the first write tool call writes it"
|
|
975
|
+
),
|
|
976
|
+
}
|
|
977
|
+
}
|
|
962
978
|
Err(e) => eprintln!("mnemo mcp: no presence lock for {a}: {e}"),
|
|
963
979
|
}
|
|
964
980
|
}
|
|
@@ -657,6 +657,10 @@ pub const MNEMO_META_WAKES: &str = "_mnemo.wakes";
|
|
|
657
657
|
/// 13a (RB-012.6 item 4): the agents a message to a role or everyone, or a
|
|
658
658
|
/// role's task, has been shown to.
|
|
659
659
|
pub const MNEMO_META_SEEN_BY: &str = "_mnemo.seen_by";
|
|
660
|
+
/// 13a (READY-NOTICE, v0.17.2): the agents a `ready` task has been shown
|
|
661
|
+
/// to as waiting for their `done`. Apart from [`MNEMO_META_SEEN_BY`]: a
|
|
662
|
+
/// creator of the task's own role was shown it while it was queued.
|
|
663
|
+
pub const MNEMO_META_READY_SEEN_BY: &str = "_mnemo.ready_seen_by";
|
|
660
664
|
/// 13a (13.1b): the claim expiry its holder was last warned about.
|
|
661
665
|
pub const MNEMO_META_WARNED_EXPIRY: &str = "_mnemo.warned_expiry";
|
|
662
666
|
|
|
@@ -161,6 +161,30 @@ fn seen_by(m: &Memory) -> Vec<String> {
|
|
|
161
161
|
.unwrap_or_default()
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/// COORD-LEGACY-SCAN: whether a stored (fp16) vector is the sentinel every
|
|
165
|
+
/// coordination record carries: all its values equal, at 1/sqrt(dims).
|
|
166
|
+
fn is_sentinel(h: &[u16]) -> bool {
|
|
167
|
+
let Some(&first) = h.first() else {
|
|
168
|
+
return false;
|
|
169
|
+
};
|
|
170
|
+
let want = 1.0 / (h.len() as f32).sqrt();
|
|
171
|
+
h.iter().all(|&x| x == first) && (crate::veccol::f16_to_f32(first) - want).abs() < 1e-3
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// READY-NOTICE: the agents a `ready` task was shown to as theirs to
|
|
175
|
+
/// close (`_mnemo.ready_seen_by`).
|
|
176
|
+
fn ready_seen_by(m: &Memory) -> Vec<String> {
|
|
177
|
+
m.metadata
|
|
178
|
+
.get(crate::memory::MNEMO_META_READY_SEEN_BY)
|
|
179
|
+
.and_then(Value::as_array)
|
|
180
|
+
.map(|a| {
|
|
181
|
+
a.iter()
|
|
182
|
+
.filter_map(|v| v.as_str().map(str::to_string))
|
|
183
|
+
.collect()
|
|
184
|
+
})
|
|
185
|
+
.unwrap_or_default()
|
|
186
|
+
}
|
|
187
|
+
|
|
164
188
|
/// Add `agent` to a record's `_mnemo.seen_by`; `false` when it was there.
|
|
165
189
|
fn add_seen_by(m: &mut Memory, agent: &str) -> bool {
|
|
166
190
|
let mut v = seen_by(m);
|
|
@@ -213,8 +237,10 @@ impl Mnemo {
|
|
|
213
237
|
/// RB-013.1: the coordination records an older build re-tagged as facts
|
|
214
238
|
/// (its `compact` writes every row again, and it computes "fact" for a
|
|
215
239
|
/// kind it doesn't know). Found once per handle: such a record keeps
|
|
216
|
-
/// its `episodic` type in the row
|
|
217
|
-
///
|
|
240
|
+
/// its `episodic` type in the row and its sentinel vector in the column,
|
|
241
|
+
/// so only `episodic` fact rows whose vector is the sentinel are
|
|
242
|
+
/// decrypted (COORD-LEGACY-SCAN, v0.17.2); a row whose vector can't be
|
|
243
|
+
/// read is decrypted, as before. A write of one re-tags its row.
|
|
218
244
|
fn legacy_coordination_ids(&mut self) -> Result<std::collections::HashSet<u128>> {
|
|
219
245
|
if let Some(ids) = &self.legacy_coordination {
|
|
220
246
|
return Ok(ids.clone());
|
|
@@ -232,7 +258,24 @@ impl Mnemo {
|
|
|
232
258
|
.cloned()
|
|
233
259
|
.collect();
|
|
234
260
|
let mut ids = std::collections::HashSet::new();
|
|
261
|
+
// Each vector page read once, for every candidate row on it.
|
|
262
|
+
let mut pages: std::collections::HashMap<(u64, u64), Option<Vec<u8>>> =
|
|
263
|
+
std::collections::HashMap::new();
|
|
235
264
|
for e in candidates {
|
|
265
|
+
let vector = match e.v9 {
|
|
266
|
+
Some(r) if r.vec_page != 0 && !self.has_hot_vector(&e) => {
|
|
267
|
+
let page = pages
|
|
268
|
+
.entry((r.vec_page, r.vec_gen))
|
|
269
|
+
.or_insert_with(|| self.pager.read_page(r.vec_page, r.vec_gen).ok());
|
|
270
|
+
page.as_ref().and_then(|p| {
|
|
271
|
+
crate::veccol::decode_entry(p, self.dimensions, r.vec_slot as usize).ok()
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
_ => self.column_entry(&e).ok(),
|
|
275
|
+
};
|
|
276
|
+
if matches!(vector, Some((h, _)) if !is_sentinel(&h)) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
236
279
|
if is_coordination(&self.read_memory(&e)?) {
|
|
237
280
|
ids.insert(e.id);
|
|
238
281
|
}
|
|
@@ -1798,6 +1841,10 @@ pub struct NewWork {
|
|
|
1798
1841
|
/// [`crate::memory::TASK_CLAIM_WARN_SECS`], not yet warned about at this
|
|
1799
1842
|
/// expiry.
|
|
1800
1843
|
pub lapsing: Vec<Claim>,
|
|
1844
|
+
/// READY-NOTICE (v0.17.2): tasks it created that are `ready`, waiting
|
|
1845
|
+
/// for its `done`, not yet shown to it as such. They wait for a
|
|
1846
|
+
/// review, so they never wake a session.
|
|
1847
|
+
pub ready_for_done: Vec<Task>,
|
|
1801
1848
|
/// The agent it was read for: [`Mnemo::mark_shown`] records this agent
|
|
1802
1849
|
/// as having seen the broadcasts and the role's tasks.
|
|
1803
1850
|
pub agent: Option<String>,
|
|
@@ -1806,7 +1853,10 @@ pub struct NewWork {
|
|
|
1806
1853
|
impl NewWork {
|
|
1807
1854
|
/// Whether there's nothing.
|
|
1808
1855
|
pub fn is_empty(&self) -> bool {
|
|
1809
|
-
self.messages.is_empty()
|
|
1856
|
+
self.messages.is_empty()
|
|
1857
|
+
&& self.tasks.is_empty()
|
|
1858
|
+
&& self.lapsing.is_empty()
|
|
1859
|
+
&& self.ready_for_done.is_empty()
|
|
1810
1860
|
}
|
|
1811
1861
|
}
|
|
1812
1862
|
|
|
@@ -1860,6 +1910,16 @@ impl Mnemo {
|
|
|
1860
1910
|
tasks.push(t);
|
|
1861
1911
|
}
|
|
1862
1912
|
}
|
|
1913
|
+
// READY-NOTICE: its own tasks waiting for its `done`, not yet
|
|
1914
|
+
// shown to it as such.
|
|
1915
|
+
let mut ready_for_done = Vec::new();
|
|
1916
|
+
if let Some(a) = agent {
|
|
1917
|
+
for t in self.tasks(Some(crate::memory::task_status::READY), None)? {
|
|
1918
|
+
if t.creator == a && !ready_seen_by(&self.get(&t.id)?).iter().any(|s| s == a) {
|
|
1919
|
+
ready_for_done.push(t);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1863
1923
|
let mut lapsing = Vec::new();
|
|
1864
1924
|
if let Some(a) = agent {
|
|
1865
1925
|
for m in self.coordination_records(MNEMO_META_KIND_CLAIM, None)? {
|
|
@@ -1887,12 +1947,15 @@ impl Mnemo {
|
|
|
1887
1947
|
messages,
|
|
1888
1948
|
tasks,
|
|
1889
1949
|
lapsing,
|
|
1950
|
+
ready_for_done,
|
|
1890
1951
|
agent: agent.map(str::to_string),
|
|
1891
1952
|
})
|
|
1892
1953
|
}
|
|
1893
1954
|
|
|
1894
1955
|
/// 13a (13.1b): record that `work` was shown: its messages and tasks
|
|
1895
|
-
/// `seen`, its
|
|
1956
|
+
/// `seen`, its tasks waiting for a `done` shown to their creator
|
|
1957
|
+
/// (READY-NOTICE), its lapsing claims warned about at their expiry. In
|
|
1958
|
+
/// place.
|
|
1896
1959
|
pub fn mark_shown(&mut self, work: &NewWork) -> Result<()> {
|
|
1897
1960
|
if self.read_only {
|
|
1898
1961
|
return Err(MnemoError::ReadOnly);
|
|
@@ -1922,6 +1985,22 @@ impl Mnemo {
|
|
|
1922
1985
|
}
|
|
1923
1986
|
}
|
|
1924
1987
|
}
|
|
1988
|
+
// READY-NOTICE: shown to its creator as waiting for its `done`.
|
|
1989
|
+
if let Some(a) = &who {
|
|
1990
|
+
for t in &work.ready_for_done {
|
|
1991
|
+
let mut m = self.get(&t.id)?;
|
|
1992
|
+
let mut v = ready_seen_by(&m);
|
|
1993
|
+
if v.iter().any(|s| s == a) {
|
|
1994
|
+
continue;
|
|
1995
|
+
}
|
|
1996
|
+
v.push(a.clone());
|
|
1997
|
+
m.metadata.insert(
|
|
1998
|
+
crate::memory::MNEMO_META_READY_SEEN_BY.into(),
|
|
1999
|
+
Value::Array(v.into_iter().map(Value::String).collect()),
|
|
2000
|
+
);
|
|
2001
|
+
self.put(m)?;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
1925
2004
|
for c in &work.lapsing {
|
|
1926
2005
|
if let Some(mut m) = self.find_claim(&c.topic)? {
|
|
1927
2006
|
m.metadata
|
|
@@ -2228,3 +2307,29 @@ impl Mnemo {
|
|
|
2228
2307
|
c
|
|
2229
2308
|
}
|
|
2230
2309
|
}
|
|
2310
|
+
|
|
2311
|
+
#[cfg(test)]
|
|
2312
|
+
mod legacy_scan_tests {
|
|
2313
|
+
use super::is_sentinel;
|
|
2314
|
+
|
|
2315
|
+
/// COORD-LEGACY-SCAN: the sentinel, quantised as the column stores it,
|
|
2316
|
+
/// is recognised at every width; an ordinary vector isn't.
|
|
2317
|
+
#[test]
|
|
2318
|
+
fn the_sentinel_is_told_from_an_ordinary_vector() {
|
|
2319
|
+
for dims in [4, 32, 384, 768] {
|
|
2320
|
+
let s = vec![1.0 / (dims as f32).sqrt(); dims];
|
|
2321
|
+
let (h, _) = crate::veccol::quantize(&s);
|
|
2322
|
+
assert!(is_sentinel(&h), "{dims}");
|
|
2323
|
+
let mut v = s.clone();
|
|
2324
|
+
v[dims / 2] += 0.05;
|
|
2325
|
+
assert!(!is_sentinel(&crate::veccol::quantize(&v).0), "{dims}");
|
|
2326
|
+
let flat = vec![0.5; dims];
|
|
2327
|
+
assert_eq!(
|
|
2328
|
+
is_sentinel(&crate::veccol::quantize(&flat).0),
|
|
2329
|
+
dims == 4,
|
|
2330
|
+
"{dims}"
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
assert!(!is_sentinel(&[]));
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
@@ -1213,6 +1213,13 @@ impl Mnemo {
|
|
|
1213
1213
|
|
|
1214
1214
|
/// FMT-9b: row `e`'s column entry (fp16 values and norm), from the
|
|
1215
1215
|
/// staged set, the resident column, or its page.
|
|
1216
|
+
/// Whether a row's vector waits in the hot set (not on a page yet).
|
|
1217
|
+
pub(super) fn has_hot_vector(&self, e: &CatalogEntry) -> bool {
|
|
1218
|
+
self.index
|
|
1219
|
+
.get(e.id, &self.catalog)
|
|
1220
|
+
.is_some_and(|idx| self.col.hot.contains_key(&idx))
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1216
1223
|
pub(super) fn column_entry(&mut self, e: &CatalogEntry) -> Result<(Vec<u16>, f32)> {
|
|
1217
1224
|
let d = self.dimensions;
|
|
1218
1225
|
if let Some(idx) = self.index.get(e.id, &self.catalog) {
|
|
@@ -1251,7 +1251,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
|
1251
1251
|
|
|
1252
1252
|
[[package]]
|
|
1253
1253
|
name = "mnemo-engine"
|
|
1254
|
-
version = "0.17.
|
|
1254
|
+
version = "0.17.2"
|
|
1255
1255
|
dependencies = [
|
|
1256
1256
|
"aes-gcm",
|
|
1257
1257
|
"apple-native-keyring-store",
|
|
@@ -1285,7 +1285,7 @@ dependencies = [
|
|
|
1285
1285
|
|
|
1286
1286
|
[[package]]
|
|
1287
1287
|
name = "mnemo-python"
|
|
1288
|
-
version = "0.17.
|
|
1288
|
+
version = "0.17.2"
|
|
1289
1289
|
dependencies = [
|
|
1290
1290
|
"mnemo-engine",
|
|
1291
1291
|
"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.17.
|
|
7
|
+
version = "0.17.2"
|
|
8
8
|
edition = "2021"
|
|
9
9
|
rust-version = "1.94"
|
|
10
10
|
description = "Python (PyO3) bindings for the Mnemo encrypted agent-memory engine; built by maturin into the mnemo-engine wheel on PyPI"
|
|
@@ -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.17.
|
|
18
|
+
version = "0.17.2"
|
|
19
19
|
description = "Encrypted, portable agent-memory engine — Python bindings"
|
|
20
20
|
readme = "README.md"
|
|
21
21
|
requires-python = ">=3.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|