mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 10:00:39 +00:00
mom: fix duplicate logging
- Remove user message logging from agent.ts (Slack handler already logs it) - Add excludeTimestamp param to syncFromLog to skip current @mention - Sync happens once before each prompt with current message excluded
This commit is contained in:
parent
5a231abe4c
commit
cc71c0a49e
2 changed files with 14 additions and 18 deletions
|
|
@ -337,11 +337,12 @@ export function createAgentRunner(sandboxConfig: SandboxConfig): AgentRunner {
|
||||||
|
|
||||||
// Update system prompt for existing session (memory may have changed)
|
// Update system prompt for existing session (memory may have changed)
|
||||||
session.agent.setSystemPrompt(systemPrompt);
|
session.agent.setSystemPrompt(systemPrompt);
|
||||||
|
|
||||||
// Sync any new messages from log.jsonl (e.g., messages that arrived while processing)
|
|
||||||
sessionManager.syncFromLog();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync messages from log.jsonl to context.jsonl
|
||||||
|
// Exclude the current message - it will be added via prompt()
|
||||||
|
sessionManager.syncFromLog(ctx.message.ts);
|
||||||
|
|
||||||
currentSession = session;
|
currentSession = session;
|
||||||
|
|
||||||
// Create logging context
|
// Create logging context
|
||||||
|
|
@ -551,19 +552,9 @@ export function createAgentRunner(sandboxConfig: SandboxConfig): AgentRunner {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Build user message from Slack context
|
// Build user message from Slack context
|
||||||
|
// Note: User message is already logged to log.jsonl by Slack event handler
|
||||||
const userMessage = ctx.message.text;
|
const userMessage = ctx.message.text;
|
||||||
|
|
||||||
// Log user message to log.jsonl (human-readable history)
|
|
||||||
await store.logMessage(ctx.message.channel, {
|
|
||||||
date: new Date().toISOString(),
|
|
||||||
ts: toSlackTs(),
|
|
||||||
user: ctx.message.user,
|
|
||||||
userName: ctx.message.userName,
|
|
||||||
text: userMessage,
|
|
||||||
attachments: ctx.message.attachments || [],
|
|
||||||
isBot: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Send prompt to agent session
|
// Send prompt to agent session
|
||||||
await session.prompt(userMessage);
|
await session.prompt(userMessage);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,7 @@ export class MomSessionManager {
|
||||||
} else {
|
} else {
|
||||||
this.sessionId = uuidv4();
|
this.sessionId = uuidv4();
|
||||||
}
|
}
|
||||||
|
// Note: syncFromLog() is called explicitly from agent.ts with excludeTimestamp
|
||||||
// Sync missing messages from log.jsonl to context.jsonl
|
|
||||||
this.syncFromLog();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -87,8 +85,10 @@ export class MomSessionManager {
|
||||||
* Channel chatter is formatted as "[username]: message" to distinguish from direct @mentions.
|
* Channel chatter is formatted as "[username]: message" to distinguish from direct @mentions.
|
||||||
*
|
*
|
||||||
* Called automatically on construction and should be called before each agent run.
|
* Called automatically on construction and should be called before each agent run.
|
||||||
|
*
|
||||||
|
* @param excludeTimestamp Optional timestamp to exclude (for the current @mention being processed)
|
||||||
*/
|
*/
|
||||||
syncFromLog(): void {
|
syncFromLog(excludeTimestamp?: string): void {
|
||||||
if (!existsSync(this.logFile)) return;
|
if (!existsSync(this.logFile)) return;
|
||||||
|
|
||||||
// Get timestamps of messages already in context
|
// Get timestamps of messages already in context
|
||||||
|
|
@ -118,12 +118,17 @@ export class MomSessionManager {
|
||||||
try {
|
try {
|
||||||
const logMsg: LogMessage = JSON.parse(line);
|
const logMsg: LogMessage = JSON.parse(line);
|
||||||
|
|
||||||
|
// Use date for context timestamp (consistent key)
|
||||||
const ts = logMsg.date || logMsg.ts;
|
const ts = logMsg.date || logMsg.ts;
|
||||||
if (!ts) continue;
|
if (!ts) continue;
|
||||||
|
|
||||||
// Skip if already in context
|
// Skip if already in context
|
||||||
if (contextTimestamps.has(ts)) continue;
|
if (contextTimestamps.has(ts)) continue;
|
||||||
|
|
||||||
|
// Skip the current message being processed (will be added via prompt())
|
||||||
|
// Compare against Slack ts since that's what ctx.message.ts provides
|
||||||
|
if (excludeTimestamp && logMsg.ts === excludeTimestamp) continue;
|
||||||
|
|
||||||
// Skip bot messages - added through agent flow
|
// Skip bot messages - added through agent flow
|
||||||
if (logMsg.isBot) continue;
|
if (logMsg.isBot) continue;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue