pi-hermes-memory 0.3.1 → 0.3.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 +1 -1
- package/src/store/memory-store.ts +8 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hermes-memory",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -92,6 +92,10 @@ export class MemoryStore {
|
|
|
92
92
|
// ─── CRUD ───
|
|
93
93
|
|
|
94
94
|
async add(target: "memory" | "user", content: string, signal?: AbortSignal): Promise<MemoryResult> {
|
|
95
|
+
return this._add(target, content, signal);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private async _add(target: "memory" | "user", content: string, signal?: AbortSignal, _retriesLeft = 1): Promise<MemoryResult> {
|
|
95
99
|
content = content.trim();
|
|
96
100
|
if (!content) return { success: false, error: "Content cannot be empty." };
|
|
97
101
|
|
|
@@ -113,27 +117,15 @@ export class MemoryStore {
|
|
|
113
117
|
|
|
114
118
|
const newTotal = [...entries, encoded].join(ENTRY_DELIMITER).length;
|
|
115
119
|
if (newTotal > limit) {
|
|
116
|
-
// Auto-consolidate if configured
|
|
117
|
-
if (this.config.autoConsolidate && this.consolidator) {
|
|
118
|
-
// Track consolidation attempts to prevent infinite recursion
|
|
119
|
-
// when the consolidator fails to free enough space
|
|
120
|
-
const beforeCount = entries.length;
|
|
120
|
+
// Auto-consolidate once if configured — limit retries to prevent infinite loops
|
|
121
|
+
if (this.config.autoConsolidate && this.consolidator && _retriesLeft > 0) {
|
|
121
122
|
try {
|
|
122
123
|
const result = await this.consolidator(target, signal);
|
|
123
124
|
if (result.consolidated) {
|
|
124
125
|
// CRITICAL: reload from disk — child process modified files, our arrays are stale
|
|
125
126
|
await this.loadFromDisk();
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
const afterCount = afterEntries.length;
|
|
129
|
-
if (afterCount >= beforeCount && afterCount > 0) {
|
|
130
|
-
return {
|
|
131
|
-
success: false,
|
|
132
|
-
error: `Memory at capacity and consolidation did not free enough space. Entry count unchanged at ${afterCount}.`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
// Retry the add with fresh data
|
|
136
|
-
return this.add(target, content, signal);
|
|
127
|
+
// Retry the add exactly once (retriesLeft = 0 means no more consolidation)
|
|
128
|
+
return this._add(target, content, signal, _retriesLeft - 1);
|
|
137
129
|
}
|
|
138
130
|
} catch {
|
|
139
131
|
// Consolidation failed — fall through to error
|