pi-hermes-memory 0.7.22 → 0.8.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 +18 -2
- package/package.json +3 -2
- package/src/config.ts +14 -1
- package/src/constants.ts +72 -0
- package/src/extension-root-migration.ts +429 -5
- package/src/handlers/auto-consolidate.ts +118 -8
- package/src/handlers/background-review.ts +164 -64
- package/src/handlers/child-process-watchdog.mjs +90 -0
- package/src/handlers/correction-detector.ts +52 -36
- package/src/handlers/pi-child-process.ts +270 -37
- package/src/handlers/review-memory-ops.ts +383 -0
- package/src/handlers/session-flush.ts +71 -4
- package/src/handlers/sync-markdown-memories.ts +143 -51
- package/src/index.ts +36 -17
- package/src/store/atomic-lock-coordinator.ts +252 -0
- package/src/store/canonical-storage-path.ts +54 -0
- package/src/store/db.ts +244 -9
- package/src/store/markdown-mutation-lock.ts +38 -0
- package/src/store/memory-store.ts +455 -57
- package/src/store/sqlite-memory-store.ts +121 -4
- package/src/tools/memory-tool.ts +48 -9
- package/src/tools/session-search-tool.ts +70 -12
- package/src/types.ts +6 -0
package/README.md
CHANGED
|
@@ -339,6 +339,19 @@ Background review triggers based on **activity level**, not just turn count:
|
|
|
339
339
|
|
|
340
340
|
Both counters reset after each review.
|
|
341
341
|
|
|
342
|
+
### Direct-Transport LLM Calls (Review, Flush, Correction, Consolidation)
|
|
343
|
+
|
|
344
|
+
By default, background review, session flush, correction save, and the manual `/memory-consolidate` command use an in-process `completeSimple()` side-channel: a small JSON-only prompt, no child `pi` process, and memory writes applied directly by the extension. This keeps the main session's system prompt, tools, and LLM prefix cache intact, and avoids the subprocess path's argv/`--no-extensions` concerns entirely on the common path.
|
|
345
|
+
|
|
346
|
+
If direct mode fails (no model, no auth, provider error, unparseable response, or — for consolidation only — a result that didn't actually free any space), it automatically falls back to the legacy `pi -p --no-session` subprocess path. The automatic over-capacity consolidator triggered from `MemoryStore` itself always uses the subprocess path, since it runs without extension-runtime access.
|
|
347
|
+
|
|
348
|
+
Set `reviewTransport` in config only when you need to override this:
|
|
349
|
+
|
|
350
|
+
| Value | Behavior |
|
|
351
|
+
|---|---|
|
|
352
|
+
| `direct` (default) | Try in-process `completeSimple()` first; fall back to subprocess on failure |
|
|
353
|
+
| `subprocess` | Always use `pi -p` subprocess for every LLM-driven memory operation (pre-PR #92 behavior) |
|
|
354
|
+
|
|
342
355
|
### Skill Auto-Extraction
|
|
343
356
|
|
|
344
357
|
After a complex task (8+ tool calls using 2+ different tools in a single turn), the extension automatically asks the agent:
|
|
@@ -430,6 +443,7 @@ Create `~/.pi/agent/hermes-memory-config.json`:
|
|
|
430
443
|
"nudgeToolCalls": 15,
|
|
431
444
|
"reviewRecentMessages": 0,
|
|
432
445
|
"reviewEnabled": true,
|
|
446
|
+
"reviewTransport": "direct",
|
|
433
447
|
"memoryOverflowStrategy": "auto-consolidate",
|
|
434
448
|
"autoConsolidate": true,
|
|
435
449
|
"correctionDetection": true,
|
|
@@ -455,12 +469,14 @@ Create `~/.pi/agent/hermes-memory-config.json`:
|
|
|
455
469
|
| `memoryDir` | `~/.pi/agent/pi-hermes-memory` | Custom directory for extension storage files |
|
|
456
470
|
| `projectsMemoryDir` | `projects-memory` | Subdirectory under `~/.pi/agent/` for project-scoped memory |
|
|
457
471
|
| `sessionSearch` | `{ "variant": "legacy" }` | Session search implementation: `legacy` keeps the existing SQLite/FTS snippet search; `anchors` uses the opt-in Markdown request surface and returns compact JSONL line-range anchors from `~/.pi/agent/sessions/` |
|
|
458
|
-
| `llmModelOverride` | unset | Optional model override for
|
|
459
|
-
| `llmThinkingOverride` | unset | Optional thinking override for those
|
|
472
|
+
| `llmModelOverride` | unset | Optional model override for background review (direct and subprocess), correction save, session flush, and consolidation |
|
|
473
|
+
| `llmThinkingOverride` | unset | Optional thinking override for those LLM calls; valid values are `off`, `minimal`, `low`, `medium`, `high`, and `xhigh`. If `llmModelOverride` is set and this is omitted, review/child calls default to `off` |
|
|
474
|
+
| `childExtensionPaths` | unset | Trusted provider/auth adapter entry paths explicitly allowed in isolated child Pi processes; sibling packages matching the `*-oauth-adapter`/`*-auth-adapter` naming convention (including scoped packages, via their `package.json` `pi.extensions` manifest) are detected automatically — this setting is only needed for adapters that don't match that convention. In-process direct transport (the default for review/flush/correction/consolidation) doesn't need this at all, since it reads whatever provider auth is already registered |
|
|
460
475
|
| `nudgeInterval` | `10` | Turns between auto-reviews |
|
|
461
476
|
| `nudgeToolCalls` | `15` | Tool calls between auto-reviews (OR with turns) |
|
|
462
477
|
| `reviewRecentMessages` | `0` | Recent messages included in background review (`0` = all) |
|
|
463
478
|
| `reviewEnabled` | `true` | Enable/disable background learning loop |
|
|
479
|
+
| `reviewTransport` | `direct` | LLM transport for background review, session flush, correction save, and manual consolidation: `direct` uses in-process `completeSimple()` with subprocess fallback; `subprocess` forces legacy `pi -p` only |
|
|
464
480
|
| `memoryOverflowStrategy` | `auto-consolidate` | Behavior when MEMORY.md, USER.md, failures.md, or project-scoped memory reaches its character limit: `auto-consolidate` runs the existing consolidation flow; `reject` returns an error; `fifo-evict` rotates older entries in file order until the new entry fits |
|
|
465
481
|
| `autoConsolidate` | `true` | Legacy alias for `memoryOverflowStrategy` when `memoryOverflowStrategy` is not set (`true` = `auto-consolidate`, `false` = `reject`) |
|
|
466
482
|
| `consolidationTimeoutMs` | `60000` | Maximum time in milliseconds for auto-consolidation to complete |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-hermes-memory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "🧠 Persistent memory + 🔍 session search + 🛡️ secret scanning for Pi. Token-aware policy-only memory by default, SQLite FTS5 search, auto-consolidation, procedural skills.
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "🧠 Persistent memory + 🔍 session search + 🛡️ secret scanning for Pi. Token-aware policy-only memory by default, SQLite FTS5 search, auto-consolidation, procedural skills. 693 tests. Ported from Hermes agent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"files": [
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"url": "https://github.com/chandra447/pi-hermes-memory"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
+
"@earendil-works/pi-ai": "*",
|
|
48
49
|
"@earendil-works/pi-coding-agent": ">=0.74.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type { MemoryConfig, MemoryOverflowStrategy, SessionSearchVariant, ThinkingLevel } from "./types.js";
|
|
3
|
+
import type { MemoryConfig, MemoryOverflowStrategy, ReviewTransport, SessionSearchVariant, ThinkingLevel } from "./types.js";
|
|
4
4
|
import {
|
|
5
5
|
DEFAULT_MEMORY_CHAR_LIMIT,
|
|
6
6
|
DEFAULT_USER_CHAR_LIMIT,
|
|
@@ -19,8 +19,13 @@ import { AGENT_ROOT, normalizeConfiguredMemoryDir, normalizeProjectsMemoryDir }
|
|
|
19
19
|
|
|
20
20
|
const MEMORY_OVERFLOW_STRATEGIES: readonly MemoryOverflowStrategy[] = ["auto-consolidate", "reject", "fifo-evict"];
|
|
21
21
|
const SESSION_SEARCH_VARIANTS: readonly SessionSearchVariant[] = ["legacy", "anchors"];
|
|
22
|
+
const REVIEW_TRANSPORTS: readonly ReviewTransport[] = ["direct", "subprocess"];
|
|
22
23
|
const THINKING_LEVELS: readonly ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
23
24
|
|
|
25
|
+
function isReviewTransport(value: unknown): value is ReviewTransport {
|
|
26
|
+
return typeof value === "string" && REVIEW_TRANSPORTS.includes(value as ReviewTransport);
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
function isMemoryOverflowStrategy(value: unknown): value is MemoryOverflowStrategy {
|
|
25
30
|
return typeof value === "string" && MEMORY_OVERFLOW_STRATEGIES.includes(value as MemoryOverflowStrategy);
|
|
26
31
|
}
|
|
@@ -42,6 +47,7 @@ const DEFAULT_CONFIG: MemoryConfig = {
|
|
|
42
47
|
nudgeInterval: DEFAULT_NUDGE_INTERVAL,
|
|
43
48
|
reviewRecentMessages: DEFAULT_REVIEW_RECENT_MESSAGES,
|
|
44
49
|
reviewEnabled: true,
|
|
50
|
+
reviewTransport: "direct",
|
|
45
51
|
flushOnCompact: true,
|
|
46
52
|
flushOnShutdown: true,
|
|
47
53
|
flushMinTurns: DEFAULT_FLUSH_MIN_TURNS,
|
|
@@ -91,6 +97,7 @@ export function loadConfig(configPath = DEFAULT_CONFIG_PATH): MemoryConfig {
|
|
|
91
97
|
if (typeof parsed.nudgeInterval === "number") config.nudgeInterval = parsed.nudgeInterval;
|
|
92
98
|
if (isNonNegativeNumber(parsed.reviewRecentMessages)) config.reviewRecentMessages = parsed.reviewRecentMessages;
|
|
93
99
|
if (typeof parsed.reviewEnabled === "boolean") config.reviewEnabled = parsed.reviewEnabled;
|
|
100
|
+
if (isReviewTransport(parsed.reviewTransport)) config.reviewTransport = parsed.reviewTransport;
|
|
94
101
|
if (typeof parsed.flushOnCompact === "boolean") config.flushOnCompact = parsed.flushOnCompact;
|
|
95
102
|
if (typeof parsed.flushOnShutdown === "boolean") config.flushOnShutdown = parsed.flushOnShutdown;
|
|
96
103
|
if (typeof parsed.flushMinTurns === "number") config.flushMinTurns = parsed.flushMinTurns;
|
|
@@ -134,6 +141,12 @@ export function loadConfig(configPath = DEFAULT_CONFIG_PATH): MemoryConfig {
|
|
|
134
141
|
if (trimmed.length > 0) config.llmModelOverride = trimmed;
|
|
135
142
|
}
|
|
136
143
|
if (isThinkingLevel(parsed.llmThinkingOverride)) config.llmThinkingOverride = parsed.llmThinkingOverride;
|
|
144
|
+
if (isStringArray(parsed.childExtensionPaths)) {
|
|
145
|
+
const childExtensionPaths = [...new Set<string>(
|
|
146
|
+
(parsed.childExtensionPaths as string[]).map((item) => item.trim()).filter(Boolean),
|
|
147
|
+
)];
|
|
148
|
+
if (childExtensionPaths.length > 0) config.childExtensionPaths = childExtensionPaths;
|
|
149
|
+
}
|
|
137
150
|
if (hasMemoryOverflowStrategy) {
|
|
138
151
|
config.autoConsolidate = config.memoryOverflowStrategy === "auto-consolidate";
|
|
139
152
|
} else if (hasLegacyAutoConsolidate) {
|
package/src/constants.ts
CHANGED
|
@@ -145,6 +145,78 @@ For failures, include: what was tried, why it failed, what error occurred, and w
|
|
|
145
145
|
|
|
146
146
|
Only act if there's something genuinely worth saving. If nothing stands out, just say 'Nothing to save.' and stop.`;
|
|
147
147
|
|
|
148
|
+
// ─── Shared JSON operations schema for direct (in-process) completions ───
|
|
149
|
+
// (review/flush/consolidation/correction all ask the model to respond with
|
|
150
|
+
// this same {"operations":[...]} shape instead of calling the memory tool,
|
|
151
|
+
// since direct mode is a single completeSimple() call with no tool loop).
|
|
152
|
+
const DIRECT_MEMORY_OPERATIONS_SCHEMA = `Respond with JSON only (no markdown fences):
|
|
153
|
+
{
|
|
154
|
+
"operations": [
|
|
155
|
+
{
|
|
156
|
+
"action": "add",
|
|
157
|
+
"target": "memory",
|
|
158
|
+
"content": "entry text"
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Operation fields:
|
|
164
|
+
- action: "add" | "replace" | "remove"
|
|
165
|
+
- target: "memory" | "user" | "project" | "failure"
|
|
166
|
+
- content: required for add/replace
|
|
167
|
+
- old_text: required for replace/remove (substring match)
|
|
168
|
+
- category: for failure target — failure | correction | insight | convention | tool-quirk | preference
|
|
169
|
+
- failure_reason: optional context for failure entries`;
|
|
170
|
+
|
|
171
|
+
export const DIRECT_REVIEW_SYSTEM_PROMPT = `You review coding conversations and extract durable memories worth saving across sessions.
|
|
172
|
+
|
|
173
|
+
Review these aspects:
|
|
174
|
+
- **Memory**: User persona, preferences, expectations about how the agent should behave, work style.
|
|
175
|
+
- **Failures & Corrections**: What failed, user corrections, insights, conventions, tool quirks.
|
|
176
|
+
|
|
177
|
+
Do NOT create or modify skills. Only save genuinely durable facts — not task progress, session outcomes, or temporary state.
|
|
178
|
+
|
|
179
|
+
${DIRECT_MEMORY_OPERATIONS_SCHEMA}
|
|
180
|
+
|
|
181
|
+
If nothing is worth saving, return {"operations":[]}.`;
|
|
182
|
+
|
|
183
|
+
// ─── Direct (in-process) flush prompt — used by session-flush.ts when the
|
|
184
|
+
// session is about to lose context (compaction/shutdown). ───
|
|
185
|
+
export const DIRECT_FLUSH_SYSTEM_PROMPT = `The session is being compressed and about to lose context. Save anything worth remembering from the conversation — prioritize user preferences, corrections, and recurring patterns over task-specific details.
|
|
186
|
+
|
|
187
|
+
${DIRECT_MEMORY_OPERATIONS_SCHEMA}
|
|
188
|
+
|
|
189
|
+
If nothing is worth saving, return {"operations":[]}.`;
|
|
190
|
+
|
|
191
|
+
// ─── Direct (in-process) consolidation prompt — used by auto-consolidate.ts.
|
|
192
|
+
// Unlike review/flush/correction, a single triggerConsolidation() call is
|
|
193
|
+
// always scoped to exactly one target/store, passed via the user prompt. ───
|
|
194
|
+
export const DIRECT_CONSOLIDATION_SYSTEM_PROMPT = `The memory store you're given is at capacity. Consolidate its current entries:
|
|
195
|
+
- Merge related entries into a single, concise entry
|
|
196
|
+
- Remove outdated or superseded entries (entries older than 30 days without recent references are candidates for removal)
|
|
197
|
+
- Keep the most important and frequently-referenced facts
|
|
198
|
+
- Preserve user preferences and corrections (highest priority)
|
|
199
|
+
|
|
200
|
+
Each entry shows when it was created and last referenced in HTML comments (<!-- created=..., last=... -->). Use this to identify stale entries.
|
|
201
|
+
|
|
202
|
+
Express a merge as "remove" operations for the entries being dropped plus one "add" operation for the new merged entry. Be aggressive about merging — less is more. Every operation MUST use the exact target given to you in the user message; do not touch any other target.
|
|
203
|
+
|
|
204
|
+
${DIRECT_MEMORY_OPERATIONS_SCHEMA}`;
|
|
205
|
+
|
|
206
|
+
// ─── Direct (in-process) correction-save prompt — used by correction-detector.ts. ───
|
|
207
|
+
export const DIRECT_CORRECTION_SYSTEM_PROMPT = `The user just corrected the agent. Review what went wrong and decide what durable memory to save.
|
|
208
|
+
|
|
209
|
+
Priority:
|
|
210
|
+
1. User preference ("don't do X", "always use Y instead")
|
|
211
|
+
2. Wrong assumption the agent made
|
|
212
|
+
3. Environment fact the agent got wrong
|
|
213
|
+
|
|
214
|
+
If this contradicts an existing entry, use a "replace" operation to update it instead of "add".
|
|
215
|
+
|
|
216
|
+
${DIRECT_MEMORY_OPERATIONS_SCHEMA}
|
|
217
|
+
|
|
218
|
+
If nothing is worth saving beyond the automatic failure-memory capture, return {"operations":[]}.`;
|
|
219
|
+
|
|
148
220
|
// ─── Flush prompt (ported from flush_memories() in run_agent.py ~L7379) ───
|
|
149
221
|
export const FLUSH_PROMPT = `[System: The session is being compressed. Save anything worth remembering — prioritize user preferences, corrections, and recurring patterns over task-specific details.]`;
|
|
150
222
|
|