memento-mcp 0.3.5 → 0.3.6
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.
- package/README.md +23 -7
- package/package.json +1 -1
- package/scripts/README.md +157 -26
- package/src/cli.js +4 -3
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ AI agents have anterograde amnesia — every session starts blank. The Memento P
|
|
|
10
10
|
npx memento-mcp init
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
This creates `.memento.json`, detects your agent (Claude Code, Codex, Gemini CLI, OpenCode), writes the correct MCP config, and
|
|
13
|
+
This creates `.memento.json`, detects your agent (Claude Code, Codex, Gemini CLI, OpenCode), writes the correct MCP config, and registers hooks — all in one command.
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
@@ -154,13 +154,29 @@ Full guide: **[The Protocol](https://hifathom.com/memento/docs/protocol)** on hi
|
|
|
154
154
|
|
|
155
155
|
## Hooks
|
|
156
156
|
|
|
157
|
-
Hooks automate memory at session boundaries — recall on every message, distillation before context loss.
|
|
157
|
+
Hooks automate memory at session boundaries — recall on every message, distillation before context loss, identity injection at session start. Five production-ready scripts are included in `scripts/`:
|
|
158
158
|
|
|
159
|
-
| Script |
|
|
160
|
-
|
|
161
|
-
| `memento-
|
|
162
|
-
| `memento-
|
|
163
|
-
| `memento-
|
|
159
|
+
| Script | What it does |
|
|
160
|
+
|--------|-------------|
|
|
161
|
+
| `memento-sessionstart-identity.sh` | Injects identity crystal + version check at session start |
|
|
162
|
+
| `memento-userprompt-recall.sh` | Recalls memories relevant to the user's message |
|
|
163
|
+
| `memento-stop-recall.sh` | Recalls memories from the assistant's own output (autonomous work) |
|
|
164
|
+
| `memento-precompact-distill.sh` | Extracts memories from the conversation before context compression |
|
|
165
|
+
| `memento-codex-notify.sh` | Stores post-turn summaries from Codex CLI as memory observations |
|
|
166
|
+
|
|
167
|
+
### Agent hook support
|
|
168
|
+
|
|
169
|
+
`npx memento-mcp init` auto-detects your agent and registers the appropriate hooks. Not all agents support the same hook events — here's what gets wired up:
|
|
170
|
+
|
|
171
|
+
| Hook | Claude Code | Gemini CLI | Codex CLI |
|
|
172
|
+
|------|:-----------:|:----------:|:---------:|
|
|
173
|
+
| Session start / identity | `SessionStart` | `SessionStart` | — |
|
|
174
|
+
| Recall on user message | `UserPromptSubmit` | `BeforeAgent` | — |
|
|
175
|
+
| Recall on assistant output | `Stop` | `SessionEnd` | — |
|
|
176
|
+
| Pre-compaction distillation | `PreCompact` | `PreCompress` | — |
|
|
177
|
+
| Post-turn memory storage | — | — | `notify` |
|
|
178
|
+
|
|
179
|
+
**OpenCode** uses a TypeScript plugin system — MCP tools work, but hooks require a different integration pattern.
|
|
164
180
|
|
|
165
181
|
See **[scripts/README.md](scripts/README.md)** for setup, configuration, and how to write your own hooks.
|
|
166
182
|
|
package/package.json
CHANGED
package/scripts/README.md
CHANGED
|
@@ -1,18 +1,56 @@
|
|
|
1
1
|
# Memento Protocol — Hook Scripts
|
|
2
2
|
|
|
3
|
-
Automation hooks
|
|
3
|
+
Automation hooks that connect the Memento API to agent lifecycle events. These scripts make memory automatic — recall on every message, distillation before context loss, identity injection at session start.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Supported agents
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Memento hooks work with three CLI agents. Each has a different hook system, but the same scripts power all of them.
|
|
8
8
|
|
|
9
|
-
|
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
9
|
+
| Hook | Claude Code | Gemini CLI | Codex CLI |
|
|
10
|
+
|------|:-----------:|:----------:|:---------:|
|
|
11
|
+
| Session start / identity | `SessionStart` | `SessionStart` | — |
|
|
12
|
+
| Recall on user message | `UserPromptSubmit` | `BeforeAgent` | — |
|
|
13
|
+
| Recall on assistant output | `Stop` | `SessionEnd` | — |
|
|
14
|
+
| Pre-compaction distillation | `PreCompact` | `PreCompress` | — |
|
|
15
|
+
| Post-turn memory storage | — | — | `notify` |
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
**OpenCode** uses a TypeScript plugin system — MCP tools work, but hooks require a different integration pattern.
|
|
18
|
+
|
|
19
|
+
**Claude Code** and **Gemini CLI** have near-identical hook architectures — JSON on stdin, JSON on stdout. The same shell scripts work for both; only the event names differ.
|
|
20
|
+
|
|
21
|
+
**Codex CLI** has a single `notify` mechanism — fire-and-forget, JSON as `argv[1]`, no context injection. Useful for post-turn memory storage only.
|
|
22
|
+
|
|
23
|
+
## Scripts
|
|
24
|
+
|
|
25
|
+
| Script | What it does |
|
|
26
|
+
|--------|-------------|
|
|
27
|
+
| `memento-sessionstart-identity.sh` | Injects identity crystal + version check at session start |
|
|
28
|
+
| `memento-userprompt-recall.sh` | Recalls memories relevant to the user's message |
|
|
29
|
+
| `memento-stop-recall.sh` | Recalls memories from the assistant's own output |
|
|
30
|
+
| `memento-precompact-distill.sh` | Extracts memories from the conversation before context compression |
|
|
31
|
+
| `memento-codex-notify.sh` | Stores post-turn summaries from Codex CLI as memory observations |
|
|
32
|
+
|
|
33
|
+
## Automatic setup
|
|
34
|
+
|
|
35
|
+
The recommended way to set up hooks:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx memento-mcp init
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This detects your agent, registers hooks in the correct config file, and copies scripts to `.memento/scripts/`. No manual configuration needed.
|
|
42
|
+
|
|
43
|
+
To update hooks in an existing project:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx memento-mcp update
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Manual setup
|
|
52
|
+
|
|
53
|
+
If you prefer to configure hooks yourself:
|
|
16
54
|
|
|
17
55
|
### 1. Create a `.env` file
|
|
18
56
|
|
|
@@ -36,18 +74,29 @@ The `.env` file is gitignored. All scripts source it automatically.
|
|
|
36
74
|
chmod +x scripts/*.sh
|
|
37
75
|
```
|
|
38
76
|
|
|
39
|
-
### 3. Register hooks
|
|
77
|
+
### 3. Register hooks
|
|
78
|
+
|
|
79
|
+
#### Claude Code
|
|
40
80
|
|
|
41
|
-
Add to `.claude/settings.json` (project-level) or `~/.claude/settings.json` (global):
|
|
81
|
+
Add to `.claude/settings.local.json` (project-level) or `~/.claude/settings.json` (global):
|
|
42
82
|
|
|
43
83
|
```json
|
|
44
84
|
{
|
|
45
85
|
"hooks": {
|
|
86
|
+
"SessionStart": [
|
|
87
|
+
{
|
|
88
|
+
"hooks": [{
|
|
89
|
+
"type": "command",
|
|
90
|
+
"command": "bash .memento/scripts/memento-sessionstart-identity.sh",
|
|
91
|
+
"timeout": 10000
|
|
92
|
+
}]
|
|
93
|
+
}
|
|
94
|
+
],
|
|
46
95
|
"UserPromptSubmit": [
|
|
47
96
|
{
|
|
48
97
|
"hooks": [{
|
|
49
98
|
"type": "command",
|
|
50
|
-
"command": "
|
|
99
|
+
"command": "bash .memento/scripts/memento-userprompt-recall.sh",
|
|
51
100
|
"timeout": 5000
|
|
52
101
|
}]
|
|
53
102
|
}
|
|
@@ -56,7 +105,7 @@ Add to `.claude/settings.json` (project-level) or `~/.claude/settings.json` (glo
|
|
|
56
105
|
{
|
|
57
106
|
"hooks": [{
|
|
58
107
|
"type": "command",
|
|
59
|
-
"command": "
|
|
108
|
+
"command": "bash .memento/scripts/memento-stop-recall.sh",
|
|
60
109
|
"timeout": 5000
|
|
61
110
|
}]
|
|
62
111
|
}
|
|
@@ -65,7 +114,54 @@ Add to `.claude/settings.json` (project-level) or `~/.claude/settings.json` (glo
|
|
|
65
114
|
{
|
|
66
115
|
"hooks": [{
|
|
67
116
|
"type": "command",
|
|
68
|
-
"command": "
|
|
117
|
+
"command": "bash .memento/scripts/memento-precompact-distill.sh",
|
|
118
|
+
"timeout": 30000
|
|
119
|
+
}]
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### Gemini CLI
|
|
127
|
+
|
|
128
|
+
Add to `.gemini/settings.json`:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"hooks": {
|
|
133
|
+
"SessionStart": [
|
|
134
|
+
{
|
|
135
|
+
"hooks": [{
|
|
136
|
+
"type": "command",
|
|
137
|
+
"command": "bash .memento/scripts/memento-sessionstart-identity.sh",
|
|
138
|
+
"timeout": 10000
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"BeforeAgent": [
|
|
143
|
+
{
|
|
144
|
+
"hooks": [{
|
|
145
|
+
"type": "command",
|
|
146
|
+
"command": "bash .memento/scripts/memento-userprompt-recall.sh",
|
|
147
|
+
"timeout": 5000
|
|
148
|
+
}]
|
|
149
|
+
}
|
|
150
|
+
],
|
|
151
|
+
"SessionEnd": [
|
|
152
|
+
{
|
|
153
|
+
"hooks": [{
|
|
154
|
+
"type": "command",
|
|
155
|
+
"command": "bash .memento/scripts/memento-stop-recall.sh",
|
|
156
|
+
"timeout": 5000
|
|
157
|
+
}]
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"PreCompress": [
|
|
161
|
+
{
|
|
162
|
+
"hooks": [{
|
|
163
|
+
"type": "command",
|
|
164
|
+
"command": "bash .memento/scripts/memento-precompact-distill.sh",
|
|
69
165
|
"timeout": 30000
|
|
70
166
|
}]
|
|
71
167
|
}
|
|
@@ -74,13 +170,29 @@ Add to `.claude/settings.json` (project-level) or `~/.claude/settings.json` (glo
|
|
|
74
170
|
}
|
|
75
171
|
```
|
|
76
172
|
|
|
77
|
-
|
|
173
|
+
#### Codex CLI
|
|
174
|
+
|
|
175
|
+
Add to `.codex/config.toml`:
|
|
176
|
+
|
|
177
|
+
```toml
|
|
178
|
+
notify = ["bash", ".memento/scripts/memento-codex-notify.sh"]
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Codex `notify` fires on `agent-turn-complete` — the script receives JSON as `argv[1]` (not stdin) and stores a memory observation from the assistant's response. Fire-and-forget only — no context injection.
|
|
78
182
|
|
|
79
183
|
---
|
|
80
184
|
|
|
81
185
|
## Script details
|
|
82
186
|
|
|
83
|
-
### `memento-
|
|
187
|
+
### `memento-sessionstart-identity.sh` — SessionStart
|
|
188
|
+
|
|
189
|
+
Fires when a session begins. Injects the identity crystal into model context and checks whether a newer version of memento-mcp is available.
|
|
190
|
+
|
|
191
|
+
- **Timeout:** 10 seconds
|
|
192
|
+
- **Model sees:** Identity crystal text + update notice (if newer version available)
|
|
193
|
+
- **Version check:** Compares `.memento/version` against npm registry (2s timeout, silent on failure)
|
|
194
|
+
|
|
195
|
+
### `memento-userprompt-recall.sh` — UserPromptSubmit / BeforeAgent
|
|
84
196
|
|
|
85
197
|
Fires before every agent response. Sends the user's message to `/v1/context`, which returns relevant memories and skip list warnings.
|
|
86
198
|
|
|
@@ -91,7 +203,7 @@ Fires before every agent response. Sends the user's message to `/v1/context`, wh
|
|
|
91
203
|
|
|
92
204
|
**Output format:** JSON with `systemMessage` (user display) + `hookSpecificOutput.additionalContext` (model context).
|
|
93
205
|
|
|
94
|
-
### `memento-stop-recall.sh` — Stop
|
|
206
|
+
### `memento-stop-recall.sh` — Stop / SessionEnd
|
|
95
207
|
|
|
96
208
|
Fires after every assistant response. Uses the assistant's own output as the recall query — so memories surface during autonomous work, not just on user messages.
|
|
97
209
|
|
|
@@ -105,9 +217,9 @@ Fires after every assistant response. Uses the assistant's own output as the rec
|
|
|
105
217
|
|
|
106
218
|
**Why this matters:** Without the Stop hook, memories only surface when a human sends a message. For autonomous agents that work independently — running ping routines, doing research, monitoring news — their own memories never get recalled. The Stop hook closes that gap.
|
|
107
219
|
|
|
108
|
-
### `memento-precompact-distill.sh` — PreCompact
|
|
220
|
+
### `memento-precompact-distill.sh` — PreCompact / PreCompress
|
|
109
221
|
|
|
110
|
-
Fires before
|
|
222
|
+
Fires before the agent compresses the conversation. Parses the full JSONL transcript and extracts novel facts, decisions, and observations as stored memories. Supports two extraction backends:
|
|
111
223
|
|
|
112
224
|
- **`"llama"` (default)** — sends transcript to `/v1/distill`, which runs Llama 3.1 8B via Cloudflare Workers AI. Free.
|
|
113
225
|
- **`"claude-code"`** — runs `claude -p` locally for better extraction quality, then pushes to `/v1/memories/ingest`. Uses API credits.
|
|
@@ -135,19 +247,33 @@ Configure the model in `.memento.json`:
|
|
|
135
247
|
|
|
136
248
|
**Why this matters:** Context compaction destroys information. Without distillation, anything discussed but not explicitly saved is lost. This hook captures what's novel — deduplicating against existing memories — so nothing important vanishes.
|
|
137
249
|
|
|
250
|
+
### `memento-codex-notify.sh` — Codex notify
|
|
251
|
+
|
|
252
|
+
Receives JSON as `argv[1]` on `agent-turn-complete` events. Extracts the assistant's response and stores it as a memory observation — best-effort, fire-and-forget.
|
|
253
|
+
|
|
254
|
+
- **Event filter:** Only handles `agent-turn-complete` (other event types exit silently)
|
|
255
|
+
- **Minimum threshold:** Messages under 50 characters are skipped
|
|
256
|
+
- **Truncation:** Stores first 500 characters of the assistant's response
|
|
257
|
+
- **Tags:** `codex`, `turn-summary`, `auto-capture`
|
|
258
|
+
- **Config:** Reads `.memento.json` for API key, URL, and workspace
|
|
259
|
+
|
|
260
|
+
**Why this matters:** Codex CLI can't inject context back into the model, so recall hooks don't apply. But post-turn storage still captures what the agent learned — available for recall in future sessions via any agent.
|
|
261
|
+
|
|
138
262
|
---
|
|
139
263
|
|
|
140
264
|
## Hook output formats
|
|
141
265
|
|
|
142
|
-
Claude Code hooks
|
|
266
|
+
Claude Code and Gemini CLI hooks output data in the same JSON formats:
|
|
143
267
|
|
|
144
268
|
| Format | Where it appears | Used by |
|
|
145
269
|
|--------|-----------------|---------|
|
|
146
270
|
| `systemMessage` | User's terminal | All scripts |
|
|
147
|
-
| `hookSpecificOutput.additionalContext` | Model context (system-reminder) | UserPromptSubmit recall |
|
|
148
|
-
| `decision: "block"` with `reason` | Model context (next instruction) | Stop recall |
|
|
271
|
+
| `hookSpecificOutput.additionalContext` | Model context (system-reminder) | UserPromptSubmit / BeforeAgent recall |
|
|
272
|
+
| `decision: "block"` with `reason` | Model context (next instruction) | Stop / SessionEnd recall |
|
|
149
273
|
|
|
150
|
-
The `additionalContext` approach
|
|
274
|
+
The `additionalContext` approach works for UserPromptSubmit/BeforeAgent, PreToolUse, and PostToolUse events. For Stop/SessionEnd hooks, the `decision: "block"` pattern is the only mechanism that injects content into model context.
|
|
275
|
+
|
|
276
|
+
Codex `notify` has no output mechanism — it's fire-and-forget.
|
|
151
277
|
|
|
152
278
|
---
|
|
153
279
|
|
|
@@ -165,8 +291,13 @@ The `additionalContext` approach only works for UserPromptSubmit, PreToolUse, an
|
|
|
165
291
|
|
|
166
292
|
Follow the naming convention: `[system]-[hook]-[verb].sh`. Your script receives JSON on stdin with event-specific fields:
|
|
167
293
|
|
|
168
|
-
|
|
169
|
-
- **
|
|
170
|
-
- **
|
|
294
|
+
**Claude Code / Gemini CLI** (JSON on stdin):
|
|
295
|
+
- **SessionStart:** `{ "session_id": "..." }`
|
|
296
|
+
- **UserPromptSubmit / BeforeAgent:** `{ "prompt": "user's message" }`
|
|
297
|
+
- **Stop / SessionEnd:** `{ "last_assistant_message": "...", "stop_hook_active": false }`
|
|
298
|
+
- **PreCompact / PreCompress:** `{ "transcript_path": "~/.claude/projects/.../conversation.jsonl" }`
|
|
299
|
+
|
|
300
|
+
**Codex CLI** (JSON as `argv[1]`):
|
|
301
|
+
- **agent-turn-complete:** `{ "type": "agent-turn-complete", "last-assistant-message": "...", "input-messages": [...] }`
|
|
171
302
|
|
|
172
303
|
Source `.env` for credentials, call the Memento API, and output JSON to stdout. Exit 0 for no-op (nothing to report).
|
package/src/cli.js
CHANGED
|
@@ -119,7 +119,7 @@ before compaction. Trust the hooks. Focus on writing good memories.`;
|
|
|
119
119
|
// ---------------------------------------------------------------------------
|
|
120
120
|
|
|
121
121
|
const HEADLESS_CMDS = {
|
|
122
|
-
"claude-code": (prompt) => ["claude", "-p", prompt],
|
|
122
|
+
"claude-code": (prompt) => ["claude", "-p", "--dangerously-skip-permissions", prompt],
|
|
123
123
|
"codex": (prompt) => ["codex", "exec", prompt],
|
|
124
124
|
"gemini": (prompt) => ["gemini", prompt],
|
|
125
125
|
"opencode": (prompt) => ["opencode", "run", prompt],
|
|
@@ -693,12 +693,13 @@ async function runInit(flags = {}) {
|
|
|
693
693
|
// Interactive: ask with explicit command shown
|
|
694
694
|
if (cmdParts) {
|
|
695
695
|
const [cmd, ...args] = cmdParts;
|
|
696
|
-
const
|
|
696
|
+
const flagArgs = args.slice(0, -1).join(" ");
|
|
697
|
+
const displayCmd = `${cmd} ${flagArgs} <prompt>`;
|
|
697
698
|
const rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
698
699
|
console.log("─".repeat(60));
|
|
699
700
|
const integrate = await askYesNo(
|
|
700
701
|
rl2,
|
|
701
|
-
`\n Auto-integrate instructions into your project?\n This will run: ${displayCmd}\n\n Proceed?`,
|
|
702
|
+
`\n Auto-integrate instructions into your project?\n This will run: ${displayCmd}\n\n ⚠ This uses --dangerously-skip-permissions so the agent can\n write to CLAUDE.md without prompting. If you prefer, decline\n and we'll print the instructions for you to add manually.\n\n Proceed?`,
|
|
702
703
|
true,
|
|
703
704
|
);
|
|
704
705
|
rl2.close();
|