Merge 505357542a into 6af205a13a
This commit is contained in:
commit
4b1823fc79
@ -14,6 +14,9 @@ import { resolveAgentWorkspaceDir } from "../../../agents/agent-scope.js";
|
||||
import { resolveAgentIdFromSessionKey } from "../../../routing/session-key.js";
|
||||
import { resolveHookConfig } from "../../config.js";
|
||||
import type { HookHandler } from "../../hooks.js";
|
||||
import { createSubsystemLogger } from "../../../logging/subsystem.js";
|
||||
|
||||
const log = createSubsystemLogger("hooks:session-memory");
|
||||
|
||||
/**
|
||||
* Read recent messages from session file for slug generation
|
||||
@ -68,8 +71,6 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("[session-memory] Hook triggered for /new command");
|
||||
|
||||
const context = event.context || {};
|
||||
const cfg = context.cfg as OpenClawConfig | undefined;
|
||||
const agentId = resolveAgentIdFromSessionKey(event.sessionKey);
|
||||
@ -88,13 +89,8 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
const currentSessionId = sessionEntry.sessionId as string;
|
||||
const currentSessionFile = sessionEntry.sessionFile as string;
|
||||
|
||||
console.log("[session-memory] Current sessionId:", currentSessionId);
|
||||
console.log("[session-memory] Current sessionFile:", currentSessionFile);
|
||||
console.log("[session-memory] cfg present:", !!cfg);
|
||||
|
||||
const sessionFile = currentSessionFile || undefined;
|
||||
|
||||
// Read message count from hook config (default: 15)
|
||||
@ -110,10 +106,8 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
if (sessionFile) {
|
||||
// Get recent conversation content
|
||||
sessionContent = await getRecentSessionContent(sessionFile, messageCount);
|
||||
console.log("[session-memory] sessionContent length:", sessionContent?.length || 0);
|
||||
|
||||
if (sessionContent && cfg) {
|
||||
console.log("[session-memory] Calling generateSlugViaLLM...");
|
||||
// Dynamically import the LLM slug generator (avoids module caching issues)
|
||||
// When compiled, handler is at dist/hooks/bundled/session-memory/handler.js
|
||||
// Going up ../.. puts us at dist/hooks/, so just add llm-slug-generator.js
|
||||
@ -123,7 +117,6 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
|
||||
// Use LLM to generate a descriptive slug
|
||||
slug = await generateSlugViaLLM({ sessionContent, cfg });
|
||||
console.log("[session-memory] Generated slug:", slug);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,14 +124,11 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
if (!slug) {
|
||||
const timeSlug = now.toISOString().split("T")[1]!.split(".")[0]!.replace(/:/g, "");
|
||||
slug = timeSlug.slice(0, 4); // HHMM
|
||||
console.log("[session-memory] Using fallback timestamp slug:", slug);
|
||||
}
|
||||
|
||||
// Create filename with date and slug
|
||||
const filename = `${dateStr}-${slug}.md`;
|
||||
const memoryFilePath = path.join(memoryDir, filename);
|
||||
console.log("[session-memory] Generated filename:", filename);
|
||||
console.log("[session-memory] Full path:", memoryFilePath);
|
||||
|
||||
// Format time as HH:MM:SS UTC
|
||||
const timeStr = now.toISOString().split("T")[1]!.split(".")[0];
|
||||
@ -166,11 +156,10 @@ const saveSessionToMemory: HookHandler = async (event) => {
|
||||
|
||||
// Write to new memory file
|
||||
await fs.writeFile(memoryFilePath, entry, "utf-8");
|
||||
console.log("[session-memory] Memory file written successfully");
|
||||
|
||||
// Log completion (but don't send user-visible confirmation - it's internal housekeeping)
|
||||
// Log completion using subsystem logger (visible when log level is trace/debug)
|
||||
const relPath = memoryFilePath.replace(os.homedir(), "~");
|
||||
console.log(`[session-memory] Session context saved to ${relPath}`);
|
||||
log.trace(`Session context saved to ${relPath}`);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[session-memory] Failed to save session memory:",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user