跳到主要内容
    ↑↓ 选择↵ 打开esc 关闭
    中文English
    option-K

    Mempalace

    v1.2.1记忆与上下文
    opencode-plugin-mempalace

    An OpenCode plugin that integrates MemPalace's lifetime memory (L0-L3 memory stack, AAAK compression, auto context saving) into the OpenCode terminal assistant.

    GitHub 星标

    25

    月装机量

    76

    近 7 天 13

    综合评分SCORE

    36.1

    生态多维模型

    最近提交

    4 个月前

    2026-04-09

    快速安装与配置

    opencode.json

    写入当前项目的 opencode.json,只对这个仓库生效。

    opencode.json

    {
      "$schema": "https://opencode.ai/config.json",
      "plugin": ["opencode-plugin-mempalace@1.2.1"]
    }

    opencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。

    npm version License: MIT

    A community open-source plugin that integrates MemPalace's "lifetime memory" (L0-L3 memory stack, AAAK compression, auto context saving) into the OpenCode terminal assistant.

    This plugin ensures your AI assistant has a long-term memory across sessions by seamlessly hooking into OpenCode's lifecycle events to fetch, inject, and save contexts related to your specific workspace.

    🌟 Features

    • Zero-Config Auto-Initialization: Opens a new folder? The plugin automatically initializes a MemPalace database for it in the background.
    • Auto-Injection (Wake-up): Automatically wakes up MemPalace on session initialization to inject L0 (Global Identity) and L1 (Critical Facts) directly into the AI's System Prompt.
    • Pre-Compaction Rescue: Adds your core memory context back right before OpenCode compresses the conversation, ensuring crucial details are never lost.
    • Silent Background Mining: Quietly exports and saves your conversational history into your MemPalace database as you chat, preserving decisions for future usage without spending extra tokens on MCP tool calls.
    • Crash Safety & Idle Auto-Save: Never lose your context, even if you close the terminal early!
      • Idle Auto-Save: If your session is deleted or you simply stop chatting (idle), any un-saved messages are softly mined in the background.
      • Crash Safety: If you force-quit the terminal (Ctrl+C), the plugin intercepts the exit signal and performs a synchronous emergency save.

    📋 Requirements

    • OpenCode AI Terminal
    • Python 3.9+
    • MemPalace installed globally (pip install mempalace or python3 -m pip install mempalace)

    🚀 Installation

    1. Install the official MemPalace CLI on your system:

      python3 -m pip install mempalace
      
    2. Add this plugin to your OpenCode configuration. Open ~/.config/opencode/opencode.json (or your project's local opencode.json) and add the package name to the plugins array:

      {
        "$schema": "https://opencode.ai/config.json",
        "plugin": ["opencode-plugin-mempalace"]
      }
      

    ⚙️ Configuration (Optional)

    You can pass configuration options to the plugin to customize its behavior. Currently supported options:

    • threshold (default: 15): The number of chat messages required before the plugin triggers a background auto-save (mining) of your conversation.
    {
      "plugin": [["opencode-plugin-mempalace", { "threshold": 20 }]]
    }
    

    🛠️ How It Works

    • The plugin wraps the mempalace CLI via the execa package.
    • It acts as the "subconscious" of your AI, rather than just an active tool.
    • Hooks used:
      • experimental.chat.system.transform: Injects memory.
      • experimental.session.compacting: Rescues memory from truncation.
      • chat.message: Tracks conversation length and triggers background mining.
      • event: Listens for session.idle and session.deleted for soft-exit saving.
      • process.on('exit' | 'SIGINT' | 'SIGTERM'): Intercepts hard process exits for emergency synchronous saving.
    • Workspace Isolation: It infers the wing name intelligently from the workspace path (e.g. /projects/my-app -> wing_my-app). Your memory stays isolated per project!

    🧑‍💻 Development

    This project is built with TypeScript (ESM) and relies on a strict TDD approach.

    npm install
    npm run lint
    npm run test
    npm run build
    

    📄 License

    MIT