Skip to content

Mempalace as session db #27710

Closed
Closed

Description

@d0uub

Question

Will consider mempalace as session db? It able to search related message across all session with 170 token only. I can use claude opus help to contribute before june

Activity

  1. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. geco commented on Jun 3, 2026

    @geco

    Hey @d0uub, I built an OpenCode plugin that persists conversations to MemPalace in real-time — might be what you are looking for:

    https://github.com/geco/opencode-mempalace-persistence

    Happy to collaborate or discuss how this could be extended as a native session backend. Also just opened a PR to list it on the ecosystem page: #30540

  3. d0uub commented on Jun 4, 2026

    @d0uub
    Author

    Thanks @geco for sharing your persistence plugin! It's great to see the MemPalace integration evolving.

    I wanted to share another approach that complements the persistence work - automatic Memory Injection with Wake-up Context using the experimental.chat.messages.transform hook.

    While your plugin handles the write side (saving conversations), I've been experimenting with the read side - automatically injecting relevant memories and wake-up context before the AI processes each message, without relying on model discipline to search MemPalace.

    Key Implementation

    The core mechanism uses experimental.chat.messages.transform to intercept and augment user messages:

    "experimental.chat.messages.transform": async (_input, output) => {
      if (!output?.messages?.length) return output
      const lastUser = [...output.messages].reverse().find(m => m.info?.role === "user")
      if (!lastUser) return output
    
      // 1. Wake-up: Inject L0+L1 context on first message
      if (!wakeupDone) {
        wakeupDone = true
        const ctx = wakeup()  // Calls `mempalace wake-up`
        if (ctx) {
          lastUser.parts.push({
            id: `mp-wakeup-${Date.now()}`,
            type: "text",
            synthetic: true,
            text: `[MemPalace Context]\n${ctx}\n[/MemPalace Context]`
          })
        }
      }
    
      // 2. Recall: Search and inject relevant memories
      const query = textFromParts(lastUser.parts, true)
      const memories = search(query)  // Similarity search with budget control
      if (memories) {
        lastUser.parts.push({
          id: `mp-recall-${Date.now()}`,
          type: "text",
          synthetic: true,
          text: `[MemPalace Recall]\n${memories}\n[/MemPalace Recall]`
        })
      }
      
      return output
    }

    Benefits

    1. Guaranteed Recall - Doesn't depend on model following AGENTS.md instructions (which smaller models skip ~60% of the time)
    2. Wake-up Context - Provides L0+L1 identity/project context automatically, similar to AAAK pattern
    3. Token Efficient - Uses similarity thresholds (MIN_SIMILARITY=0.20) and character budgets (MAX_INJECT_CHARS=900)
    4. Zero Configuration - No need for separate AGENTS.md or identity.txt files

    Storage Side

    For the persistence side, maybe consider following:

    function store(content) {
      // Write to temp file
      const tempFile = `/tmp/mp-store-${Date.now()}.txt`
      writeFileSync(tempFile, content)
      
      // Call mempalace mine
      execSync(`mempalace mine ${tempFile} --mode convos`)
      
      // Cleanup
      unlinkSync(tempFile)
    }
  4. geco commented on Jun 4, 2026

    @geco

    @d0uub I ended up implementing this as a plugin — opencode-mempalace-persistence. It uses experimental.chat.messages.transform to inject relevant MemPalace memories into every prompt automatically (the approach you pioneered). The plugin also saves conversations back to MemPalace in real-time.

    Repo: https://github.com/geco/opencode-mempalace-persistence
    npm: opencode-mempalace-persistence@1.3.1

    Thanks for the inspiration — your comment sparked the auto-inject approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions