memgrid 0.5.0 → 0.5.2
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/CHANGELOG.md +99 -80
- package/LICENSE +21 -21
- package/README.md +284 -251
- package/dist/claude-md.d.ts +4 -0
- package/dist/claude-md.d.ts.map +1 -0
- package/dist/claude-md.js +58 -0
- package/dist/claude-md.js.map +1 -0
- package/dist/hooks.d.ts +18 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +138 -0
- package/dist/hooks.js.map +1 -0
- package/dist/learn/index.d.ts.map +1 -1
- package/dist/learn/index.js +28 -9
- package/dist/learn/index.js.map +1 -1
- package/dist/memgrid.d.ts.map +1 -1
- package/dist/memgrid.js +39 -6
- package/dist/memgrid.js.map +1 -1
- package/dist/retrieve/index.d.ts +1 -1
- package/dist/retrieve/index.d.ts.map +1 -1
- package/dist/retrieve/index.js +17 -13
- package/dist/retrieve/index.js.map +1 -1
- package/dist/retrieve/semantic.d.ts.map +1 -1
- package/dist/retrieve/semantic.js +9 -7
- package/dist/retrieve/semantic.js.map +1 -1
- package/dist/scanner/composite.d.ts.map +1 -1
- package/dist/scanner/composite.js +1 -3
- package/dist/scanner/composite.js.map +1 -1
- package/dist/scanner/config.d.ts.map +1 -1
- package/dist/scanner/config.js +30 -8
- package/dist/scanner/config.js.map +1 -1
- package/dist/scanner/golang.d.ts.map +1 -1
- package/dist/scanner/golang.js +11 -6
- package/dist/scanner/golang.js.map +1 -1
- package/dist/scanner/javascript.d.ts.map +1 -1
- package/dist/scanner/javascript.js +9 -5
- package/dist/scanner/javascript.js.map +1 -1
- package/dist/scanner/markdown.d.ts.map +1 -1
- package/dist/scanner/markdown.js +8 -3
- package/dist/scanner/markdown.js.map +1 -1
- package/dist/scanner/python.d.ts.map +1 -1
- package/dist/scanner/python.js +7 -3
- package/dist/scanner/python.js.map +1 -1
- package/dist/scanner/rules.d.ts.map +1 -1
- package/dist/scanner/rules.js +17 -3
- package/dist/scanner/rules.js.map +1 -1
- package/dist/scanner/rust.d.ts.map +1 -1
- package/dist/scanner/rust.js +4 -2
- package/dist/scanner/rust.js.map +1 -1
- package/dist/scanner/sync.d.ts +50 -0
- package/dist/scanner/sync.d.ts.map +1 -0
- package/dist/scanner/sync.js +384 -0
- package/dist/scanner/sync.js.map +1 -0
- package/dist/scanner/typescript.d.ts.map +1 -1
- package/dist/scanner/typescript.js +93 -17
- package/dist/scanner/typescript.js.map +1 -1
- package/dist/serve/cli.js +15 -1
- package/dist/serve/cli.js.map +1 -1
- package/dist/serve/mcp-server.d.ts.map +1 -1
- package/dist/serve/mcp-server.js +27 -9
- package/dist/serve/mcp-server.js.map +1 -1
- package/dist/store/file-store.d.ts +5 -0
- package/dist/store/file-store.d.ts.map +1 -1
- package/dist/store/file-store.js +36 -8
- package/dist/store/file-store.js.map +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +64 -23
- package/dist/sync/index.js.map +1 -1
- package/package.json +64 -51
package/README.md
CHANGED
|
@@ -1,251 +1,284 @@
|
|
|
1
|
-
# MemGrid
|
|
2
|
-
|
|
3
|
-
> Project-level semantic memory for AI coding agents. Replaces full-codebase context loading with a self-evolving knowledge-mesh.
|
|
4
|
-
|
|
5
|
-
## 🧠 What is MemGrid?
|
|
6
|
-
|
|
7
|
-
MemGrid builds a **memory mesh** of your project — not as flat documents, but as interconnected **knowledge units**. Each unit represents one thing: a method, a component, a design pattern, a bug fix, a coding style preference, or a tooling rule.
|
|
8
|
-
|
|
9
|
-
When an AI coding agent starts a task, instead of dumping your entire codebase into context, MemGrid retrieves only the relevant units — and traverses their associations to pull in related context.
|
|
10
|
-
|
|
11
|
-
Think of it as **your project's persistent brain** that gets sharper with every task.
|
|
12
|
-
|
|
13
|
-
## 🎯 The Problem
|
|
14
|
-
|
|
15
|
-
AI coding tools today face a context dilemma:
|
|
16
|
-
|
|
17
|
-
- Load the whole project → massive token waste, slow responses, OOM
|
|
18
|
-
- Load only open files → no context, generic output, repeated mistakes
|
|
19
|
-
- Start fresh every session → no learning, inconsistent style
|
|
20
|
-
|
|
21
|
-
MemGrid solves this by giving the agent exactly what it needs, nothing it doesn't.
|
|
22
|
-
|
|
23
|
-
## 📐 Architecture
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
┌─────────────────────────────────────────┐
|
|
27
|
-
│ MemGrid (Agent Brain) │
|
|
28
|
-
│ │
|
|
29
|
-
│ ┌────────────────────────────────────┐ │
|
|
30
|
-
│ │ Scheduler Layer (Meta-Cognition) │ │
|
|
31
|
-
│ │ skill_trigger / mcp_trigger │ │
|
|
32
|
-
│ │ rule_trigger │ │
|
|
33
|
-
│ │ "What tool for what task" │ │
|
|
34
|
-
│ └──────────┬─────────────────────────┘ │
|
|
35
|
-
│ │ drives │
|
|
36
|
-
│ ┌──────────▼─────────────────────────┐ │
|
|
37
|
-
│ │ Knowledge Layer (Semantics) │ │
|
|
38
|
-
│ │ method / component / pattern │ │
|
|
39
|
-
│ │ config / error_solution │ │
|
|
40
|
-
│ │ "What this project is" │ │
|
|
41
|
-
│ └──────────┬─────────────────────────┘ │
|
|
42
|
-
│ │ shapes │
|
|
43
|
-
│ ┌──────────▼─────────────────────────┐ │
|
|
44
|
-
│ │ Style Layer (Your DNA) │ │
|
|
45
|
-
│ │ style_preference │ │
|
|
46
|
-
│ │ architecture_principle │ │
|
|
47
|
-
│ │ decision (why we did this) │ │
|
|
48
|
-
│ │ "What your code looks like" │ │
|
|
49
|
-
│ └────────────────────────────────────┘ │
|
|
50
|
-
└─────────────────────────────────────────┘
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## 🚀 Quick Start
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
npm install -g memgrid
|
|
57
|
-
# or
|
|
58
|
-
pnpm add -g memgrid
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Initialize
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
cd your-project
|
|
65
|
-
memgrid init
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
MemGrid auto-detects your project's languages and scans all relevant source files.
|
|
69
|
-
|
|
70
|
-
**Supported languages:** TypeScript, JavaScript, Python, Go, Rust, and any Markdown documentation.
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
# Example output for a TypeScript + Markdown + Rules project:
|
|
74
|
-
# 🔍 Scanning project (typescript, markdown, rules, config)...
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
The grid is stored in `.claude/memory-grid/`.
|
|
78
|
-
|
|
79
|
-
### Search
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
# Hybrid search (keyword + semantic, configurable weight)
|
|
83
|
-
memgrid search "add file upload to creation endpoint"
|
|
84
|
-
|
|
85
|
-
# With options
|
|
86
|
-
memgrid search "error handling pattern" --semantic 0.6 --max 5 --hops 2
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Incremental Sync
|
|
90
|
-
|
|
91
|
-
Fast sync after code changes — only re-scans changed files:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
memgrid sync
|
|
95
|
-
# Output:
|
|
96
|
-
# 📁 Changed files: 3
|
|
97
|
-
# 🗑️ Removed files: 0
|
|
98
|
-
# 📝 Updated units: 12
|
|
99
|
-
# ⚠️ Stale units: 0
|
|
100
|
-
# 🔗 Repaired links: 2
|
|
101
|
-
# ⏱️ Done in 1834ms
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Add Custom Units
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
memgrid add \
|
|
108
|
-
--type decision \
|
|
109
|
-
--summary "Why we chose PostgreSQL over MongoDB" \
|
|
110
|
-
--description "ACID compliance for financial data, team expertise, $REASON" \
|
|
111
|
-
--file docs/decisions/database.md
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Stats
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
memgrid stats
|
|
118
|
-
# 📊 MemGrid Statistics
|
|
119
|
-
# Total units: 150
|
|
120
|
-
# Active: 142
|
|
121
|
-
# Archived: 8
|
|
122
|
-
# Last scan: 2026-06-28T10:00:00.000Z
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### MCP Server
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
memgrid serve
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Exposes MemGrid as an MCP tool — plug into Claude Desktop, VS Code, or any MCP-compatible agent.
|
|
132
|
-
|
|
133
|
-
## 📦 Memory Unit Types
|
|
134
|
-
|
|
135
|
-
| Type | What it stores | Example |
|
|
136
|
-
|------|---------------|---------|
|
|
137
|
-
| `method` | A function/class method | `CreationDomainService.create()` |
|
|
138
|
-
| `component` | A UI component | `CreationCard` |
|
|
139
|
-
| `pattern` | Design pattern or convention | ResponseBuilder chain pattern |
|
|
140
|
-
| `config` | Configuration/env | Docker services, tech stack |
|
|
141
|
-
| `error_solution` | A bug + how it was fixed | "GLM OOM → switch to DeepSeek" |
|
|
142
|
-
| `decision` | A code decision + rationale | "Why delete returns true, not null" |
|
|
143
|
-
| `skill_trigger` | When to use which skill | "Figma work → enable chakra MCP" |
|
|
144
|
-
| `mcp_trigger` | When to call which MCP | "New Chakra component → get_component_example" |
|
|
145
|
-
| `rule_trigger` | When to load which rule | "Server code → load coding-philosophy" |
|
|
146
|
-
| `style_preference` | Your coding style | "functional pipes over for-loops" |
|
|
147
|
-
| `architecture_principle` | Architecture red lines | "Controller never calls Repository directly" |
|
|
148
|
-
|
|
149
|
-
## 🆚 vs Alternatives
|
|
150
|
-
|
|
151
|
-
| | Claude Auto Memory | Mem0 | Cursor Indexing | **MemGrid** |
|
|
152
|
-
|---|---|---|---|---|
|
|
153
|
-
| Granularity | Documents | Conversations | Files | **Knowledge units** |
|
|
154
|
-
| Structure | Flat text | Flat | File tree | **Mesh (graph)** |
|
|
155
|
-
| Retrieval | Full load | Semantic | Semantic | **Hybrid + Traverse** |
|
|
156
|
-
| Learning | Linear append | None | None | **Post-task self-evolution** |
|
|
157
|
-
| Incremental sync | No | No | Full re-index | **Hash-diff incremental** |
|
|
158
|
-
| Tool-aware | No | No | No | **Trigger units** |
|
|
159
|
-
| Style-aware | Rules only | No | No | **Style layer** |
|
|
160
|
-
|
|
161
|
-
## 📊 Performance
|
|
162
|
-
|
|
163
|
-
| Scenario | Time |
|
|
164
|
-
|----------|------|
|
|
165
|
-
| Search (keyword) | < 3ms |
|
|
166
|
-
| Search (repeated, LRU) | 0ms |
|
|
167
|
-
| Sync (0 changes) | ~5ms |
|
|
168
|
-
| Sync (1 file changed) | ~2s |
|
|
169
|
-
| Full init (150 units) | ~10s |
|
|
170
|
-
|
|
171
|
-
## 📁 File Format
|
|
172
|
-
|
|
173
|
-
Memory units are stored as JSON in `.claude/memory-grid/units/` — **Git-friendly and human-readable**.
|
|
174
|
-
|
|
175
|
-
```json
|
|
176
|
-
{
|
|
177
|
-
"id": "method_creation_create",
|
|
178
|
-
"type": "method",
|
|
179
|
-
"summary": "CreationDomainService.create — Create a new work",
|
|
180
|
-
"source": {
|
|
181
|
-
"file": "apps/server/src/creation/creation.domain-service.ts",
|
|
182
|
-
"lines": "45-67"
|
|
183
|
-
},
|
|
184
|
-
"signatures": ["CreationDomainService.create"],
|
|
185
|
-
"content": {
|
|
186
|
-
"description": "Creates a new work, verifies ownership, saves to DB",
|
|
187
|
-
"inputs": "userId: string, dto: Partial<CreationEntity>",
|
|
188
|
-
"outputs": "ApiResponse{ value: savedEntity }"
|
|
189
|
-
},
|
|
190
|
-
"associations": [
|
|
191
|
-
{
|
|
192
|
-
"to": "pattern_response_builder",
|
|
193
|
-
"relation": "implements_pattern",
|
|
194
|
-
"weight": 0.9
|
|
195
|
-
}
|
|
196
|
-
],
|
|
197
|
-
"meta": {
|
|
198
|
-
"created": "2026-06-28T00:00:00.000Z",
|
|
199
|
-
"updated": "2026-06-28T00:00:00.000Z",
|
|
200
|
-
"confidence": 0.8,
|
|
201
|
-
"usage_count": 0,
|
|
202
|
-
"status": "active"
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
`mesh.json` stores the grid metadata including `fileSnapshot` for incremental sync and `edgeIndex` for fast association traversal.
|
|
208
|
-
|
|
209
|
-
## 🌐 Language Support
|
|
210
|
-
|
|
211
|
-
MemGrid is **language-agnostic** at its core. Scanners are swappable plugins:
|
|
212
|
-
|
|
213
|
-
| Scanner | Detects | Extracts |
|
|
214
|
-
|---------|---------|----------|
|
|
215
|
-
| **TypeScript** | `tsconfig.json`, `.ts` files | Classes, methods, exported functions (AST via ts-morph) |
|
|
216
|
-
| **JavaScript** | `package.json` (no tsconfig), `.js` files | Exported functions, classes, arrow functions (regex) |
|
|
217
|
-
| **Python** | `pyproject.toml`, `.py` files | Functions, classes, decorators, docstrings (regex) |
|
|
218
|
-
| **Go** | `go.mod`, `.go` files | Functions, methods, structs, interfaces (regex) |
|
|
219
|
-
| **Rust** | `Cargo.toml`, `.rs` files | Functions, structs, enums, traits, impl blocks (regex) |
|
|
220
|
-
| **Markdown** | Any `.md` files | Headings as knowledge units |
|
|
221
|
-
| **Rules** | `.claude/rules/*.md` | Design patterns, coding rules, trigger units |
|
|
222
|
-
| **Config** | `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, `docker-compose.yml` | Tech stack, dependencies, infrastructure |
|
|
223
|
-
|
|
224
|
-
**Adding a new language** means implementing the `Scanner` interface — the core engine (storage, retrieval, learning, sync) stays untouched.
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
// src/scanner/python.ts (example)
|
|
228
|
-
export class PythonScanner implements Scanner {
|
|
229
|
-
readonly name = 'python';
|
|
230
|
-
detect(projectRoot: string): boolean { ... }
|
|
231
|
-
async scan(options: ScanOptions): Promise<MemoryUnit[]> { ... }
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
## 🔌 Integration
|
|
236
|
-
|
|
237
|
-
MemGrid outputs **standardized Markdown context** consumable by any AI coding tool:
|
|
238
|
-
|
|
239
|
-
- **Claude Code** — via MCP Server or Hook
|
|
240
|
-
- **Cursor / Windsurf** — via Rules file injection
|
|
241
|
-
- **GitHub Copilot** — via `.github/copilot-instructions.md`
|
|
242
|
-
- **Aider / Cline / Continue** — via custom prompt templates
|
|
243
|
-
|
|
244
|
-
```bash
|
|
245
|
-
# Start MCP Server
|
|
246
|
-
memgrid serve
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
##
|
|
250
|
-
|
|
251
|
-
|
|
1
|
+
# MemGrid
|
|
2
|
+
|
|
3
|
+
> Project-level semantic memory for AI coding agents. Replaces full-codebase context loading with a self-evolving knowledge-mesh.
|
|
4
|
+
|
|
5
|
+
## 🧠 What is MemGrid?
|
|
6
|
+
|
|
7
|
+
MemGrid builds a **memory mesh** of your project — not as flat documents, but as interconnected **knowledge units**. Each unit represents one thing: a method, a component, a design pattern, a bug fix, a coding style preference, or a tooling rule.
|
|
8
|
+
|
|
9
|
+
When an AI coding agent starts a task, instead of dumping your entire codebase into context, MemGrid retrieves only the relevant units — and traverses their associations to pull in related context.
|
|
10
|
+
|
|
11
|
+
Think of it as **your project's persistent brain** that gets sharper with every task.
|
|
12
|
+
|
|
13
|
+
## 🎯 The Problem
|
|
14
|
+
|
|
15
|
+
AI coding tools today face a context dilemma:
|
|
16
|
+
|
|
17
|
+
- Load the whole project → massive token waste, slow responses, OOM
|
|
18
|
+
- Load only open files → no context, generic output, repeated mistakes
|
|
19
|
+
- Start fresh every session → no learning, inconsistent style
|
|
20
|
+
|
|
21
|
+
MemGrid solves this by giving the agent exactly what it needs, nothing it doesn't.
|
|
22
|
+
|
|
23
|
+
## 📐 Architecture
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
┌─────────────────────────────────────────┐
|
|
27
|
+
│ MemGrid (Agent Brain) │
|
|
28
|
+
│ │
|
|
29
|
+
│ ┌────────────────────────────────────┐ │
|
|
30
|
+
│ │ Scheduler Layer (Meta-Cognition) │ │
|
|
31
|
+
│ │ skill_trigger / mcp_trigger │ │
|
|
32
|
+
│ │ rule_trigger │ │
|
|
33
|
+
│ │ "What tool for what task" │ │
|
|
34
|
+
│ └──────────┬─────────────────────────┘ │
|
|
35
|
+
│ │ drives │
|
|
36
|
+
│ ┌──────────▼─────────────────────────┐ │
|
|
37
|
+
│ │ Knowledge Layer (Semantics) │ │
|
|
38
|
+
│ │ method / component / pattern │ │
|
|
39
|
+
│ │ config / error_solution │ │
|
|
40
|
+
│ │ "What this project is" │ │
|
|
41
|
+
│ └──────────┬─────────────────────────┘ │
|
|
42
|
+
│ │ shapes │
|
|
43
|
+
│ ┌──────────▼─────────────────────────┐ │
|
|
44
|
+
│ │ Style Layer (Your DNA) │ │
|
|
45
|
+
│ │ style_preference │ │
|
|
46
|
+
│ │ architecture_principle │ │
|
|
47
|
+
│ │ decision (why we did this) │ │
|
|
48
|
+
│ │ "What your code looks like" │ │
|
|
49
|
+
│ └────────────────────────────────────┘ │
|
|
50
|
+
└─────────────────────────────────────────┘
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 🚀 Quick Start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install -g memgrid
|
|
57
|
+
# or
|
|
58
|
+
pnpm add -g memgrid
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Initialize
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd your-project
|
|
65
|
+
memgrid init
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
MemGrid auto-detects your project's languages and scans all relevant source files.
|
|
69
|
+
|
|
70
|
+
**Supported languages:** TypeScript, JavaScript, Python, Go, Rust, and any Markdown documentation.
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Example output for a TypeScript + Markdown + Rules project:
|
|
74
|
+
# 🔍 Scanning project (typescript, markdown, rules, config)...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The grid is stored in `.claude/memory-grid/`.
|
|
78
|
+
|
|
79
|
+
### Search
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Hybrid search (keyword + semantic, configurable weight)
|
|
83
|
+
memgrid search "add file upload to creation endpoint"
|
|
84
|
+
|
|
85
|
+
# With options
|
|
86
|
+
memgrid search "error handling pattern" --semantic 0.6 --max 5 --hops 2
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Incremental Sync
|
|
90
|
+
|
|
91
|
+
Fast sync after code changes — only re-scans changed files:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
memgrid sync
|
|
95
|
+
# Output:
|
|
96
|
+
# 📁 Changed files: 3
|
|
97
|
+
# 🗑️ Removed files: 0
|
|
98
|
+
# 📝 Updated units: 12
|
|
99
|
+
# ⚠️ Stale units: 0
|
|
100
|
+
# 🔗 Repaired links: 2
|
|
101
|
+
# ⏱️ Done in 1834ms
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Add Custom Units
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
memgrid add \
|
|
108
|
+
--type decision \
|
|
109
|
+
--summary "Why we chose PostgreSQL over MongoDB" \
|
|
110
|
+
--description "ACID compliance for financial data, team expertise, $REASON" \
|
|
111
|
+
--file docs/decisions/database.md
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Stats
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
memgrid stats
|
|
118
|
+
# 📊 MemGrid Statistics
|
|
119
|
+
# Total units: 150
|
|
120
|
+
# Active: 142
|
|
121
|
+
# Archived: 8
|
|
122
|
+
# Last scan: 2026-06-28T10:00:00.000Z
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### MCP Server
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
memgrid serve
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Exposes MemGrid as an MCP tool — plug into Claude Desktop, VS Code, or any MCP-compatible agent.
|
|
132
|
+
|
|
133
|
+
## 📦 Memory Unit Types
|
|
134
|
+
|
|
135
|
+
| Type | What it stores | Example |
|
|
136
|
+
|------|---------------|---------|
|
|
137
|
+
| `method` | A function/class method | `CreationDomainService.create()` |
|
|
138
|
+
| `component` | A UI component | `CreationCard` |
|
|
139
|
+
| `pattern` | Design pattern or convention | ResponseBuilder chain pattern |
|
|
140
|
+
| `config` | Configuration/env | Docker services, tech stack |
|
|
141
|
+
| `error_solution` | A bug + how it was fixed | "GLM OOM → switch to DeepSeek" |
|
|
142
|
+
| `decision` | A code decision + rationale | "Why delete returns true, not null" |
|
|
143
|
+
| `skill_trigger` | When to use which skill | "Figma work → enable chakra MCP" |
|
|
144
|
+
| `mcp_trigger` | When to call which MCP | "New Chakra component → get_component_example" |
|
|
145
|
+
| `rule_trigger` | When to load which rule | "Server code → load coding-philosophy" |
|
|
146
|
+
| `style_preference` | Your coding style | "functional pipes over for-loops" |
|
|
147
|
+
| `architecture_principle` | Architecture red lines | "Controller never calls Repository directly" |
|
|
148
|
+
|
|
149
|
+
## 🆚 vs Alternatives
|
|
150
|
+
|
|
151
|
+
| | Claude Auto Memory | Mem0 | Cursor Indexing | **MemGrid** |
|
|
152
|
+
|---|---|---|---|---|
|
|
153
|
+
| Granularity | Documents | Conversations | Files | **Knowledge units** |
|
|
154
|
+
| Structure | Flat text | Flat | File tree | **Mesh (graph)** |
|
|
155
|
+
| Retrieval | Full load | Semantic | Semantic | **Hybrid + Traverse** |
|
|
156
|
+
| Learning | Linear append | None | None | **Post-task self-evolution** |
|
|
157
|
+
| Incremental sync | No | No | Full re-index | **Hash-diff incremental** |
|
|
158
|
+
| Tool-aware | No | No | No | **Trigger units** |
|
|
159
|
+
| Style-aware | Rules only | No | No | **Style layer** |
|
|
160
|
+
|
|
161
|
+
## 📊 Performance
|
|
162
|
+
|
|
163
|
+
| Scenario | Time |
|
|
164
|
+
|----------|------|
|
|
165
|
+
| Search (keyword) | < 3ms |
|
|
166
|
+
| Search (repeated, LRU) | 0ms |
|
|
167
|
+
| Sync (0 changes) | ~5ms |
|
|
168
|
+
| Sync (1 file changed) | ~2s |
|
|
169
|
+
| Full init (150 units) | ~10s |
|
|
170
|
+
|
|
171
|
+
## 📁 File Format
|
|
172
|
+
|
|
173
|
+
Memory units are stored as JSON in `.claude/memory-grid/units/` — **Git-friendly and human-readable**.
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"id": "method_creation_create",
|
|
178
|
+
"type": "method",
|
|
179
|
+
"summary": "CreationDomainService.create — Create a new work",
|
|
180
|
+
"source": {
|
|
181
|
+
"file": "apps/server/src/creation/creation.domain-service.ts",
|
|
182
|
+
"lines": "45-67"
|
|
183
|
+
},
|
|
184
|
+
"signatures": ["CreationDomainService.create"],
|
|
185
|
+
"content": {
|
|
186
|
+
"description": "Creates a new work, verifies ownership, saves to DB",
|
|
187
|
+
"inputs": "userId: string, dto: Partial<CreationEntity>",
|
|
188
|
+
"outputs": "ApiResponse{ value: savedEntity }"
|
|
189
|
+
},
|
|
190
|
+
"associations": [
|
|
191
|
+
{
|
|
192
|
+
"to": "pattern_response_builder",
|
|
193
|
+
"relation": "implements_pattern",
|
|
194
|
+
"weight": 0.9
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"meta": {
|
|
198
|
+
"created": "2026-06-28T00:00:00.000Z",
|
|
199
|
+
"updated": "2026-06-28T00:00:00.000Z",
|
|
200
|
+
"confidence": 0.8,
|
|
201
|
+
"usage_count": 0,
|
|
202
|
+
"status": "active"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`mesh.json` stores the grid metadata including `fileSnapshot` for incremental sync and `edgeIndex` for fast association traversal.
|
|
208
|
+
|
|
209
|
+
## 🌐 Language Support
|
|
210
|
+
|
|
211
|
+
MemGrid is **language-agnostic** at its core. Scanners are swappable plugins:
|
|
212
|
+
|
|
213
|
+
| Scanner | Detects | Extracts |
|
|
214
|
+
|---------|---------|----------|
|
|
215
|
+
| **TypeScript** | `tsconfig.json`, `.ts` files | Classes, methods, exported functions (AST via ts-morph) |
|
|
216
|
+
| **JavaScript** | `package.json` (no tsconfig), `.js` files | Exported functions, classes, arrow functions (regex) |
|
|
217
|
+
| **Python** | `pyproject.toml`, `.py` files | Functions, classes, decorators, docstrings (regex) |
|
|
218
|
+
| **Go** | `go.mod`, `.go` files | Functions, methods, structs, interfaces (regex) |
|
|
219
|
+
| **Rust** | `Cargo.toml`, `.rs` files | Functions, structs, enums, traits, impl blocks (regex) |
|
|
220
|
+
| **Markdown** | Any `.md` files | Headings as knowledge units |
|
|
221
|
+
| **Rules** | `.claude/rules/*.md` | Design patterns, coding rules, trigger units |
|
|
222
|
+
| **Config** | `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, `docker-compose.yml` | Tech stack, dependencies, infrastructure |
|
|
223
|
+
|
|
224
|
+
**Adding a new language** means implementing the `Scanner` interface — the core engine (storage, retrieval, learning, sync) stays untouched.
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
// src/scanner/python.ts (example)
|
|
228
|
+
export class PythonScanner implements Scanner {
|
|
229
|
+
readonly name = 'python';
|
|
230
|
+
detect(projectRoot: string): boolean { ... }
|
|
231
|
+
async scan(options: ScanOptions): Promise<MemoryUnit[]> { ... }
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🔌 Integration
|
|
236
|
+
|
|
237
|
+
MemGrid outputs **standardized Markdown context** consumable by any AI coding tool:
|
|
238
|
+
|
|
239
|
+
- **Claude Code** — via MCP Server or Hook
|
|
240
|
+
- **Cursor / Windsurf** — via Rules file injection
|
|
241
|
+
- **GitHub Copilot** — via `.github/copilot-instructions.md`
|
|
242
|
+
- **Aider / Cline / Continue** — via custom prompt templates
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
# Start MCP Server
|
|
246
|
+
memgrid serve
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## 🔄 Auto-Sync Hooks
|
|
250
|
+
|
|
251
|
+
`memgrid init` automatically configures hooks so your memory grid stays up to date without manual effort:
|
|
252
|
+
|
|
253
|
+
| Hook | Trigger | What it does |
|
|
254
|
+
|------|---------|--------------|
|
|
255
|
+
| **PostCompletion** | Claude Code finishes a task | Runs `memgrid sync` automatically |
|
|
256
|
+
| **post-commit** | `git commit` | Runs `memgrid sync` (covers non-Claude changes) |
|
|
257
|
+
|
|
258
|
+
All injections are **non-destructive** — existing config is merged, never overwritten.
|
|
259
|
+
|
|
260
|
+
## 📝 CLAUDE.md Integration (optional)
|
|
261
|
+
|
|
262
|
+
To make your AI agent proactive about memory, add these sections to your CLAUDE.md:
|
|
263
|
+
|
|
264
|
+
```markdown
|
|
265
|
+
## MemGrid
|
|
266
|
+
|
|
267
|
+
Before any task, search the memory grid for relevant context:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npx memgrid search "<what you're about to do>" --max 10
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
After completing code changes, sync the grid back:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
npx memgrid sync
|
|
277
|
+
```
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
> ⚠️ MemGrid won't touch your CLAUDE.md. The hooks above handle automatic sync. This snippet is just a recommendation — add it if you want your AI agent to actively *search* the grid before starting.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-md.d.ts","sourceRoot":"","sources":["../src/claude-md.ts"],"names":[],"mappings":"AA4BA,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,GAClB;IAAE,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,CAqChD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
const STARTUP_SECTION = `## 启动流程
|
|
4
|
+
|
|
5
|
+
**每次任务开始时,必须先执行:**
|
|
6
|
+
|
|
7
|
+
\`\`\`bash
|
|
8
|
+
npx memgrid search "<任务关键词>" --max 10
|
|
9
|
+
\`\`\`
|
|
10
|
+
|
|
11
|
+
这会从项目的记忆网格中检索最相关的上下文:
|
|
12
|
+
|
|
13
|
+
- 方法签名与实现
|
|
14
|
+
- 设计模式与规则
|
|
15
|
+
- 代码哲学与决策
|
|
16
|
+
- 项目结构与配置`;
|
|
17
|
+
const END_SECTION = `## 结束流程
|
|
18
|
+
|
|
19
|
+
**每次代码变更完成后,必须执行:**
|
|
20
|
+
|
|
21
|
+
\`\`\`bash
|
|
22
|
+
npx memgrid sync
|
|
23
|
+
\`\`\`
|
|
24
|
+
|
|
25
|
+
这不是可选的——是任务结束的强制步骤。MemGrid 会增量分析代码变更,将新的方法签名、设计模式、决策等写入记忆网格,确保下一次任务启动时知识是最新的。`;
|
|
26
|
+
export function injectMemGridFlow(projectRoot) {
|
|
27
|
+
const claudeMdPath = path.join(projectRoot, 'CLAUDE.md');
|
|
28
|
+
if (!fs.existsSync(claudeMdPath)) {
|
|
29
|
+
const content = `# Project\n\n${STARTUP_SECTION}\n\n${END_SECTION}\n`;
|
|
30
|
+
fs.writeFileSync(claudeMdPath, content, 'utf-8');
|
|
31
|
+
return { action: 'created' };
|
|
32
|
+
}
|
|
33
|
+
const existing = fs.readFileSync(claudeMdPath, 'utf-8');
|
|
34
|
+
const hasSearch = existing.includes('memgrid search');
|
|
35
|
+
const hasSync = existing.includes('memgrid sync');
|
|
36
|
+
if (hasSearch && hasSync) {
|
|
37
|
+
return { action: 'skipped' };
|
|
38
|
+
}
|
|
39
|
+
let modified = existing;
|
|
40
|
+
// Inject startup section after the first # heading line
|
|
41
|
+
if (!hasSearch) {
|
|
42
|
+
const headingMatch = modified.match(/^# .+$/m);
|
|
43
|
+
if (headingMatch && headingMatch.index !== undefined) {
|
|
44
|
+
const insertAt = headingMatch.index + headingMatch[0].length;
|
|
45
|
+
modified = modified.slice(0, insertAt) + '\n\n' + STARTUP_SECTION + '\n' + modified.slice(insertAt);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
modified = STARTUP_SECTION + '\n\n' + modified;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Append end section
|
|
52
|
+
if (!hasSync) {
|
|
53
|
+
modified = modified.trimEnd() + '\n\n' + END_SECTION + '\n';
|
|
54
|
+
}
|
|
55
|
+
fs.writeFileSync(claudeMdPath, modified, 'utf-8');
|
|
56
|
+
return { action: 'injected' };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=claude-md.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-md.js","sourceRoot":"","sources":["../src/claude-md.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,eAAe,GAAG;;;;;;;;;;;;;UAad,CAAC;AAEX,MAAM,WAAW,GAAG;;;;;;;;8EAQ0D,CAAC;AAE/E,MAAM,UAAU,iBAAiB,CAC/B,WAAmB;IAEnB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAEzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,gBAAgB,eAAe,OAAO,WAAW,IAAI,CAAC;QACtE,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACxD,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAElD,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;QACzB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,QAAQ,GAAG,QAAQ,CAAC;IAExB,wDAAwD;IACxD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC/C,IAAI,YAAY,IAAI,YAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACrD,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7D,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACtG,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,eAAe,GAAG,MAAM,GAAG,QAAQ,CAAC;QACjD,CAAC;IACH,CAAC;IAED,qBAAqB;IACrB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAC9D,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAChC,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface InjectResult {
|
|
2
|
+
/** Which hooks were configured */
|
|
3
|
+
actions: string[];
|
|
4
|
+
/** Per-hook status */
|
|
5
|
+
details: {
|
|
6
|
+
claudeSettings?: 'created' | 'merged' | 'already_exists';
|
|
7
|
+
postCommit?: 'created' | 'already_exists' | 'not_hooky_project';
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Inject MemGrid sync hooks into the project.
|
|
12
|
+
*
|
|
13
|
+
* Two hooks:
|
|
14
|
+
* 1. .claude/settings.json → PostCompletion: auto-sync after Claude finishes a task
|
|
15
|
+
* 2. .git/hooks/post-commit → auto-sync after git commit (covers non-Claude changes)
|
|
16
|
+
*/
|
|
17
|
+
export declare function injectHooks(projectRoot: string): InjectResult;
|
|
18
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,sBAAsB;IACtB,OAAO,EAAE;QACP,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,gBAAgB,CAAC;QACzD,UAAU,CAAC,EAAE,SAAS,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;KACjE,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAqB7D"}
|