Tools
Cross Session Sync
Cross-session memory synchronization plugin for OpenClaw
Install
npm install
```
README
# Cross-Session Memory Synchronization for OpenClaw
An OpenClaw plugin that synchronizes relevant knowledge between independent messaging sessions in near real-time. When a user shares information on one channel (e.g., WhatsApp), that knowledge becomes available to the assistant on other channels (e.g., Slack, Telegram) โ without merging conversation contexts or inflating token costs.
## How It Works
```
User on WhatsApp: "My meeting with Acme was moved to Thursday"
โ
โผ
Plugin captures message โ filters noise โ extracts fact โ stores locally
โ
โผ
User on Slack: "When is my Acme meeting?"
โ
โผ
Plugin injects fact into Slack session's prompt โ LLM knows the answer
```
The plugin uses two OpenClaw hooks:
- **`message_received`** โ intercepts inbound messages, filters noise via heuristics, extracts facts via a cheap LLM call, stores them with conflict resolution
- **`before_prompt_build`** โ injects relevant facts from other sessions into the system prompt before each LLM call
## Key Features
- **Near real-time sync** โ facts available within seconds across all sessions
- **Selective propagation** โ two-layer filtering (heuristic + LLM) prevents noise from polluting other sessions
- **Conflict resolution** โ last-write-wins with supersedes chain preserves history
- **Zero core modifications** โ pure plugin using OpenClaw's official hook API
- **Cost-efficient** โ heuristic filter eliminates ~80% of messages without any LLM call; fact extraction uses the cheapest available model
## Prerequisites
- Node.js 22.16+ (recommended: 24)
- pnpm
- An OpenRouter API key (or any OpenAI-compatible LLM provider)
- OpenClaw installed and configured
## Installation
### 1. Clone and set up OpenClaw
```bash
git clone https://github.com/ricardobnjunior/openclaw-cross-session-sync.git
cd openclaw-cross-session-sync
```
### 2. Install as an OpenClaw extension
Copy the plugin into your OpenClaw installation's `extensions/` directory:
```bash
cp -r . /path/to/openclaw/extensions/cross-session-sync
cd /path/to/openclaw
pnpm install
```
### 3. Set your OpenRouter API key
```bash
export OPENROUTER_API_KEY="sk-or-v1-..."
```
### 4. Start the gateway
```bash
openclaw gateway
```
The plugin loads automatically on startup. You should see `Cross-session sync plugin loaded` in the logs.
## Running Tests
```bash
# From the OpenClaw root directory
pnpm vitest run extensions/cross-session-sync/tests/
```
### Test Coverage
| Test File | What It Covers |
|---|---|
| `noise-filter.test.ts` | Noise messages discarded, factual messages accepted |
| `fact-store.test.ts` | Save/retrieve, session exclusion, conflict resolution, persistence |
| `fact-extractor.test.ts` | LLM extraction, null handling, invalid JSON resilience |
| `integration.test.ts` | **3 mandatory scenarios:** fact sharing, conflict resolution, noise filtering |
### The 3 Mandatory Scenarios
1. **Fact shared across sessions** โ A fact stated on WhatsApp becomes available when querying from Slack
2. **Conflicting updates resolved** โ "Favorite color is blue" (WhatsApp) then "Favorite color is green" (Slack) โ only "green" is active
3. **Noise not propagated** โ Messages like "lol", "ok", "๐" never reach other sessions
## Manual Testing
1. Open two TUI sessions in separate terminals:
```bash
# Terminal 1
openclaw tui
# Terminal 2
openclaw tui
```
2. In Terminal 1, say: `My meeting with Acme Corp was moved to Thursday`
3. In Terminal 2, ask: `When is my Acme Corp meeting?`
4. The assistant in Terminal 2 should know about the Thursday meeting โ even though it was never mentioned in that session.
## Project Structure
```
โโโ src/
โ โโโ index.ts # Entry point โ registers hooks, wires components
โ โโโ types.ts # TypeScript interfaces (CrossSessionFact, etc.)
โ โโโ noise-filter.ts # Heuristic noise filter (zero LLM cost)
โ โโโ fact-store.ts # JSON-based fact store with conflict resolution
โ โโโ fact-extractor.ts # LLM-based fact extraction
โโโ tests/
โ โโโ noise-filter.test.ts # Noise filter unit tests
โ โโโ fact-store.test.ts # Fact store unit tests
โ โโโ fact-extractor.test.ts # Fact extractor unit tests
โ โโโ integration.test.ts # End-to-end integration tests
โโโ docs/
โ โโโ architecture.md # Architecture document with diagrams
โ โโโ discussion.md # Discussion questions and analysis
โโโ package.json # npm manifest
โโโ openclaw.plugin.json # OpenClaw plugin manifest
```
## Documentation
- [Architecture Document](docs/architecture.md) โ System design, data flow, conflict resolution, cost analysis
- [Discussion](docs/discussion.md) โ Alternatives analysis, OpenClaw pros/cons, fork maintenance strategy
tools
Comments
Sign in to leave a comment