memleaf 0.2.22__tar.gz → 0.2.24__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.
- {memleaf-0.2.22 → memleaf-0.2.24}/CHANGELOG.md +17 -0
- {memleaf-0.2.22/src/memleaf.egg-info → memleaf-0.2.24}/PKG-INFO +3 -3
- {memleaf-0.2.22 → memleaf-0.2.24}/README.en.md +2 -2
- {memleaf-0.2.22 → memleaf-0.2.24}/README.md +2 -2
- {memleaf-0.2.22 → memleaf-0.2.24}/pyproject.toml +1 -1
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/__init__.py +1 -1
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/capture.py +46 -1
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/cli.py +124 -14
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/hermes_provider/README.md +28 -4
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/hermes_provider/__init__.py +94 -1
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/hermes_provider/plugin.yaml +1 -1
- memleaf-0.2.24/src/memleaf/hermes_runtime.py +349 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/inbox.py +28 -1
- memleaf-0.2.24/src/memleaf/installer.py +1100 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/mcp_server.py +11 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/memory_writer.py +64 -2
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/processing.py +325 -21
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/scope_state.py +52 -1
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/service.py +2 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/validation.py +41 -0
- {memleaf-0.2.22 → memleaf-0.2.24/src/memleaf.egg-info}/PKG-INFO +3 -3
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf.egg-info/SOURCES.txt +3 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_extraction_quality_regressions.py +2 -2
- memleaf-0.2.24/tests/test_hermes_runtime_install.py +642 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_host_events.py +8 -2
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_pypi_install.py +27 -12
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_c1_mcp.py +2 -2
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_c3_packaging.py +0 -1
- memleaf-0.2.24/tests/test_v023_scope_correction.py +171 -0
- memleaf-0.2.22/src/memleaf/installer.py +0 -547
- {memleaf-0.2.22 → memleaf-0.2.24}/IMPLEMENTATION_PLAN.md +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/LICENSE +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/MANIFEST.in +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/RELEASE_CHECKLIST.md +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/examples/README.md +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/examples/basic_usage.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/examples/mcp_stdio.ndjson +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/install.ps1 +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/install.sh +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/setup.cfg +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/__main__.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/adapters/__init__.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/adapters/antigravity.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/adapters/base.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/adapters/codex.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/adapters/hermes.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/budget.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/compaction.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/config.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/credentials.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/frontmatter.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/host_events.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/host_runtime.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/index.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/__init__.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/base.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/claude_compatible.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/gemini.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/openai_compatible.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/llm/router.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/locking.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/model_discovery.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/models.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/native_index.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/native_registration.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/prompts.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/redaction.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/retrieval.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/retrieval_gate.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/scope_maintenance.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf/vault.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf.egg-info/dependency_links.txt +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf.egg-info/entry_points.txt +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/src/memleaf.egg-info/top_level.txt +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/__init__.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_admission_noise.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_codex_install.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_codex_native_cli.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_context_budget.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_credential_safety.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_cross_host_acceptance.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_cross_turn_dedupe_regressions.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_global_todo_acceptance.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_global_todo_retrieval.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_hermes_native_registration.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_hermes_provider.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_hermes_stdio_transport.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_host_runtime_contract.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_install.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_maintenance_v2.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_model_discovery.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_retrieval_gate.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_retrieval_v2.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_session_lineage.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_a.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b1.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b2a.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b2b.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3a_commit.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3a_contract.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3b_native_context.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3b_native_index.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3b_scope.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3c_retrieval.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_b3d_scope_maintenance.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_stage_c2_init.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_todo_state_recovery.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_update_target_recovery.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_upgrade_preserves_vault.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_v2_gate_limits.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_v2_host_flow.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_v2_mcp_flow.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_v2_nomatch_semantics.py +0 -0
- {memleaf-0.2.22 → memleaf-0.2.24}/tests/test_v2_search_gate_acceptance.py +0 -0
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to memleaf are documented here.
|
|
4
4
|
|
|
5
|
+
## 0.2.24 — 2026-09-04
|
|
6
|
+
|
|
7
|
+
- Make Hermes MCP installation reliably persistent: write `mcp_servers.memleaf` through Hermes' canonical `config set` interface, disable the entry while command/arguments are updated, then read `config.yaml` back and require an exact command plus `--vault` match before reporting success.
|
|
8
|
+
- Detect a same-Vault MCP entry that points at a different absolute memleaf runtime before changing Hermes. Add explicit `--mcp-runtime auto|current|existing` policies, prefer the current Python interpreter's scripts directory over `PATH`, and require an exact version check before retaining another environment.
|
|
9
|
+
- Snapshot Hermes `config.yaml`, `memleaf.json`, and `plugins/memleaf` during installation; on a later failure, attempt every rollback target even when one restore fails, and report the failed paths together with the installation stage and recovery commands.
|
|
10
|
+
- Improve human and JSON diagnostics for MCP persistence, runtime conflicts, lifecycle/test failures, and rollback results; document `memleaf-mcp --vault`, manual YAML, and the difference between Hermes connection discovery and final configuration persistence.
|
|
11
|
+
- Make Windows CI fail immediately after every native command and keep POSIX command-rendering assertions platform-specific, preventing intermediate Windows test failures from being reported as green.
|
|
12
|
+
- Leave memory extraction, CREATE/UPDATE/NO_CHANGE decisions, retrieval, injection, todo handling, and globally shared Vault visibility unchanged.
|
|
13
|
+
|
|
14
|
+
## 0.2.23 — 2026-09-03
|
|
15
|
+
|
|
16
|
+
- Add a strict `scope_correction` transaction for explicit cross-project corrections without weakening ordinary UPDATE scope isolation: uniquely recover the wrong active target, reuse its `memory_id` when appropriate, or retire it to history with `invalidated_reason: scope_correction` and `superseded_by` when a correct active survivor already exists.
|
|
17
|
+
- Deterministically split same-project `mixed_future_use` candidates after bounded model retries only when every clause is safely classifiable as durable project/fact state or an unfinished todo; ambiguous fragments remain deferred and valid siblings continue independently.
|
|
18
|
+
- Add bounded mail-tool evidence capture limited to message ID, subject, sender and sender domain, plus private per-scope domain identifiers; a unique domain/scope conflict defers extraction instead of writing a wrongly attributed project memory, while full tool output remains excluded.
|
|
19
|
+
- Preserve global `list_todos` pagination and unlimited aggregate managed reads from 0.2.20; no source/session ownership filter or aggregate read quota is reintroduced.
|
|
20
|
+
- Hermes still uses its existing Soft Gate in this package release. Generic fail-closed pre-final retrieval enforcement requires a Hermes host lifecycle hook and is tracked upstream in NousResearch/hermes-agent#101973.
|
|
21
|
+
|
|
5
22
|
## 0.2.22 — 2026-09-03
|
|
6
23
|
|
|
7
24
|
- Safely split valid multi-project `unscoped` aggregate candidates using only
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memleaf
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.24
|
|
4
4
|
Summary: A local-first Markdown memory core for AI agents
|
|
5
5
|
Author: memleaf contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -23,8 +23,8 @@ Dynamic: license-file
|
|
|
23
23
|
|
|
24
24
|
[English](README.en.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
25
25
|
|
|
26
|
-
> **当前版本:0.2.
|
|
27
|
-
> 核心库、Vault、stdio MCP Server、初始化 CLI、模型路由、提炼流程、受控检索协议和宿主适配器已经实现。memleaf 0.2.
|
|
26
|
+
> **当前版本:0.2.24。**
|
|
27
|
+
> 核心库、Vault、stdio MCP Server、初始化 CLI、模型路由、提炼流程、受控检索协议和宿主适配器已经实现。memleaf 0.2.24 通过 PyPI 分发。
|
|
28
28
|
> **当前版本支持 Hermes 和 Codex。** Antigravity(反重力)不检测、不安装、不配置。
|
|
29
29
|
|
|
30
30
|
## 项目定位
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[中文](README.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
6
6
|
|
|
7
|
-
> **Version: 0.2.
|
|
8
|
-
> The core library, Vault, stdio MCP server, initialization CLI, model routing, memory extraction, controlled retrieval protocol, and host adapters are implemented. memleaf 0.2.
|
|
7
|
+
> **Version: 0.2.24.**
|
|
8
|
+
> The core library, Vault, stdio MCP server, initialization CLI, model routing, memory extraction, controlled retrieval protocol, and host adapters are implemented. memleaf 0.2.24 is distributed through PyPI.
|
|
9
9
|
> **The current release supports Hermes and Codex.** Antigravity is not detected, installed, or configured.
|
|
10
10
|
|
|
11
11
|
## Project scope
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[English](README.en.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
6
6
|
|
|
7
|
-
> **当前版本:0.2.
|
|
8
|
-
> 核心库、Vault、stdio MCP Server、初始化 CLI、模型路由、提炼流程、受控检索协议和宿主适配器已经实现。memleaf 0.2.
|
|
7
|
+
> **当前版本:0.2.24。**
|
|
8
|
+
> 核心库、Vault、stdio MCP Server、初始化 CLI、模型路由、提炼流程、受控检索协议和宿主适配器已经实现。memleaf 0.2.24 通过 PyPI 分发。
|
|
9
9
|
> **当前版本支持 Hermes 和 Codex。** Antigravity(反重力)不检测、不安装、不配置。
|
|
10
10
|
|
|
11
11
|
## 项目定位
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Local-first Markdown memory core for AI agents."""
|
|
2
2
|
|
|
3
|
-
__version__ = "0.2.
|
|
3
|
+
__version__ = "0.2.24"
|
|
4
4
|
|
|
5
5
|
from .config import DEFAULT_CONFIG, default_config, load_config, save_config
|
|
6
6
|
from .frontmatter import FrontmatterError, dump_frontmatter, dump_yaml, load_yaml, parse_frontmatter
|
|
@@ -6,7 +6,7 @@ import json
|
|
|
6
6
|
import re
|
|
7
7
|
from datetime import datetime, timezone
|
|
8
8
|
from pathlib import Path
|
|
9
|
-
from typing import Optional
|
|
9
|
+
from typing import Any, Mapping, Optional
|
|
10
10
|
|
|
11
11
|
from .index import (
|
|
12
12
|
EVENT_CONTENT,
|
|
@@ -28,6 +28,45 @@ def _timestamp() -> str:
|
|
|
28
28
|
return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
|
|
32
|
+
_MAIL_EVIDENCE_FIELDS = frozenset({"message_id", "subject", "sender", "domain"})
|
|
33
|
+
_MAIL_DOMAIN_RE = re.compile(r"^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$", re.IGNORECASE)
|
|
34
|
+
_MAX_MAIL_EVIDENCE_ITEMS = 8
|
|
35
|
+
_MAX_MAIL_EVIDENCE_TEXT = 320
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _normalize_tool_evidence(value: Any) -> list[dict[str, str]]:
|
|
39
|
+
if value is None:
|
|
40
|
+
return []
|
|
41
|
+
if not isinstance(value, (list, tuple)):
|
|
42
|
+
raise ValueError("tool evidence must be a list")
|
|
43
|
+
result: list[dict[str, str]] = []
|
|
44
|
+
seen: set[tuple[tuple[str, str], ...]] = set()
|
|
45
|
+
for raw in list(value)[:_MAX_MAIL_EVIDENCE_ITEMS]:
|
|
46
|
+
if not isinstance(raw, Mapping) or set(raw) - _MAIL_EVIDENCE_FIELDS:
|
|
47
|
+
raise ValueError("invalid tool evidence record")
|
|
48
|
+
item: dict[str, str] = {}
|
|
49
|
+
for key in _MAIL_EVIDENCE_FIELDS:
|
|
50
|
+
field = raw.get(key)
|
|
51
|
+
if field is None:
|
|
52
|
+
continue
|
|
53
|
+
if not isinstance(field, str) or not field.strip() or any(ch in field for ch in "\x00\r\n"):
|
|
54
|
+
raise ValueError("invalid tool evidence field")
|
|
55
|
+
text = redact_text(field.strip())[:_MAX_MAIL_EVIDENCE_TEXT]
|
|
56
|
+
if key == "domain":
|
|
57
|
+
text = text.casefold().lstrip("@")
|
|
58
|
+
if not _MAIL_DOMAIN_RE.fullmatch(text):
|
|
59
|
+
raise ValueError("invalid tool evidence domain")
|
|
60
|
+
item[key] = text
|
|
61
|
+
if not item:
|
|
62
|
+
continue
|
|
63
|
+
fingerprint = tuple(sorted(item.items()))
|
|
64
|
+
if fingerprint in seen:
|
|
65
|
+
continue
|
|
66
|
+
seen.add(fingerprint)
|
|
67
|
+
result.append(item)
|
|
68
|
+
return result
|
|
69
|
+
|
|
31
70
|
def _event_id(source: str, session_id: str, turn_id: str, role: str, event_id: Optional[str]) -> str:
|
|
32
71
|
if event_id is not None:
|
|
33
72
|
if not isinstance(event_id, str) or not event_id or "\x00" in event_id or "\n" in event_id or "\r" in event_id:
|
|
@@ -149,6 +188,7 @@ def _append_event(
|
|
|
149
188
|
event_digest: str,
|
|
150
189
|
event_turn_key: str,
|
|
151
190
|
turn_index: int,
|
|
191
|
+
tool_evidence: list[dict[str, str]] | None = None,
|
|
152
192
|
) -> str:
|
|
153
193
|
timestamp = _timestamp()
|
|
154
194
|
if not existing:
|
|
@@ -168,6 +208,8 @@ def _append_event(
|
|
|
168
208
|
"turn_index": turn_index,
|
|
169
209
|
"timestamp": timestamp,
|
|
170
210
|
}
|
|
211
|
+
if tool_evidence:
|
|
212
|
+
metadata["tool_evidence"] = [dict(item) for item in tool_evidence]
|
|
171
213
|
metadata_line = json.dumps(metadata, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
172
214
|
return (
|
|
173
215
|
f"{updated}{EVENT_START}\n"
|
|
@@ -207,6 +249,7 @@ def capture_event(
|
|
|
207
249
|
event_id: Optional[str] = None,
|
|
208
250
|
record: bool = True,
|
|
209
251
|
visible: bool = True,
|
|
252
|
+
tool_evidence: Any = None,
|
|
210
253
|
) -> CaptureResult:
|
|
211
254
|
"""Capture one visible event; all persisted text is redacted first."""
|
|
212
255
|
|
|
@@ -222,6 +265,7 @@ def capture_event(
|
|
|
222
265
|
resolved_turn_key = turn_key(turn_id)
|
|
223
266
|
persisted_turn_id = _safe_turn_id(turn_id)
|
|
224
267
|
safe_content = escape_event_markers(redact_text(content))
|
|
268
|
+
safe_tool_evidence = _normalize_tool_evidence(tool_evidence)
|
|
225
269
|
if not record or not visible or role not in ("user", "assistant"):
|
|
226
270
|
return CaptureResult(resolved_event_id, stored=False, duplicate=False, content=safe_content)
|
|
227
271
|
|
|
@@ -266,6 +310,7 @@ def capture_event(
|
|
|
266
310
|
resolved_event_key,
|
|
267
311
|
resolved_turn_key,
|
|
268
312
|
turn_index,
|
|
313
|
+
safe_tool_evidence,
|
|
269
314
|
)
|
|
270
315
|
atomic_write_text(path, updated)
|
|
271
316
|
|
|
@@ -6,6 +6,8 @@ import argparse
|
|
|
6
6
|
import getpass
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
9
|
+
import shlex
|
|
10
|
+
import subprocess
|
|
9
11
|
import sys
|
|
10
12
|
from pathlib import Path
|
|
11
13
|
from typing import Sequence
|
|
@@ -65,6 +67,15 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
65
67
|
help="host to configure (default: hermes)",
|
|
66
68
|
)
|
|
67
69
|
install.add_argument("--vault", type=Path, default=None, help="vault directory")
|
|
70
|
+
install.add_argument(
|
|
71
|
+
"--mcp-runtime",
|
|
72
|
+
choices=("auto", "current", "existing"),
|
|
73
|
+
default="auto",
|
|
74
|
+
help=(
|
|
75
|
+
"Hermes only: fail on a second memleaf runtime (auto), migrate to "
|
|
76
|
+
"this installation (current), or retain a version-matched configured runtime (existing)"
|
|
77
|
+
),
|
|
78
|
+
)
|
|
68
79
|
install.add_argument("--json", action="store_true", help="emit one JSON result")
|
|
69
80
|
host_event = commands.add_parser(
|
|
70
81
|
"host-event",
|
|
@@ -87,6 +98,96 @@ def _configure_stdio_utf8() -> None:
|
|
|
87
98
|
continue
|
|
88
99
|
|
|
89
100
|
|
|
101
|
+
def _format_command(command: Sequence[object]) -> str:
|
|
102
|
+
values = [str(item) for item in command]
|
|
103
|
+
return subprocess.list2cmdline(values) if os.name == "nt" else shlex.join(values)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _print_install_failure(output: dict, *, host: str) -> None:
|
|
107
|
+
print(
|
|
108
|
+
f"memleaf install failed: {output.get('reason', 'unknown error')}",
|
|
109
|
+
file=sys.stderr,
|
|
110
|
+
)
|
|
111
|
+
stage = output.get("stage")
|
|
112
|
+
if isinstance(stage, str) and stage:
|
|
113
|
+
print(f"failed stage: {stage}", file=sys.stderr)
|
|
114
|
+
|
|
115
|
+
if host == "hermes" and output.get("core_version") is not None:
|
|
116
|
+
provider_version = output.get("provider_version")
|
|
117
|
+
if output.get("provider_updated"):
|
|
118
|
+
provider_text = provider_version or "unknown"
|
|
119
|
+
elif provider_version:
|
|
120
|
+
provider_text = f"not changed (rejected candidate {provider_version})"
|
|
121
|
+
else:
|
|
122
|
+
provider_text = "not changed"
|
|
123
|
+
print(
|
|
124
|
+
"memleaf versions: "
|
|
125
|
+
f"core={output.get('core_version') or 'unknown'}, "
|
|
126
|
+
f"Hermes provider={provider_text}",
|
|
127
|
+
file=sys.stderr,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
runtime = output.get("mcp_runtime")
|
|
131
|
+
if isinstance(runtime, dict):
|
|
132
|
+
config_path = runtime.get("config_path")
|
|
133
|
+
configured = runtime.get("configured_command")
|
|
134
|
+
current = runtime.get("current_command") or runtime.get("expected_command")
|
|
135
|
+
existing_version = runtime.get("existing_version")
|
|
136
|
+
if config_path:
|
|
137
|
+
print(f"Hermes config: {config_path}", file=sys.stderr)
|
|
138
|
+
if configured:
|
|
139
|
+
print(f"configured MCP runtime: {configured}", file=sys.stderr)
|
|
140
|
+
if current:
|
|
141
|
+
print(f"current memleaf runtime: {current}", file=sys.stderr)
|
|
142
|
+
if existing_version:
|
|
143
|
+
print(f"configured MCP version: {existing_version}", file=sys.stderr)
|
|
144
|
+
|
|
145
|
+
mcp = output.get("mcp")
|
|
146
|
+
if isinstance(mcp, dict):
|
|
147
|
+
mcp_reason = mcp.get("reason")
|
|
148
|
+
if isinstance(mcp_reason, str) and mcp_reason and mcp_reason != output.get("reason"):
|
|
149
|
+
print(f"MCP detail: {mcp_reason}", file=sys.stderr)
|
|
150
|
+
config_path = mcp.get("config_path")
|
|
151
|
+
if config_path and not (
|
|
152
|
+
isinstance(runtime, dict) and config_path == runtime.get("config_path")
|
|
153
|
+
):
|
|
154
|
+
print(f"Hermes config: {config_path}", file=sys.stderr)
|
|
155
|
+
backup_path = mcp.get("backup_path")
|
|
156
|
+
if backup_path:
|
|
157
|
+
print(f"config backup: {backup_path}", file=sys.stderr)
|
|
158
|
+
|
|
159
|
+
rollback = output.get("rollback_status")
|
|
160
|
+
if rollback == "completed":
|
|
161
|
+
print("Hermes configuration was restored to its pre-install state.", file=sys.stderr)
|
|
162
|
+
elif rollback == "failed":
|
|
163
|
+
print(
|
|
164
|
+
"WARNING: automatic rollback failed; inspect the reported Hermes paths before restarting.",
|
|
165
|
+
file=sys.stderr,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
user_action = output.get("user_action")
|
|
169
|
+
if output.get("user_action_required") and isinstance(user_action, str) and user_action:
|
|
170
|
+
print(f"action required: {user_action}", file=sys.stderr)
|
|
171
|
+
|
|
172
|
+
commands = output.get("recovery_commands")
|
|
173
|
+
if isinstance(commands, list) and commands:
|
|
174
|
+
print("recovery commands:", file=sys.stderr)
|
|
175
|
+
for command in commands:
|
|
176
|
+
if isinstance(command, list) and command:
|
|
177
|
+
print(f" {_format_command(command)}", file=sys.stderr)
|
|
178
|
+
|
|
179
|
+
diagnostic = ["python", "-m", "memleaf", "install", "--host", host]
|
|
180
|
+
if host == "hermes" and isinstance(runtime, dict):
|
|
181
|
+
policy = runtime.get("policy")
|
|
182
|
+
if policy in {"current", "existing"}:
|
|
183
|
+
diagnostic.extend(["--mcp-runtime", policy])
|
|
184
|
+
diagnostic.append("--json")
|
|
185
|
+
print(
|
|
186
|
+
f"Run `{_format_command(diagnostic)}` for the complete diagnostic result.",
|
|
187
|
+
file=sys.stderr,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
|
|
90
191
|
def main(argv: Sequence[str] | None = None) -> int:
|
|
91
192
|
_configure_stdio_utf8()
|
|
92
193
|
parser = build_parser()
|
|
@@ -96,8 +197,22 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
96
197
|
output = _init(args)
|
|
97
198
|
elif args.command == "install":
|
|
98
199
|
from .installer import install_codex, install_hermes
|
|
99
|
-
|
|
100
|
-
|
|
200
|
+
|
|
201
|
+
if args.host == "codex":
|
|
202
|
+
if args.mcp_runtime != "auto":
|
|
203
|
+
output = {
|
|
204
|
+
"status": "failure",
|
|
205
|
+
"stage": "arguments",
|
|
206
|
+
"reason": "--mcp-runtime applies only to Hermes installations",
|
|
207
|
+
"vault": str(args.vault) if args.vault is not None else None,
|
|
208
|
+
}
|
|
209
|
+
else:
|
|
210
|
+
output = install_codex(vault_path=args.vault)
|
|
211
|
+
else:
|
|
212
|
+
install_kwargs = {"vault_path": args.vault}
|
|
213
|
+
if args.mcp_runtime != "auto":
|
|
214
|
+
install_kwargs["mcp_runtime"] = args.mcp_runtime
|
|
215
|
+
output = install_hermes(**install_kwargs)
|
|
101
216
|
elif args.command == "host-event":
|
|
102
217
|
output = _host_event(args)
|
|
103
218
|
else: # pragma: no cover - argparse requires a known subcommand.
|
|
@@ -116,7 +231,8 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
116
231
|
if getattr(args, "json", False):
|
|
117
232
|
print(json.dumps({"error": "initialization failed"}, ensure_ascii=False))
|
|
118
233
|
else:
|
|
119
|
-
|
|
234
|
+
action = getattr(args, "command", "init")
|
|
235
|
+
print(f"memleaf {action} failed unexpectedly", file=sys.stderr)
|
|
120
236
|
return 1
|
|
121
237
|
|
|
122
238
|
if args.command == "host-event":
|
|
@@ -139,22 +255,16 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
139
255
|
if output.get("vault_source") == "hermes_config":
|
|
140
256
|
print("Preserved the Vault from the existing Hermes memleaf configuration.")
|
|
141
257
|
if args.host == "hermes":
|
|
258
|
+
runtime = output.get("mcp_runtime")
|
|
259
|
+
if isinstance(runtime, dict) and runtime.get("selected_command"):
|
|
260
|
+
print(f"Hermes MCP runtime: {runtime['selected_command']}")
|
|
142
261
|
print("Restart Hermes to use memleaf.")
|
|
143
262
|
elif output.get("user_action_required"):
|
|
144
263
|
print(f"Codex action required: {output.get('user_action')}")
|
|
145
264
|
if output.get("model", {}).get("status") == "not_configured":
|
|
146
265
|
print("Configure a memleaf model route before using automatic processing.")
|
|
147
266
|
else:
|
|
148
|
-
|
|
149
|
-
output.get("core_version") is not None
|
|
150
|
-
or output.get("provider_version") is not None
|
|
151
|
-
):
|
|
152
|
-
print(
|
|
153
|
-
"memleaf versions: "
|
|
154
|
-
f"core={output.get('core_version') or 'unknown'}, "
|
|
155
|
-
f"Hermes provider={output.get('provider_version') or 'unknown'}"
|
|
156
|
-
)
|
|
157
|
-
print(f"memleaf install failed: {output.get('reason', 'unknown error')}", file=sys.stderr)
|
|
267
|
+
_print_install_failure(output, host=args.host)
|
|
158
268
|
return 0 if output.get("status") in {"configured", "already_configured"} else 2
|
|
159
269
|
if args.json:
|
|
160
270
|
print(json.dumps(output, ensure_ascii=False, sort_keys=True))
|
|
@@ -309,7 +419,7 @@ def _prepare_model_route(
|
|
|
309
419
|
candidate = discovery.selected
|
|
310
420
|
diagnostics = list(discovery.diagnostics)
|
|
311
421
|
if candidate is None:
|
|
312
|
-
# An existing direct route is a safe idempotency fallback.
|
|
422
|
+
# An existing direct route is a safe idempotency fallback. It is not
|
|
313
423
|
# reported as a host discovery result and never appears with its key.
|
|
314
424
|
candidate = _existing_memleaf_route(requested_vault / "config.yaml")
|
|
315
425
|
if candidate is None and not dry_run and not non_interactive and sys.stdin.isatty():
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Memleaf memory provider for Hermes
|
|
2
2
|
|
|
3
3
|
This is a Hermes user-level memory-provider plugin for the local memleaf vault.
|
|
4
|
-
It is separate from the `memleaf-mcp` MCP server, but uses the same
|
|
5
|
-
|
|
4
|
+
It is separate from the `memleaf-mcp` MCP server, but uses the same Vault and
|
|
5
|
+
must use a version-compatible memleaf runtime.
|
|
6
6
|
|
|
7
7
|
The native provider supplies a bounded Scope Map (no memory titles or bodies),
|
|
8
8
|
captures visible Hermes turns, and automatically processes complete turns.
|
|
@@ -28,12 +28,36 @@ The optional provider config is `~/.hermes/memleaf.json`:
|
|
|
28
28
|
```json
|
|
29
29
|
{
|
|
30
30
|
"vault": "~/.memleaf",
|
|
31
|
-
"command": "memleaf-mcp",
|
|
31
|
+
"command": "/absolute/path/to/memleaf-mcp",
|
|
32
32
|
"timeout": 5,
|
|
33
|
-
"process_timeout": 300
|
|
33
|
+
"process_timeout": 300,
|
|
34
|
+
"auto_process": true
|
|
34
35
|
}
|
|
35
36
|
```
|
|
36
37
|
|
|
38
|
+
The separate persisted MCP entry uses the same executable and Vault:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
mcp_servers:
|
|
42
|
+
memleaf:
|
|
43
|
+
command: /absolute/path/to/memleaf-mcp
|
|
44
|
+
args:
|
|
45
|
+
- --vault
|
|
46
|
+
- /absolute/path/to/vault
|
|
47
|
+
enabled: true
|
|
48
|
+
lazy: true
|
|
49
|
+
idle_timeout_seconds: 60
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Use `python -m memleaf install` to configure both entries. The installer writes
|
|
53
|
+
the MCP entry through `hermes config set`, reads `config.yaml` back, and tests
|
|
54
|
+
that all 12 tools are discoverable before it reports success. When two memleaf
|
|
55
|
+
virtual environments are present, use `--mcp-runtime current` to migrate to the
|
|
56
|
+
runtime executing the installer or `--mcp-runtime existing` to retain an
|
|
57
|
+
already configured executable after an exact version check. See the
|
|
58
|
+
[Hermes MCP runtime guide](https://github.com/miffyblueboo/memleaf/blob/main/docs/hermes-mcp-runtime.md)
|
|
59
|
+
for the full multi-environment and manual-recovery procedure.
|
|
60
|
+
|
|
37
61
|
Capture, stats, and context calls use the short `timeout`; model-backed
|
|
38
62
|
processing uses `process_timeout` so a slow local model does not get mistaken
|
|
39
63
|
for a dead MCP worker. A failed or timed-out request closes the MCP process;
|
|
@@ -108,6 +108,11 @@ _UNTRUSTED_TOOL_RESULT_TAG = "<untrusted_tool_result"
|
|
|
108
108
|
_UNTRUSTED_TOOL_RESULT_END = "</untrusted_tool_result>"
|
|
109
109
|
|
|
110
110
|
|
|
111
|
+
_MAX_MAIL_EVIDENCE_ITEMS = 8
|
|
112
|
+
_MAIL_ADDRESS_RE = re.compile(r"(?i)([A-Z0-9._%+-]+@([A-Z0-9.-]+\.[A-Z]{2,63}))")
|
|
113
|
+
_MAIL_TOOL_RE = re.compile(r"(?:gmail|outlook|mail|email)", re.IGNORECASE)
|
|
114
|
+
|
|
115
|
+
|
|
111
116
|
class _MCPToolError(RuntimeError):
|
|
112
117
|
"""Safe structured model error returned by the local MCP boundary."""
|
|
113
118
|
|
|
@@ -1152,6 +1157,83 @@ def _resolve_command(config: Mapping[str, Any]) -> Optional[str]:
|
|
|
1152
1157
|
)
|
|
1153
1158
|
|
|
1154
1159
|
|
|
1160
|
+
def _bounded_mail_evidence(messages: Optional[List[Dict[str, Any]]]) -> list[dict[str, str]]:
|
|
1161
|
+
"""Extract only message id/subject/sender/domain from visible mail tool results."""
|
|
1162
|
+
|
|
1163
|
+
calls = _visible_tool_calls(messages)
|
|
1164
|
+
results = _visible_tool_results(messages)
|
|
1165
|
+
used: set[int] = set()
|
|
1166
|
+
output: list[dict[str, str]] = []
|
|
1167
|
+
seen: set[tuple[tuple[str, str], ...]] = set()
|
|
1168
|
+
|
|
1169
|
+
def add_record(mapping: Mapping[str, Any]) -> None:
|
|
1170
|
+
if len(output) >= _MAX_MAIL_EVIDENCE_ITEMS:
|
|
1171
|
+
return
|
|
1172
|
+
lowered = {str(key).casefold(): value for key, value in mapping.items()}
|
|
1173
|
+
message_id = next((lowered.get(key) for key in ("message_id", "messageid", "id") if isinstance(lowered.get(key), (str, int))), None)
|
|
1174
|
+
subject = next((lowered.get(key) for key in ("subject", "title") if isinstance(lowered.get(key), str)), None)
|
|
1175
|
+
sender = next((lowered.get(key) for key in ("sender", "from", "from_address", "from_email", "email") if isinstance(lowered.get(key), str)), None)
|
|
1176
|
+
domain = next((lowered.get(key) for key in ("domain", "sender_domain") if isinstance(lowered.get(key), str)), None)
|
|
1177
|
+
if isinstance(sender, str):
|
|
1178
|
+
match = _MAIL_ADDRESS_RE.search(sender)
|
|
1179
|
+
if match and not domain:
|
|
1180
|
+
domain = match.group(2)
|
|
1181
|
+
item: dict[str, str] = {}
|
|
1182
|
+
for key, value, limit in (
|
|
1183
|
+
("message_id", message_id, 160),
|
|
1184
|
+
("subject", subject, 320),
|
|
1185
|
+
("sender", sender, 320),
|
|
1186
|
+
("domain", domain, 253),
|
|
1187
|
+
):
|
|
1188
|
+
if value is None:
|
|
1189
|
+
continue
|
|
1190
|
+
text = str(value).strip()
|
|
1191
|
+
if not text or any(ch in text for ch in "\x00\r\n"):
|
|
1192
|
+
continue
|
|
1193
|
+
if key == "domain":
|
|
1194
|
+
text = text.casefold().lstrip("@")
|
|
1195
|
+
if not re.fullmatch(r"(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}", text):
|
|
1196
|
+
continue
|
|
1197
|
+
item[key] = text[:limit]
|
|
1198
|
+
if "domain" not in item:
|
|
1199
|
+
return
|
|
1200
|
+
fingerprint = tuple(sorted(item.items()))
|
|
1201
|
+
if fingerprint not in seen:
|
|
1202
|
+
seen.add(fingerprint)
|
|
1203
|
+
output.append(item)
|
|
1204
|
+
|
|
1205
|
+
def visit(value: Any, depth: int = 0) -> None:
|
|
1206
|
+
if depth > 4 or len(output) >= _MAX_MAIL_EVIDENCE_ITEMS:
|
|
1207
|
+
return
|
|
1208
|
+
decoded = _decode_hermes_tool_result(value)
|
|
1209
|
+
if decoded is _MISSING_TOOL_RESULT:
|
|
1210
|
+
return
|
|
1211
|
+
if decoded is not value:
|
|
1212
|
+
visit(decoded, depth + 1)
|
|
1213
|
+
return
|
|
1214
|
+
if isinstance(value, Mapping):
|
|
1215
|
+
add_record(value)
|
|
1216
|
+
for child in value.values():
|
|
1217
|
+
if isinstance(child, (Mapping, list, tuple)):
|
|
1218
|
+
visit(child, depth + 1)
|
|
1219
|
+
elif isinstance(value, (list, tuple)):
|
|
1220
|
+
for child in value:
|
|
1221
|
+
visit(child, depth + 1)
|
|
1222
|
+
|
|
1223
|
+
ordinal = 0
|
|
1224
|
+
for call in calls:
|
|
1225
|
+
name = call.get("name")
|
|
1226
|
+
if not isinstance(name, str) or not _MAIL_TOOL_RE.search(name):
|
|
1227
|
+
continue
|
|
1228
|
+
ordinal += 1
|
|
1229
|
+
payload = _tool_result_for_call(call, calls, results, used)
|
|
1230
|
+
if payload is not _CALL_FAILED:
|
|
1231
|
+
visit(payload)
|
|
1232
|
+
if len(output) >= _MAX_MAIL_EVIDENCE_ITEMS:
|
|
1233
|
+
break
|
|
1234
|
+
return output
|
|
1235
|
+
|
|
1236
|
+
|
|
1155
1237
|
class MemleafMemoryProvider(MemoryProvider):
|
|
1156
1238
|
"""Use the local memleaf vault as Hermes' single external provider."""
|
|
1157
1239
|
|
|
@@ -2115,7 +2197,15 @@ class MemleafMemoryProvider(MemoryProvider):
|
|
|
2115
2197
|
)
|
|
2116
2198
|
return result
|
|
2117
2199
|
|
|
2118
|
-
def _capture_visible(
|
|
2200
|
+
def _capture_visible(
|
|
2201
|
+
self,
|
|
2202
|
+
*,
|
|
2203
|
+
session_id: str,
|
|
2204
|
+
turn_id: str,
|
|
2205
|
+
role: str,
|
|
2206
|
+
content: str,
|
|
2207
|
+
tool_evidence: Optional[List[Dict[str, str]]] = None,
|
|
2208
|
+
) -> bool:
|
|
2119
2209
|
result = self._call(
|
|
2120
2210
|
"capture",
|
|
2121
2211
|
{
|
|
@@ -2126,6 +2216,7 @@ class MemleafMemoryProvider(MemoryProvider):
|
|
|
2126
2216
|
"content": content,
|
|
2127
2217
|
"record": True,
|
|
2128
2218
|
"visible": True,
|
|
2219
|
+
**({"tool_evidence": tool_evidence} if tool_evidence else {}),
|
|
2129
2220
|
},
|
|
2130
2221
|
stage=f"capture_{role}",
|
|
2131
2222
|
session_id=session_id,
|
|
@@ -2414,12 +2505,14 @@ class MemleafMemoryProvider(MemoryProvider):
|
|
|
2414
2505
|
self._last_retrieval_observation = observation
|
|
2415
2506
|
self._last_retrieval_audit = str(audit_state.get("status") or "SEARCH_UNKNOWN")
|
|
2416
2507
|
lineage_ready = self._retry_pending_lineage(effective_session)
|
|
2508
|
+
mail_evidence = _bounded_mail_evidence(messages)
|
|
2417
2509
|
for role, content in visible_events:
|
|
2418
2510
|
if not self._capture_visible(
|
|
2419
2511
|
session_id=effective_session,
|
|
2420
2512
|
turn_id=turn_id,
|
|
2421
2513
|
role=role,
|
|
2422
2514
|
content=content,
|
|
2515
|
+
tool_evidence=mail_evidence if role == "assistant" else None,
|
|
2423
2516
|
):
|
|
2424
2517
|
return
|
|
2425
2518
|
if not self._auto_process:
|