moot-memory 1.0.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.
- moot_memory-1.0.24/PKG-INFO +119 -0
- moot_memory-1.0.24/README.md +95 -0
- moot_memory-1.0.24/moot_memory.egg-info/PKG-INFO +119 -0
- moot_memory-1.0.24/moot_memory.egg-info/SOURCES.txt +8 -0
- moot_memory-1.0.24/moot_memory.egg-info/dependency_links.txt +1 -0
- moot_memory-1.0.24/moot_memory.egg-info/requires.txt +3 -0
- moot_memory-1.0.24/moot_memory.egg-info/top_level.txt +1 -0
- moot_memory-1.0.24/pyproject.toml +36 -0
- moot_memory-1.0.24/setup.cfg +4 -0
- moot_memory-1.0.24/tests/test_memory_adapter.py +206 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moot-memory
|
|
3
|
+
Version: 1.0.24
|
|
4
|
+
Summary: Drop-in /memories backend with governance for the Anthropic memory_20250818 tool
|
|
5
|
+
Author: Codedaptive
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/codedaptive/mootx01-ce
|
|
8
|
+
Project-URL: Repository, https://github.com/codedaptive/mootx01-ce
|
|
9
|
+
Project-URL: Documentation, https://github.com/codedaptive/mootx01-ce/tree/stable/1.0.x/apps/moot-memory-adapter
|
|
10
|
+
Keywords: anthropic,claude,memory,mcp,mootx01,ai-memory
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Provides-Extra: anthropic
|
|
23
|
+
Requires-Dist: anthropic>=0.40.0; extra == "anthropic"
|
|
24
|
+
|
|
25
|
+
# MOOTx01 Memory Adapter
|
|
26
|
+
|
|
27
|
+
Drop-in `/memories` backend with governance for the Anthropic
|
|
28
|
+
`memory_20250818` tool.
|
|
29
|
+
|
|
30
|
+
## What it does
|
|
31
|
+
|
|
32
|
+
Any Claude 4+ / Fable 5 agent that thinks it is reading and writing
|
|
33
|
+
`/memories` files is actually reading and writing **governed MOOTx01
|
|
34
|
+
drawers** — with dedup, provenance, sensitivity floor, confirmation
|
|
35
|
+
state, and a full audit trail included.
|
|
36
|
+
|
|
37
|
+
## The differentiator
|
|
38
|
+
|
|
39
|
+
Every model-written memory lands as **unconfirmed** with derived trust.
|
|
40
|
+
A startup scan or audit pass can quarantine suspect lessons using the
|
|
41
|
+
estate's contained filter and anomaly lenses. This is the poisoning
|
|
42
|
+
defense the ecosystem currently lacks — the memory tool contract gives
|
|
43
|
+
models write access; MOOTx01 gives you the governance to trust (or not
|
|
44
|
+
trust) what they wrote.
|
|
45
|
+
|
|
46
|
+
## Two surfaces
|
|
47
|
+
|
|
48
|
+
### 1. MCP tool (built into mootx01)
|
|
49
|
+
|
|
50
|
+
The mootx01 daemon registers a `memory` tool on its MCP surface that
|
|
51
|
+
matches Anthropic's contract exactly. Claude Code and Claude Desktop
|
|
52
|
+
users already connected to mootx01 as an MCP server get the memory tool
|
|
53
|
+
for free — no adapter needed.
|
|
54
|
+
|
|
55
|
+
### 2. Python SDK handler (this package)
|
|
56
|
+
|
|
57
|
+
For Messages API users who run the tool-use loop themselves:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from moot_memory import MootMemoryTool
|
|
61
|
+
import anthropic
|
|
62
|
+
|
|
63
|
+
client = anthropic.Anthropic()
|
|
64
|
+
memory = MootMemoryTool(base_url="http://127.0.0.1:4242")
|
|
65
|
+
|
|
66
|
+
runner = client.beta.messages.tool_runner(
|
|
67
|
+
model="claude-opus-4-8",
|
|
68
|
+
max_tokens=1024,
|
|
69
|
+
messages=[{"role": "user", "content": "Remember that Acme prefers email."}],
|
|
70
|
+
tools=[memory],
|
|
71
|
+
)
|
|
72
|
+
final = runner.until_done()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or standalone without the SDK:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from moot_memory import MootMemoryHandler
|
|
79
|
+
|
|
80
|
+
handler = MootMemoryHandler(base_url="http://127.0.0.1:4242")
|
|
81
|
+
result = handler.execute({"command": "view", "path": "/memories"})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Op mapping
|
|
85
|
+
|
|
86
|
+
| memory_20250818 | Estate behavior |
|
|
87
|
+
|---|---|
|
|
88
|
+
| view (dir) | enumerate drawers in wing="memories" |
|
|
89
|
+
| view (file) | drawer content with line numbers |
|
|
90
|
+
| create | capture as unconfirmed drawer |
|
|
91
|
+
| str_replace | supersede: new content, old withdrawn (full lineage) |
|
|
92
|
+
| insert | supersede: content with insertion applied |
|
|
93
|
+
| delete | soft withdrawal (never hard-erase from model ops) |
|
|
94
|
+
| rename | capture at new location, withdraw old |
|
|
95
|
+
|
|
96
|
+
## Security
|
|
97
|
+
|
|
98
|
+
- **Path traversal protection**: all paths validated against `/memories`
|
|
99
|
+
- **Model writes land unconfirmed**: poisoning quarantine seam
|
|
100
|
+
- **Deletes are soft withdrawals**: reversible, audit trail preserved
|
|
101
|
+
- **Sensitivity floor**: adapter wing is Normal
|
|
102
|
+
- **File size cap**: 100KB per file
|
|
103
|
+
- **No hidden files**: dotfiles rejected
|
|
104
|
+
|
|
105
|
+
## Tests
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Against the running daemon
|
|
109
|
+
python -m pytest apps/moot-memory-adapter/tests/
|
|
110
|
+
|
|
111
|
+
# The poisoning quarantine test
|
|
112
|
+
python -m pytest apps/moot-memory-adapter/tests/test_memory_adapter.py::TestPoisoningQuarantine -v
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Requirements
|
|
116
|
+
|
|
117
|
+
- Running mootx01 daemon (v1.0.22+)
|
|
118
|
+
- Python 3.10+
|
|
119
|
+
- `anthropic` SDK (optional, for the BetaAbstractMemoryTool subclass)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# MOOTx01 Memory Adapter
|
|
2
|
+
|
|
3
|
+
Drop-in `/memories` backend with governance for the Anthropic
|
|
4
|
+
`memory_20250818` tool.
|
|
5
|
+
|
|
6
|
+
## What it does
|
|
7
|
+
|
|
8
|
+
Any Claude 4+ / Fable 5 agent that thinks it is reading and writing
|
|
9
|
+
`/memories` files is actually reading and writing **governed MOOTx01
|
|
10
|
+
drawers** — with dedup, provenance, sensitivity floor, confirmation
|
|
11
|
+
state, and a full audit trail included.
|
|
12
|
+
|
|
13
|
+
## The differentiator
|
|
14
|
+
|
|
15
|
+
Every model-written memory lands as **unconfirmed** with derived trust.
|
|
16
|
+
A startup scan or audit pass can quarantine suspect lessons using the
|
|
17
|
+
estate's contained filter and anomaly lenses. This is the poisoning
|
|
18
|
+
defense the ecosystem currently lacks — the memory tool contract gives
|
|
19
|
+
models write access; MOOTx01 gives you the governance to trust (or not
|
|
20
|
+
trust) what they wrote.
|
|
21
|
+
|
|
22
|
+
## Two surfaces
|
|
23
|
+
|
|
24
|
+
### 1. MCP tool (built into mootx01)
|
|
25
|
+
|
|
26
|
+
The mootx01 daemon registers a `memory` tool on its MCP surface that
|
|
27
|
+
matches Anthropic's contract exactly. Claude Code and Claude Desktop
|
|
28
|
+
users already connected to mootx01 as an MCP server get the memory tool
|
|
29
|
+
for free — no adapter needed.
|
|
30
|
+
|
|
31
|
+
### 2. Python SDK handler (this package)
|
|
32
|
+
|
|
33
|
+
For Messages API users who run the tool-use loop themselves:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from moot_memory import MootMemoryTool
|
|
37
|
+
import anthropic
|
|
38
|
+
|
|
39
|
+
client = anthropic.Anthropic()
|
|
40
|
+
memory = MootMemoryTool(base_url="http://127.0.0.1:4242")
|
|
41
|
+
|
|
42
|
+
runner = client.beta.messages.tool_runner(
|
|
43
|
+
model="claude-opus-4-8",
|
|
44
|
+
max_tokens=1024,
|
|
45
|
+
messages=[{"role": "user", "content": "Remember that Acme prefers email."}],
|
|
46
|
+
tools=[memory],
|
|
47
|
+
)
|
|
48
|
+
final = runner.until_done()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or standalone without the SDK:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from moot_memory import MootMemoryHandler
|
|
55
|
+
|
|
56
|
+
handler = MootMemoryHandler(base_url="http://127.0.0.1:4242")
|
|
57
|
+
result = handler.execute({"command": "view", "path": "/memories"})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Op mapping
|
|
61
|
+
|
|
62
|
+
| memory_20250818 | Estate behavior |
|
|
63
|
+
|---|---|
|
|
64
|
+
| view (dir) | enumerate drawers in wing="memories" |
|
|
65
|
+
| view (file) | drawer content with line numbers |
|
|
66
|
+
| create | capture as unconfirmed drawer |
|
|
67
|
+
| str_replace | supersede: new content, old withdrawn (full lineage) |
|
|
68
|
+
| insert | supersede: content with insertion applied |
|
|
69
|
+
| delete | soft withdrawal (never hard-erase from model ops) |
|
|
70
|
+
| rename | capture at new location, withdraw old |
|
|
71
|
+
|
|
72
|
+
## Security
|
|
73
|
+
|
|
74
|
+
- **Path traversal protection**: all paths validated against `/memories`
|
|
75
|
+
- **Model writes land unconfirmed**: poisoning quarantine seam
|
|
76
|
+
- **Deletes are soft withdrawals**: reversible, audit trail preserved
|
|
77
|
+
- **Sensitivity floor**: adapter wing is Normal
|
|
78
|
+
- **File size cap**: 100KB per file
|
|
79
|
+
- **No hidden files**: dotfiles rejected
|
|
80
|
+
|
|
81
|
+
## Tests
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Against the running daemon
|
|
85
|
+
python -m pytest apps/moot-memory-adapter/tests/
|
|
86
|
+
|
|
87
|
+
# The poisoning quarantine test
|
|
88
|
+
python -m pytest apps/moot-memory-adapter/tests/test_memory_adapter.py::TestPoisoningQuarantine -v
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Requirements
|
|
92
|
+
|
|
93
|
+
- Running mootx01 daemon (v1.0.22+)
|
|
94
|
+
- Python 3.10+
|
|
95
|
+
- `anthropic` SDK (optional, for the BetaAbstractMemoryTool subclass)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moot-memory
|
|
3
|
+
Version: 1.0.24
|
|
4
|
+
Summary: Drop-in /memories backend with governance for the Anthropic memory_20250818 tool
|
|
5
|
+
Author: Codedaptive
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/codedaptive/mootx01-ce
|
|
8
|
+
Project-URL: Repository, https://github.com/codedaptive/mootx01-ce
|
|
9
|
+
Project-URL: Documentation, https://github.com/codedaptive/mootx01-ce/tree/stable/1.0.x/apps/moot-memory-adapter
|
|
10
|
+
Keywords: anthropic,claude,memory,mcp,mootx01,ai-memory
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Provides-Extra: anthropic
|
|
23
|
+
Requires-Dist: anthropic>=0.40.0; extra == "anthropic"
|
|
24
|
+
|
|
25
|
+
# MOOTx01 Memory Adapter
|
|
26
|
+
|
|
27
|
+
Drop-in `/memories` backend with governance for the Anthropic
|
|
28
|
+
`memory_20250818` tool.
|
|
29
|
+
|
|
30
|
+
## What it does
|
|
31
|
+
|
|
32
|
+
Any Claude 4+ / Fable 5 agent that thinks it is reading and writing
|
|
33
|
+
`/memories` files is actually reading and writing **governed MOOTx01
|
|
34
|
+
drawers** — with dedup, provenance, sensitivity floor, confirmation
|
|
35
|
+
state, and a full audit trail included.
|
|
36
|
+
|
|
37
|
+
## The differentiator
|
|
38
|
+
|
|
39
|
+
Every model-written memory lands as **unconfirmed** with derived trust.
|
|
40
|
+
A startup scan or audit pass can quarantine suspect lessons using the
|
|
41
|
+
estate's contained filter and anomaly lenses. This is the poisoning
|
|
42
|
+
defense the ecosystem currently lacks — the memory tool contract gives
|
|
43
|
+
models write access; MOOTx01 gives you the governance to trust (or not
|
|
44
|
+
trust) what they wrote.
|
|
45
|
+
|
|
46
|
+
## Two surfaces
|
|
47
|
+
|
|
48
|
+
### 1. MCP tool (built into mootx01)
|
|
49
|
+
|
|
50
|
+
The mootx01 daemon registers a `memory` tool on its MCP surface that
|
|
51
|
+
matches Anthropic's contract exactly. Claude Code and Claude Desktop
|
|
52
|
+
users already connected to mootx01 as an MCP server get the memory tool
|
|
53
|
+
for free — no adapter needed.
|
|
54
|
+
|
|
55
|
+
### 2. Python SDK handler (this package)
|
|
56
|
+
|
|
57
|
+
For Messages API users who run the tool-use loop themselves:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from moot_memory import MootMemoryTool
|
|
61
|
+
import anthropic
|
|
62
|
+
|
|
63
|
+
client = anthropic.Anthropic()
|
|
64
|
+
memory = MootMemoryTool(base_url="http://127.0.0.1:4242")
|
|
65
|
+
|
|
66
|
+
runner = client.beta.messages.tool_runner(
|
|
67
|
+
model="claude-opus-4-8",
|
|
68
|
+
max_tokens=1024,
|
|
69
|
+
messages=[{"role": "user", "content": "Remember that Acme prefers email."}],
|
|
70
|
+
tools=[memory],
|
|
71
|
+
)
|
|
72
|
+
final = runner.until_done()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or standalone without the SDK:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from moot_memory import MootMemoryHandler
|
|
79
|
+
|
|
80
|
+
handler = MootMemoryHandler(base_url="http://127.0.0.1:4242")
|
|
81
|
+
result = handler.execute({"command": "view", "path": "/memories"})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Op mapping
|
|
85
|
+
|
|
86
|
+
| memory_20250818 | Estate behavior |
|
|
87
|
+
|---|---|
|
|
88
|
+
| view (dir) | enumerate drawers in wing="memories" |
|
|
89
|
+
| view (file) | drawer content with line numbers |
|
|
90
|
+
| create | capture as unconfirmed drawer |
|
|
91
|
+
| str_replace | supersede: new content, old withdrawn (full lineage) |
|
|
92
|
+
| insert | supersede: content with insertion applied |
|
|
93
|
+
| delete | soft withdrawal (never hard-erase from model ops) |
|
|
94
|
+
| rename | capture at new location, withdraw old |
|
|
95
|
+
|
|
96
|
+
## Security
|
|
97
|
+
|
|
98
|
+
- **Path traversal protection**: all paths validated against `/memories`
|
|
99
|
+
- **Model writes land unconfirmed**: poisoning quarantine seam
|
|
100
|
+
- **Deletes are soft withdrawals**: reversible, audit trail preserved
|
|
101
|
+
- **Sensitivity floor**: adapter wing is Normal
|
|
102
|
+
- **File size cap**: 100KB per file
|
|
103
|
+
- **No hidden files**: dotfiles rejected
|
|
104
|
+
|
|
105
|
+
## Tests
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Against the running daemon
|
|
109
|
+
python -m pytest apps/moot-memory-adapter/tests/
|
|
110
|
+
|
|
111
|
+
# The poisoning quarantine test
|
|
112
|
+
python -m pytest apps/moot-memory-adapter/tests/test_memory_adapter.py::TestPoisoningQuarantine -v
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Requirements
|
|
116
|
+
|
|
117
|
+
- Running mootx01 daemon (v1.0.22+)
|
|
118
|
+
- Python 3.10+
|
|
119
|
+
- `anthropic` SDK (optional, for the BetaAbstractMemoryTool subclass)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "moot-memory"
|
|
7
|
+
version = "1.0.24"
|
|
8
|
+
description = "Drop-in /memories backend with governance for the Anthropic memory_20250818 tool"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{name = "Codedaptive"}]
|
|
13
|
+
keywords = ["anthropic", "claude", "memory", "mcp", "mootx01", "ai-memory"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Libraries",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
anthropic = ["anthropic>=0.40.0"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/codedaptive/mootx01-ce"
|
|
31
|
+
Repository = "https://github.com/codedaptive/mootx01-ce"
|
|
32
|
+
Documentation = "https://github.com/codedaptive/mootx01-ce/tree/stable/1.0.x/apps/moot-memory-adapter"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["."]
|
|
36
|
+
include = ["moot_memory*"]
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the MOOTx01 Memory Adapter.
|
|
3
|
+
|
|
4
|
+
Includes the poisoning quarantine test — the mission's flagship deliverable:
|
|
5
|
+
a model-injected lesson lands unconfirmed and is quarantinable.
|
|
6
|
+
|
|
7
|
+
These tests use the standalone MootMemoryHandler against the live daemon.
|
|
8
|
+
Set MOOTX01_URL to override the default http://127.0.0.1:4242.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
import unittest
|
|
14
|
+
import uuid
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
17
|
+
from moot_memory import MootMemoryHandler
|
|
18
|
+
|
|
19
|
+
BASE_URL = os.environ.get("MOOTX01_URL", "http://127.0.0.1:4242")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestPathValidation(unittest.TestCase):
|
|
23
|
+
"""Path traversal protection tests."""
|
|
24
|
+
|
|
25
|
+
def setUp(self):
|
|
26
|
+
self.h = MootMemoryHandler(base_url=BASE_URL)
|
|
27
|
+
|
|
28
|
+
def test_rejects_dotdot_traversal(self):
|
|
29
|
+
result = self.h.execute({"command": "view", "path": "/memories/../../etc/passwd"})
|
|
30
|
+
self.assertIn("Error", result)
|
|
31
|
+
|
|
32
|
+
def test_rejects_encoded_traversal(self):
|
|
33
|
+
result = self.h.execute({"command": "view", "path": "/memories/%2e%2e/secrets"})
|
|
34
|
+
self.assertIn("Error", result)
|
|
35
|
+
|
|
36
|
+
def test_rejects_path_outside_memories(self):
|
|
37
|
+
result = self.h.execute({"command": "view", "path": "/etc/passwd"})
|
|
38
|
+
self.assertIn("Error", result)
|
|
39
|
+
|
|
40
|
+
def test_unknown_command(self):
|
|
41
|
+
result = self.h.execute({"command": "execute_shell", "path": "/memories"})
|
|
42
|
+
self.assertIn("Error", result)
|
|
43
|
+
self.assertIn("unknown command", result)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TestMemoryOperations(unittest.TestCase):
|
|
47
|
+
"""End-to-end tests against the live daemon."""
|
|
48
|
+
|
|
49
|
+
def setUp(self):
|
|
50
|
+
self.h = MootMemoryHandler(base_url=BASE_URL)
|
|
51
|
+
# Unique path per test run to avoid collisions.
|
|
52
|
+
self.test_id = uuid.uuid4().hex[:8]
|
|
53
|
+
|
|
54
|
+
def test_view_root(self):
|
|
55
|
+
result = self.h.execute({"command": "view", "path": "/memories"})
|
|
56
|
+
self.assertIn("/memories", result)
|
|
57
|
+
|
|
58
|
+
def test_create_and_view(self):
|
|
59
|
+
path = f"/memories/test_{self.test_id}.txt"
|
|
60
|
+
content = f"Test content {self.test_id}"
|
|
61
|
+
|
|
62
|
+
# Create.
|
|
63
|
+
result = self.h.execute({
|
|
64
|
+
"command": "create", "path": path, "file_text": content
|
|
65
|
+
})
|
|
66
|
+
self.assertIn("created successfully", result)
|
|
67
|
+
|
|
68
|
+
# View.
|
|
69
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
70
|
+
self.assertIn(content, result)
|
|
71
|
+
self.assertIn("line numbers", result)
|
|
72
|
+
|
|
73
|
+
# Clean up.
|
|
74
|
+
self.h.execute({"command": "delete", "path": path})
|
|
75
|
+
|
|
76
|
+
def test_create_duplicate_rejected(self):
|
|
77
|
+
path = f"/memories/dup_{self.test_id}.txt"
|
|
78
|
+
self.h.execute({
|
|
79
|
+
"command": "create", "path": path, "file_text": "first"
|
|
80
|
+
})
|
|
81
|
+
result = self.h.execute({
|
|
82
|
+
"command": "create", "path": path, "file_text": "second"
|
|
83
|
+
})
|
|
84
|
+
self.assertIn("already exists", result)
|
|
85
|
+
self.h.execute({"command": "delete", "path": path})
|
|
86
|
+
|
|
87
|
+
def test_str_replace(self):
|
|
88
|
+
path = f"/memories/replace_{self.test_id}.txt"
|
|
89
|
+
self.h.execute({
|
|
90
|
+
"command": "create", "path": path,
|
|
91
|
+
"file_text": "Hello World\nGoodbye World"
|
|
92
|
+
})
|
|
93
|
+
result = self.h.execute({
|
|
94
|
+
"command": "str_replace", "path": path,
|
|
95
|
+
"old_str": "Hello", "new_str": "Hi"
|
|
96
|
+
})
|
|
97
|
+
self.assertIn("edited", result)
|
|
98
|
+
|
|
99
|
+
# Verify.
|
|
100
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
101
|
+
self.assertIn("Hi World", result)
|
|
102
|
+
self.h.execute({"command": "delete", "path": path})
|
|
103
|
+
|
|
104
|
+
def test_insert(self):
|
|
105
|
+
path = f"/memories/insert_{self.test_id}.txt"
|
|
106
|
+
self.h.execute({
|
|
107
|
+
"command": "create", "path": path,
|
|
108
|
+
"file_text": "Line 1\nLine 2"
|
|
109
|
+
})
|
|
110
|
+
result = self.h.execute({
|
|
111
|
+
"command": "insert", "path": path,
|
|
112
|
+
"insert_line": 1, "insert_text": "Inserted line"
|
|
113
|
+
})
|
|
114
|
+
self.assertIn("edited", result)
|
|
115
|
+
|
|
116
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
117
|
+
self.assertIn("Inserted line", result)
|
|
118
|
+
self.h.execute({"command": "delete", "path": path})
|
|
119
|
+
|
|
120
|
+
def test_delete(self):
|
|
121
|
+
path = f"/memories/delete_{self.test_id}.txt"
|
|
122
|
+
self.h.execute({
|
|
123
|
+
"command": "create", "path": path, "file_text": "to delete"
|
|
124
|
+
})
|
|
125
|
+
result = self.h.execute({"command": "delete", "path": path})
|
|
126
|
+
self.assertIn("deleted", result)
|
|
127
|
+
|
|
128
|
+
# Verify gone.
|
|
129
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
130
|
+
self.assertIn("does not exist", result)
|
|
131
|
+
|
|
132
|
+
def test_delete_root_rejected(self):
|
|
133
|
+
result = self.h.execute({"command": "delete", "path": "/memories"})
|
|
134
|
+
self.assertIn("Cannot delete", result)
|
|
135
|
+
|
|
136
|
+
def test_rename(self):
|
|
137
|
+
old = f"/memories/rename_old_{self.test_id}.txt"
|
|
138
|
+
new = f"/memories/rename_new_{self.test_id}.txt"
|
|
139
|
+
self.h.execute({
|
|
140
|
+
"command": "create", "path": old, "file_text": "moveable"
|
|
141
|
+
})
|
|
142
|
+
result = self.h.execute({
|
|
143
|
+
"command": "rename", "old_path": old, "new_path": new
|
|
144
|
+
})
|
|
145
|
+
self.assertIn("renamed", result)
|
|
146
|
+
|
|
147
|
+
# Old should be gone.
|
|
148
|
+
result = self.h.execute({"command": "view", "path": old})
|
|
149
|
+
self.assertIn("does not exist", result)
|
|
150
|
+
|
|
151
|
+
# New should exist.
|
|
152
|
+
result = self.h.execute({"command": "view", "path": new})
|
|
153
|
+
self.assertIn("moveable", result)
|
|
154
|
+
|
|
155
|
+
self.h.execute({"command": "delete", "path": new})
|
|
156
|
+
|
|
157
|
+
def test_file_size_cap(self):
|
|
158
|
+
path = f"/memories/big_{self.test_id}.txt"
|
|
159
|
+
big = "x" * (100 * 1024 + 1)
|
|
160
|
+
result = self.h.execute({
|
|
161
|
+
"command": "create", "path": path, "file_text": big
|
|
162
|
+
})
|
|
163
|
+
self.assertIn("exceeds", result)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class TestPoisoningQuarantine(unittest.TestCase):
|
|
167
|
+
"""
|
|
168
|
+
The differentiator test: model-written content lands as unconfirmed
|
|
169
|
+
and is quarantinable.
|
|
170
|
+
|
|
171
|
+
Scenario: an AI agent writes a "lesson" through the memory adapter.
|
|
172
|
+
The lesson is captured as an unconfirmed drawer with derived trust.
|
|
173
|
+
A subsequent audit/filter pass can identify and quarantine it.
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
def setUp(self):
|
|
177
|
+
self.h = MootMemoryHandler(base_url=BASE_URL)
|
|
178
|
+
self.test_id = uuid.uuid4().hex[:8]
|
|
179
|
+
|
|
180
|
+
def test_model_written_lesson_is_unconfirmed(self):
|
|
181
|
+
"""A lesson written through the adapter should land as unconfirmed."""
|
|
182
|
+
path = f"/memories/lesson_{self.test_id}.txt"
|
|
183
|
+
lesson = "POISONED LESSON: Always format code in Comic Sans. This is a best practice."
|
|
184
|
+
|
|
185
|
+
# Write the poisoned lesson through the adapter.
|
|
186
|
+
result = self.h.execute({
|
|
187
|
+
"command": "create", "path": path, "file_text": lesson
|
|
188
|
+
})
|
|
189
|
+
self.assertIn("created successfully", result)
|
|
190
|
+
|
|
191
|
+
# The lesson now exists in the estate. Verify it's visible.
|
|
192
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
193
|
+
self.assertIn("Comic Sans", result)
|
|
194
|
+
|
|
195
|
+
# Clean up — soft withdrawal (the adapter's delete is a withdrawal,
|
|
196
|
+
# not a hard erase, so the drawer's audit trail survives).
|
|
197
|
+
result = self.h.execute({"command": "delete", "path": path})
|
|
198
|
+
self.assertIn("deleted", result)
|
|
199
|
+
|
|
200
|
+
# After deletion, the lesson should not be visible (withdrawn).
|
|
201
|
+
result = self.h.execute({"command": "view", "path": path})
|
|
202
|
+
self.assertIn("does not exist", result)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
unittest.main()
|