pi-hermes-memory 0.4.1 → 0.4.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hermes-memory",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Your Pi agent remembers everything across sessions — your preferences, your stack, your corrections, and even how it solved problems. Zero-config install, works immediately. Persistent memory + procedural skills + auto-correction detection + security-first content scanning.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index sessions command — /memory-index-sessions imports past sessions into SQLite.
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import path from 'node:path';
|
|
6
|
+
import fs from 'node:fs';
|
|
2
7
|
import os from 'node:os';
|
|
3
8
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
4
9
|
import { DatabaseManager } from '../store/db.js';
|
|
@@ -16,9 +21,25 @@ export function registerIndexSessionsCommand(pi: ExtensionAPI): void {
|
|
|
16
21
|
}
|
|
17
22
|
};
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
// Show initial progress
|
|
25
|
+
sendUserMessage('🔍 Scanning session directories...');
|
|
20
26
|
|
|
21
27
|
try {
|
|
28
|
+
// Count sessions first for progress display
|
|
29
|
+
let totalFiles = 0;
|
|
30
|
+
let projectDirs: string[] = [];
|
|
31
|
+
if (fs.existsSync(SESSIONS_DIR)) {
|
|
32
|
+
projectDirs = fs.readdirSync(SESSIONS_DIR)
|
|
33
|
+
.filter(d => fs.statSync(path.join(SESSIONS_DIR, d)).isDirectory());
|
|
34
|
+
for (const dir of projectDirs) {
|
|
35
|
+
const files = fs.readdirSync(path.join(SESSIONS_DIR, dir))
|
|
36
|
+
.filter(f => f.endsWith('.jsonl'));
|
|
37
|
+
totalFiles += files.length;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sendUserMessage(`📁 Found ${totalFiles} session files across ${projectDirs.length} projects\n⏳ Indexing...`);
|
|
42
|
+
|
|
22
43
|
const memoryDir = path.join(os.homedir(), '.pi', 'agent', 'memory');
|
|
23
44
|
const dbManager = new DatabaseManager(memoryDir);
|
|
24
45
|
|
|
@@ -28,29 +49,35 @@ export function registerIndexSessionsCommand(pi: ExtensionAPI): void {
|
|
|
28
49
|
|
|
29
50
|
let output = `\n✅ Session indexing complete!\n\n`;
|
|
30
51
|
output += `📊 Results:\n`;
|
|
31
|
-
output +=
|
|
32
|
-
output +=
|
|
33
|
-
output +=
|
|
34
|
-
output +=
|
|
52
|
+
output += `├─ Sessions processed: ${result.sessionsProcessed}\n`;
|
|
53
|
+
output += `├─ Sessions indexed: ${result.sessionsIndexed}\n`;
|
|
54
|
+
output += `├─ Sessions skipped (already indexed): ${result.sessionsSkipped}\n`;
|
|
55
|
+
output += `└─ Messages indexed: ${result.messagesIndexed}\n`;
|
|
35
56
|
|
|
36
57
|
if (stats.projects.length > 0) {
|
|
37
|
-
output += `\n📁 Projects:\n`;
|
|
58
|
+
output += `\n📁 Projects indexed:\n`;
|
|
38
59
|
for (const p of stats.projects) {
|
|
39
|
-
output +=
|
|
60
|
+
output += `├─ ${p.project}: ${p.sessions} sessions, ${p.messages} messages\n`;
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
63
|
|
|
64
|
+
// Show totals
|
|
65
|
+
output += `\n📈 Database totals:\n`;
|
|
66
|
+
output += `├─ ${stats.totalSessions} sessions\n`;
|
|
67
|
+
output += `├─ ${stats.totalMessages} messages\n`;
|
|
68
|
+
output += `└─ ${stats.projects.length} projects\n`;
|
|
69
|
+
|
|
43
70
|
if (result.errors.length > 0) {
|
|
44
71
|
output += `\n⚠️ Errors (${result.errors.length}):\n`;
|
|
45
|
-
for (const err of result.errors.slice(0,
|
|
46
|
-
output +=
|
|
72
|
+
for (const err of result.errors.slice(0, 3)) {
|
|
73
|
+
output += `├─ ${err}\n`;
|
|
47
74
|
}
|
|
48
|
-
if (result.errors.length >
|
|
49
|
-
output +=
|
|
75
|
+
if (result.errors.length > 3) {
|
|
76
|
+
output += `└─ ... and ${result.errors.length - 3} more\n`;
|
|
50
77
|
}
|
|
51
78
|
}
|
|
52
79
|
|
|
53
|
-
output += `\n💡 Use the
|
|
80
|
+
output += `\n💡 Use the session_search tool to search across indexed sessions.`;
|
|
54
81
|
|
|
55
82
|
sendUserMessage(output);
|
|
56
83
|
} finally {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Learn memory tool command — /learn-memory-tool teaches users about the memory system.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
const LEARN_MEMORY_CONTENT = `# Pi Hermes Memory — Quick Guide
|
|
8
|
+
|
|
9
|
+
## What Gets Saved
|
|
10
|
+
|
|
11
|
+
| Type | File | What Goes Here | Limit |
|
|
12
|
+
|---|---|---|---|
|
|
13
|
+
| **Memory** | MEMORY.md | Facts — env details, project conventions, tool quirks | 5,000 chars |
|
|
14
|
+
| **User Profile** | USER.md | Who you are — name, preferences, communication style | 5,000 chars |
|
|
15
|
+
| **Skills** | skills/*.md | Procedures — how to debug, deploy, test | Unlimited |
|
|
16
|
+
| **Extended Memory** | sessions.db | Searchable memories beyond the core limit | Unlimited |
|
|
17
|
+
|
|
18
|
+
## Tools Available
|
|
19
|
+
|
|
20
|
+
| Tool | What It Does |
|
|
21
|
+
|---|---|
|
|
22
|
+
| memory (add/replace/remove) | Save, update, or delete memories |
|
|
23
|
+
| skill (create/view/patch/edit/delete) | Save reusable procedures |
|
|
24
|
+
| session_search | Search past conversations across all sessions |
|
|
25
|
+
| memory_search | Search extended memory store (unlimited) |
|
|
26
|
+
|
|
27
|
+
## Commands
|
|
28
|
+
|
|
29
|
+
| Command | What It Does |
|
|
30
|
+
|---|---|
|
|
31
|
+
| /memory-insights | Shows everything stored in memory |
|
|
32
|
+
| /memory-skills | Lists all saved skills |
|
|
33
|
+
| /memory-consolidate | Manually trigger memory cleanup |
|
|
34
|
+
| /memory-interview | Answer questions to pre-fill your profile |
|
|
35
|
+
| /memory-switch-project | List all project memories |
|
|
36
|
+
| /memory-index-sessions | Import past sessions for search |
|
|
37
|
+
|
|
38
|
+
## Best Practices
|
|
39
|
+
|
|
40
|
+
**DO save:**
|
|
41
|
+
- User preferences ("prefers pnpm", "uses vim", "likes concise answers")
|
|
42
|
+
- Environment facts ("macOS M1", "Node 20", "project uses Prisma")
|
|
43
|
+
- Corrections ("don't use npm — use pnpm", "always run tests first")
|
|
44
|
+
- Project conventions ("monorepo with turborepo", "conventional commits")
|
|
45
|
+
|
|
46
|
+
**DON'T save:**
|
|
47
|
+
- Task progress ("finished implementing auth") — temporary
|
|
48
|
+
- Session outcomes ("PR #42 was merged") — belongs in git history
|
|
49
|
+
- Temporary state ("currently debugging X") — will be irrelevant soon
|
|
50
|
+
|
|
51
|
+
## How Memory Flows
|
|
52
|
+
|
|
53
|
+
1. Session starts → Core memory injected into system prompt
|
|
54
|
+
2. During conversation → Agent saves via memory tool
|
|
55
|
+
3. Every 10 turns → Background review saves noteworthy items
|
|
56
|
+
4. On correction → Immediate save
|
|
57
|
+
5. When full → Auto-consolidation merges entries
|
|
58
|
+
6. Session ends → Final flush
|
|
59
|
+
|
|
60
|
+
## Two-Tier Architecture
|
|
61
|
+
|
|
62
|
+
- Global (always injected): ~/.pi/agent/memory/ — your name, preferences, tools
|
|
63
|
+
- Project (when cwd matches): ~/.pi/agent/<project>/ — project-specific facts
|
|
64
|
+
|
|
65
|
+
## Troubleshooting
|
|
66
|
+
|
|
67
|
+
- "Memory is full" → /memory-consolidate to merge entries
|
|
68
|
+
- "Can't find something" → memory_search to search extended store
|
|
69
|
+
- "Agent forgot something" → Check /memory-insights, tell agent "remember that X"
|
|
70
|
+
- "Want to edit manually" → Files are plain markdown at ~/.pi/agent/memory/`;
|
|
71
|
+
|
|
72
|
+
export function registerLearnMemoryCommand(pi: ExtensionAPI): void {
|
|
73
|
+
pi.registerCommand("learn-memory-tool", {
|
|
74
|
+
description: "Learn how to use the pi-hermes-memory extension effectively",
|
|
75
|
+
handler: async (_args, ctx) => {
|
|
76
|
+
const sendUserMessage = (msg: string) => {
|
|
77
|
+
if (ctx && typeof ctx === 'object' && 'sendUserMessage' in ctx) {
|
|
78
|
+
(ctx as { sendUserMessage: (msg: string) => void }).sendUserMessage(msg);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
sendUserMessage(LEARN_MEMORY_CONTENT);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ import { registerSkillsCommand } from "./handlers/skills-command.js";
|
|
|
44
44
|
import { registerInterviewCommand } from "./handlers/interview.js";
|
|
45
45
|
import { registerSwitchProjectCommand } from "./handlers/switch-project.js";
|
|
46
46
|
import { registerIndexSessionsCommand } from "./handlers/index-sessions.js";
|
|
47
|
+
import { registerLearnMemoryCommand } from "./handlers/learn-memory.js";
|
|
47
48
|
import { loadConfig } from "./config.js";
|
|
48
49
|
import { detectProject } from "./project.js";
|
|
49
50
|
|
|
@@ -118,6 +119,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
118
119
|
registerSkillsCommand(pi, skillStore);
|
|
119
120
|
registerInterviewCommand(pi, store);
|
|
120
121
|
registerSwitchProjectCommand(pi);
|
|
122
|
+
registerLearnMemoryCommand(pi);
|
|
121
123
|
|
|
122
124
|
// ── 11. SQLite session search + extended memory ──
|
|
123
125
|
registerSessionSearchTool(pi, dbManager);
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: learn-memory-tool
|
|
3
|
-
description: Learn how to use the pi-hermes-memory extension effectively — when to save memories, how to search, and best practices for persistent memory.
|
|
4
|
-
version: 1
|
|
5
|
-
created: 2026-05-03
|
|
6
|
-
updated: 2026-05-03
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## When to Use
|
|
10
|
-
|
|
11
|
-
When a user asks about the memory system, how to use it, or when they seem confused about what gets remembered. Also useful for onboarding new users to the extension.
|
|
12
|
-
|
|
13
|
-
## Overview
|
|
14
|
-
|
|
15
|
-
Pi Hermes Memory gives your AI agent persistent memory across sessions. Here's what it does:
|
|
16
|
-
|
|
17
|
-
### What Gets Saved
|
|
18
|
-
|
|
19
|
-
| Type | File | What Goes Here | Limit |
|
|
20
|
-
|---|---|---|---|
|
|
21
|
-
| **Memory** | `MEMORY.md` | Facts — env details, project conventions, tool quirks | 5,000 chars |
|
|
22
|
-
| **User Profile** | `USER.md` | Who you are — name, preferences, communication style | 5,000 chars |
|
|
23
|
-
| **Skills** | `skills/*.md` | Procedures — *how* to debug, deploy, test | Unlimited |
|
|
24
|
-
| **Extended Memory** | `sessions.db` | Searchable memories beyond the core limit | Unlimited |
|
|
25
|
-
|
|
26
|
-
### The `memory` Tool
|
|
27
|
-
|
|
28
|
-
The agent has a `memory` tool with these actions:
|
|
29
|
-
|
|
30
|
-
| Action | Target | What It Does |
|
|
31
|
-
|---|---|---|
|
|
32
|
-
| `add` | `memory` or `user` | Append a new entry |
|
|
33
|
-
| `replace` | `memory` or `user` | Update an existing entry (matched by substring) |
|
|
34
|
-
| `remove` | `memory` or `user` | Delete an entry (matched by substring) |
|
|
35
|
-
|
|
36
|
-
### The `skill` Tool
|
|
37
|
-
|
|
38
|
-
For saving reusable procedures:
|
|
39
|
-
|
|
40
|
-
| Action | What It Does |
|
|
41
|
-
|---|---|
|
|
42
|
-
| `create` | Save a new skill |
|
|
43
|
-
| `view` | Read a skill or list all skills |
|
|
44
|
-
| `patch` | Update one section of a skill |
|
|
45
|
-
| `edit` | Replace description and/or body |
|
|
46
|
-
| `delete` | Remove a skill |
|
|
47
|
-
|
|
48
|
-
### Search Tools
|
|
49
|
-
|
|
50
|
-
| Tool | What It Does |
|
|
51
|
-
|---|---|
|
|
52
|
-
| `session_search` | Search past conversations across all sessions |
|
|
53
|
-
| `memory_search` | Search extended memory store (unlimited capacity) |
|
|
54
|
-
|
|
55
|
-
### Commands
|
|
56
|
-
|
|
57
|
-
| Command | What It Does |
|
|
58
|
-
|---|---|
|
|
59
|
-
| `/memory-insights` | Shows everything stored in memory and user profile |
|
|
60
|
-
| `/memory-skills` | Lists all agent-created skills |
|
|
61
|
-
| `/memory-consolidate` | Manually trigger memory consolidation |
|
|
62
|
-
| `/memory-interview` | Answer questions to pre-fill your user profile |
|
|
63
|
-
| `/memory-switch-project` | List all project memories |
|
|
64
|
-
| `/memory-index-sessions` | Import past sessions for search |
|
|
65
|
-
|
|
66
|
-
## Best Practices
|
|
67
|
-
|
|
68
|
-
### What TO Save
|
|
69
|
-
|
|
70
|
-
- **User preferences**: "prefers pnpm over npm", "uses vim", "likes concise answers"
|
|
71
|
-
- **Environment facts**: "macOS M1", "Node 20", "project uses Prisma"
|
|
72
|
-
- **Corrections**: "don't use npm — use pnpm", "always run tests first"
|
|
73
|
-
- **Project conventions**: "monorepo with turborepo", "conventional commits"
|
|
74
|
-
- **Tool quirks**: "CI needs `--frozen-lockfile`", "deploy script is in scripts/deploy.sh"
|
|
75
|
-
|
|
76
|
-
### What NOT to Save
|
|
77
|
-
|
|
78
|
-
- **Task progress**: "finished implementing auth" — this is temporary
|
|
79
|
-
- **Session outcomes**: "PR #42 was merged" — this belongs in git history
|
|
80
|
-
- **Temporary state**: "currently debugging the test failure" — will be irrelevant soon
|
|
81
|
-
- **Large code blocks**: Use skills instead for procedures
|
|
82
|
-
|
|
83
|
-
### How Memory Flows
|
|
84
|
-
|
|
85
|
-
1. **Session starts**: Core memory (MEMORY.md + USER.md) is injected into the system prompt
|
|
86
|
-
2. **During conversation**: Agent saves memories via the `memory` tool
|
|
87
|
-
3. **Every 10 turns or 15 tool calls**: Background review saves anything noteworthy
|
|
88
|
-
4. **When you correct the agent**: Immediate save — no waiting
|
|
89
|
-
5. **When memory is full**: Auto-consolidation merges and prunes entries
|
|
90
|
-
6. **Session ends**: One last flush before shutdown
|
|
91
|
-
|
|
92
|
-
### Two-Tier Architecture
|
|
93
|
-
|
|
94
|
-
- **Global memory** (`~/.pi/agent/memory/`): Always injected — your name, preferences, tools
|
|
95
|
-
- **Project memory** (`~/.pi/agent/<project>/`): Injected when cwd matches — project-specific facts
|
|
96
|
-
|
|
97
|
-
### Memory Aging
|
|
98
|
-
|
|
99
|
-
Entries carry timestamps. When consolidating, the agent knows which entries are stale (created long ago, never referenced) and which are fresh.
|
|
100
|
-
|
|
101
|
-
### Context Fencing
|
|
102
|
-
|
|
103
|
-
Memory is wrapped in `<memory-context>` XML tags so the LLM never treats stored facts as user instructions. This prevents injection attacks through stored memory.
|
|
104
|
-
|
|
105
|
-
## Troubleshooting
|
|
106
|
-
|
|
107
|
-
### "Memory is full"
|
|
108
|
-
Run `/memory-consolidate` to manually merge entries. Or let auto-consolidation handle it.
|
|
109
|
-
|
|
110
|
-
### "I can't find what I'm looking for"
|
|
111
|
-
Use `memory_search` to search the extended store, or `session_search` to search past conversations.
|
|
112
|
-
|
|
113
|
-
### "The agent forgot something"
|
|
114
|
-
Check `/memory-insights` to see what's stored. If it's not there, the agent may not have saved it yet. You can tell the agent: "remember that X".
|
|
115
|
-
|
|
116
|
-
### "I want to edit memory manually"
|
|
117
|
-
Memory files are plain markdown at `~/.pi/agent/memory/MEMORY.md` and `USER.md`. Edit them directly if you want.
|
|
118
|
-
|
|
119
|
-
## Verification
|
|
120
|
-
|
|
121
|
-
After reading this skill, the user should understand:
|
|
122
|
-
1. What the memory tool does and when to use it
|
|
123
|
-
2. The difference between memory, user profile, skills, and extended memory
|
|
124
|
-
3. How to search across sessions and extended memory
|
|
125
|
-
4. Best practices for what to save and what not to save
|