memory-session-summary.mjs
59 lines 2.1 KB
Raw
sha256:87f84653ce4706be8c65b0c4494ed6fb891213cca82db2b1824772cddc41a752 feat(auth): durable MCP OAuth refresh via shared strong sto… Agent minor 56 days ago
1 /**
2 * Session summary generation: LLM-powered summarization of recent memory events
3 * into a single session_summary event.
4 *
5 * Uses completeChat (OpenAI → Anthropic → Ollama fallback chain).
6 */
7
8 import { createMemoryManager } from './memory.mjs';
9 import { completeChat } from './llm-complete.mjs';
10
11 const SYSTEM_PROMPT = `You are a session summarizer for a personal knowledge vault system called Knowtation. Given a log of recent agent/user activity events, produce a concise summary covering:
12 1. What was accomplished (searches, writes, exports, imports, index operations)
13 2. Key topics and queries explored
14 3. Decisions made or pending
15 4. Suggested next steps
16
17 Be concise and factual. Focus on actionable takeaways. Output plain text, no markdown headings.`;
18
19 /**
20 * Generate a session summary from recent memory events and store it.
21 * @param {object} config — loadConfig() result
22 * @param {{ since?: string, limit?: number, maxTokens?: number, dryRun?: boolean }} [opts]
23 * @returns {Promise<{ summary: string, event_count: number, id?: string, ts?: string }>}
24 */
25 export async function generateSessionSummary(config, opts = {}) {
26 const mm = createMemoryManager(config);
27 const since = opts.since || new Date(Date.now() - 86_400_000).toISOString();
28 const limit = opts.limit ?? 50;
29
30 const events = mm.list({ since, limit });
31 if (events.length === 0) {
32 return { summary: 'No events to summarize.', event_count: 0 };
33 }
34
35 const eventLines = events.map((e) => {
36 const summary = JSON.stringify(e.data).slice(0, 300);
37 return `[${e.ts}] ${e.type}: ${summary}`;
38 });
39
40 const userPrompt = `Here are ${events.length} recent activity events from the knowledge vault:\n\n${eventLines.join('\n')}\n\nSummarize this session.`;
41
42 const summary = await completeChat(config, {
43 system: SYSTEM_PROMPT,
44 user: userPrompt,
45 maxTokens: opts.maxTokens ?? 512,
46 });
47
48 if (opts.dryRun) {
49 return { summary, event_count: events.length };
50 }
51
52 const result = mm.store('session_summary', {
53 summary_text: summary,
54 event_count: events.length,
55 since,
56 });
57
58 return { summary, event_count: events.length, id: result.id, ts: result.ts };
59 }
File History 5 commits
sha256:87f84653ce4706be8c65b0c4494ed6fb891213cca82db2b1824772cddc41a752 feat(auth): durable MCP OAuth refresh via shared strong sto… Agent minor 56 days ago
sha256:873e30b7fafe601346295f8f4289f388f21d8f715f28584d5481899ba2b714fc Merge pull request #249 from aaronrene/muse-mirror Agent 73 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 76 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 96 days ago