pi-hermes-memory 0.3.3 → 0.4.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 +42 -9
- package/docs/0.4/PLAN.md +160 -0
- package/docs/0.4/TASKS.md +146 -0
- package/docs/ROADMAP.md +47 -29
- package/package.json +5 -1
- package/src/constants.ts +3 -3
- package/src/handlers/index-sessions.ts +61 -0
- package/src/index.ts +42 -0
- package/src/skills/learn-memory-tool/SKILL.md +125 -0
- package/src/store/db.ts +84 -0
- package/src/store/schema.ts +94 -0
- package/src/store/session-indexer.ts +153 -0
- package/src/store/session-parser.ts +214 -0
- package/src/store/session-search.ts +134 -0
- package/src/store/sqlite-memory-store.ts +215 -0
- package/src/tools/memory-search-tool.ts +78 -0
- package/src/tools/session-search-tool.ts +83 -0
- package/src/types.ts +7 -3
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DatabaseManager } from '../store/db.js';
|
|
2
|
+
import { searchSessions, getIndexedMessageCount } from '../store/session-search.js';
|
|
3
|
+
|
|
4
|
+
export function registerSessionSearchTool(ctx: {
|
|
5
|
+
registerTool: (tool: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
parameters: Record<string, unknown>;
|
|
9
|
+
handler: (args: Record<string, unknown>) => Promise<string>;
|
|
10
|
+
}) => void;
|
|
11
|
+
}, dbManager: DatabaseManager) {
|
|
12
|
+
ctx.registerTool({
|
|
13
|
+
name: 'session_search',
|
|
14
|
+
description: `Search across past Pi coding sessions for relevant conversation context. Use this when the user asks about previous discussions, past work, or when you need context from earlier sessions.
|
|
15
|
+
|
|
16
|
+
Examples:
|
|
17
|
+
- "What did we discuss about auth last week?"
|
|
18
|
+
- "Find the PR where we fixed the test hang"
|
|
19
|
+
- "What approach did we take for the database migration?"
|
|
20
|
+
|
|
21
|
+
Returns conversation snippets with session dates and project context.`,
|
|
22
|
+
parameters: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
query: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'Search query. Use natural language or specific terms.',
|
|
28
|
+
},
|
|
29
|
+
project: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'Filter by project name (optional).',
|
|
32
|
+
},
|
|
33
|
+
role: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
enum: ['user', 'assistant'],
|
|
36
|
+
description: 'Filter by message role (optional).',
|
|
37
|
+
},
|
|
38
|
+
limit: {
|
|
39
|
+
type: 'number',
|
|
40
|
+
description: 'Maximum results to return (default: 10, max: 20).',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ['query'],
|
|
44
|
+
},
|
|
45
|
+
handler: async (args: Record<string, unknown>) => {
|
|
46
|
+
const query = args.query as string;
|
|
47
|
+
const project = args.project as string | undefined;
|
|
48
|
+
const role = args.role as string | undefined;
|
|
49
|
+
const limit = Math.min((args.limit as number) || 10, 20);
|
|
50
|
+
|
|
51
|
+
if (!query || query.trim().length === 0) {
|
|
52
|
+
return 'Error: query is required';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const totalMessages = getIndexedMessageCount(dbManager);
|
|
56
|
+
if (totalMessages === 0) {
|
|
57
|
+
return 'No sessions indexed yet. Run /memory-index-sessions to import past sessions.';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const results = searchSessions(dbManager, query, { project, role, limit });
|
|
61
|
+
|
|
62
|
+
if (results.length === 0) {
|
|
63
|
+
return `No results found for "${query}". Try a different search term or broader query.`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let output = `Found ${results.length} results for "${query}":\n\n`;
|
|
67
|
+
|
|
68
|
+
for (const result of results) {
|
|
69
|
+
const date = new Date(result.timestamp).toLocaleDateString('en-US', {
|
|
70
|
+
year: 'numeric',
|
|
71
|
+
month: 'short',
|
|
72
|
+
day: 'numeric',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
output += `---\n`;
|
|
76
|
+
output += `📅 ${date} | 📁 ${result.project} | ${result.role === 'user' ? '👤 User' : '🤖 Assistant'}\n`;
|
|
77
|
+
output += `${result.snippet}\n\n`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return output.trim();
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
import type { TextContent } from "@mariozechner/pi-ai";
|
|
6
6
|
|
|
7
7
|
export interface MemoryConfig {
|
|
8
|
-
/** Max chars for MEMORY.md (agent notes). Default:
|
|
8
|
+
/** Max chars for MEMORY.md (agent notes). Default: 5000 */
|
|
9
9
|
memoryCharLimit: number;
|
|
10
|
-
/** Max chars for USER.md (user profile). Default:
|
|
10
|
+
/** Max chars for USER.md (user profile). Default: 5000 */
|
|
11
11
|
userCharLimit: number;
|
|
12
|
-
/** Max chars for project-level MEMORY.md. Default:
|
|
12
|
+
/** Max chars for project-level MEMORY.md. Default: 5000 */
|
|
13
13
|
projectCharLimit: number;
|
|
14
14
|
/** Turns between background auto-reviews. Default: 10 */
|
|
15
15
|
nudgeInterval: number;
|
|
@@ -29,6 +29,10 @@ export interface MemoryConfig {
|
|
|
29
29
|
correctionDetection: boolean;
|
|
30
30
|
/** Tool calls before triggering background review (in addition to turn count). Default: 15 */
|
|
31
31
|
nudgeToolCalls: number;
|
|
32
|
+
/** Enable session history search via SQLite FTS5. Default: true */
|
|
33
|
+
sessionSearchEnabled?: boolean;
|
|
34
|
+
/** Days to retain session history. Default: 90 */
|
|
35
|
+
sessionRetentionDays?: number;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
export interface MemoryResult {
|