mnemosyne-lite 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mnemosyne_lite-0.4.1/LICENSE +203 -0
- mnemosyne_lite-0.4.1/PKG-INFO +293 -0
- mnemosyne_lite-0.4.1/README.md +265 -0
- mnemosyne_lite-0.4.1/agentbrain/__init__.py +3 -0
- mnemosyne_lite-0.4.1/agentbrain/api.py +343 -0
- mnemosyne_lite-0.4.1/agentbrain/apply.py +106 -0
- mnemosyne_lite-0.4.1/agentbrain/cli.py +141 -0
- mnemosyne_lite-0.4.1/agentbrain/config.py +18 -0
- mnemosyne_lite-0.4.1/agentbrain/doctor.py +97 -0
- mnemosyne_lite-0.4.1/agentbrain/frontmatter.py +27 -0
- mnemosyne_lite-0.4.1/agentbrain/locking.py +106 -0
- mnemosyne_lite-0.4.1/agentbrain/mcp_server.py +112 -0
- mnemosyne_lite-0.4.1/agentbrain/models.py +21 -0
- mnemosyne_lite-0.4.1/agentbrain/profile.py +60 -0
- mnemosyne_lite-0.4.1/agentbrain/redact.py +63 -0
- mnemosyne_lite-0.4.1/agentbrain/retrieval.py +99 -0
- mnemosyne_lite-0.4.1/agentbrain/scaffold.py +77 -0
- mnemosyne_lite-0.4.1/agentbrain/snapshot.py +71 -0
- mnemosyne_lite-0.4.1/agentbrain/templates/AGENTS.md +60 -0
- mnemosyne_lite-0.4.1/agentbrain/templates/Index.md +6 -0
- mnemosyne_lite-0.4.1/agentbrain/templates/lesson-demo.md +27 -0
- mnemosyne_lite-0.4.1/agentbrain/templates/log.md +4 -0
- mnemosyne_lite-0.4.1/agentbrain/templates/profile.md +22 -0
- mnemosyne_lite-0.4.1/agentbrain/vault.py +255 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/PKG-INFO +293 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/SOURCES.txt +42 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/dependency_links.txt +1 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/entry_points.txt +2 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/requires.txt +5 -0
- mnemosyne_lite-0.4.1/mnemosyne_lite.egg-info/top_level.txt +1 -0
- mnemosyne_lite-0.4.1/pyproject.toml +45 -0
- mnemosyne_lite-0.4.1/setup.cfg +4 -0
- mnemosyne_lite-0.4.1/tests/test_api.py +73 -0
- mnemosyne_lite-0.4.1/tests/test_apply.py +107 -0
- mnemosyne_lite-0.4.1/tests/test_fixes_v031.py +88 -0
- mnemosyne_lite-0.4.1/tests/test_fixes_v032.py +52 -0
- mnemosyne_lite-0.4.1/tests/test_frontmatter.py +23 -0
- mnemosyne_lite-0.4.1/tests/test_locking.py +220 -0
- mnemosyne_lite-0.4.1/tests/test_mcp_server.py +94 -0
- mnemosyne_lite-0.4.1/tests/test_profile.py +50 -0
- mnemosyne_lite-0.4.1/tests/test_redact.py +107 -0
- mnemosyne_lite-0.4.1/tests/test_retrieval.py +48 -0
- mnemosyne_lite-0.4.1/tests/test_snapshot.py +134 -0
- mnemosyne_lite-0.4.1/tests/test_vault.py +54 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
```
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
```
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mnemosyne-lite
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Local-first long-term memory for AI agents: a plain Markdown vault plus a thin MCP server. Token-efficient, plug-and-play.
|
|
5
|
+
Author: agentbrain contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/2672243194/agentbrain
|
|
8
|
+
Project-URL: Issues, https://github.com/2672243194/agentbrain/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/2672243194/agentbrain/releases
|
|
10
|
+
Keywords: agent,memory,mcp,llm,claude-code,codex,opencode,obsidian,long-term-memory,bm25
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: mcp>=1.2.0
|
|
24
|
+
Requires-Dist: PyYAML>=6.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# agentbrain
|
|
30
|
+
|
|
31
|
+
> Local-first long-term memory for AI agents — a plain Markdown vault + a thin MCP server.
|
|
32
|
+
> 给 AI Agent 用的本地长期记忆:纯 Markdown 知识库 + 薄 MCP server。
|
|
33
|
+
|
|
34
|
+
**三步上手 / Quick start (3 steps)**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install mnemosyne-lite # Python >= 3.10(PyPI 包名;命令仍是 agentbrain)
|
|
38
|
+
agentbrain init ~/agentbrain # 建立记忆库(幂等,可重复执行)
|
|
39
|
+
agentbrain doctor # 自检:一切正常会显示 "Everything looks healthy."
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"agentbrain": {
|
|
46
|
+
"command": "agentbrain",
|
|
47
|
+
"args": ["serve"],
|
|
48
|
+
"env": { "AGENTBRAIN_VAULT": "D:\\agentbrain" }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
把上面 JSON(vault 路径换成你的)粘进任意 MCP 客户端(Claude Code / Codex / Cursor / DSH / Open WebUI…),重启客户端,完成。Agent 从此有了跨会话、跨工具的长期记忆。
|
|
55
|
+
|
|
56
|
+
Paste that JSON (with your vault path) into any MCP client and restart it — done. Your agents now share one long-term memory.
|
|
57
|
+
|
|
58
|
+
[中文详细说明](#中文快速上手) · [English quickstart](#english-quickstart)
|
|
59
|
+
|
|
60
|
+
## Why agentbrain / 设计理念
|
|
61
|
+
|
|
62
|
+
- **Plain Markdown, no lock-in** — your memory is a folder of `.md` files. Open it in
|
|
63
|
+
Obsidian, grep it, version it with Git. Remove agentbrain and the memory stays.
|
|
64
|
+
- **Token-efficient by design** — index-first retrieval: `Index.md` is the cheap first
|
|
65
|
+
layer, BM25 (CJK-aware) only ranks candidates, and query output is compact by
|
|
66
|
+
default (`mode='index'`); full text only on demand.
|
|
67
|
+
- **Append-only for agents** — agents may create lessons, never edit or delete them.
|
|
68
|
+
Consolidation happens through proposals in `_consolidations/` that a human approves,
|
|
69
|
+
which keeps multi-agent writes conflict-free.
|
|
70
|
+
- **Plug-and-play via MCP** — one server, every client: Claude Code, Codex CLI,
|
|
71
|
+
OpenCode, Cursor, DSH, Open WebUI, ...
|
|
72
|
+
- **Secrets never enter the vault** — credentials live in env/keyring; lessons reference
|
|
73
|
+
`${ENV:VAR_NAME}` placeholders only, resolved at runtime via shell. Since 0.4.1 this
|
|
74
|
+
is enforced, not just a rule: `memory_ingest` scans for credential-shaped content
|
|
75
|
+
(sk-/ghp_/AKIA/xox-/AIza keys, bearer tokens, private-key blocks, `password=`
|
|
76
|
+
assignments) and refuses the write, telling the agent to use a placeholder instead.
|
|
77
|
+
Placeholders and teaching examples (`sk-xxx`, `YOUR_KEY`) ingest fine. `lint` also
|
|
78
|
+
scans existing lessons and reports `SECRET` findings — read-only, never rewrites
|
|
79
|
+
files. Hand-written files are never touched.
|
|
80
|
+
|
|
81
|
+
## Vault layout
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
agentbrain/ # vault root (git-friendly, Obsidian-friendly)
|
|
85
|
+
├─ AGENTS.md # rules every agent reads at session start
|
|
86
|
+
├─ Case-Learnings/
|
|
87
|
+
│ ├─ Index.md # auto-generated lesson index (retrieval layer 1)
|
|
88
|
+
│ ├─ log.md # append-only audit log
|
|
89
|
+
│ ├─ Learnings/ # one lesson per file, YAML frontmatter
|
|
90
|
+
│ │ └─ case-001-lesson-01.md # 文件名 = {case_id}-lesson-{NN},自动生成
|
|
91
|
+
│ └─ _consolidations/ # merge/promotion proposals (human approval)
|
|
92
|
+
└─ Agent-Profile/
|
|
93
|
+
├─ Immutable/ # owner preferences & environment (agent read-only)
|
|
94
|
+
├─ Mutable-Hints/ # soft preferences (agent read-only)
|
|
95
|
+
└─ _suggestions/ # agent-suggested profile changes
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 中文快速上手
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install mnemosyne-lite # Python >= 3.10
|
|
102
|
+
agentbrain init ~/agentbrain # 生成 vault 脚手架(幂等),自动开启 Git 快照
|
|
103
|
+
agentbrain doctor # 体检:vault/索引/锁/快照/log 一览
|
|
104
|
+
agentbrain ingest --case demo --lesson "部署前必须先跑迁移脚本" --tags 部署,运维
|
|
105
|
+
agentbrain query "部署 迁移"
|
|
106
|
+
agentbrain profile # 查看个人偏好(Immutable + Mutable-Hints)
|
|
107
|
+
agentbrain suggest --title "回复用中文" --change "偏好简洁的中文回复" # 提交偏好建议
|
|
108
|
+
agentbrain lint # 体检:重复/过时/无标签/低置信度 → 生成整合提案
|
|
109
|
+
agentbrain apply lint-20260820-172206.md # 人工审核后执行提案(自动归档)
|
|
110
|
+
agentbrain distill # 分析 log 中重复出现的模式 → 生成提升提案
|
|
111
|
+
agentbrain snapshot -m "手动备份" # 手动提交快照(如用 Obsidian 手改文件后)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
> 说明:PyPI 包名为 `mnemosyne-lite`(`agentbrain` 在 PyPI 上与已有项目过于相似,无法注册)。
|
|
115
|
+
> 安装后的 CLI 命令与 Python 包名仍是 `agentbrain`,GitHub 仓库地址不变。
|
|
116
|
+
|
|
117
|
+
日常你只需要做三件事(频率都很低):
|
|
118
|
+
|
|
119
|
+
| 事 | 命令 | 频率 |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| 想看库健不健康 | `agentbrain doctor` | 随意 |
|
|
122
|
+
| 记忆整理(清重复/过时) | `agentbrain lint` → 审核 → `agentbrain apply <提案>` | 约一周一次 |
|
|
123
|
+
| 手改文件后备份 | `agentbrain snapshot` | 改完就跑 |
|
|
124
|
+
|
|
125
|
+
其余全自动:Agent 会话开始读偏好、任务前查经验、学到东西写入(每次写入自动 git 快照,可回滚)。
|
|
126
|
+
|
|
127
|
+
在 MCP 客户端里接入(以 Claude Code 为例):
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
claude mcp add agentbrain -- agentbrain serve
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
通用 MCP JSON 配置(Cursor / Open WebUI 等):
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"agentbrain": {
|
|
139
|
+
"command": "agentbrain",
|
|
140
|
+
"args": ["serve"],
|
|
141
|
+
"env": { "AGENTBRAIN_VAULT": "D:\\agentbrain" }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Vault 路径解析顺序:`--vault` 参数 > `AGENTBRAIN_VAULT` 环境变量 > `~/agentbrain`。
|
|
148
|
+
|
|
149
|
+
## English quickstart
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pip install mnemosyne-lite # Python >= 3.10
|
|
153
|
+
agentbrain init ~/agentbrain # scaffold the vault (idempotent), enables git snapshots
|
|
154
|
+
agentbrain doctor # health check: vault, index, lock, snapshots, log
|
|
155
|
+
agentbrain ingest --case demo --lesson "Always run migrations before deploy" --tags deploy,ops
|
|
156
|
+
agentbrain query "deploy migrations"
|
|
157
|
+
agentbrain profile # print the owner profile
|
|
158
|
+
agentbrain suggest --title "Short replies" --change "Keep answers under 3 sentences."
|
|
159
|
+
agentbrain lint # health check → consolidation proposals
|
|
160
|
+
agentbrain apply lint-20260820-172206.md # execute an approved proposal (archives it)
|
|
161
|
+
agentbrain distill # recurring-pattern analysis → promotion proposals
|
|
162
|
+
agentbrain snapshot -m "manual backup" # commit a snapshot (e.g. after hand-edits)
|
|
163
|
+
agentbrain serve # start the MCP server on stdio
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
> Note: the PyPI distribution name is `mnemosyne-lite` (`agentbrain` was rejected
|
|
167
|
+
> as too similar to an existing PyPI project); the installed CLI command and the
|
|
168
|
+
> Python import name remain `agentbrain`.
|
|
169
|
+
|
|
170
|
+
Codex CLI (`~/.codex/config.toml`):
|
|
171
|
+
|
|
172
|
+
```toml
|
|
173
|
+
[mcp_servers.agentbrain]
|
|
174
|
+
command = "agentbrain"
|
|
175
|
+
args = ["serve"]
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## MCP tools
|
|
179
|
+
|
|
180
|
+
| Tool | Purpose |
|
|
181
|
+
|------|---------|
|
|
182
|
+
| `memory_query(query, top_k=5, mode="index")` | Search lessons. `mode='index'` returns compact hits (id, summary, tags, path, gist); `mode='full'` adds full text. |
|
|
183
|
+
| `memory_ingest(case_id, lesson, tags, confidence=0.8, source_summary=None)` | Save a new lesson (facts + scenario + fix, ≤ 30 lines). Creates a file, updates Index.md and log.md. |
|
|
184
|
+
| `memory_lint(scope="all")` | Health check: duplicates, stale, expired, untagged, low-confidence. Writes a merge proposal to `_consolidations/`. |
|
|
185
|
+
| `memory_distill(window_days=30, min_repeat=3)` | Finds cases/tags ingested ≥ N times in the window and writes a promotion proposal. |
|
|
186
|
+
| `memory_profile()` | Returns the owner profile (hard rules + soft preferences). Read-only; agents call it once per session to tailor behavior. |
|
|
187
|
+
| `memory_suggest(title, change)` | Proposes a profile change into `Agent-Profile/_suggestions/` for the owner to review — agents never edit the profile itself. |
|
|
188
|
+
|
|
189
|
+
## MCP resources
|
|
190
|
+
|
|
191
|
+
| URI | Content |
|
|
192
|
+
|-----|---------|
|
|
193
|
+
| `agentbrain://rules` | `AGENTS.md` — vault rules for every agent |
|
|
194
|
+
| `agentbrain://index` | `Case-Learnings/Index.md` — retrieval layer 1 |
|
|
195
|
+
| `agentbrain://profile` | merged owner profile (read-only) |
|
|
196
|
+
|
|
197
|
+
Agents are expected to follow `AGENTS.md` in the vault root: read the profile at
|
|
198
|
+
session start, query at task start, ingest on learnings, never edit existing
|
|
199
|
+
lessons, never write secrets into the vault. Consolidation proposals carry
|
|
200
|
+
machine-readable directive blocks (```` ```agentbrain ````); only the owner
|
|
201
|
+
executes them via `agentbrain apply`.
|
|
202
|
+
|
|
203
|
+
## Design notes
|
|
204
|
+
|
|
205
|
+
- **Retrieval scoring**: BM25 over summary (×3), tags (×2), case id and body, with a
|
|
206
|
+
CJK bigram tokenizer so Chinese queries work out of the box; results are boosted by
|
|
207
|
+
`verified`, `use_count` and recent `last_verified_at`, demoted when stale (> 1 year).
|
|
208
|
+
- **Self-maintenance signals**: every query hit increments `use_count`; `log.md`
|
|
209
|
+
feeds `memory_distill` pattern analysis; `lint` refreshes nothing silently —
|
|
210
|
+
every mutation of history goes through human-approved proposals.
|
|
211
|
+
- **Single-user, local-first**: no daemon, no ports; concurrent writes from several
|
|
212
|
+
agents are serialized by an OS-level byte-range lock (`.vault.lock`, msvcrt/fcntl —
|
|
213
|
+
released instantly if the holder crashes), and all file writes are atomic
|
|
214
|
+
(temp + rename) so readers never see torn files.
|
|
215
|
+
- **Point-in-time recovery**: every vault is its own git repo (created by `init`,
|
|
216
|
+
repo-local identity only). Each content write — ingest, apply, lint/distill
|
|
217
|
+
proposal, suggestion, index rebuild — is auto-committed, so any bad edit can be
|
|
218
|
+
rolled back with plain git. Query-driven `use_count` bumps ride along with the
|
|
219
|
+
next content commit instead of polluting history. Works fully without git; if git
|
|
220
|
+
is missing, snapshots are silently disabled.
|
|
221
|
+
|
|
222
|
+
## Changelog
|
|
223
|
+
|
|
224
|
+
- **0.4.1** — Enforced secret redaction: `memory_ingest` scans content and
|
|
225
|
+
summaries for credential-shaped patterns (OpenAI/Anthropic/GitHub/AWS/Slack/Google
|
|
226
|
+
tokens, Bearer headers, private-key blocks, `password=`/`api_key=` assignments) and
|
|
227
|
+
refuses the write with a placeholder hint — the "secrets never enter the vault" rule
|
|
228
|
+
is now a mechanism, not just AGENTS.md discipline. `${ENV:VAR}` references and
|
|
229
|
+
teaching examples (`sk-xxx`) pass through. `lint` reports `SECRET` findings for
|
|
230
|
+
pre-existing lessons (read-only). 84 tests.
|
|
231
|
+
- **0.4.0** — Maturity pass: git snapshots (every vault is a self-contained git repo;
|
|
232
|
+
every content write is an auto-commit you can roll back — repo-local identity,
|
|
233
|
+
graceful without git), `agentbrain doctor` one-shot health check (vault, index
|
|
234
|
+
freshness, lock round-trip, snapshot status, log; prints a copy-paste MCP config
|
|
235
|
+
with your vault path), `agentbrain snapshot` manual commit, fool-proof 3-step
|
|
236
|
+
quickstart, PyPI-ready packaging. 74 tests.
|
|
237
|
+
- **0.3.2** — Locking rewrite + edge cases: the vault lock now uses OS-level
|
|
238
|
+
byte-range locks (msvcrt on Windows, fcntl on POSIX) instead of
|
|
239
|
+
create-file-and-reclaim — a crashed holder releases instantly (previously all
|
|
240
|
+
writes failed for up to 60 s) and the stale-reclaim race (two waiters both
|
|
241
|
+
unlinking and both acquiring) is gone. `agentbrain lint --scope tag:x` no longer
|
|
242
|
+
reports false DANGLING for supersede targets outside the scope; `case_id`s
|
|
243
|
+
containing glob metacharacters (`[`, `?`, `*`) no longer collide lesson ids;
|
|
244
|
+
suggestion files use real YAML frontmatter (titles with colons/newlines used to
|
|
245
|
+
corrupt it) and atomic writes. 65 tests.
|
|
246
|
+
- **0.3.1** — Data-integrity fixes: concurrent same-case ingests no longer overwrite
|
|
247
|
+
each other (lesson-id allocation moved inside the vault lock); `confidence: 0.0`
|
|
248
|
+
round-trips correctly (was silently coerced to 0.8); lint/distill proposals are
|
|
249
|
+
written atomically under the lock with collision-free names; merge proposals now
|
|
250
|
+
keep the more-used lesson as the keeper; duplicate detection pre-tokenizes (O(n²)
|
|
251
|
+
without re-tokenizing per pair). Session wrap-up rule added to AGENTS.md. 59 tests.
|
|
252
|
+
- **0.3.0** — Concurrency & robustness: cross-process/thread vault write lock
|
|
253
|
+
(`.vault.lock`, re-entrant, stale-reclaim), atomic writes (temp + rename),
|
|
254
|
+
`apply` is now a single transaction; query no longer rebuilds the index once per
|
|
255
|
+
hit (one rebuild per query); stray non-lesson `.md` files in `Learnings/` are
|
|
256
|
+
ignored; `confidence` clamped to [0,1]; unknown `mode` falls back to `index`;
|
|
257
|
+
same-second suggestions no longer overwrite each other. 54 tests.
|
|
258
|
+
- **0.2.0** — Owner profile layer (`memory_profile` / `memory_suggest` + MCP
|
|
259
|
+
resources), lint/distill proposals with machine-readable directive blocks,
|
|
260
|
+
`agentbrain apply` with cycle/self-supersede/dangling checks.
|
|
261
|
+
- **0.1.0** — Initial MVP: vault + frontmatter + CJK-aware BM25 retrieval,
|
|
262
|
+
MCP server (query/ingest/lint/distill) + CLI, scaffold templates.
|
|
263
|
+
|
|
264
|
+
## Roadmap — maintenance mode
|
|
265
|
+
|
|
266
|
+
The core promise — *a local, token-efficient, agent-shared long-term memory that
|
|
267
|
+
you own as plain Markdown* — is complete and battle-tested in daily use.
|
|
268
|
+
The project is now in maintenance mode: bug fixes, compatibility with new MCP
|
|
269
|
+
client versions, and small quality-of-life improvements. Big new subsystems are
|
|
270
|
+
deliberately out of scope; if a vault ever grows past a few hundred lessons,
|
|
271
|
+
these are the parked ideas:
|
|
272
|
+
|
|
273
|
+
- Hybrid fallback search (SQLite FTS5 + local embedding, RRF fusion)
|
|
274
|
+
- Keyring-backed `${ENV:...}` resolution helper
|
|
275
|
+
|
|
276
|
+
Done along the way:
|
|
277
|
+
|
|
278
|
+
- [x] Enforced secret redaction on ingest + SECRET findings in lint
|
|
279
|
+
- [x] Git snapshot on every write
|
|
280
|
+
- [x] `agentbrain apply <proposal>` to execute approved consolidations
|
|
281
|
+
- [x] Owner profile layer: `memory_profile` / `memory_suggest` + MCP resources
|
|
282
|
+
- [x] OS-level cross-process vault lock + atomic writes
|
|
283
|
+
|
|
284
|
+
## Development
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
pip install -e ".[dev]"
|
|
288
|
+
pytest
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## License
|
|
292
|
+
|
|
293
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|