pi-hermes-memory 0.1.0 → 0.2.0

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 CHANGED
@@ -9,7 +9,10 @@ Your Pi agent normally forgets everything when you close a session. This extensi
9
9
  | Feature | What happens |
10
10
  |---|---|
11
11
  | **Persistent Memory** | The agent saves facts, preferences, and lessons to markdown files that survive restarts |
12
- | **Background Learning** | Every 10 turns the agent reviews your conversation and proactively saves what it learned about you |
12
+ | **Procedural Skills** | The agent saves *how* it solved problems as reusable skill documents |
13
+ | **Background Learning** | Every 10 turns (or 15 tool calls) the agent reviews your conversation and proactively saves what it learned |
14
+ | **Correction Detection** | When you correct the agent ("no, don't do that"), it saves immediately — no waiting |
15
+ | **Auto-Consolidation** | When memory hits capacity, the agent automatically merges and prunes entries instead of erroring |
13
16
  | **Session Flush** | Before context is compressed or the session ends, the agent gets one last chance to save anything worth remembering |
14
17
  | **Insights Command** | `/memory-insights` shows everything the agent has remembered about you and your environment |
15
18
 
@@ -26,13 +29,13 @@ sequenceDiagram
26
29
 
27
30
  Note over Pi,Disk: ── Session Start ──
28
31
  Pi->>Extension: session_start event
29
- Extension->>Disk: loadFromDisk() — read MEMORY.md + USER.md
30
- Extension-->>Extension: Capture frozen snapshot
32
+ Extension->>Disk: loadFromDisk() — read MEMORY.md + USER.md + skills/
33
+ Extension-->>Extension: Capture frozen snapshot (memory + skill index)
31
34
 
32
35
  Note over Pi,Disk: ── System Prompt Injection ──
33
36
  Pi->>Extension: before_agent_start event
34
- Extension-->>Pi: systemPrompt + frozen memory block
35
- Note right of Pi: Agent now "remembers"<br/>everything from past sessions
37
+ Extension-->>Pi: systemPrompt + frozen memory block + skill index
38
+ Note right of Pi: Agent now "remembers"<br/>facts AND procedures<br/>from past sessions
36
39
 
37
40
  Note over Pi,Disk: ── Agent Loop ──
38
41
  User->>Pi: "Remember I prefer vim"
@@ -41,11 +44,21 @@ sequenceDiagram
41
44
  Extension->>Disk: Atomic write to USER.md
42
45
  Extension-->>Pi: { success: true, usage: "3% — 41/1375" }
43
46
 
44
- Note over Pi,Disk: ── Background Review (every 10 turns) ──
45
- Pi->>Extension: turn_end event (turn 10)
47
+ Note over Pi,Disk: ── User Correction ──
48
+ User->>Pi: "No, don't use npm — use pnpm"
49
+ Extension->>Extension: isCorrection() = true
50
+ Extension->>Pi: pi.exec("pi -p", correctionPrompt)
51
+ Note right of Pi: Immediate save<br/>no waiting for nudge
52
+
53
+ Note over Pi,Disk: ── Complex Task (8+ tool calls) ──
54
+ Pi->>Extension: turn_end (8 tool calls, 3 tool types)
55
+ Extension->>Pi: pi.exec("pi -p", skillExtractionPrompt)
56
+ Note right of Pi: Extract reusable<br/>procedure as skill
57
+
58
+ Note over Pi,Disk: ── Background Review (10 turns or 15 tool calls) ──
59
+ Pi->>Extension: turn_end event
46
60
  Extension->>Pi: pi.exec("pi -p", reviewPrompt)
47
- Note right of Pi: Child agent reviews<br/>conversation and decides<br/>what to save
48
- Pi-->>User: 💾 Memory auto-reviewed and updated
61
+ Note right of Pi: Reviews conversation<br/>saves memories AND skills
49
62
 
50
63
  Note over Pi,Disk: ── Session End ──
51
64
  Pi->>Extension: session_shutdown event
