@mingxy/cerebro 1.5.7 → 1.5.9
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/hooks.ts +12 -0
- package/src/index.ts +1 -1
package/package.json
CHANGED
package/src/hooks.ts
CHANGED
|
@@ -334,6 +334,7 @@ export function compactingHook(client: OmemClient, containerTags: string[], tui:
|
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
const processedMessageIds = new Set<string>();
|
|
337
|
+
const pluginStartTime = Date.now();
|
|
337
338
|
|
|
338
339
|
export function sessionIdleHook(
|
|
339
340
|
omemClient: OmemClient,
|
|
@@ -341,6 +342,7 @@ export function sessionIdleHook(
|
|
|
341
342
|
tui: any,
|
|
342
343
|
sdkClient: any,
|
|
343
344
|
_ingestMode: "smart" | "raw" = "smart",
|
|
345
|
+
threshold: number = 0,
|
|
344
346
|
getMainSessionId?: () => string | undefined,
|
|
345
347
|
) {
|
|
346
348
|
let idleTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
@@ -376,6 +378,11 @@ export function sessionIdleHook(
|
|
|
376
378
|
const msgId = msg.info?.id;
|
|
377
379
|
if (!msgId || processedMessageIds.has(msgId)) continue;
|
|
378
380
|
|
|
381
|
+
// Skip messages created before this plugin instance started
|
|
382
|
+
// (prevents replaying entire session history on restart)
|
|
383
|
+
const msgTime = msg.info?.createdAt ? new Date(msg.info.createdAt).getTime() : 0;
|
|
384
|
+
if (msgTime > 0 && msgTime < pluginStartTime) continue;
|
|
385
|
+
|
|
379
386
|
const role = msg.info?.role;
|
|
380
387
|
if (role !== "user" && role !== "assistant") continue;
|
|
381
388
|
|
|
@@ -392,6 +399,11 @@ export function sessionIdleHook(
|
|
|
392
399
|
|
|
393
400
|
if (!hasNewMessages || conversationMessages.length === 0) return;
|
|
394
401
|
|
|
402
|
+
if (threshold > 1 && conversationMessages.length < threshold) {
|
|
403
|
+
// Log that we're waiting for more messages
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
395
407
|
try {
|
|
396
408
|
await omemClient.sessionIngest(conversationMessages, sessionID);
|
|
397
409
|
for (const id of newMessageIds) {
|
package/src/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ const OmemPlugin: Plugin = async (input) => {
|
|
|
96
96
|
"chat.message": keywordDetectionHook(omemClient, containerTags, config.autoCaptureThreshold, tui, config.ingestMode),
|
|
97
97
|
"experimental.session.compacting": compactingHook(omemClient, containerTags, tui, config.ingestMode),
|
|
98
98
|
tool: buildTools(omemClient, containerTags, { agentId, getSessionId: () => currentSessionId }),
|
|
99
|
-
event: sessionIdleHook(omemClient, containerTags, tui, client, config.ingestMode, () => currentSessionId),
|
|
99
|
+
event: sessionIdleHook(omemClient, containerTags, tui, client, config.ingestMode, config.autoCaptureThreshold, () => currentSessionId),
|
|
100
100
|
"shell.env": async (_input: any, output: any) => {
|
|
101
101
|
if (directory) {
|
|
102
102
|
output.env.OMEM_PROJECT_DIR = directory;
|