@nhatnguyen9317/memory-mcp-server 1.1.1
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/GUIDELINES.md +44 -0
- package/README.md +265 -0
- package/dist/constants.js +16 -0
- package/dist/db.js +17 -0
- package/dist/index.js +32 -0
- package/dist/migrations/0001_initial.js +74 -0
- package/dist/migrations/0002_reasoning_step_marks.js +22 -0
- package/dist/migrations/0003_reasoning_steps_fts.js +34 -0
- package/dist/migrations/0004_tool_usage_events.js +48 -0
- package/dist/migrations/index.js +40 -0
- package/dist/schemas/memory.js +213 -0
- package/dist/schemas/reasoning.js +159 -0
- package/dist/tools/memory.js +998 -0
- package/dist/tools/reasoning.js +1001 -0
- package/dist/tools/telemetry.js +103 -0
- package/dist/tools/usage-guide.js +83 -0
- package/dist/types.js +2 -0
- package/dist/utils.js +67 -0
- package/package.json +41 -0
package/GUIDELINES.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Memory MCP Guidelines
|
|
2
|
+
|
|
3
|
+
Version: 2026-07-07.v1
|
|
4
|
+
|
|
5
|
+
This file is the single source of truth for how an agent should use this MCP.
|
|
6
|
+
|
|
7
|
+
## Fast Rule
|
|
8
|
+
|
|
9
|
+
1. Trivial one-step lookup:
|
|
10
|
+
- do not open a reasoning session
|
|
11
|
+
- do not use memory tools unless prior recall is actually needed
|
|
12
|
+
2. Single-step factual task where prior context may change the answer:
|
|
13
|
+
- use `memory_search` when you have a real keyword or topic
|
|
14
|
+
- use `memory_list` only when browsing is better than searching
|
|
15
|
+
3. Non-trivial task with multiple steps, uncertainty, debugging, planning, review, or trade-offs:
|
|
16
|
+
- start with `reasoning_start_session` before the main investigation
|
|
17
|
+
- add only meaningful steps with `reasoning_add_step`
|
|
18
|
+
- finish with `reasoning_complete_session`
|
|
19
|
+
- save only durable conclusions
|
|
20
|
+
|
|
21
|
+
## Tool Choice
|
|
22
|
+
|
|
23
|
+
- `memory_search`: targeted recall by keyword, topic, or hypothesis
|
|
24
|
+
- `memory_list`: recent or filtered browsing
|
|
25
|
+
- `memory_get`: fetch one memory when you already know the exact id
|
|
26
|
+
- `memory_save`: store durable facts, decisions, preferences, or reasoning summaries
|
|
27
|
+
- `memory_update`: correct an existing memory in place
|
|
28
|
+
- `memory_delete`: remove unsafe, duplicated, or wrong memory
|
|
29
|
+
- `reasoning_start_session`: open live trace capture for a non-trivial task
|
|
30
|
+
- `reasoning_add_step`: log a decision, hypothesis, rejected option, or meaningful observation
|
|
31
|
+
- `reasoning_complete_session`: close the session and optionally persist only the conclusion
|
|
32
|
+
|
|
33
|
+
## Do Not Store
|
|
34
|
+
|
|
35
|
+
- secrets, tokens, or credentials
|
|
36
|
+
- full hidden chain-of-thought
|
|
37
|
+
- transient debugging noise
|
|
38
|
+
- raw tool dumps with no durable value
|
|
39
|
+
|
|
40
|
+
## Rule Of Thumb
|
|
41
|
+
|
|
42
|
+
- durable reusable knowledge -> `memory_*`
|
|
43
|
+
- live multi-step task trace -> `reasoning_*`
|
|
44
|
+
- when in doubt, skip storage unless the information will help a future agent or future run
|
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# memory-mcp-server
|
|
2
|
+
|
|
3
|
+
MCP server for agents that need:
|
|
4
|
+
|
|
5
|
+
- durable memory across tasks
|
|
6
|
+
- per-task reasoning traces
|
|
7
|
+
- lightweight audit/review tools over those traces
|
|
8
|
+
|
|
9
|
+
This server runs over stdio, stores data in SQLite, and is meant to be installed into an MCP client such as Claude Code, Codex, or another MCP-compatible agent.
|
|
10
|
+
|
|
11
|
+
## What This MCP Is For
|
|
12
|
+
|
|
13
|
+
Use this MCP when you want an agent to:
|
|
14
|
+
|
|
15
|
+
- save stable facts, decisions, and preferences for later reuse
|
|
16
|
+
- keep a reasoning session for one concrete task
|
|
17
|
+
- search or review prior reasoning traces
|
|
18
|
+
- measure memory/reasoning usage through telemetry reports
|
|
19
|
+
|
|
20
|
+
High-level split:
|
|
21
|
+
|
|
22
|
+
- `memory_*` tools: durable recall
|
|
23
|
+
- `reasoning_*` tools: live task trace and audit retrieval
|
|
24
|
+
- `get_usage_guide`: runtime usage guide an agent can call after connection
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Node.js `>= 22.5.0`
|
|
29
|
+
- support for Node's built-in `node:sqlite`
|
|
30
|
+
|
|
31
|
+
No native addon build is required.
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install
|
|
37
|
+
npm run build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Built entrypoint:
|
|
41
|
+
|
|
42
|
+
- `dist/index.js`
|
|
43
|
+
|
|
44
|
+
## Run
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm start
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
or:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
node dist/index.js
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The server runs over stdio and logs the active DB path to stderr on startup.
|
|
57
|
+
|
|
58
|
+
## Practical Setup
|
|
59
|
+
|
|
60
|
+
If you are a real user wiring this into Claude Code, Codex, Antigravity, or another MCP client, the normal setup is:
|
|
61
|
+
|
|
62
|
+
1. Build this repo:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install
|
|
66
|
+
npm run build
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. Register it in your MCP client as a stdio server:
|
|
70
|
+
|
|
71
|
+
- command: `node`
|
|
72
|
+
- args: `["/absolute/path/to/memory-mcp-server/dist/index.js"]`
|
|
73
|
+
|
|
74
|
+
3. Optionally set `MEMORY_DB_PATH` if you do not want the default database location.
|
|
75
|
+
|
|
76
|
+
Default DB path:
|
|
77
|
+
|
|
78
|
+
- `~/.memory-mcp-server/memory.db`
|
|
79
|
+
|
|
80
|
+
4. Restart the MCP client.
|
|
81
|
+
|
|
82
|
+
5. Verify the connection with a cheap read-only tool such as:
|
|
83
|
+
|
|
84
|
+
- `get_usage_guide`
|
|
85
|
+
- `memory_list`
|
|
86
|
+
|
|
87
|
+
### Example MCP Config
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"mcpServers": {
|
|
92
|
+
"memory": {
|
|
93
|
+
"command": "node",
|
|
94
|
+
"args": ["/absolute/path/to/memory-mcp-server/dist/index.js"],
|
|
95
|
+
"env": {
|
|
96
|
+
"MEMORY_DB_PATH": "/absolute/path/to/memory.db"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Shared vs Project-Scoped Memory
|
|
104
|
+
|
|
105
|
+
Shared memory across many repos:
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"env": {
|
|
110
|
+
"MEMORY_DB_PATH": "/Users/you/.memory-mcp-server/shared-memory.db"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Project-scoped memory:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"env": {
|
|
120
|
+
"MEMORY_DB_PATH": "/absolute/path/to/your-project/.memory/project-memory.db"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Practical recommendation:
|
|
126
|
+
|
|
127
|
+
- use shared memory if you want one agent persona to accumulate knowledge across projects
|
|
128
|
+
- use project-scoped memory if you want isolation per repository or customer
|
|
129
|
+
|
|
130
|
+
### How An Agent Learns To Use This MCP
|
|
131
|
+
|
|
132
|
+
The human installer reads this `README`.
|
|
133
|
+
|
|
134
|
+
The runtime agent usually does not.
|
|
135
|
+
|
|
136
|
+
That means:
|
|
137
|
+
|
|
138
|
+
- `README.md` is for the person installing the MCP
|
|
139
|
+
- `AGENTS.md` in this repo is for agents working inside this repo
|
|
140
|
+
- an agent working in some other repo will usually only see:
|
|
141
|
+
- tool names
|
|
142
|
+
- tool descriptions
|
|
143
|
+
- schemas
|
|
144
|
+
- any runtime tool it can call, especially `get_usage_guide`
|
|
145
|
+
|
|
146
|
+
If you want a newly connected agent to use this MCP correctly, the most reliable pattern is:
|
|
147
|
+
|
|
148
|
+
1. install the MCP
|
|
149
|
+
2. add a short instruction snippet to your own repo's `AGENTS.md` or client prompt
|
|
150
|
+
3. tell the agent to call `get_usage_guide` before using memory/reasoning tools the first time
|
|
151
|
+
|
|
152
|
+
## Suggested AGENTS.md Snippet
|
|
153
|
+
|
|
154
|
+
If you want your agent to use this MCP well, you can paste something like this into your own repo's `AGENTS.md`:
|
|
155
|
+
|
|
156
|
+
```md
|
|
157
|
+
## Memory MCP
|
|
158
|
+
|
|
159
|
+
When the `memory` MCP server is available:
|
|
160
|
+
|
|
161
|
+
- On first use, call `get_usage_guide` to load the current usage rules.
|
|
162
|
+
- Use `memory_*` tools for durable facts, decisions, and reusable context.
|
|
163
|
+
- Use `reasoning_*` tools for multi-step task traces, debugging, or planning.
|
|
164
|
+
- Do not store secrets, tokens, or raw sensitive data in memory.
|
|
165
|
+
- Prefer `memory_search` for targeted recall and `memory_list` only for browsing.
|
|
166
|
+
- Start a `reasoning_start_session` before substantial multi-step investigation, then close it with `reasoning_complete_session`.
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Keep that snippet in the repo where the agent actually works. Do not rely on the agent reading this MCP repo.
|
|
170
|
+
|
|
171
|
+
## Do I Need `AGENTS.md` or `CLAUDE.md` In This Repo?
|
|
172
|
+
|
|
173
|
+
Usually no.
|
|
174
|
+
|
|
175
|
+
- You do not need to edit this repo's `AGENTS.md` just to install the MCP into your own agent.
|
|
176
|
+
- You do not need a `CLAUDE.md` here unless you want Claude-specific rules for contributors working inside this MCP repo.
|
|
177
|
+
- The useful place for runtime instructions is the user's own repo or client prompt, not this MCP repo.
|
|
178
|
+
|
|
179
|
+
## Tool Surface
|
|
180
|
+
|
|
181
|
+
### Memory tools
|
|
182
|
+
|
|
183
|
+
| Tool | Purpose |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| `memory_save` | Save a durable memory |
|
|
186
|
+
| `memory_search` | Search memory content and tags |
|
|
187
|
+
| `memory_list` | Browse memories with filters |
|
|
188
|
+
| `memory_get` | Fetch one memory by id |
|
|
189
|
+
| `memory_update` | Update an existing memory |
|
|
190
|
+
| `memory_delete` | Delete a memory |
|
|
191
|
+
| `memory_usage_report` | Aggregate tool usage telemetry |
|
|
192
|
+
| `memory_adoption_report` | Summarize adoption behavior across memory and reasoning |
|
|
193
|
+
| `memory_agent_scorecard` | Compare agent usage patterns |
|
|
194
|
+
| `memory_record_usage_feedback` | Record whether recalled memory was useful |
|
|
195
|
+
| `get_usage_guide` | Return the runtime usage guide for this MCP |
|
|
196
|
+
|
|
197
|
+
### Reasoning tools
|
|
198
|
+
|
|
199
|
+
| Tool | Purpose |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `reasoning_start_session` | Open a reasoning session |
|
|
202
|
+
| `reasoning_add_step` | Append a thought, action, or observation |
|
|
203
|
+
| `reasoning_get_trace` | Return the full ordered trace |
|
|
204
|
+
| `reasoning_list_sessions` | List sessions with grouped step counts |
|
|
205
|
+
| `reasoning_mark_step` | Add or update an audit mark on a step |
|
|
206
|
+
| `reasoning_search_steps` | Search reasoning steps |
|
|
207
|
+
| `reasoning_list_milestones` | List marked steps without loading a full trace |
|
|
208
|
+
| `reasoning_get_session_outline` | Return marked steps or deterministic fallback outline |
|
|
209
|
+
| `reasoning_complete_session` | Close a session and optionally save its conclusion as memory |
|
|
210
|
+
|
|
211
|
+
## Storage Model
|
|
212
|
+
|
|
213
|
+
Main tables:
|
|
214
|
+
|
|
215
|
+
- `memories`
|
|
216
|
+
- `reasoning_sessions`
|
|
217
|
+
- `reasoning_steps`
|
|
218
|
+
- `reasoning_step_marks`
|
|
219
|
+
- `tool_usage_events`
|
|
220
|
+
- `schema_migrations`
|
|
221
|
+
|
|
222
|
+
FTS tables:
|
|
223
|
+
|
|
224
|
+
- `memories_fts`
|
|
225
|
+
- `reasoning_steps_fts`
|
|
226
|
+
|
|
227
|
+
## Migrations
|
|
228
|
+
|
|
229
|
+
Schema is managed in `src/migrations/`.
|
|
230
|
+
|
|
231
|
+
Migrations run automatically at server startup. There is currently no separate manual migration CLI command in this repo.
|
|
232
|
+
|
|
233
|
+
If you need migrations applied, start the server normally:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
npm start
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
or:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
node dist/index.js
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Development
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
npm run dev
|
|
249
|
+
npm run build
|
|
250
|
+
npm run test
|
|
251
|
+
npm run clean
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Implementation Notes
|
|
255
|
+
|
|
256
|
+
- `src/db.ts` owns DB open and migration bootstrap
|
|
257
|
+
- `src/tools/memory.ts` owns memory tool handlers
|
|
258
|
+
- `src/tools/reasoning.ts` owns reasoning and audit tool handlers
|
|
259
|
+
- `src/tools/usage-guide.ts` owns `get_usage_guide`
|
|
260
|
+
|
|
261
|
+
## Notes
|
|
262
|
+
|
|
263
|
+
- `node:sqlite` is still experimental in Node and may print an `ExperimentalWarning`
|
|
264
|
+
- this is a local stdio MCP server, not a network service
|
|
265
|
+
- `agent_id` is a filtering aid, not a security boundary
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
/** Max characters returned in a single tool response before truncation. */
|
|
4
|
+
export const CHARACTER_LIMIT = 25000;
|
|
5
|
+
export const MCP_VERSION = "1.1.1";
|
|
6
|
+
export const TELEMETRY_ENABLED = process.env.MEMORY_TELEMETRY !== "off";
|
|
7
|
+
/**
|
|
8
|
+
* Location of the SQLite database file.
|
|
9
|
+
* Override with the MEMORY_DB_PATH environment variable, e.g. to keep
|
|
10
|
+
* per-project memory stores instead of one global store.
|
|
11
|
+
*/
|
|
12
|
+
export const DB_PATH = process.env.MEMORY_DB_PATH ??
|
|
13
|
+
path.join(os.homedir(), ".memory-mcp-server", "memory.db");
|
|
14
|
+
export const DEFAULT_LIST_LIMIT = 20;
|
|
15
|
+
export const MAX_LIST_LIMIT = 200;
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DatabaseSync } from "node:sqlite";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DB_PATH } from "./constants.js";
|
|
5
|
+
import { runMigrations } from "./migrations/index.js";
|
|
6
|
+
function ensureDir(filePath) {
|
|
7
|
+
const dir = path.dirname(filePath);
|
|
8
|
+
if (!fs.existsSync(dir)) {
|
|
9
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
ensureDir(DB_PATH);
|
|
13
|
+
export const db = new DatabaseSync(DB_PATH);
|
|
14
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
15
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
16
|
+
runMigrations(db);
|
|
17
|
+
//# sourceMappingURL=db.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* memory-mcp-server
|
|
4
|
+
*
|
|
5
|
+
* An MCP server that gives an agent durable long-term memory and the
|
|
6
|
+
* ability to record/retrieve step-by-step reasoning traces, backed by
|
|
7
|
+
* a local SQLite database (with full-text search over memories).
|
|
8
|
+
*/
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { DB_PATH, MCP_VERSION } from "./constants.js";
|
|
12
|
+
import "./db.js"; // ensures schema is created before tools run
|
|
13
|
+
import { registerMemoryTools } from "./tools/memory.js";
|
|
14
|
+
import { registerReasoningTools } from "./tools/reasoning.js";
|
|
15
|
+
import { registerUsageGuideTool } from "./tools/usage-guide.js";
|
|
16
|
+
const server = new McpServer({
|
|
17
|
+
name: "memory-mcp-server",
|
|
18
|
+
version: MCP_VERSION,
|
|
19
|
+
});
|
|
20
|
+
registerMemoryTools(server);
|
|
21
|
+
registerReasoningTools(server);
|
|
22
|
+
registerUsageGuideTool(server);
|
|
23
|
+
async function main() {
|
|
24
|
+
const transport = new StdioServerTransport();
|
|
25
|
+
await server.connect(transport);
|
|
26
|
+
console.error(`memory-mcp-server running via stdio (db: ${DB_PATH})`);
|
|
27
|
+
}
|
|
28
|
+
main().catch((error) => {
|
|
29
|
+
console.error("Fatal error starting memory-mcp-server:", error);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export const migration0001Initial = {
|
|
2
|
+
version: "0001_initial",
|
|
3
|
+
apply(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
type TEXT NOT NULL,
|
|
8
|
+
content TEXT NOT NULL,
|
|
9
|
+
tags TEXT,
|
|
10
|
+
agent_id TEXT,
|
|
11
|
+
importance INTEGER NOT NULL DEFAULT 3 CHECK (importance BETWEEN 1 AND 5),
|
|
12
|
+
metadata TEXT,
|
|
13
|
+
created_at TEXT NOT NULL,
|
|
14
|
+
updated_at TEXT NOT NULL
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);
|
|
18
|
+
CREATE INDEX IF NOT EXISTS idx_memories_agent ON memories(agent_id);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at);
|
|
20
|
+
|
|
21
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
22
|
+
content,
|
|
23
|
+
tags,
|
|
24
|
+
content='memories',
|
|
25
|
+
content_rowid='rowid'
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
29
|
+
INSERT INTO memories_fts(rowid, content, tags)
|
|
30
|
+
VALUES (new.rowid, new.content, coalesce(new.tags, ''));
|
|
31
|
+
END;
|
|
32
|
+
|
|
33
|
+
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
34
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, tags)
|
|
35
|
+
VALUES ('delete', old.rowid, old.content, coalesce(old.tags, ''));
|
|
36
|
+
END;
|
|
37
|
+
|
|
38
|
+
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
39
|
+
INSERT INTO memories_fts(memories_fts, rowid, content, tags)
|
|
40
|
+
VALUES ('delete', old.rowid, old.content, coalesce(old.tags, ''));
|
|
41
|
+
INSERT INTO memories_fts(rowid, content, tags)
|
|
42
|
+
VALUES (new.rowid, new.content, coalesce(new.tags, ''));
|
|
43
|
+
END;
|
|
44
|
+
|
|
45
|
+
CREATE TABLE IF NOT EXISTS reasoning_sessions (
|
|
46
|
+
id TEXT PRIMARY KEY,
|
|
47
|
+
title TEXT NOT NULL,
|
|
48
|
+
agent_id TEXT,
|
|
49
|
+
status TEXT NOT NULL DEFAULT 'in_progress'
|
|
50
|
+
CHECK (status IN ('in_progress','completed','abandoned')),
|
|
51
|
+
conclusion TEXT,
|
|
52
|
+
created_at TEXT NOT NULL,
|
|
53
|
+
updated_at TEXT NOT NULL
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_agent ON reasoning_sessions(agent_id);
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_status ON reasoning_sessions(status);
|
|
58
|
+
|
|
59
|
+
CREATE TABLE IF NOT EXISTS reasoning_steps (
|
|
60
|
+
id TEXT PRIMARY KEY,
|
|
61
|
+
session_id TEXT NOT NULL REFERENCES reasoning_sessions(id) ON DELETE CASCADE,
|
|
62
|
+
step_number INTEGER NOT NULL,
|
|
63
|
+
thought TEXT,
|
|
64
|
+
action TEXT,
|
|
65
|
+
observation TEXT,
|
|
66
|
+
created_at TEXT NOT NULL,
|
|
67
|
+
UNIQUE(session_id, step_number)
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
CREATE INDEX IF NOT EXISTS idx_steps_session ON reasoning_steps(session_id, step_number);
|
|
71
|
+
`);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=0001_initial.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const migration0002ReasoningStepMarks = {
|
|
2
|
+
version: "0002_reasoning_step_marks",
|
|
3
|
+
apply(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS reasoning_step_marks (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
step_id TEXT NOT NULL REFERENCES reasoning_steps(id) ON DELETE CASCADE,
|
|
8
|
+
mark_type TEXT NOT NULL
|
|
9
|
+
CHECK (mark_type IN ('milestone','decision','conflict','important','hypothesis')),
|
|
10
|
+
note TEXT,
|
|
11
|
+
created_at TEXT NOT NULL,
|
|
12
|
+
UNIQUE(step_id, mark_type)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX IF NOT EXISTS idx_reasoning_step_marks_step_id
|
|
16
|
+
ON reasoning_step_marks(step_id);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS idx_reasoning_step_marks_type_created
|
|
18
|
+
ON reasoning_step_marks(mark_type, created_at);
|
|
19
|
+
`);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=0002_reasoning_step_marks.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const migration0003ReasoningStepsFts = {
|
|
2
|
+
version: "0003_reasoning_steps_fts",
|
|
3
|
+
apply(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS reasoning_steps_fts USING fts5(
|
|
6
|
+
thought,
|
|
7
|
+
action,
|
|
8
|
+
observation,
|
|
9
|
+
content='reasoning_steps',
|
|
10
|
+
content_rowid='rowid'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
CREATE TRIGGER IF NOT EXISTS reasoning_steps_ai AFTER INSERT ON reasoning_steps BEGIN
|
|
14
|
+
INSERT INTO reasoning_steps_fts(rowid, thought, action, observation)
|
|
15
|
+
VALUES (new.rowid, coalesce(new.thought, ''), coalesce(new.action, ''), coalesce(new.observation, ''));
|
|
16
|
+
END;
|
|
17
|
+
|
|
18
|
+
CREATE TRIGGER IF NOT EXISTS reasoning_steps_ad AFTER DELETE ON reasoning_steps BEGIN
|
|
19
|
+
INSERT INTO reasoning_steps_fts(reasoning_steps_fts, rowid, thought, action, observation)
|
|
20
|
+
VALUES ('delete', old.rowid, coalesce(old.thought, ''), coalesce(old.action, ''), coalesce(old.observation, ''));
|
|
21
|
+
END;
|
|
22
|
+
|
|
23
|
+
CREATE TRIGGER IF NOT EXISTS reasoning_steps_au AFTER UPDATE ON reasoning_steps BEGIN
|
|
24
|
+
INSERT INTO reasoning_steps_fts(reasoning_steps_fts, rowid, thought, action, observation)
|
|
25
|
+
VALUES ('delete', old.rowid, coalesce(old.thought, ''), coalesce(old.action, ''), coalesce(old.observation, ''));
|
|
26
|
+
INSERT INTO reasoning_steps_fts(rowid, thought, action, observation)
|
|
27
|
+
VALUES (new.rowid, coalesce(new.thought, ''), coalesce(new.action, ''), coalesce(new.observation, ''));
|
|
28
|
+
END;
|
|
29
|
+
|
|
30
|
+
INSERT INTO reasoning_steps_fts(reasoning_steps_fts) VALUES ('rebuild');
|
|
31
|
+
`);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=0003_reasoning_steps_fts.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const migration0004ToolUsageEvents = {
|
|
2
|
+
version: "0004_tool_usage_events",
|
|
3
|
+
apply(db) {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS tool_usage_events (
|
|
6
|
+
id TEXT PRIMARY KEY,
|
|
7
|
+
created_at TEXT NOT NULL,
|
|
8
|
+
agent_id TEXT,
|
|
9
|
+
client_name TEXT,
|
|
10
|
+
client_version TEXT,
|
|
11
|
+
mcp_version TEXT NOT NULL,
|
|
12
|
+
guidance_version TEXT,
|
|
13
|
+
tool_name TEXT NOT NULL,
|
|
14
|
+
operation_type TEXT NOT NULL
|
|
15
|
+
CHECK (operation_type IN ('memory','reasoning','guidance','report','feedback')),
|
|
16
|
+
access_type TEXT NOT NULL
|
|
17
|
+
CHECK (access_type IN ('read','write','delete','derived')),
|
|
18
|
+
status TEXT NOT NULL
|
|
19
|
+
CHECK (status IN ('success','error','skipped')),
|
|
20
|
+
error_code TEXT,
|
|
21
|
+
latency_ms INTEGER,
|
|
22
|
+
session_id TEXT,
|
|
23
|
+
step_id TEXT,
|
|
24
|
+
memory_id TEXT,
|
|
25
|
+
related_event_id TEXT,
|
|
26
|
+
input_shape TEXT,
|
|
27
|
+
output_shape TEXT,
|
|
28
|
+
metadata TEXT
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_created_at
|
|
32
|
+
ON tool_usage_events(created_at);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_agent_created_at
|
|
34
|
+
ON tool_usage_events(agent_id, created_at);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_mcp_created_at
|
|
36
|
+
ON tool_usage_events(mcp_version, created_at);
|
|
37
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_tool_created_at
|
|
38
|
+
ON tool_usage_events(tool_name, created_at);
|
|
39
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_status_created_at
|
|
40
|
+
ON tool_usage_events(status, created_at);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_session_id
|
|
42
|
+
ON tool_usage_events(session_id);
|
|
43
|
+
CREATE INDEX IF NOT EXISTS idx_tool_usage_events_memory_id
|
|
44
|
+
ON tool_usage_events(memory_id);
|
|
45
|
+
`);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=0004_tool_usage_events.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { nowIso } from "../utils.js";
|
|
2
|
+
import { migration0001Initial } from "./0001_initial.js";
|
|
3
|
+
import { migration0002ReasoningStepMarks } from "./0002_reasoning_step_marks.js";
|
|
4
|
+
import { migration0003ReasoningStepsFts } from "./0003_reasoning_steps_fts.js";
|
|
5
|
+
import { migration0004ToolUsageEvents } from "./0004_tool_usage_events.js";
|
|
6
|
+
const migrations = [
|
|
7
|
+
migration0001Initial,
|
|
8
|
+
migration0002ReasoningStepMarks,
|
|
9
|
+
migration0003ReasoningStepsFts,
|
|
10
|
+
migration0004ToolUsageEvents,
|
|
11
|
+
];
|
|
12
|
+
export function runMigrations(db) {
|
|
13
|
+
db.exec(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
15
|
+
version TEXT PRIMARY KEY,
|
|
16
|
+
applied_at TEXT NOT NULL
|
|
17
|
+
)
|
|
18
|
+
`);
|
|
19
|
+
const applied = new Set(db.prepare("SELECT version FROM schema_migrations").all().map((row) => row.version));
|
|
20
|
+
const pending = migrations.filter((migration) => !applied.has(migration.version));
|
|
21
|
+
if (pending.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
const insertMigration = db.prepare(`
|
|
24
|
+
INSERT INTO schema_migrations (version, applied_at)
|
|
25
|
+
VALUES (?, ?)
|
|
26
|
+
`);
|
|
27
|
+
for (const migration of pending) {
|
|
28
|
+
db.exec("BEGIN");
|
|
29
|
+
try {
|
|
30
|
+
migration.apply(db);
|
|
31
|
+
insertMigration.run(migration.version, nowIso());
|
|
32
|
+
db.exec("COMMIT");
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
db.exec("ROLLBACK");
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|