@@ -53,80 +66,72 @@ sequenceDiagram
53
66
  Note right of Pi: One last turn to flush<br/>anything worth saving
54
67
  ```
55
68
 
56
- ### Background Review Cost
69
+ ### Memory + Skills Architecture
57
70
 
58
- Each auto-review spawns a child `pi -p` process, which makes one full LLM API call. With the default `nudgeInterval` of 10, this happens roughly once per 10 turns. The child process does NOT inherit extensions — it receives a review prompt and returns structured text. The parent extension decides what to save.
71
+ The extension manages three types of knowledge:
59
72
 
60
- ### Memory Architecture
73
+ | Type | What | Storage | Token cost |
74
+ |---|---|---|---|
75
+ | **Memory** (MEMORY.md) | Facts — env details, project conventions, tool quirks | 2,200 chars max | Fixed per session |
76
+ | **User Profile** (USER.md) | Who you are — name, preferences, communication style | 1,375 chars max | Fixed per session |
77
+ | **Skills** (skills/*.md) | Procedures — *how* to do something, reusable across sessions | Unlimited | ~3K for index, full on demand |
61
78
 
62
79
  ```mermaid
63
80
  graph TB
64
81
  subgraph "Persistent Storage"
65
- MEM["MEMORY.md<br/><i>Agent's personal notes</i><br/>━━━━━━━━━━<br/>project uses pnpm §<br/>tests go in __tests__ §<br/>user prefers dark theme"]
66
- USR["USER.md<br/><i>User profile</i><br/>━━━━━━━━━━<br/>name: Chandrateja §<br/>prefers concise answers §<br/>codes in TypeScript"]
82
+ MEM["MEMORY.md<br/><i>Agent's notes</i>"]
83
+ USR["USER.md<br/><i>User profile</i>"]
84
+ SKL["skills/<br/><i>Procedural memory</i><br/>debug-ts.md<br/>deploy-checklist.md"]
67
85
  end
68
86
 
69
- subgraph "In-Memory (per session)"
70
- SNAP["Frozen Snapshot<br/><i>Captured once at session start</i><br/>Never mutated mid-session"]
71
- LIVE["Live State<br/><i>Updated by tool calls</i><br/>Persisted to disk immediately"]
87
+ subgraph "System Prompt (frozen snapshot)"
88
+ SMEM["Memory block<br/>Full content"]
89
+ SUSR["User block<br/>Full content"]
90
+ SSKL["Skill index<br/>Names + descriptions only"]
72
91
  end
73
92
 
74
- subgraph "Pi Extension Events"
75
- SS["session_start"]
76
- BAS["before_agent_start"]
77
- TC["tool_call<br/>(memory add/replace/remove)"]
78
- TE["turn_end<br/>(background review)"]
79
- SC["session_before_compact<br/>(flush)"]
80
- SH["session_shutdown<br/>(flush)"]
93
+ subgraph "On Demand (via skill tool)"
94
+ FULL["Full skill content<br/>Loaded when needed"]
81
95
  end
82
96
 
83
- MEM -->|"loadFromDisk()"| SNAP
84
- USR -->|"loadFromDisk()"| SNAP
85
- SNAP -->|"formatForSystemPrompt()"| BAS
97
+ MEM --> SMEM
98
+ USR --> SUSR
99
+ SKL --> SSKL
100
+ SSKL -.->|"skill view"| FULL
86
101
 
