kyp-mem 0.4.4 → 0.5.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/README.md +64 -230
- package/kyp_mem/cli.py +32 -0
- package/kyp_mem/config.py +6 -0
- package/kyp_mem/hooks.py +244 -34
- package/kyp_mem/server.py +32 -9
- package/kyp_mem/static/index.html +1673 -2740
- package/kyp_mem/ui.py +80 -0
- package/package.json +1 -1
- package/pyproject.toml +1 -0
package/README.md
CHANGED
|
@@ -1,288 +1,122 @@
|
|
|
1
|
-
# KYP-MEM
|
|
1
|
+
# KYP-MEM
|
|
2
2
|
|
|
3
|
-
**Persistent memory for AI coding agents.** Your AI agent forgets everything between sessions. KYP-MEM fixes that.
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
> Claude that remembers your conversations AND understands your project.
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
KYP-MEM gives AI coding agents two-layer memory:
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
- **Session Memory(Episodic)** → remembers what happened across coding sessions
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
- **Project Intelligence** → understands architecture, decisions, docs, and relationships
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
Your AI agent stops starting from zero every day.
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
## Example
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
MyProject/
|
|
19
|
-
├── Knowledge.md # Architecture, bugs, decisions, notes
|
|
20
|
-
├── API.md # Endpoints and contracts
|
|
21
|
-
├── Setup.md # Environment setup guide
|
|
22
|
-
└── Sessions/
|
|
23
|
-
```
|
|
16
|
+
User:
|
|
24
17
|
|
|
25
|
-
|
|
18
|
+
> "Why did we move from REST to Kafka?"
|
|
26
19
|
|
|
27
|
-
|
|
20
|
+
Claude:
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
├── 2026-05-12_091544.md # "Investigated flaky tests — race condition"
|
|
33
|
-
└── 2026-05-11_162301.md # "Set up CI, decided on GitHub Actions"
|
|
34
|
-
```
|
|
22
|
+
> "In the May 12 session, we found the REST pipeline couldn't handle peak trading volume.
|
|
23
|
+
> We decided to migrate to Kafka for async processing.
|
|
24
|
+
> See [[Architecture Decisions]] and [[Event Pipeline]]."
|
|
35
25
|
|
|
36
|
-
|
|
26
|
+
By intercepting the prompt, KYP-MEM automatically provided the agent with:
|
|
27
|
+
- The vectorized semantic search results of past session logs.
|
|
28
|
+
- The relevant markdown files from the project knowledge base.
|
|
37
29
|
|
|
38
|
-
```
|
|
39
|
-
Session Start
|
|
40
|
-
→ Agent loads project knowledge + recent sessions
|
|
41
|
-
→ Agent is grounded: knows architecture, past bugs, last session's next steps
|
|
42
30
|
|
|
43
|
-
During Work
|
|
44
|
-
→ Agent hits a bug → searches session memory → finds it was already investigated
|
|
45
|
-
→ Agent makes a decision → updates Knowledge.md so future sessions know
|
|
46
31
|
|
|
47
|
-
Session End
|
|
48
|
-
→ Hooks auto-capture everything into a structured session note
|
|
49
|
-
→ Note is embedded into the vector store for future semantic search
|
|
50
|
-
```
|
|
51
32
|
|
|
52
|
-
|
|
33
|
+
## How it works
|
|
53
34
|
|
|
54
|
-
|
|
35
|
+
KYP-MEM operates as a Model Context Protocol (MCP) server that runs silently in the background, integrating directly with Claude Code.
|
|
55
36
|
|
|
56
|
-
|
|
57
|
-
pip install kyp-mem
|
|
58
|
-
```
|
|
37
|
+
## Two-Layer Memory System
|
|
59
38
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
kyp-mem init # Choose where to store your vault
|
|
64
|
-
kyp-mem setup-claude # Register MCP server with Claude Code
|
|
65
|
-
kyp-mem install-hooks # Enable automatic session capture
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Restart Claude Code. KYP-MEM runs automatically with 14 tools available to the agent.
|
|
69
|
-
|
|
70
|
-
### Quick Setup (one command)
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
claude mcp add -s user -e KYP_VAULT="$HOME/.kyp-mem/vault" kyp-mem -- kyp-mem serve
|
|
74
|
-
```
|
|
39
|
+
### 1. Episodic Memory
|
|
75
40
|
|
|
76
|
-
|
|
41
|
+
Every coding session is automatically captured:
|
|
77
42
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
- prompts
|
|
44
|
+
- commands
|
|
45
|
+
- files changed
|
|
46
|
+
- bugs investigated
|
|
47
|
+
- decisions made
|
|
82
48
|
|
|
83
|
-
|
|
49
|
+
Sessions are semantically searchable.
|
|
84
50
|
|
|
85
|
-
|
|
51
|
+
### 2. Project Intelligence
|
|
86
52
|
|
|
87
|
-
KYP-MEM
|
|
53
|
+
KYP-MEM maintains structured project knowledge:
|
|
88
54
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
55
|
+
- architecture
|
|
56
|
+
- APIs
|
|
57
|
+
- setup docs
|
|
58
|
+
- known issues
|
|
59
|
+
- linked concepts
|
|
60
|
+
- decision history
|
|
94
61
|
|
|
95
|
-
|
|
62
|
+
The agent continuously updates this knowledge as it learns.
|
|
96
63
|
|
|
97
|
-
|
|
64
|
+
1. **Vault Storage:** Your knowledge base and session logs are stored locally as Markdown files in your `~/.kyp-mem/vault` directory.
|
|
65
|
+
2. **Vector Database:** Session logs are embedded into a local ChromaDB vector database, enabling semantic search ("Find me the session where we debugged the database connection").
|
|
66
|
+
3. **Auto-Learning Hooks:** KYP-MEM hooks into Claude Code's execution lifecycle. It silently listens to prompts, file reads, edits, and terminal commands. When a session ends, it automatically generates a comprehensive summary and timeline using an LLM and saves it to your Vault.
|
|
67
|
+
4. **Agent Tooling:** Claude is equipped with 14 custom MCP tools to read, write, search, and navigate your project's knowledge graph using `[[wikilinks]]`.
|
|
98
68
|
|
|
99
|
-
##
|
|
69
|
+
## Installation
|
|
100
70
|
|
|
101
71
|
```bash
|
|
102
|
-
kyp-mem
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
Installs three Claude Code hooks:
|
|
106
|
-
|
|
107
|
-
- **UserPromptSubmit** — captures every prompt you send to the agent
|
|
108
|
-
- **PostToolUse** — captures file edits, writes, and shell commands in real-time
|
|
109
|
-
- **Stop** — when the session ends, compiles all activity into a structured note
|
|
110
|
-
|
|
111
|
-
Each session note looks like this:
|
|
112
|
-
|
|
113
|
-
```markdown
|
|
114
|
-
# Session 2026-05-12_143022
|
|
115
|
-
|
|
116
|
-
**Project:** MyProject
|
|
117
|
-
**Actions:** 15 total, 12 substantive
|
|
72
|
+
npm i kyp-mem
|
|
118
73
|
|
|
119
|
-
|
|
120
|
-
Fixed auth bug, refactored token refresh logic.
|
|
121
|
-
|
|
122
|
-
## PROMPTS
|
|
123
|
-
### 1. [14:25:01]
|
|
124
|
-
> fix the token refresh bug in auth.py
|
|
125
|
-
|
|
126
|
-
### 2. [14:30:22]
|
|
127
|
-
> also add retry logic for expired tokens
|
|
128
|
-
|
|
129
|
-
## INVESTIGATED
|
|
130
|
-
- grep for "token expired" across auth module
|
|
131
|
-
- read OAuth provider docs
|
|
132
|
-
|
|
133
|
-
## LEARNED
|
|
134
|
-
- Refresh tokens expire after 30 days, not 90
|
|
135
|
-
|
|
136
|
-
## COMPLETED
|
|
137
|
-
- Fixed token refresh in auth.py
|
|
138
|
-
- Added retry logic for expired tokens
|
|
139
|
-
|
|
140
|
-
## NEXT STEPS
|
|
141
|
-
- Add integration test for token refresh flow
|
|
74
|
+
pip install kyp-mem (coming soon)
|
|
142
75
|
```
|
|
143
76
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
|
-
## Semantic Search
|
|
149
|
-
|
|
150
|
-
Session notes are embedded into a vector database (ChromaDB). This enables search by meaning:
|
|
151
|
-
|
|
152
|
-
- Searching **"authentication failing"** finds sessions about "login bug" and "OAuth token expiry"
|
|
153
|
-
- Searching **"deploy process"** finds sessions about "CI pipeline setup" and "release workflow"
|
|
154
|
-
|
|
155
|
-
The agent doesn't need exact keywords — it finds semantically related past work.
|
|
77
|
+
## Setup
|
|
156
78
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
## Web UI
|
|
79
|
+
Run the initialization commands to get started:
|
|
160
80
|
|
|
161
81
|
```bash
|
|
162
|
-
kyp-mem
|
|
82
|
+
kyp-mem init # Choose where to store your vault
|
|
83
|
+
kyp-mem setup-claude # Register the MCP server with Claude Code
|
|
84
|
+
kyp-mem install-hooks # Enable automatic session capture (Episodic Memory)
|
|
163
85
|
```
|
|
164
86
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
**Session Memory** — semantic search across all sessions, grouped by project with timestamps
|
|
168
|
-
|
|
169
|
-
**Knowledge Base** — file tree with folders, notes, tags. Full-text search, tag filtering, quick switcher (`Cmd+O`)
|
|
170
|
-
|
|
171
|
-
**Editor** — rendered markdown with `[[wikilink]]` navigation, inline editing
|
|
172
|
-
|
|
173
|
-
**Graph** — knowledge graph showing connections between notes, backlinks, and related content
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
## MCP Tools (14 total)
|
|
178
|
-
|
|
179
|
-
### Agent Behavior
|
|
180
|
-
|
|
181
|
-
| Tool | Purpose |
|
|
182
|
-
|------|---------|
|
|
183
|
-
| `____kyp_instructions` | Embeds behavioral rules the agent follows automatically |
|
|
184
|
-
| `kyp_project_context` | Loads project knowledge + recent sessions at session start |
|
|
185
|
-
|
|
186
|
-
### Knowledge Base
|
|
87
|
+
Restart Claude Code. The agent will automatically have access to the memory tools.
|
|
187
88
|
|
|
188
|
-
|
|
189
|
-
|------|---------|
|
|
190
|
-
| `kyp_list` | Browse folders and notes |
|
|
191
|
-
| `kyp_read` | Read a note (summary by default, `full=True` for complete) |
|
|
192
|
-
| `kyp_write` | Create or update a note with tags and `[[wikilinks]]` |
|
|
193
|
-
| `kyp_delete` | Delete a note |
|
|
194
|
-
| `kyp_search` | Full-text search with optional tag filter |
|
|
195
|
-
| `kyp_tags` | List all tags or filter notes by tag |
|
|
196
|
-
| `kyp_related` | Find related notes by links, tags, proximity |
|
|
197
|
-
| `kyp_recent` | Recently modified notes |
|
|
198
|
-
| `kyp_stats` | Vault statistics |
|
|
89
|
+
*(To enable globally for all projects run: `kyp-mem setup-claude --global` and `kyp-mem install-hooks --global`)*
|
|
199
90
|
|
|
200
|
-
|
|
91
|
+
## The Agent's Workflow
|
|
201
92
|
|
|
202
|
-
|
|
203
|
-
|------|---------|
|
|
204
|
-
| `kyp_session_search` | Semantic search across all session logs |
|
|
205
|
-
| `kyp_session_create` | Manually create a session note |
|
|
206
|
-
| `kyp_sessions` | List sessions by project |
|
|
93
|
+
KYP-MEM embeds behavioral instructions directly into its tools. Without any prompting required from you, the agent will automatically:
|
|
207
94
|
|
|
208
|
-
|
|
95
|
+
1. **Load Context:** On session start, it loads the project's ground truth (`Knowledge.md`) and recent session summaries.
|
|
96
|
+
2. **Search Before Acting:** Before investigating bugs or making architectural decisions, it searches past episodic memory to avoid repeating work.
|
|
97
|
+
3. **Persist Knowledge:** After fixing a bug or making a decision, it uses its tools to update the project's knowledge base for future sessions.
|
|
209
98
|
|
|
210
|
-
##
|
|
211
|
-
|
|
212
|
-
Add a `CLAUDE.md` to any project root:
|
|
213
|
-
|
|
214
|
-
```markdown
|
|
215
|
-
# Project Memory
|
|
216
|
-
|
|
217
|
-
## Session Start (MANDATORY)
|
|
218
|
-
Call `kyp_project_context("PROJECT_NAME")` at the start of every session to load:
|
|
219
|
-
- Project knowledge base (architecture, bugs, decisions)
|
|
220
|
-
- Recent session history (what was done, what's next)
|
|
221
|
-
|
|
222
|
-
## During Work
|
|
223
|
-
- Before investigating bugs: `kyp_session_search("error or symptom")`
|
|
224
|
-
- Before making decisions: `kyp_session_search("topic")`
|
|
225
|
-
- After fixing bugs: update Knowledge.md via `kyp_write`
|
|
226
|
-
- After decisions: add to Key Decisions in Knowledge.md
|
|
227
|
-
|
|
228
|
-
## Rules
|
|
229
|
-
- Never hallucinate project details — check the knowledge base first.
|
|
230
|
-
- Use [[wikilinks]] to connect related notes.
|
|
231
|
-
- Sessions are captured automatically — no manual logging needed.
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
A template is available at `templates/CLAUDE.md.template`.
|
|
235
|
-
|
|
236
|
-
---
|
|
237
|
-
|
|
238
|
-
## Vault Structure
|
|
239
|
-
|
|
240
|
-
```
|
|
241
|
-
~/.kyp-mem/
|
|
242
|
-
├── config.json # Vault path configuration
|
|
243
|
-
├── chroma/ # Vector database for semantic search
|
|
244
|
-
└── vault/
|
|
245
|
-
├── ProjectA/
|
|
246
|
-
│ ├── Knowledge.md # Ground truth: architecture, bugs, decisions
|
|
247
|
-
│ ├── API.md
|
|
248
|
-
│ └── Sessions/
|
|
249
|
-
│ ├── 2026-05-12_143022.md
|
|
250
|
-
│ └── 2026-05-11_091544.md
|
|
251
|
-
├── ProjectB/
|
|
252
|
-
│ ├── Knowledge.md
|
|
253
|
-
│ └── Sessions/
|
|
254
|
-
└── ...
|
|
255
|
-
```
|
|
99
|
+
## Web UI
|
|
256
100
|
|
|
257
|
-
|
|
101
|
+
Browse your knowledge graph, view session timelines, and see semantic relationships visually.
|
|
258
102
|
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
tags: [trading, config]
|
|
262
|
-
created: 2026-05-12
|
|
263
|
-
---
|
|
264
|
-
# Configuration
|
|
265
|
-
Settings are in `HedgeConfig`. See [[Risk Management]] for limits.
|
|
103
|
+
```bash
|
|
104
|
+
kyp-mem ui
|
|
266
105
|
```
|
|
267
|
-
|
|
268
|
-
---
|
|
106
|
+
*Opens at `localhost:3333`.*
|
|
269
107
|
|
|
270
108
|
## CLI Commands
|
|
271
109
|
|
|
272
|
-
| Command |
|
|
110
|
+
| Command | Description |
|
|
273
111
|
|---------|-------------|
|
|
274
112
|
| `kyp-mem init` | First-time setup — choose vault location |
|
|
275
113
|
| `kyp-mem setup-claude` | Register MCP server with Claude Code |
|
|
276
|
-
| `kyp-mem setup-claude --global` | Register globally (all projects) |
|
|
277
114
|
| `kyp-mem install-hooks` | Enable automatic session capture |
|
|
278
|
-
| `kyp-mem install-hooks --remove` | Remove session capture hooks |
|
|
279
115
|
| `kyp-mem serve` | Start MCP server (stdio, used by the agent) |
|
|
280
|
-
| `kyp-mem ui` | Open web UI
|
|
116
|
+
| `kyp-mem ui` | Open the local web UI |
|
|
281
117
|
| `kyp-mem stats` | Print vault statistics |
|
|
282
|
-
| `kyp-mem tree` | Print vault tree |
|
|
283
|
-
| `kyp-mem doctor` | Check installation health |
|
|
284
|
-
|
|
285
|
-
---
|
|
118
|
+
| `kyp-mem tree` | Print vault file tree |
|
|
119
|
+
| `kyp-mem doctor` | Check installation and configuration health |
|
|
286
120
|
|
|
287
121
|
## License
|
|
288
122
|
|
package/kyp_mem/cli.py
CHANGED
|
@@ -43,6 +43,10 @@ def main():
|
|
|
43
43
|
|
|
44
44
|
subparsers.add_parser("doctor", help="Check installation and config health")
|
|
45
45
|
|
|
46
|
+
cfg_parser = subparsers.add_parser("config", help="Get or set configuration values")
|
|
47
|
+
cfg_parser.add_argument("key", nargs="?", help="Config key (e.g. session_model)")
|
|
48
|
+
cfg_parser.add_argument("value", nargs="?", help="Value to set")
|
|
49
|
+
|
|
46
50
|
hook_parser = subparsers.add_parser("hook", help="Handle Claude Code hook events (internal)")
|
|
47
51
|
hook_sub = hook_parser.add_subparsers(dest="hook_command")
|
|
48
52
|
hook_sub.add_parser("session-start", help="Inject project context at session start")
|
|
@@ -71,6 +75,8 @@ def main():
|
|
|
71
75
|
_run_tree()
|
|
72
76
|
elif args.command == "install-hooks":
|
|
73
77
|
_run_install_hooks(global_config=args.global_config, remove=args.remove)
|
|
78
|
+
elif args.command == "config":
|
|
79
|
+
_run_config(args.key, args.value)
|
|
74
80
|
elif args.command == "doctor":
|
|
75
81
|
_run_doctor()
|
|
76
82
|
elif args.command == "hook":
|
|
@@ -351,6 +357,32 @@ def _run_install_hooks(global_config: bool = False, remove: bool = False):
|
|
|
351
357
|
print()
|
|
352
358
|
|
|
353
359
|
|
|
360
|
+
def _run_config(key, value):
|
|
361
|
+
from .config import load_config, save_config
|
|
362
|
+
|
|
363
|
+
config = load_config()
|
|
364
|
+
|
|
365
|
+
if key is None:
|
|
366
|
+
print(f"\n {C}KYP-MEM{R} — Configuration\n")
|
|
367
|
+
for k, v in sorted(config.items()):
|
|
368
|
+
print(f" {k}: {G}{v}{R}")
|
|
369
|
+
print(f"\n {D}Configurable keys:{R}")
|
|
370
|
+
print(f" {D} vault_path — Path to vault directory{R}")
|
|
371
|
+
print(f" {D} session_model — Claude model for session summarization{R}")
|
|
372
|
+
print(f" {D} (default: claude-haiku-4-5-20251001){R}")
|
|
373
|
+
print()
|
|
374
|
+
return
|
|
375
|
+
|
|
376
|
+
if value is None:
|
|
377
|
+
current = config.get(key, f"{Y}(not set){R}")
|
|
378
|
+
print(f" {key}: {G}{current}{R}")
|
|
379
|
+
return
|
|
380
|
+
|
|
381
|
+
config[key] = value
|
|
382
|
+
save_config(config)
|
|
383
|
+
print(f" {G}✓{R} {key} = {value}")
|
|
384
|
+
|
|
385
|
+
|
|
354
386
|
def _run_stats():
|
|
355
387
|
from .config import get_vault_path
|
|
356
388
|
from .vault import Vault
|
package/kyp_mem/config.py
CHANGED
|
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
CONFIG_DIR = Path.home() / ".kyp-mem"
|
|
8
8
|
CONFIG_FILE = CONFIG_DIR / "config.json"
|
|
9
|
+
STATS_FILE = CONFIG_DIR / "token_stats.json"
|
|
9
10
|
DEFAULT_VAULT = str(CONFIG_DIR / "vault")
|
|
10
11
|
|
|
11
12
|
|
|
@@ -29,3 +30,8 @@ def get_vault_path() -> str:
|
|
|
29
30
|
return env
|
|
30
31
|
config = load_config()
|
|
31
32
|
return config.get("vault_path", DEFAULT_VAULT)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_session_model() -> str:
|
|
36
|
+
config = load_config()
|
|
37
|
+
return config.get("session_model", "claude-haiku-4-5-20251001")
|