mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 07:02:04 +00:00
mom: add working memory system and improve log querying
- Add MEMORY.md files for persistent working memory - Global memory: workspace/MEMORY.md (shared across channels) - Channel memory: workspace/<channel>/MEMORY.md (channel-specific) - Automatically loaded into system prompt on each request - Enhance JSONL log format with ISO 8601 dates - Add 'date' field for easy grepping (e.g., grep '"date":"2025-11-26"') - Migrated existing logs to include date field - Improve log query efficiency - Add jq query patterns to prevent context overflow - Emphasize limiting NUMBER of messages (10-50), not truncating text - Show full message text and attachments in queries - Handle null/empty attachments with (.attachments // []) - Optimize system prompt - Add current date/time for date-aware operations - Format recent messages as TSV (43% token savings vs raw JSONL) - Add efficient query examples with both JSON and TSV output - Enhanced security documentation - Add prompt injection risk warnings - Document credential exfiltration scenarios - Provide mitigation strategies
This commit is contained in:
parent
a484330cd1
commit
4e01eca40e
5 changed files with 309 additions and 18 deletions
|
|
@ -8,7 +8,8 @@ export interface Attachment {
|
|||
}
|
||||
|
||||
export interface LoggedMessage {
|
||||
ts: string; // slack timestamp
|
||||
date: string; // ISO 8601 date (e.g., "2025-11-26T10:44:00.000Z") for easy grepping
|
||||
ts: string; // slack timestamp or epoch ms
|
||||
user: string; // user ID (or "bot" for bot responses)
|
||||
userName?: string; // handle (e.g., "mario")
|
||||
displayName?: string; // display name (e.g., "Mario Zechner")
|
||||
|
|
@ -104,6 +105,21 @@ export class ChannelStore {
|
|||
*/
|
||||
async logMessage(channelId: string, message: LoggedMessage): Promise<void> {
|
||||
const logPath = join(this.getChannelDir(channelId), "log.jsonl");
|
||||
|
||||
// Ensure message has a date field
|
||||
if (!message.date) {
|
||||
// Parse timestamp to get date
|
||||
let date: Date;
|
||||
if (message.ts.includes(".")) {
|
||||
// Slack timestamp format (1234567890.123456)
|
||||
date = new Date(parseFloat(message.ts) * 1000);
|
||||
} else {
|
||||
// Epoch milliseconds
|
||||
date = new Date(parseInt(message.ts, 10));
|
||||
}
|
||||
message.date = date.toISOString();
|
||||
}
|
||||
|
||||
const line = JSON.stringify(message) + "\n";
|
||||
await appendFile(logPath, line, "utf-8");
|
||||
}
|
||||
|
|
@ -113,6 +129,7 @@ export class ChannelStore {
|
|||
*/
|
||||
async logBotResponse(channelId: string, text: string, ts: string): Promise<void> {
|
||||
await this.logMessage(channelId, {
|
||||
date: new Date().toISOString(),
|
||||
ts,
|
||||
user: "bot",
|
||||
text,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue