0gm-memory 0.1.0__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.
Files changed (39) hide show
  1. 0gm_memory-0.1.0/.gitignore +25 -0
  2. 0gm_memory-0.1.0/CHANGELOG.md +109 -0
  3. 0gm_memory-0.1.0/LICENSE +21 -0
  4. 0gm_memory-0.1.0/PKG-INFO +440 -0
  5. 0gm_memory-0.1.0/PRIVACY.md +61 -0
  6. 0gm_memory-0.1.0/README.md +410 -0
  7. 0gm_memory-0.1.0/SECURITY.md +37 -0
  8. 0gm_memory-0.1.0/pyproject.toml +69 -0
  9. 0gm_memory-0.1.0/src/zgm_memory/__init__.py +3 -0
  10. 0gm_memory-0.1.0/src/zgm_memory/__main__.py +4 -0
  11. 0gm_memory-0.1.0/src/zgm_memory/cli.py +284 -0
  12. 0gm_memory-0.1.0/src/zgm_memory/client.py +189 -0
  13. 0gm_memory-0.1.0/src/zgm_memory/config.py +293 -0
  14. 0gm_memory-0.1.0/src/zgm_memory/dateindex.py +108 -0
  15. 0gm_memory-0.1.0/src/zgm_memory/entry.py +30 -0
  16. 0gm_memory-0.1.0/src/zgm_memory/hook.py +88 -0
  17. 0gm_memory-0.1.0/src/zgm_memory/mcp_server.py +165 -0
  18. 0gm_memory-0.1.0/src/zgm_memory/memory.py +562 -0
  19. 0gm_memory-0.1.0/src/zgm_memory/opencode.py +216 -0
  20. 0gm_memory-0.1.0/src/zgm_memory/redact.py +234 -0
  21. 0gm_memory-0.1.0/src/zgm_memory/store.py +146 -0
  22. 0gm_memory-0.1.0/src/zgm_memory/transcripts.py +549 -0
  23. 0gm_memory-0.1.0/tests/__init__.py +0 -0
  24. 0gm_memory-0.1.0/tests/conftest.py +143 -0
  25. 0gm_memory-0.1.0/tests/fixtures/claude_session.jsonl +11 -0
  26. 0gm_memory-0.1.0/tests/fixtures/codex_legacy.jsonl +4 -0
  27. 0gm_memory-0.1.0/tests/fixtures/codex_rollout.jsonl +13 -0
  28. 0gm_memory-0.1.0/tests/fixtures/opencode_session.json +155 -0
  29. 0gm_memory-0.1.0/tests/fixtures/plain.jsonl +3 -0
  30. 0gm_memory-0.1.0/tests/test_cli.py +171 -0
  31. 0gm_memory-0.1.0/tests/test_client_config.py +229 -0
  32. 0gm_memory-0.1.0/tests/test_hermes.py +133 -0
  33. 0gm_memory-0.1.0/tests/test_live.py +27 -0
  34. 0gm_memory-0.1.0/tests/test_memory.py +502 -0
  35. 0gm_memory-0.1.0/tests/test_opencode.py +243 -0
  36. 0gm_memory-0.1.0/tests/test_protocol.py +188 -0
  37. 0gm_memory-0.1.0/tests/test_redact.py +167 -0
  38. 0gm_memory-0.1.0/tests/test_rename.py +150 -0
  39. 0gm_memory-0.1.0/tests/test_transcripts.py +383 -0
@@ -0,0 +1,25 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+
14
+ # Local state and secrets: never commit
15
+ .env
16
+ .env.*
17
+ *.sqlite
18
+ state.json
19
+ .state/
20
+ e2e-results/
21
+
22
+ # OS / editors
23
+ .DS_Store
24
+ .idea/
25
+ .vscode/
@@ -0,0 +1,109 @@
1
+ # Changelog
2
+
3
+ All notable changes are listed here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
4
+ the project uses [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ### Changed
9
+ - The default model id is now `0gm-2.0` (0GM-2.0 is live on 0G Private Computer), replacing the preview id
10
+ `0gm-msa-1.1-35b`. `ZGM_MEMORY_MODEL` still overrides it. In testing, memories saved
11
+ under the preview id were not returned under `0gm-2.0`.
12
+ - Docs: a recommended project rule for `CLAUDE.md` / `AGENTS.md` (check `ask_memory` before changing configuration,
13
+ dependencies or an earlier decision; stop and ask on a conflict), linked from each integration README.
14
+ - Docs: PRIVACY.md states that requests carry `User-Agent: 0gm-memory/<version>`.
15
+ - Docs: memories expire after 30 days without use, matching 0GM-2.0's memory pricing (PRIVACY.md previously said
16
+ there was no expiry).
17
+ - Docs: wallet capacity is stated as up to 120M tokens of memory; the 64-save figure from preview testing is no
18
+ longer described as a limit.
19
+
20
+ Fixes from real-agent tests in Claude Code, Codex, OpenCode and Hermes (24 Nov 2026).
21
+
22
+ ### Added
23
+ - OpenCode: MCP config snippet and a save plugin (`integrations/opencode`). The plugin uses OpenCode's
24
+ `experimental.idle` session hook; a detached worker reads the session from OpenCode's database (falling back to
25
+ `opencode session export`) and saves it. New parser for OpenCode sessions; `OPENCODE_DB`, `ZGM_MEMORY_OPENCODE_BIN`.
26
+ - `save --opencode` saves a project's past OpenCode sessions straight from OpenCode's database (read-only), skipping
27
+ subagent sessions; it falls back to `opencode session list` and `session export`. `--since YYYY-MM-DD` and
28
+ `--session ID` narrow `--claude`, `--codex` and `--opencode`. OpenCode sessions are keyed by session id and their
29
+ tool records by call id, so the plugin and the backfill never buffer a session twice.
30
+ - README rewritten: a 15-second sequence diagram, a before/after exchange, a per-agent support matrix (ask,
31
+ auto-save, tested in a real session), a from-source quick start, per-agent install, tools and commands tables,
32
+ BEAM-10M and real-session results with a chart, privacy, cost, limits and FAQ.
33
+
34
+ ### Changed
35
+ - Renamed to `0gm-memory` (repository `0gfoundation/0gm-memory`, registry id `io.github.0gfoundation/0gm-memory`,
36
+ MCP server and plugin name `0gm-memory`, Hermes tools `zgm_ask_memory` and `zgm_memory_status`). The Python import
37
+ package is `zgm_memory`, since an identifier cannot start with a digit. Settings are `ZGM_MEMORY_*` (the keychain
38
+ item is `ZGM_MEMORY_KEY_SERVICE`) and the ignore file is `.0gmmemoryignore`. The old names still work: `MSA_MEMORY_*`
39
+ and `MSA_KEY_SERVICE` are read as fallbacks (the new name wins), `.msamemoryignore` is still read, `0gm-msa-memory`
40
+ remains as a deprecated alias command, and the old data folder (`0gm-msa-memory`, and `$HERMES_HOME/0gm-msa-memory`)
41
+ is copied to the new one on first run and left in place. Transcripts that call the tools by their old names are
42
+ still recognised, so old memory lookups are never saved back.
43
+ - Naming: the model is 0GM-2.0 and its memory 0GM-CMSA ("0GM-CMSA memory", or "0GM-2.0's in-model memory"),
44
+ across the README, docs, manifests, `server.json`, `plugin.yaml`, tool descriptions, CLI help and messages. The
45
+ `ask_memory` footer reads `[0GM-CMSA: memory tool ...]`; transcripts with the old footer or tool description are
46
+ still recognised and not saved back. The package, console script, module paths, environment variables and
47
+ registry ids are unchanged. The default model id stays `0gm-msa-1.1-35b` (the 0GM-2.0 preview id) until the
48
+ 0GM-2.0 id is live; `ZGM_MEMORY_MODEL` overrides it.
49
+ - Hooks prefer a persistent install (`uv tool install` / `pipx install 0gm-memory`) and fall back to `uvx`; if
50
+ neither is on `PATH` they fail with a message saying what to install. The `uvx` fallback starts in the background,
51
+ so a first build (1 to 2 s) no longer overruns Claude Code's 1.5 s SessionEnd budget (it used to, and that session
52
+ was not saved).
53
+ - The `hook` command does the minimum while the agent waits: read the hook JSON, check opt-out, log one line and
54
+ start a detached worker. Finding a Codex rollout and resolving the key (including the macOS keychain) moved to the
55
+ worker. One `hook.log` in the data folder, rotated at 1 MB; `status` prints its path.
56
+ - `save` exits 3 when the save to the wallet fails (buffer kept) and 1 for a bad transcript; it used to exit 0.
57
+ - With no network (DNS failure, connection refused) calls fail at once instead of retrying for about 30 s; 429 and
58
+ 5xx are still retried. A lookup that times out is not retried (it could take 25 minutes).
59
+ - Local buffer matches show the whole message up to 1,000 characters, centred on the match (was about 360).
60
+ - `memory_status` says its numbers cover one state folder (Hermes keeps its own).
61
+ - Codex: `env_vars` lists every setting the package reads, so the MCP server and the hooks agree.
62
+ - Cursor: `${env:ZGM_MEMORY_KEY}` everywhere, the interpolation form Cursor documents.
63
+ - Hermes: clearer message when the `0gm-memory` package is missing.
64
+
65
+ ### Fixed
66
+ - Memory lookups were saved back into memory and came back in later lookups as if they were original work. Calls to
67
+ `ask_memory` / `memory_status` / `save_session` and their results are now dropped from Claude Code, Codex and
68
+ Hermes sessions, and so is the answer in a turn whose only tool calls were these (Codex script calls, `wait` polls
69
+ and tool-schema listings included).
70
+ - `log.jsonl` flush events lost their ISO timestamp to the flush record's float.
71
+ - A save held the state lock during the network call (up to 600 s), so `ask_memory` and other saves waited for it.
72
+ The lock is now held only to plan and apply a save; a separate flush lock stops two processes sending the same
73
+ window.
74
+ - Short quotes could not be date-checked: messages up to 300 words now index every phrase.
75
+ - Redaction: a password or key said in a sentence ("the wifi password is ...") is redacted; counts and limits named
76
+ after secrets (`"original_token_count": 1234`) are not.
77
+ - Local buffer search ignored decisions when the query was wordy ("find dated verbatim messages explaining ...") or
78
+ used a 3-letter acronym such as UTC.
79
+ - `state.json` is fsynced before replacing the old file; Codex rollouts match the project case-insensitively on
80
+ Windows.
81
+
82
+ ### Documentation
83
+ - README: how to get uv, the persistent install for hooks, running without uv (pipx), exit codes.
84
+ - Codex: hooks run only once trusted and `codex exec` never asks; how to trust them (interactive hooks browser,
85
+ `[hooks.state."<key>"] trusted_hash`, `--dangerously-bypass-hook-trust` for automation).
86
+ - Claude Code: `CLAUDE_CODE_SESSIONEND_HOOKS_TIMEOUT_MS`, PreCompact and `save --claude` as safety nets.
87
+ - Hermes: the `python_dependencies` package comes from PyPI through Hermes's plugin manager.
88
+
89
+ ## [0.1.0] - 2026-12-04
90
+
91
+ First public release.
92
+
93
+ ### Added
94
+ - MCP server over stdio with `ask_memory`, `save_session` and `memory_status`; standard library only, runs with
95
+ `uvx 0gm-msa-memory`.
96
+ - Command line: `serve`, `save` (with `--claude` and `--codex` to backfill a folder's sessions), `ask`, `status`,
97
+ `hook` and `forget`.
98
+ - Transcript parsers for Claude Code session JSONL, Codex rollouts (current and pre-2025 formats) and plain JSONL.
99
+ - Secret redaction before anything is buffered or sent, a second pass on the request body, and dropping of tool
100
+ output from sensitive files. Per-project `.msamemoryignore` and `MSA_MEMORY_DISABLE=1`.
101
+ - Buffering to about 70K tokens before a save, retries with backoff on 429 and 5xx, no retry of a save that timed out,
102
+ learning of the server's token count, per-wallet state in the user data folder.
103
+ - Every saved message carries its session date, and quote dates in answers are checked against a local index of
104
+ hashed phrases. Fixes quotes dated with the day they were saved.
105
+ - Integrations: Claude Code plugin with SessionEnd and PreCompact hooks, Cursor plugin, Codex config and hooks, Cline
106
+ install notes, Hermes Agent memory provider, MCP registry `server.json`, Dockerfile.
107
+
108
+ [Unreleased]: https://github.com/0gfoundation/0gm-memory/compare/v0.1.0...HEAD
109
+ [0.1.0]: https://github.com/0gfoundation/0gm-memory/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 0G Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,440 @@
1
+ Metadata-Version: 2.5
2
+ Name: 0gm-memory
3
+ Version: 0.1.0
4
+ Summary: Long-term memory for coding agents, stored in 0GM-2.0's in-model memory (0GM-CMSA). MCP server, CLI and agent hooks.
5
+ Project-URL: Homepage, https://github.com/0gfoundation/0gm-memory
6
+ Project-URL: Repository, https://github.com/0gfoundation/0gm-memory
7
+ Project-URL: Issues, https://github.com/0gfoundation/0gm-memory/issues
8
+ Project-URL: Changelog, https://github.com/0gfoundation/0gm-memory/blob/main/CHANGELOG.md
9
+ Author: 0G Foundation
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: 0g,agents,claude-code,codex,cursor,llm,long-term-memory,mcp,memory,msa,opencode
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Software Development
25
+ Requires-Python: >=3.10
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8; extra == 'dev'
28
+ Requires-Dist: ruff>=0.6; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # 0gm-memory
32
+
33
+ **Long-term memory for coding agents.** Your agent's past sessions are saved to 0GM-2.0's in-model memory
34
+ (0GM-CMSA), and when it needs history it gets the exact past messages back, quoted word for word with their dates.
35
+
36
+ [![CI](https://github.com/0gfoundation/0gm-memory/actions/workflows/ci.yml/badge.svg)](https://github.com/0gfoundation/0gm-memory/actions/workflows/ci.yml)
37
+ [![Licence: MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/0gfoundation/0gm-memory/blob/main/LICENSE)
38
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue.svg)](https://github.com/0gfoundation/0gm-memory/blob/main/pyproject.toml)
39
+
40
+ Claude Code · Codex · OpenCode · Hermes Agent · Cursor · Cline · any MCP client
41
+
42
+ <!-- mcp-name: io.github.0gfoundation/0gm-memory -->
43
+
44
+ - **Agents forget.** Every new session starts blank, so decisions, reverted attempts and their reasons get lost.
45
+ - **This remembers for them.** Finished sessions are saved automatically, secrets stripped on your machine first, into
46
+ a wallet that holds up to 120M tokens of memory.
47
+ - **It returns evidence, not a summary.** `ask_memory` hands back dated, verbatim quotes, so the agent reasons over
48
+ what was actually said.
49
+
50
+ [Quick start](#quick-start) · [Install per agent](#install-per-agent) · [How it works](#how-it-works) ·
51
+ [Results](#results) · [Privacy](#privacy-and-data) · [FAQ](#faq)
52
+
53
+ ## In 15 seconds
54
+
55
+ ```mermaid
56
+ sequenceDiagram
57
+ autonumber
58
+ participant A as Coding agent
59
+ participant P as 0gm-memory (your machine)
60
+ participant W as 0GM-CMSA memory
61
+ A->>P: session ends (hook or plugin)
62
+ P->>P: redact secrets, buffer locally
63
+ P->>W: save once the buffer passes about 70K tokens
64
+ Note over A,W: days later, in a fresh session
65
+ A->>P: ask_memory("why is the dev server on 47831?")
66
+ P->>W: find the relevant past messages
67
+ W-->>P: verbatim quotes with session dates
68
+ P->>P: check each date against a local index
69
+ P-->>A: [2026-11-24] User: "the Zebra scanner bridge hard-codes 8080 ..."
70
+ ```
71
+
72
+ The same question in a fresh session, in the invented warehouse project (`pallet-ledger`) used for the real-session
73
+ tests:
74
+
75
+ <table>
76
+ <tr><th>Without memory</th><th>With 0gm-memory</th></tr>
77
+ <tr valign="top"><td>
78
+
79
+ **You:** Why is the dev server on port 47831 and not 8080?
80
+
81
+ **Agent:** `PORT` defaults to 47831 in `config.py`, but nothing in the code says why. It may have been chosen to
82
+ avoid a conflict. Shall I change it back to 8080?
83
+
84
+ </td><td>
85
+
86
+ **You:** Why is the dev server on port 47831 and not 8080?
87
+
88
+ **Agent** *(calls `ask_memory`)*:
89
+
90
+ > [2026-11-24] User: "Move the dev server off port 8080. Reason: the Zebra scanner bridge on the dock PCs hard-codes
91
+ > 8080, so 'pallet-ledger serve' collides with it on every dock PC. We decided on port 47831."
92
+
93
+ It moved because the scanner bridge on the dock PCs owns 8080; changing it back would break every dock PC.
94
+
95
+ </td></tr>
96
+ </table>
97
+
98
+ The quote is verbatim from a real Claude Code session on 24 Nov 2026; the answers are shortened.
99
+
100
+ ## What each agent gets
101
+
102
+ | Agent | Ask (`ask_memory`) | Auto-save | How sessions are saved | Tested in a real session |
103
+ |---|---|---|---|---|
104
+ | Claude Code | yes | yes | `SessionEnd` and `PreCompact` hooks | yes, 24 Nov 2026 |
105
+ | Codex CLI | yes | yes, once its hooks are trusted | `SessionEnd` and `PreCompact` hooks on the rollout | yes, 24 Nov 2026 |
106
+ | OpenCode | yes | yes | plugin on the session idle hook; `save --opencode` for past sessions | yes, 24 Nov 2026 |
107
+ | Hermes Agent | yes (`zgm_ask_memory`) | yes | memory provider, after every turn | yes, 24 Nov 2026 |
108
+ | Cursor | yes | no, ask only | its chat history is not in a format this package reads | no (manifests checked only) |
109
+ | Cline | yes | no, ask only | none | no |
110
+ | Other MCP clients | yes | no, ask only | `0gm-memory save FILE` by hand, for a supported transcript format | no |
111
+
112
+ Sessions saved from one agent can be asked about from any other agent on the same key.
113
+
114
+ ## Quick start
115
+
116
+ Not yet released to PyPI, so install from source. You need Python 3.10 or later, [uv](https://docs.astral.sh/uv/)
117
+ (or pipx) and an API key from [pc.0g.ai](https://pc.0g.ai) for a wallet that will hold only this project's memory.
118
+
119
+ ```sh
120
+ git clone https://github.com/0gfoundation/0gm-memory
121
+ uv tool install ./0gm-memory # or: pipx install ./0gm-memory
122
+ export ZGM_MEMORY_KEY=<key from pc.0g.ai>
123
+ 0gm-memory status # free, no network: shows the wallet and an empty buffer
124
+ ```
125
+
126
+ Connect your agent. For Claude Code:
127
+
128
+ ```sh
129
+ claude mcp add 0gm-memory -e ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve
130
+ ```
131
+
132
+ and merge [`integrations/claude-code/hooks/hooks.json`](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/claude-code/hooks/hooks.json) into
133
+ `.claude/settings.json` so sessions are saved. Already have history? `0gm-memory save --claude` (or `--codex`,
134
+ `--opencode`) saves this folder's past sessions. Then ask your agent about something you decided earlier.
135
+
136
+ ## Install per agent
137
+
138
+ Each block assumes the command is installed as in the quick start. Lines marked *at release* work once the package is
139
+ on PyPI; until then use the `0gm-memory` command shown.
140
+
141
+ <details>
142
+ <summary><b>Claude Code</b>: MCP server and save hooks</summary>
143
+
144
+ ```sh
145
+ claude mcp add 0gm-memory -e ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve
146
+ ```
147
+
148
+ Merge [`hooks/hooks.json`](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/claude-code/hooks/hooks.json) into `.claude/settings.json`. To keep the key
149
+ per project, put `{ "env": { "ZGM_MEMORY_KEY": "<key>" } }` in `.claude/settings.local.json` (not committed).
150
+
151
+ *At release:* the plugin installs both in one go: `/plugin marketplace add 0gfoundation/0gm-memory`, then
152
+ `/plugin install 0gm-memory@0gm-memory`. Details, timeouts and safety nets:
153
+ [integrations/claude-code](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/claude-code/README.md).
154
+ </details>
155
+
156
+ <details>
157
+ <summary><b>Codex CLI</b>: MCP server and save hooks</summary>
158
+
159
+ ```sh
160
+ codex mcp add 0gm-memory --env ZGM_MEMORY_KEY="$ZGM_MEMORY_KEY" -- 0gm-memory serve
161
+ ```
162
+
163
+ Merge [`hooks.json`](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/codex/hooks.json) into `~/.codex/hooks.json` and **trust the hooks**: Codex skips
164
+ untrusted hooks silently, and `codex exec` never asks. How to trust them, and the `env_vars` list for
165
+ `config.toml`: [integrations/codex](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/codex/README.md).
166
+ </details>
167
+
168
+ <details>
169
+ <summary><b>OpenCode</b>: MCP server and a save plugin</summary>
170
+
171
+ In the project's `opencode.json`:
172
+
173
+ ```json
174
+ { "mcp": { "servers": { "0gm-memory": { "type": "local", "command": ["0gm-memory", "serve"],
175
+ "environment": { "ZGM_MEMORY_KEY": "{env:ZGM_MEMORY_KEY}" }, "timeout": { "execution": 300000 } } } } }
176
+ ```
177
+
178
+ Copy [`plugins/0gm-memory.js`](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/opencode/plugins/0gm-memory.js) to `.opencode/plugins/` to save
179
+ sessions, and run `0gm-memory save --opencode` once for past ones. Details:
180
+ [integrations/opencode](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/opencode/README.md).
181
+ </details>
182
+
183
+ <details>
184
+ <summary><b>Hermes Agent</b>: memory provider</summary>
185
+
186
+ ```sh
187
+ hermes plugins install 0gfoundation/0gm-memory --subdir integrations/hermes
188
+ hermes memory setup # choose 0gm-memory, paste the key
189
+ ```
190
+
191
+ The provider imports the `0gm-memory` package, which Hermes installs from PyPI *at release*; until then install it
192
+ from your clone into the Python that runs Hermes. See [integrations/hermes](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/hermes/README.md).
193
+ </details>
194
+
195
+ <details>
196
+ <summary><b>Cursor</b>: ask only</summary>
197
+
198
+ In `.cursor/mcp.json`:
199
+
200
+ ```json
201
+ { "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
202
+ "env": { "ZGM_MEMORY_KEY": "${env:ZGM_MEMORY_KEY}" } } } }
203
+ ```
204
+
205
+ *At release:* the one-click [Add to Cursor](cursor://anysphere.cursor-deeplink/mcp/install?name=0gm-memory&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyIwZ20tbWVtb3J5Iiwic2VydmUiXSwiZW52Ijp7IlpHTV9NRU1PUllfS0VZIjoiJHtlbnY6WkdNX01FTU9SWV9LRVl9In19)
206
+ link and the Cursor plugin. Details: [integrations/cursor](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/cursor/README.md).
207
+ </details>
208
+
209
+ <details>
210
+ <summary><b>Cline</b>: ask only</summary>
211
+
212
+ In `cline_mcp_settings.json` (or ask Cline to install this repository; it follows [llms-install.md](https://github.com/0gfoundation/0gm-memory/blob/main/llms-install.md)):
213
+
214
+ ```json
215
+ { "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
216
+ "env": { "ZGM_MEMORY_KEY": "<key>" }, "timeout": 300 } } }
217
+ ```
218
+ </details>
219
+
220
+ <details>
221
+ <summary><b>Any other MCP client, Docker</b></summary>
222
+
223
+ ```json
224
+ { "mcpServers": { "0gm-memory": { "command": "0gm-memory", "args": ["serve"],
225
+ "env": { "ZGM_MEMORY_KEY": "<key>" } } } }
226
+ ```
227
+
228
+ *At release:* `"command": "uvx", "args": ["0gm-memory", "serve"]` needs no install step. Docker:
229
+ [integrations/docker](https://github.com/0gfoundation/0gm-memory/blob/main/integrations/docker/README.md).
230
+ </details>
231
+
232
+ ## How it works
233
+
234
+ ```mermaid
235
+ flowchart LR
236
+ A[Session ends<br/>or compacts] -->|hook or plugin| B[Read transcript]
237
+ B --> C[Drop memory lookups,<br/>redact secrets]
238
+ C --> D[(Local buffer)]
239
+ D -->|over ~70K tokens| E[One multi-turn call<br/>to the 0G router]
240
+ E --> F[(0GM-CMSA memory)]
241
+ G[ask_memory] --> H[0GM-2.0<br/>quotes past messages]
242
+ F -.-> H
243
+ H --> I[Dates checked<br/>against local index]
244
+ I --> J[Dated verbatim quotes,<br/>plus buffer matches]
245
+ ```
246
+
247
+ 0GM-2.0 writes memory when its server compacts a conversation, which it does by itself once a plain multi-turn call
248
+ passes 65,536 tokens. So the package buffers sessions locally and sends them as one call at about 70K estimated tokens, and
249
+ the server archives them into the wallet. Each message carries its session date, and every quote that comes back is
250
+ checked against a local index of what was saved, so a wrong date is corrected and marked. Until a session is saved,
251
+ `ask_memory` also searches the local buffer and lists those matches separately. Calls to the memory tools, and answers
252
+ that only restate memory, are never saved back, so old answers do not echo into new ones.
253
+
254
+ ## Tools and commands
255
+
256
+ | MCP tool | What it does | Cost and time |
257
+ |---|---|---|
258
+ | `ask_memory(query)` | Returns verbatim quotes of the relevant past messages with their session dates, or `NO RELEVANT MESSAGES`. It does not answer; the agent reasons over the quotes | A few cents a call (about $0.07 measured on 0GM-2.0). Seconds on a small wallet, up to about 100 s on one of millions of tokens |
259
+ | `save_session(transcript_path)` | Redacts and buffers a transcript; saves to the wallet once the buffer is big enough. Re-saving adds only new messages | Free while buffering; see [Cost](#cost) |
260
+ | `memory_status()` | What is buffered and saved, memories used of 64, last save, spend | Free, no network |
261
+
262
+ | Command | What it does |
263
+ |---|---|
264
+ | `0gm-memory serve` | Run the MCP server on stdio |
265
+ | `0gm-memory ask "question"` | The same as `ask_memory` |
266
+ | `0gm-memory save FILE...` | Save transcripts (Claude Code, Codex, an OpenCode export, or JSONL of role and content) |
267
+ | `0gm-memory save --claude` / `--codex` / `--opencode` | Save this folder's past sessions from that agent. `--since YYYY-MM-DD` and `--session ID` narrow it; messages already saved are skipped |
268
+ | `0gm-memory status [--json]` | Buffer, saves, spend and the hook log path. No network |
269
+ | `0gm-memory hook` | For agent hooks: reads the hook JSON and saves in the background |
270
+ | `0gm-memory forget --local` / `--wallet` | Delete this machine's buffer and logs, or every memory in the wallet (asks for the wallet id) |
271
+
272
+ Exit codes: 0 ok, 1 bad input, 2 configuration (for example no key), 3 the router call failed (`save` keeps the buffer
273
+ and sends it again next time). With no network a call fails at once; rate limits and server errors are retried with
274
+ backoff.
275
+
276
+ ## Recommended project rule
277
+
278
+ Agents call `ask_memory` when you mention past work, but not by themselves before a routine change such as "move the
279
+ port back to 8080". To make them check first, add this line to the project's `CLAUDE.md` or `AGENTS.md`:
280
+
281
+ ```text
282
+ Before changing configuration, dependencies or an earlier decision, call ask_memory to check for a past decision; if it conflicts, stop and ask the user before changing it.
283
+ ```
284
+
285
+ ## Configuration
286
+
287
+ | Variable | Default | What it does |
288
+ |---|---|---|
289
+ | `ZGM_MEMORY_KEY` | | API key for this project's wallet |
290
+ | `ZGM_MEMORY_KEY_SERVICE` | | macOS: name of a keychain item holding the key |
291
+ | `ZG_API_KEY` | | Used if nothing above is set |
292
+ | `ZGM_MEMORY_DISABLE` | | `1` turns everything off: nothing is read or sent |
293
+ | `ZGM_MEMORY_HOME` | platform data folder | Local state: `~/Library/Application Support/0gm-memory`, `~/.local/share/0gm-memory` or `%LOCALAPPDATA%\0gm-memory` |
294
+ | `ZGM_MEMORY_FLUSH_TOKENS` | `70000` | Estimated tokens per save. Larger saves mean fewer, bigger saves |
295
+ | `ZGM_MEMORY_ASK_TIMEOUT`, `ZGM_MEMORY_SAVE_TIMEOUT` | `300`, `600` | Seconds per call |
296
+ | `ZGM_MEMORY_MAX_RETRIES` | `4` | Retries on 429 and 5xx, with backoff |
297
+ | `ZGM_MEMORY_TOOL_RESULT_CHARS` | `1500` | How much of each tool result is kept |
298
+ | `ZGM_MEMORY_NO_ENTROPY_REDACTION` | | `1` keeps random-looking strings that match no known secret format |
299
+ | `OPENCODE_DB` | `$XDG_DATA_HOME/opencode/opencode.db` | OpenCode's database, read by `save --opencode` and the plugin |
300
+ | `ZGM_MEMORY_OPENCODE_BIN` | `opencode` | OpenCode command, used only if its database cannot be read |
301
+ | `ZGM_MEMORY_BASE_URL` | `https://router-api.0g.ai/v1` | Router |
302
+ | `ZGM_MEMORY_MODEL` | `0gm-2.0` | Model id; the default is one constant (`DEFAULT_MODEL` in `src/zgm_memory/config.py`) |
303
+
304
+ The key is read in this order: `ZGM_MEMORY_KEY`, `ZGM_MEMORY_KEY_SERVICE`, a key entered in plugin settings,
305
+ `ZG_API_KEY`. It is only sent in the `Authorization` header and never logged; local state is filed under a one-way hash
306
+ of it.
307
+
308
+ **Upgrading from `0gm-msa-memory`.** The package was renamed. The old names keep working for now:
309
+
310
+ - Every `ZGM_MEMORY_*` variable falls back to its old name `MSA_MEMORY_*` (and `ZGM_MEMORY_KEY_SERVICE` to
311
+ `MSA_KEY_SERVICE`); when both are set, the new name wins.
312
+ - On first run, local state in the old `0gm-msa-memory` data folder is copied to the new `0gm-memory` folder. The old
313
+ folder is left untouched; delete it once you are happy.
314
+ - A `.msamemoryignore` file is still read; `.0gmmemoryignore` wins when both are present.
315
+ - `0gm-msa-memory` still runs as a deprecated alias of the `0gm-memory` command.
316
+
317
+ ## Results
318
+
319
+ Measured on test wallets. Small samples and single runs, so read them as indications, not rankings. Methods and raw
320
+ results: [FINDINGS](https://github.com/0gfoundation/0gm-msa-demos/blob/main/docs/FINDINGS.md) and
321
+ [`eval/beam/`](https://github.com/0gfoundation/0gm-msa-demos/tree/main/eval/beam) in the demos repository.
322
+
323
+ **BEAM at 10M tokens** (Mem0's long-conversation benchmark): 40 questions, one run, questions answered correctly.
324
+
325
+ ```mermaid
326
+ xychart-beta
327
+ title "BEAM-10M: correct answers out of 40 (one run)"
328
+ x-axis ["0GM-2.0 (preview)", "This plug-in", "GPT-5.1 + RAG", "Mem0 + GPT-5", "Perfect context"]
329
+ y-axis "Correct (of 40)" 0 --> 40
330
+ bar [22, 22, 21, 19, 34]
331
+ ```
332
+
333
+ | Setup | Correct of 40 |
334
+ |---|---|
335
+ | 0GM-2.0 (preview), a plain question to the wallet | 22 |
336
+ | This plug-in (quoting lookup, v2) | 22 |
337
+ | GPT-5.1 with embedding retrieval (RAG) | 21 |
338
+ | Mem0 with GPT-5 | 19 |
339
+ | Ceiling: the right evidence placed in the prompt | 34 |
340
+
341
+ The first four are within noise of each other on 40 questions, and the gap to the ceiling shows that finding the
342
+ evidence is still the hard part. What this package offers is not a higher score but nothing to host, and answers that
343
+ come back as dated quotes.
344
+
345
+ **Real agent sessions** (24 Nov 2026, invented project, test wallet):
346
+
347
+ | Check | Result |
348
+ |---|---|
349
+ | Fresh Claude Code session, memory tools only, three questions about past decisions | 3 of 3 answered with verbatim, correctly dated quotes (34 s and $0.022 for the lookup) |
350
+ | Fresh Codex, OpenCode and Hermes sessions | Each recalled decisions from earlier sessions, from the wallet, with dates |
351
+ | Synthetic history spanning 17 Sep to 24 Nov | Quotes carried the right session dates |
352
+ | Fake keys, passwords and `.env` contents planted in sessions | 0 found on disk or in any request |
353
+ | Time | A lookup took 6 to 45 s on a small wallet; a save took 18 to 31 s |
354
+
355
+ ## Privacy and data
356
+
357
+ - **What is sent**, after redaction: user and assistant message text, tool calls (cut to 400 characters), tool results
358
+ (cut to 1,500) and your `ask_memory` questions. They go to 0G's router (`router-api.0g.ai`) and are stored in your
359
+ wallet. Nothing is sent while sessions are only buffered.
360
+ - **What is never sent:** thinking blocks, subagent side chains, system reminders, calls to the memory tools, and the
361
+ output of tool calls that touched `.env`, key or credential files.
362
+ - **Redaction** runs on your machine before anything is buffered, and again on the exact request body: API keys and
363
+ tokens in known formats, private keys, secret-looking assignments, passwords said in a sentence and random-looking
364
+ strings. It is a strong filter, not a guarantee; see [SECURITY.md](https://github.com/0gfoundation/0gm-memory/blob/main/SECURITY.md).
365
+ - **Opt out, or add rules**, per project with a `.0gmmemoryignore` file in the project or any parent folder:
366
+
367
+ ```text
368
+ * # save nothing from this project
369
+ Acme Corp # or: redact this string everywhere
370
+ re:CUST-\d{6} # and this pattern
371
+ path:legal/** # and drop tool output for these files
372
+ ```
373
+
374
+ Retention and how to wipe everything: [PRIVACY.md](https://github.com/0gfoundation/0gm-memory/blob/main/PRIVACY.md).
375
+
376
+ ## Cost
377
+
378
+ Measured on 4 Dec 2026 with 0GM-2.0: a save (about 70K tokens of sessions) cost $0.28, and a question $0.07.
379
+
380
+ | A typical week | Saves | Questions | About |
381
+ |---|---|---|---|
382
+ | Busy: 1M tokens of sessions | 14 | 30 | $6 |
383
+ | Light: 300K tokens of sessions | 4 | 10 | $2 |
384
+
385
+ 0GM-2.0 pricing on 0G Private Computer: memory writes are $3.00 per million newly written tokens, including the first
386
+ 30 days of storage; stored memory renews at $3.00 per million tokens per 30 days, and using it resets the 30 days.
387
+ Unused memory expires after 30 days. Check [pc.0g.ai](https://pc.0g.ai) for current prices. `memory_status` shows what has
388
+ been spent from its state folder (Hermes keeps its own folder, so it reports its own share).
389
+
390
+ ## Limits
391
+
392
+ - **A save needs about 70K tokens.** The most recent sessions wait in the local buffer until there is enough;
393
+ `ask_memory` still finds them there.
394
+ - **Up to 120M tokens of memory per wallet.** If a save is ever refused with `429 "Automatic session quota reached"`,
395
+ raise `ZGM_MEMORY_FLUSH_TOKENS` so each save carries more, and open an issue.
396
+ - **Memories expire after 30 days without use**, under 0GM-2.0's memory pricing. See [PRIVACY.md](https://github.com/0gfoundation/0gm-memory/blob/main/PRIVACY.md).
397
+ - **Slow on big wallets.** Seconds on a small wallet; 55 to 101 s per lookup on wallets of 1M to 12M tokens.
398
+ - **Recall is not complete.** Ask one specific question per call: a lookup that bundled five questions missed a fact
399
+ that a specific question then found.
400
+ - **No per-fact delete.** You can wipe a whole wallet, not one session.
401
+ - **One wallet per project.** Everything in a wallet can turn up in any answer (see the [FAQ](#faq)).
402
+ - **Backfills cost per save.** `save --claude` on a long history saves once per ~70K tokens.
403
+
404
+ ## FAQ
405
+
406
+ **What is a wallet?** The account that holds the memory. You create it with an API key from pc.0g.ai and pay for
407
+ use with credit on that key; nothing else is needed.
408
+
409
+ **Why one wallet per project?** With two long conversations in one wallet, 7 of 20 answers about the first brought in
410
+ material from the second; loaded one per wallet, the same 40 questions scored 0.664 against 0.593. The package keeps a
411
+ separate buffer per key, but only separate wallets keep memories apart.
412
+
413
+ **Is this RAG?** No index is built: the model reads its own memory. On the benchmark above it scored about the same as
414
+ embedding retrieval. The trade is different: nothing to host, and evidence comes back as dated quotes.
415
+
416
+ **What happens if a save fails?** Nothing is lost: the buffer is kept and sent again with the next save. `save` exits
417
+ with 3, and `memory_status` counts the failure.
418
+
419
+ **Can I delete memories?** `0gm-memory forget --wallet` deletes every memory in the wallet (it asks you to confirm
420
+ with the wallet id). `forget --local` deletes this machine's buffer and logs.
421
+
422
+ **Does it work offline?** Buffering does; saving and asking need the router.
423
+
424
+ **Will it slow my agent down?** The save hooks return in about 0.1 s and do the work in the background. A lookup takes
425
+ seconds, and runs only when the agent asks.
426
+
427
+ ## Contributing
428
+
429
+ ```sh
430
+ uv run --extra dev pytest # unit tests, no network
431
+ uv run --extra dev ruff check .
432
+ ZGM_MEMORY_KEY=... uv run python scripts/live_e2e.py all --out e2e-results # live, costs under $0.50
433
+ ```
434
+
435
+ Issues and pull requests are welcome; see [CONTRIBUTING.md](https://github.com/0gfoundation/0gm-memory/blob/main/CONTRIBUTING.md) and the
436
+ [Code of Conduct](https://github.com/0gfoundation/0gm-memory/blob/main/CODE_OF_CONDUCT.md). Security reports: [SECURITY.md](https://github.com/0gfoundation/0gm-memory/blob/main/SECURITY.md).
437
+
438
+ ## Licence
439
+
440
+ [MIT](https://github.com/0gfoundation/0gm-memory/blob/main/LICENSE)
@@ -0,0 +1,61 @@
1
+ # Privacy
2
+
3
+ What 0gm-memory reads, stores, sends and keeps, and how to remove it.
4
+
5
+ ## What it reads
6
+ - Transcript files you or a hook point it at: Claude Code session JSONL (`~/.claude/projects/...`), Codex rollouts
7
+ (`~/.codex/sessions/...`) or plain JSONL. With `save --claude` or `save --codex` it lists those folders to find the
8
+ current project's sessions.
9
+ - `.0gmmemoryignore` in the project folder or its parents.
10
+ - The key from the environment, or the macOS keychain item you name in `ZGM_MEMORY_KEY_SERVICE`.
11
+
12
+ ## What is kept from a transcript
13
+ Kept: user and assistant message text, a one-line summary of each tool call (up to 400 characters), and tool results
14
+ (up to 1,500 characters each).
15
+
16
+ Left out: thinking blocks, side chains (subagents), meta and command records, compaction summaries,
17
+ `<system-reminder>` and environment blocks, Codex developer messages, and the whole output of any tool call that
18
+ touched a sensitive file (`.env*`, `*.pem`, `*.key`, SSH keys, `.netrc`, `.npmrc`, `.pypirc`, credential and
19
+ service-account files, `*.tfvars`, `*.tfstate`, and your `path:` rules).
20
+
21
+ ## Redaction
22
+ Before anything is written to the local buffer, and again on the exact request body before it is sent, the text is
23
+ scanned and these are replaced with `[REDACTED:<kind>]`: private key blocks; OpenAI, Anthropic, GitHub, GitLab, AWS,
24
+ Slack, Google, Stripe, Hugging Face, npm and PyPI tokens; JWTs; `0x` + 64 hex (EVM private keys, and transaction hashes
25
+ with them); bearer tokens; passwords in URLs; values assigned to names like `PASSWORD`, `SECRET`, `TOKEN`, `API_KEY`,
26
+ `PRIVATE_KEY`, `MNEMONIC` in `.env`, shell, YAML, JSON and TOML forms; long random-looking strings; and your own
27
+ literals and patterns from `.0gmmemoryignore`. Your `ask_memory` queries are redacted the same way.
28
+
29
+ ## What is sent, and where
30
+ To `https://router-api.0g.ai/v1/chat/completions` (0G's router), authenticated with your key:
31
+ - **On save:** the buffered, redacted messages as one multi-turn call, plus `Reply with: OK`. Nothing is sent while the
32
+ buffer is under the save size.
33
+ - **On ask:** your redacted question inside a fixed instruction to quote matching messages.
34
+
35
+ The server stores saved messages in your wallet's in-model memory. 0G's handling of data on its servers is covered by
36
+ 0G's own terms at pc.0g.ai. Every request carries `User-Agent: 0gm-memory/<version>`. This package sends nothing anywhere else: no telemetry, no analytics, no update checks.
37
+
38
+ ## What is stored on your machine
39
+ In `ZGM_MEMORY_HOME` (default: `~/Library/Application Support/0gm-memory` on macOS,
40
+ `~/.local/share/0gm-memory` on Linux, `%LOCALAPPDATA%\0gm-memory` on Windows), one folder per wallet, named by
41
+ the first 12 hex characters of a SHA-256 of the key:
42
+
43
+ | File | Contents | Kept until |
44
+ |---|---|---|
45
+ | `state.json` | The redacted buffer of messages not yet saved, ids of records already seen per transcript, a record of each save (counts, status, cost, no text) | Buffered messages leave once saved; the rest stays until you delete it |
46
+ | `dates.sqlite` | One-way 64-bit hashes of sampled six-word phrases of saved text, each with its session date. Used only to check dates in quotes. No text | Until you delete it |
47
+ | `log.jsonl` | Events: saves, asks, failures, with counts, timings and cost. No message text, no queries | Until you delete it |
48
+ | `hook.log` | One line per hook run (time, event, transcript path) and the save output | Until you delete it |
49
+
50
+ Folders are created with owner-only permissions on macOS and Linux. The key itself is never written to disk.
51
+
52
+ ## Retention on the server
53
+ Saved memories expire after 30 days without use, under 0GM-2.0's memory pricing on 0G Private Computer. Until then
54
+ they stay in the wallet until the wallet is cleared. There is no per-session or per-fact delete.
55
+
56
+ ## How to wipe
57
+ - Stop saving: `ZGM_MEMORY_DISABLE=1`, or `*` in the project's `.0gmmemoryignore`, or remove the hooks.
58
+ - This machine: `0gm-memory forget --local` (or delete the wallet's folder above).
59
+ - The wallet on the server: `0gm-memory forget --wallet`, which asks you to repeat the wallet id and then sends
60
+ 0GM-2.0's clear command. This deletes **every** memory in the wallet, from every project and machine that uses it, and
61
+ cannot be undone.