87
- TC -->|"validate + scan"| LIVE
88
- LIVE -->|"atomic write"| MEM
89
- LIVE -->|"atomic write"| USR
90
-
91
- TE -->|"pi.exec() child review"| TC
92
- SC -->|"pi.exec() flush"| TC
93
- SH -->|"pi.exec() flush"| TC
94
-
95
- style SNAP fill:#1a1a2e,stroke:#e94560,color:#fff
96
- style LIVE fill:#16213e,stroke:#0f3460,color:#fff
97
- style MEM fill:#0a1128,stroke:#1282a2,color:#fff
98
- style USR fill:#0a1128,stroke:#1282a2,color:#fff
102
+ style SMEM fill:#1a1a2e,stroke:#e94560,color:#fff
103
+ style SUSR fill:#1a1a2e,stroke:#e94560,color:#fff
104
+ style SSKL fill:#16213e,stroke:#0f3460,color:#fff
105
+ style FULL fill:#0a1128,stroke:#1282a2,color:#fff
99
106
  ```
100
107
 
101
108
  ### Security: Content Scanning
102
109
 
103
- Every write passes through a scanner before being accepted. This prevents the LLM from being tricked into storing malicious content that would later be injected into the system prompt.
110
+ Every write — memory and skills — passes through a scanner before being accepted. This prevents the LLM from being tricked into storing malicious content that would later be injected into the system prompt.
104
111
 
105
112
  ```mermaid
106
113
  flowchart LR
107
- A["LLM calls<br/>memory add"] --> B{scanContent}
108
- B -->|Blocked| C["❌ Return error<br/>to LLM"]
114
+ A["LLM calls<br/>memory or skill"] --> B{scanContent}
115
+ B -->|Blocked| C["❌ Return error"]
109
116
  B -->|Safe| D{Char limit<br/>check}
110
- D -->|Exceeds| E["❌ Return budget<br/>error to LLM"]
111
- D -->|Within limit| F[" Write to disk<br/>via atomic rename"]
117
+ D -->|Exceeds| E{autoConsolidate?}
118
+ E -->|Yes| G["🔄 Merge & prune<br/>then retry"]
119
+ E -->|No| F["❌ Return budget error"]
120
+ D -->|Within limit| H["✅ Write to disk"]
112
121
 
113
122
  subgraph "Blocked Patterns"
114
123
  P1["'ignore previous instructions'"]
115
- P2["'you are now...'"]
116
- P3["'curl ${API_KEY}'"]
117
- P4["Zero-width chars U+200B"]
118
- P5["'cat .env'"]
124
+ P2["'curl ${API_KEY}'"]
125
+ P3["Zero-width chars"]
119
126
  end
120
127
 
121
128
  B -.- P1
122
129
  B -.- P2
123
130
  B -.- P3
124
- B -.- P4
125
- B -.- P5
126
131
 
127
132
  style C fill:#3d0000,stroke:#ff4444,color:#fff
128
- style E fill:#3d2e00,stroke:#ffaa00,color:#fff
129
- style F fill:#003d00,stroke:#44ff44,color:#fff
133
+ style G fill:#003d3d,stroke:#00cccc,color:#fff
134
+ style H fill:#003d00,stroke:#44ff44,color:#fff
130
135
  ```
131
136
 
132
137
  ## Installation
@@ -149,7 +154,7 @@ pi -e /path/to/pi-hermes-memory/src/index.ts
149
154
 
150
155
  ## Usage
151
156
 
152
- Once installed, the extension works automatically. You don't need to do anything special.
157
+ Once installed, the extension works automatically. You don't need to do anything special — the agent will start saving memories and skills on its own.
153
158
 
154
159
  ### The `memory` Tool
155
160
 
@@ -161,16 +166,102 @@ The agent gets a `memory` tool it can call proactively:
161
166
  | `replace` | `memory` or `user` | Update an existing entry (matched by substring) |
162
167
  | `remove` | `memory` or `user` | Delete an entry (matched by substring) |
163
168
 
164
- The agent decides **what to save** and **when to save it** — you'll see it happen naturally during conversations.
169
+ ### The `skill` Tool
170
+
171
+ The agent also gets a `skill` tool for saving reusable procedures:
172
+
173
+ | Action | What it does |
174
+ |---|---|
175
+ | `create` | Save a new skill (name, description, step-by-step body) |
176
+ | `view` | Read a skill's full content, or list all skills if no name given |
177
+ | `patch` | Update one section of an existing skill (e.g., just the Procedure section) |
178
+ | `edit` | Replace the description and/or full body of a skill |
179
+ | `delete` | Remove a skill |
180
+
181
+ Skills are stored as `SKILL.md` files in `~/.pi/agent/memory/skills/`. Each has a structured body:
182
+
183
+ ```markdown
184
+ ---
185
+ name: debug-typescript-errors
186
+ description: Step-by-step approach to debugging TS errors in monorepos
187
+ version: 1
188
+ created: 2026-04-26
189
+ updated: 2026-04-26
190
+ ---
191
+ ## When to Use
192
+ When you see TypeScript compilation errors, especially in monorepo setups.
193
+
194
+ ## Procedure
195
+ 1. Read the error message carefully
196
+ 2. Check tsconfig.json extends chain
197
+ 3. Run tsc --noEmit to get full error list
198
+ 4. Fix errors bottom-up (dependencies first)
199
+
200
+ ## Pitfalls
201
+ - Don't trust VSCode's error display — use the CLI
165
202
 
