8.8 KiB
description, proactive
| description | proactive |
|---|---|
| Automatically process queued memory storage requests from hooks. Always checks .memory-queue.jsonl and processes items, reporting to user what was saved. | true |
Memory Queue Processor Skill
⚡ CRITICAL: This skill MUST check and process the queue on EVERY user message automatically, and report what was saved.
Purpose
Fully autonomous memory processing with user feedback:
- Hooks write to
.memory-queue.jsonlfile - This skill checks the queue on EVERY interaction
- Processes all queued items automatically
- Reports to user what was saved
- Zero user intervention required
When to Activate
ALWAYS activate on EVERY user message:
- Before responding - Check queue first thing
- Process all items - Invoke MCP tools automatically
- Report to user - Tell them what was saved
- Clear queue - Remove processed items
- Continue - Respond to their question normally
No exceptions - this happens automatically every single time.
How It Works
1. Check for Queue File
ls -la .memory-queue.jsonl
If file exists and is non-empty, process it.
2. Read Queue Contents
Each line is a JSON object:
{"memory":"Session started...","background":"Project: mem-plugin...","importance":"normal","queued_at":"2025-11-21T15:00:00Z"}
3. Process Each Item
For each line:
- Parse JSON
- Invoke
mcp__memory-store__recordwith the parameters - Mark as processed (remove from queue or move to
.memory-queue-processed.jsonl)
4. Clean Up
After processing:
- Clear the queue file or archive it
- Report how many items were processed (optional, only if > 5 items)
Implementation
HYBRID APPROACH: Hooks provide foundational metadata, Claude adds conversational intelligence.
ALWAYS check the queue at the start of EVERY response:
// 1. Check if queue exists
if (fileExists('.memory-queue.jsonl')) {
// 2. Read all queued items
const queue = readFileLines('.memory-queue.jsonl')
.filter(line => line.trim())
.map(line => JSON.parse(line));
// 3. ENRICH each item with conversational context before storing
for (const item of queue) {
// Hook provided: File: X, Action: created, Session: Y, Language: Z...
const foundationalContext = item.background;
// Claude adds: What's being discussed? What problem is being solved?
const conversationalContext = analyzeCurrentContext({
recentMessages: last5UserMessages,
currentTask: whatUserIsWorkingOn,
fileBeingModified: item.memory,
projectInfo: loadedFrom_claude_project_context
});
// Combine: Foundational (reliable) + Conversational (intelligent)
const enrichedBackground = `${foundationalContext}. Context: ${conversationalContext}`;
await mcp__memory-store__record({
memory: item.memory,
background: enrichedBackground, // ← Now includes BOTH
importance: item.importance
});
}
// 4. Clear queue
clearFile('.memory-queue.jsonl');
}
// 5. Continue with normal response
Rules:
- ✅ ALWAYS CHECK - Every single message, no exceptions
- ✅ ENRICH CONTEXT - Add conversation context to hook metadata
- ✅ REPORT TO USER - Tell user what was saved in Memory Store
- ✅ FAIL GRACEFULLY - If error, continue anyway
- ✅ BE BRIEF - Quick confirmation, don't interrupt workflow
Context Enrichment Strategy:
- What user is working on: "Fixing OAuth authentication", "Adding MCP validation", "Refactoring queue system"
- Why this change matters: "This script validates MCP connection at session start to catch config issues early"
- How it relates to conversation: "Part of implementing the hybrid context approach discussed with user"
- Project-specific details: From
.claude-project-context- architecture, purpose, components
Hybrid Context Examples
Example 1: File Change with Conversational Enrichment
Hook writes (foundational):
{
"memory": "File modified: scripts/session-start.sh (Shell)",
"background": "File: scripts/session-start.sh, Action: modified, Session: mem-xyz, Language: Shell, Pattern: , Change: #5, Project: mem-plugin, Version: 1.2.3, Component: script"
}
Claude enriches (before storing):
- Sees conversation: User said "add MCP validation at session start"
- Understands context: This is part of fixing broken MCP detection
- Reads
.claude-project-context: Understands mem-plugin architecture - Adds: "Context: User implementing MCP connection validation at session start. This script now checks if memory-store MCP is configured using
claude mcp listand displays status/setup command. Part of making the plugin more user-friendly by catching configuration issues early. Related to queue-based architecture where hooks need reliable MCP connection."
Final stored background:
File: scripts/session-start.sh, Action: modified, Session: mem-xyz, Language: Shell, Pattern: , Change: #5, Project: mem-plugin, Version: 1.2.3, Component: script. Context: User implementing MCP connection validation at session start. This script now checks if memory-store MCP is configured using `claude mcp list` and displays status/setup command. Part of making the plugin more user-friendly by catching configuration issues early. Related to queue-based architecture where hooks need reliable MCP connection.
Example 2: Session Start with Intelligence
Hook writes (foundational):
{
"memory": "Session mem-20251121-ABC started in mem-plugin on branch main",
"background": "Session: mem-20251121-ABC, Started: 2025-11-21T15:00:00Z, Project: mem-plugin, Branch: main, Commit: 7005850, Files: 48, MCP: configured, Version: 1.2.3"
}
Claude enriches:
- Sees recent commits: "feat: add enriched background context", "feat: add MCP validation"
- Understands ongoing work: Improving context quality in memory storage
- Adds: "Context: Continuing work on hybrid context approach - hooks provide foundational metadata, Claude adds conversational intelligence. Recent work includes MCP validation and enriched background context. User wants reliable but intelligent memory storage."
Result: Future sessions know what was being worked on and why!
Example 3: Original Approach
Scenario: User starts new session, previous session queued 3 items
Action:
- Check
.memory-queue.jsonlexists - Read 3 items
- Invoke
mcp__memory-store__recordfor each - Clear queue
- Report: "💾 Saved 3 items to Memory Store (session start, 2 file changes)"
Example 2: File Changes
Scenario: User edits 5 files rapidly, hooks queue each
Action:
- After user's next message, check queue
- Find 5 items
- Process all 5
- Report: "💾 Saved 5 file changes to Memory Store"
Example 3: Empty Queue
Scenario: No queued items
Action:
- Check file (doesn't exist or empty)
- Skip processing
- Continue normally (no report needed)
Reporting Format
When items processed, always tell the user:
- 1-2 items: "💾 Saved to Memory Store: [brief description]"
- 3-5 items: "💾 Saved 4 items to Memory Store (session, 3 files)"
- 6+ items: "💾 Saved 8 items to Memory Store"
Keep it brief - just confirm what was saved, don't interrupt their workflow.
Integration with Hooks
Hooks use queue-memory.sh instead of outputting signals:
Old approach (didn't work):
cat <<EOF
{
"additionalContext": "🤖 MEMORY_STORE_AUTO_RECORD: {...}"
}
EOF
New approach (works):
bash "${CLAUDE_PLUGIN_ROOT}/scripts/queue-memory.sh" \
--memory "Session started..." \
--background "Project: mem-plugin..." \
--importance "normal"
Advantages
- Bypasses visibility issue - File-based, not conversation-based
- Reliable - Files persist across Claude Code restarts
- Auditable - Can inspect
.memory-queue.jsonlmanually - Batching - Process multiple items efficiently
- Resilient - Failures don't lose data (re-process on next check)
Error Handling
If processing fails:
- Keep items in queue for retry
- Log error to
.memory-queue-errors.log - Don't block user workflow
- Retry on next session/check
If auth fails:
- Keep all items in queue
- Warn user once: "Memory Store authentication needed"
- Don't spam warnings on every check
Testing
To verify this skill works:
-
Manually queue an item:
./scripts/queue-memory.sh --memory "Test item" --background "Testing queue" --importance "low" -
Trigger skill: Say: "Check for queued memories"
-
Verify processing:
- Queue file should be empty
- Item should be in Memory Store
- Can retrieve with recall
Success criteria: ✓ Item queued, processed, retrievable, queue cleared
💡 Pro Tip: This queue-based approach is MORE reliable than signal-based because it persists data to disk and doesn't depend on conversation context visibility!