Commit graph

18 commits

Author SHA1 Message Date
Mario Zechner
706554a5d3 fix(mom): private channel messages not being logged
- Add message.groups to required bot events in README
- Add groups:history and groups:read to required scopes in README
- app_mention handler now logs messages directly instead of relying on message event
- Add deduplication in ChannelStore.logMessage() to prevent double-logging
- Remove redundant current message append in agent.ts (already in log)
2025-12-04 12:24:29 +01:00
Mario Zechner
f02194296d feat(mom): backfill missed messages on startup using conversations.history API
- Add getLastTimestamp() to ChannelStore to read last ts from log.jsonl
- Add backfillChannel() to fetch up to 3 pages (3000 messages) per channel
- Add backfillAllChannels() called in start() before socket connection
- Include mom's own messages (as bot) and user messages, exclude other bots
- Process attachments from backfilled messages
- Add logging: logBackfillStart, logBackfillChannel, logBackfillComplete
- Warn if attachment missing name instead of failing

fixes #103
2025-12-03 22:05:13 +01:00
Mario Zechner
75bb14cc4d fix(mom): include triggering message in context
Fix race condition where app_mention event fires before message event
logs to log.jsonl, causing the user's triggering message to be missing
from the agent's context. Now append the current message directly from
ctx.message to recentMessages.
2025-12-01 11:56:40 +01:00
Mario Zechner
9ebee631be mom: turn-based context, timestamp fixes, system prompt improvements (#68)
Breaking Changes:
- Timestamps now use Slack format - run migrate-timestamps.ts for existing logs

Added:
- Channel/user ID mappings in system prompt
- Skills documentation in system prompt
- Debug last_prompt.txt output
- Bash working directory info
- Token-efficient log queries filtering tool calls

Changed:
- Turn-based message context (groups consecutive bot messages as one turn)
- Messages sorted by Slack timestamp
- Condensed system prompt (~5k → ~2.7k chars)
- Simplified user prompt
- Selective logging (skip UI status labels)

Fixed:
- Duplicate message logging from app_mention handler
- Username obfuscation in thread messages
2025-11-27 23:45:25 +01:00
Mario Zechner
330e044b55 feat(mom): split long messages instead of truncating
- Messages > 40k chars are split into multiple Slack messages
- Full tool results now shown in thread (no truncation)
- Main message truncates with 'see thread for full response' if too long
- Keep jsonl log truncation for storage efficiency
2025-11-27 19:32:54 +01:00
Mario Zechner
4f845cdd1b fix(mom): handle Slack message length limits and API errors gracefully
- Truncate messages exceeding Slack's 40,000 char limit
- Catch Slack API errors in queue and post to thread instead of crashing
- Add error context to queue operations for better debugging
- Wrap replaceMessage in try/catch
2025-11-27 19:22:53 +01:00
Mario Zechner
5fcdf0cfd8 feat(mom): add arrow prefix to tool labels for visual distinction
Closes #65
2025-11-27 14:11:08 +01:00
Mario Zechner
effb4d0b7c feat(mom): reduce tool verbosity in main Slack messages
- During execution: show tool labels, thinking, and text in main message
- After completion: replace main message with only final assistant text
- Post thinking (italic) and text to thread for full audit trail
- Add promise queue to ensure ctx.respond calls execute sequentially
- Add log.logThinking() and log.logResponse() for console output
- Get final text from agent.state.messages instead of tracking

Closes #65
2025-11-27 14:07:21 +01:00
Mario Zechner
0c6c0f34dd mom: add working indicator and improve stop command
Working Indicator:
- Add '...' to channel messages while mom is processing
- Automatically removed when work completes or stops
- Applies to working message, not status messages

Improved Stop Command:
- Posts separate 'Stopping...' message that updates to 'Stopped'
- Original working message continues updating with tool results
- Clean separation between status and work output
- Properly handles abort during multi-step operations

Clean Stop Reason Handling:
- Agent run() now returns { stopReason } instead of throwing
- Handle 'aborted', 'error', 'stop', 'length', 'toolUse' cases cleanly
- No more exception-based control flow
- Track stopReason from assistant message.stopReason field

New SlackContext Methods:
- replaceMessage() - replace message text instead of appending
- setWorking() - add/remove working indicator
- Improved context tracking for stop command updates
2025-11-26 20:49:02 +01:00
Mario Zechner
bfe7df6a49 fix: biome linter warnings (unused parameters) 2025-11-26 18:04:37 +01:00
Mario Zechner
213bc4df1c mom: add centralized logging, usage tracking, and improve prompt caching
Major improvements to mom's logging and cost reporting:

Centralized Logging System:
- Add src/log.ts with type-safe logging functions
- Colored console output (green=user, yellow=mom, dim=details)
- Consistent format: [HH:MM:SS] [context] message
- Replace scattered console.log/error calls throughout codebase

Usage Tracking & Cost Reporting:
- Track tokens (input, output, cache read/write) and costs per run
- Display summary at end of each run in console and Slack thread
- Example: 💰 Usage: 12,543 in + 847 out (5,234 cache read) = $0.0234

Prompt Caching Optimization:
- Move recent messages from system prompt to user message
- System prompt now mostly static (only changes with memory files)
- Enables effective use of Anthropic's prompt caching
- Significantly reduces costs on subsequent requests

Model & Cost Improvements:
- Switch from Claude Opus 4.5 to Sonnet 4.5 (~40% cost reduction)
- Fix Claude Opus 4.5 cache pricing in ai package (was 3x too expensive)
- Add manual override in generate-models.ts until upstream fix merges
- Submitted PR to models.dev: https://github.com/sst/models.dev/pull/439

UI/UX Improvements:
- Extract actual text from tool results instead of JSON wrapper
- Cleaner Slack thread formatting with duration and labels
- Tool args formatting shows paths with offset:limit notation
- Add chalk for colored terminal output

Dependencies:
- Add chalk package for terminal colors
2025-11-26 18:04:16 +01:00
Mario Zechner
4e01eca40e 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
2025-11-26 13:21:43 +01:00
Mario Zechner
30964e0c33 mom: Thread-based tool details, improved README, fixed message ordering 2025-11-26 01:48:41 +01:00
Mario Zechner
f53e4fba42 mom: Add scratchpad directory to system prompt 2025-11-26 01:22:47 +01:00
Mario Zechner
6117127b02 mom: Single accumulated message per run, exclude data dir from biome 2025-11-26 01:21:45 +01:00
Mario Zechner
9e0255b10b mom: Tell mom what environment she's in (Docker vs host) 2025-11-26 01:09:43 +01:00
Mario Zechner
f140f2e432 mom: Docker sandbox support with --sandbox=docker:container-name option 2025-11-26 01:06:00 +01:00
Mario Zechner
aa9e058249 mom: Slack bot with abort support, streaming console output, removed sandbox 2025-11-26 00:27:21 +01:00