jungjaehoon-lifegamez

mama-context

Always-on background context injection from MAMA memory. Automatically surfaces relevant decisions when you work on code, without explicit invocation.

jungjaehoon-lifegamez 12 5 Updated 6mo ago
GitHub

Install

npx skillscat add jungjaehoon-lifegamez/mama/mama-context

Install via the SkillsCat registry.

SKILL.md

MAMA Context - Auto-Injection Skill

Overview

This skill provides automatic background context injection using MAMA's hook system. It runs silently and surfaces relevant past decisions via the UserPromptSubmit hook (~150ms latency with HTTP embedding server).

Philosophy: Gentle hints, not intrusive walls of text. Claude sees topic + time, decides if relevant.


How It Works

The skill uses a multi-hook system for comprehensive context injection:

UserPromptSubmit Hook (active, ~150ms โ€” no plugin-side script; handled by Claude Code host)

  • Triggers: On every user message submission
  • Purpose: Inject relevant decisions as context before Claude responds
  • Latency: ~150ms (HTTP embedding server keeps model in memory)
  • Token budget: 40 tokens (teaser format)

SessionStart Hook (scripts/sessionstart-hook.js)

  • Triggers: Once per session
  • Purpose: Initialize MAMA, pre-warm embedding model
  • Timeout: 15s

PreToolUse Hook (scripts/pretooluse-hook.js) - disabled (script retained)

  • Previously: Injected contracts before Edit/Write operations
  • Status: Disabled for performance. Script retained for future use.

PostToolUse Hook (scripts/posttooluse-hook.js) - disabled (script retained)

  • Previously: Tracked code changes, suggested decision saves
  • Status: Disabled for performance. Script retained for future use.

PreCompact Hook (scripts/precompact-hook.js)

  • Triggers: Before context compaction
  • Purpose: Preserve unsaved decisions in compacted context
  • Timeout: 10s

Teaser Format (40 tokens)

๐Ÿ’ก MAMA: 2 related
   โ€ข authentication_strategy (85%, 3 days ago)
   โ€ข mesh_detail (78%, 1 week ago)
   /mama:search <topic> for details

Why teaser?

  • Hooks fire on user messages (UserPromptSubmit) โ†’ Must be lightweight
  • Claude infers relevance from topic + similarity + time
  • Full details available via /mama:search if needed
  • Avoids token bloat (250 tokens โ†’ 40 tokens)

Status Transparency

Every injection shows current tier status:

Tier 1 (Full Features):

๐Ÿ” System Status: โœ… Full Features Active (Tier 1)
   - Vector Search: โœ… ON (Transformers.js, 3ms latency)
   - Search Quality: HIGH (80% accuracy)

Tier 2 (Degraded):

๐Ÿ” System Status: โš ๏ธ DEGRADED MODE (Tier 2)
   - Vector Search: โŒ OFF (embedding model failed)
   - Search Quality: BASIC (40% accuracy, exact match only)

โš ๏ธ Fix: Check embedding model installation

Configuration

Disable Skill:

# Environment variable
export MAMA_DISABLE_HOOKS=true

# Or in config file (~/.mama/config.json)
{
  "disable_hooks": true
}

Adjust Thresholds:

{
  "similarity_threshold": 0.7,
  "token_budget": 40,
  "rate_limit_ms": 1000
}

Note: similarity_threshold: 0.7 applies to explicit searches (/mama:search). The disabled pretooluse-hook.js uses a looser SIMILARITY_THRESHOLD = 0.6 (kept from its original contract-injection design). The active UserPromptSubmit hook delegates search to the MCP server, which uses its own default threshold. Hook thresholds are intentionally separate from the config value shown above.


When Claude Should Use This

โœ… Automatic (no action needed):

  • Context appears when relevant decisions exist
  • Claude notices hints and can request details
  • User sees transparent status (Tier 1/2)

โŒ Don't explicitly invoke this skill:

  • It's always-on (background process)
  • Hooks handle triggering automatically
  • Use /mama:search for explicit lookups

Technical Details

Hook Integration:

  • UserPromptSubmit: Active (~150ms, no plugin-side script; handled by Claude Code host via MCP)
  • SessionStart: scripts/sessionstart-hook.js (initialization)
  • PreToolUse: scripts/pretooluse-hook.js (disabled, script retained)
  • PostToolUse: scripts/posttooluse-hook.js (disabled, script retained)
  • PreCompact: scripts/precompact-hook.js (decision preservation)

Performance:

  • Hook latency: ~150ms (HTTP embedding server, model stays in memory)
  • Cold start: ~1500ms (embedding model initialization, first session only)
  • Warm: ~50ms (HTTP embedding request)
  • Timeout: 1800ms (graceful degradation if exceeded)

Search Algorithm:

  • Vector search: Transformers.js (3ms embedding)
  • Hybrid scoring: 20% recency + 50% importance + 30% semantic
  • Graph expansion: Follows supersedes edges
  • Recency boost: Gaussian decay (30-day half-life)

Acceptance Criteria Mapping

  • โœ… AC1: Declared in plugin.json, references hook outputs
  • โœ… AC2: Similarity thresholds (70%) + token budgets (40 teaser / 250 full)
  • โœ… AC3: Disable via config (MAMA_DISABLE_HOOKS)
  • โœ… AC4: Status indicator (Tier 1/2, accuracy, fix instructions)
  • โœ… AC5: Smoke test - fires during normal coding session

Example Output

User edits a file related to authentication:

Skill injects (via UserPromptSubmit hook):

๐Ÿ’ก MAMA: 1 related
   โ€ข auth_strategy (90%, 2 days ago)
   /mama:search auth_strategy for full decision

๐Ÿ” System Status: โœ… Full Features Active (Tier 1)

Claude sees the hint and can:

  1. Ignore (if not relevant)
  2. Suggest /mama:search auth_strategy to user
  3. Continue with general advice

For Developers

Testing:

# Test SessionStart hook (the only testable standalone hook)
node packages/claude-code-plugin/scripts/sessionstart-hook.js

# UserPromptSubmit hook is triggered automatically by Claude Code
# on every user message โ€” no manual invocation needed.

Architecture:

User submits prompt
    โ†“
UserPromptSubmit Hook (~150ms, 1800ms timeout)
    โ†“
Decision search (generate embedding, search, score)
    โ†“
Context injection to Claude (40-token teaser)
    โ†“
Claude sees context

Key Principles

  1. Lightweight: 40 tokens teaser format
  2. Transparent: Always show tier status and latency
  3. Non-intrusive: Hints, not walls of text
  4. Opt-out: User control via config (MAMA_DISABLE_HOOKS)
  5. Graceful degradation: Tier 2 fallback if embeddings unavailable
  6. Multi-hook system: UserPromptSubmit (active) + SessionStart + PreCompact + PreToolUse/PostToolUse (disabled)

Related

  • Story M3.2 (this skill)
  • Story M2.2 (PreToolUse hook โ€” disabled, scripts retained)
  • Story M2.4 (Transparency banner)
  • Architecture: docs/MAMA-ARCHITECTURE.md (Decision 4 - Hook Implementation)