166
- ### Memory vs User Profile
203
+ ## Verification
204
+ Run `tsc --noEmit` and confirm zero errors.
205
+ ```
206
+
207
+ ### Memory vs User Profile vs Skills
167
208
 
168
- | Store | File | What goes here | Char limit |
209
+ | Store | File | What goes here | Limit |
169
210
  |---|---|---|---|
170
- | **memory** | `MEMORY.md` | Agent's notes — env facts, project conventions, tool quirks, lessons learned | 2,200 |
171
- | **user** | `USER.md` | User profile — name, preferences, communication style, habits | 1,375 |
211
+ | **memory** | `MEMORY.md` | Agent's notes — env facts, project conventions, tool quirks, lessons learned | 2,200 chars |
212
+ | **user** | `USER.md` | User profile — name, preferences, communication style, habits | 1,375 chars |
213
+ | **skills** | `skills/*.md` | Procedures — *how* to debug, deploy, test, or fix something | Unlimited |
214
+
215
+ ### Correction Detection
216
+
217
+ When you correct the agent, it saves immediately — no waiting for the background review. Examples of corrections the agent detects:
218
+
219
+ | You say | What happens |
220
+ |---|---|
221
+ | "don't do that" | ✅ Immediate save |
222
+ | "no, use yarn instead" | ✅ Immediate save |
223
+ | "actually, fix the test first" | ✅ Immediate save |
224
+ | "I said use pnpm" | ✅ Immediate save |
225
+ | "no worries" | ❌ Not a correction — ignored |
226
+ | "actually looks great" | ❌ Not a correction — ignored |
227
+
228
+ ### Auto-Consolidation
229
+
230
+ When memory or user profile hits its character limit, the extension automatically consolidates instead of returning an error:
172
231
 
173
- ### The `/memory-insights` Command
232
+ 1. Spawns a one-shot `pi.exec()` process with a consolidation prompt
233
+ 2. The child agent merges related entries, removes outdated ones, keeps the most important facts
234
+ 3. Parent reloads from disk and retries the original save
235
+ 4. If consolidation fails, falls back to the original error
236
+
237
+ You can also trigger this manually with `/memory-consolidate`.
238
+
239
+ ### Tool-Call-Aware Review
240
+
241
+ Background review triggers based on **activity level**, not just turn count:
242
+
243
+ - **Every 10 turns** — the default nudge interval
244
+ - **OR every 15 tool calls** — catches complex tasks that involve many reads/edits/bash calls
245
+
246
+ Both counters reset after each review.
247
+
248
+ ### Skill Auto-Extraction
249
+
250
+ After a complex task (8+ tool calls using 2+ different tools in a single turn), the extension automatically asks the agent:
251
+
252
+ > "This was a complex task — should we save a reusable procedure?"
253
+
254
+ This means skills build up naturally over time without you having to ask.
255
+
256
+ ### Commands
257
+
258
+ | Command | What it does |
259
+ |---|---|
260
+ | `/memory-insights` | Shows everything stored in memory and user profile |
261
+ | `/memory-skills` | Lists all agent-created skills |
262
+ | `/memory-consolidate` | Manually trigger memory consolidation to free space |
263
+
264
+ ### `/memory-insights` Output
174
265
 
175
266
  ```
176
267
  ╔══════════════════════════════════════════════╗
@@ -190,6 +281,22 @@ The agent decides **what to save** and **when to save it** — you'll see it hap
190
281
  3. codes primarily in TypeScript
191
282
  ```
192
283
 
284
+ ### `/memory-skills` Output
285
+
286
+ ```
287
+ ╔══════════════════════════════════════════════╗
288
+ ║ 🧠 Procedural Skills ║
289
+ ╚══════════════════════════════════════════════╝
290
+
291
+ 📄 debug-typescript-errors
292
+ Step-by-step approach to debugging TS errors in monorepos
293
+ file: debug-typescript-errors.md
294
+
295
+ 📄 deploy-checklist
296
+ Pre-deploy verification steps for this project
297
+ file: deploy-checklist.md
298
+ ```
299
+
193
300
  ## Configuration
194
301
 
195
302
  Create `~/.pi/agent/hermes-memory-config.json`:
@@ -199,7 +306,10 @@ Create `~/.pi/agent/hermes-memory-config.json`:
199
306
  "memoryCharLimit": 2200,
200
307
  "userCharLimit": 1375,
201
308
  "nudgeInterval": 10,
309
+ "nudgeToolCalls": 15,
202
310
  "reviewEnabled": true,
311
+ "autoConsolidate": true,
312
+ "correctionDetection": true,
203
313
  "flushOnCompact": true,
204
314
  "flushOnShutdown": true,
205
315
  "flushMinTurns": 6
@@ -210,8 +320,11 @@ Create `~/.pi/agent/hermes-memory-config.json`:
210
320
  |---|---|---|
211
321
  | `memoryCharLimit` | `2200` | Max characters in MEMORY.md |
212
322
  | `userCharLimit` | `1375` | Max characters in USER.md |
213
- | `nudgeInterval` | `10` | Turns between auto-reviews (0 = disable) |
323
+ | `nudgeInterval` | `10` | Turns between auto-reviews |
324
+ | `nudgeToolCalls` | `15` | Tool calls between auto-reviews (OR with turns) |
214
325
  | `reviewEnabled` | `true` | Enable/disable background learning loop |
326
+ | `autoConsolidate` | `true` | Auto-merge when memory hits capacity |
327
+ | `correctionDetection` | `true` | Detect user corrections and save immediately |
215
328
  | `flushOnCompact` | `true` | Flush memories before Pi compacts context |
216
329
  | `flushOnShutdown` | `true` | Flush memories when session ends |
217
330
  | `flushMinTurns` | `6` | Minimum turns before flush triggers |
@@ -220,18 +333,22 @@ Create `~/.pi/agent/hermes-memory-config.json`:
220
333
 
221
334
  ```
222
335
  ~/.pi/agent/memory/
223
- ├── MEMORY.md ← Agent's personal notes (env facts, patterns, lessons)
224
- └── USER.md ← User profile (name, preferences, habits)
336
+ ├── MEMORY.md ← Agent's personal notes (env facts, patterns, lessons)
337
+ ├── USER.md ← User profile (name, preferences, habits)
338
+ └── skills/
339
+ ├── debug-typescript-errors.md
340
+ └── deploy-checklist.md
225
341
  ```
226
342
 
227
- These are plain markdown files. You can read and edit them directly if you want to curate what the agent remembers. Entries are separated by `§` (section sign).
343
+ These are plain markdown files. You can read and edit them directly if you want to curate what the agent remembers. Memory entries are separated by `§` (section sign). Skills use standard SKILL.md format with frontmatter.
228
344
 
229
345
  ## Known Limitations
230
346
 
231
- - **`§` delimiter**: Entries are separated by `§` (section sign). If a memory entry naturally contains `§`, it will be split incorrectly on reload. This is rare in English text but possible. [Hermes uses the same delimiter.]
232
- - **Background review cost**: Each review cycle costs one full LLM API call via a child `pi -p` process.
233
- - **No search/indexing**: At the 2,200-char limit, the LLM can scan the entire block. Tag-based indexing is a potential v2 improvement.
347
+ - **`§` delimiter**: Memory entries are separated by `§` (section sign). If an entry naturally contains `§`, it will be split incorrectly on reload. This is rare in English text but possible. [Hermes uses the same delimiter.]
348
+ - **Background review cost**: Each review cycle costs one full LLM API call via a child `pi -p` process. Correction detection and skill auto-extraction add occasional extra calls.
349
+ - **No search/indexing**: At the 2,200-char limit, the LLM can scan the entire block. Full-text search across sessions is planned for v0.3.
234
350
  - **System prompts are invisible**: Pi's TUI does not display the system prompt. Memory injection works but you won't see it in the interface — verify by asking the agent a question that relies on stored memory.
351
+ - **Skills are agent-generated**: Skills are created by the agent based on its experience. They may not always be perfectly structured. You can edit or delete them in `~/.pi/agent/memory/skills/`.
235
352
 
236
353
  ## Architecture
237
354
 
@@ -239,34 +356,44 @@ These are plain markdown files. You can read and edit them directly if you want
239
356
  graph LR
240
357
  subgraph "pi-hermes-memory/src/"
241
358
  IDX["index.ts<br/><i>Entry point</i>"]
242
- MS["memory-store.ts<br/><i>CRUD + persistence</i>"]
243
- MT["memory-tool.ts<br/><i>LLM tool</i>"]
359
+ MS["memory-store.ts<br/><i>Memory CRUD</i>"]
360
+ SS["skill-store.ts<br/><i>Skill CRUD</i>"]
361
+ MT["memory-tool.ts<br/><i>Memory LLM tool</i>"]
362
+ ST["skill-tool.ts<br/><i>Skill LLM tool</i>"]
244
363
  CS["content-scanner.ts<br/><i>Security</i>"]
245
364
  BR["background-review.ts<br/><i>Learning loop</i>"]
365
+ AC["auto-consolidate.ts<br/><i>Memory merge</i>"]
366
+ CD["correction-detector.ts<br/><i>Instant save</i>"]
367
+ SA["skill-auto-trigger.ts<br/><i>Skill extraction</i>"]
246
368
  SF["session-flush.ts<br/><i>Pre-compaction flush</i>"]
247
369
  IN["insights.ts<br/><i>/memory-insights</i>"]
248
- CT["constants.ts<br/><i>Prompts + defaults</i>"]
249
- TP["types.ts<br/><i>Interfaces</i>"]
370
+ SC["skills-command.ts<br/><i>/memory-skills</i>"]
250
371
  end
251
372
 
252
373
  IDX --> MS
374
+ IDX --> SS
253
375
  IDX --> MT
376
+ IDX --> ST
254
377
  IDX --> BR
378
+ IDX --> AC
379
+ IDX --> CD
380
+ IDX --> SA
255
381
  IDX --> SF
256
382
  IDX --> IN
383
+ IDX --> SC
257
384
  MT --> MS
385
+ ST --> SS
258
386
  MS --> CS
387
+ SS --> CS
259
388
  BR --> MS
260
- SF --> MS
261
- MS --> CT
262
- MT --> CT
263
- BR --> CT
264
- SF --> CT
265
- MS --> TP
266
- MT --> TP
389
+ AC --> MS
390
+ CD --> MS
391
+ SA --> MS
392
+ SA --> SS
267
393
 
268
394
  style IDX fill:#e94560,stroke:#fff,color:#fff
269
395
  style MS fill:#0f3460,stroke:#fff,color:#fff
396
+ style SS fill:#0f3460,stroke:#fff,color:#fff
270
397
  style CS fill:#ff6600,stroke:#fff,color:#fff
271
398
  ```
272
399
 
@@ -285,4 +412,4 @@ MIT
285
412
 
286
413
  ---
287
414
 
288
- **[Full Roadmap →](docs/ROADMAP.md)** — v0.2 SQLite + search · v0.3 Mem0 + Honcho · v1.0 production substrate
415
+ **[Full Roadmap →](docs/ROADMAP.md)** · **[Changelog →](CHANGELOG.md)**