This file is the repository-wide guide for coding agents working on ClawXMemory.
Use this file for agent-facing implementation guidance. Keep user-facing product and usage documentation in README.md and docs/README_zh.md.
ClawXMemory is an OpenClaw memory plugin. The repository contains:
- the plugin runtime and hook wiring
- the file-based long-term memory store
- background indexing and Dream organization
- answer-time recall and prompt injection
- the local dashboard and trace views
- prompt assets and agent workflows
The current architecture is markdown-first:
- long-term memory lives in markdown files under the memory directory
- SQLite stores runtime control-plane state only
- recall, Dream, and UI all operate on file-memory, not on legacy aggregated tables
clawxmemory/src/index.tsPlugin entry, service registration, tool registration, and prompt section registration.clawxmemory/src/runtime.tsRuntime composition, queue/timer orchestration, retrieval entrypoints, UI state, and memory boundary diagnostics.clawxmemory/src/hooks.tsHook wiring forbefore_prompt_build,before_message_write,agent_end,before_reset, and internal message/command filtering.clawxmemory/src/tools.tsUser-facing tool contracts:memory_search,memory_overview,memory_list,memory_get, andmemory_flush.clawxmemory/src/core/pipeline/heartbeat.tsBackground indexing pipeline from raw sessions into file-memory candidates and user profile rewrites.clawxmemory/src/core/retrieval/reasoning-loop.tsSingle-project recall flow, project shortlist building, header-scan manifest selection, and final context assembly.clawxmemory/src/core/review/dream-review.tsDream planning, project rewrite execution, file deletion, and user-profile rewrite orchestration.clawxmemory/src/core/skills/llm-extraction.tsStructured LLM prompts and parsers for extraction, route selection, project selection, manifest selection, Dream planning, and profile rewrites.clawxmemory/src/core/storage/sqlite.tsSQLite runtime state, raw session queue, indexing settings, and recent trace persistence.clawxmemory/src/core/file-memory.tsMarkdown-backed memory store foruser-profile.md,project.meta.md,Project/*.md,Feedback/*.md, and derivedMEMORY.md.clawxmemory/src/ui-server.tsLocal dashboard server.clawxmemory/ui-source/*Dashboard frontend.
ClawXMemory is intentionally plugin-first, not skills-only.
Use the plugin runtime for:
- lifecycle hooks
- automatic raw session capture
- background indexing
- retrieval-time prompt injection
- Dream execution
- tool registration
- the local UI server
Use skills and prompt assets for:
- extraction rules
- recall routing and project selection
- Dream planning and project rewrite instructions
- retrieval context rendering
- agent workflows built on top of the plugin tools
Do not redesign the system as a pure skill layer unless the OpenClaw lifecycle constraints also change.
The current system has two distinct layers.
SQLite is a control-plane store, not the long-term memory truth source.
It persists:
l0_sessionsRaw captured conversation sessions waiting for or already processed by indexing.pipeline_stateRuntime settings, recent case/index/dream traces, timestamps, and other plugin state.
Field semantics that should stay stable unless a migration is introduced:
indexedOnly onL0SessionRecord. Marks whether the raw session has already been consumed by the indexing pipeline.sourceOnly onL0SessionRecord. Tracks where raw sessions came from, such asopenclaw,skill, orimport.createdAtFirst persistence time for a record.updatedAtLast runtime rewrite time for mutable state rows.
Long-term memory is stored as markdown files:
global/User/user-profile.mdprojects/<projectId>/project.meta.mdprojects/<projectId>/Project/*.mdprojects/<projectId>/Feedback/*.mdglobal/MEMORY.mdandprojects/*/MEMORY.md
MEMORY.md is a derived directory file for UI and debugging. It is not the recall truth source.
The main answer-time hook is before_prompt_build.
Current flow:
- Read the current user query and recent messages.
- Call
ReasoningRetriever.retrieve(...). - Run the memory gate with route values:
noneuserproject_memory
- Load the global user profile when memory is needed.
- For
project_memory, build a formal project shortlist and let the model select at most one project. - Scan file headers from the selected project's
Project/*.mdandFeedback/*.md. - Let the model choose top-k memory files from the compact manifest.
- Load selected files with full-text preference and hard limits.
- Inject the rendered recall context through
prependSystemContext.
Important:
- recall is single-project by design
- assistant replies are not used as project-resolution evidence
project.meta.mdis fixed context once a project is selectedMEMORY.mdis not used for semantic recall
The indexing pipeline is centered on clawxmemory/src/core/pipeline/heartbeat.ts.
Current responsibilities:
- capture raw sessions into
l0_sessions - batch unread sessions
- extract file-memory candidates
- write
Project/*.md,Feedback/*.md, and user-profile updates - record index traces and runtime stats
The indexing output is file-memory directly. There is no second persistent L1/L2 aggregation layer anymore.
Dream is centered on clawxmemory/src/core/review/dream-review.ts.
Current responsibilities:
- read formal and
_tmpfile-memory - ask the model for a global project plan
- ask the model to rewrite files per final project
- promote
_tmpfiles into formal projects - delete absorbed or superseded files
- rewrite
user-profile.mdwhen needed - record Dream traces and summary state
Dream does not create a separate project summary layer and does not rely on overview.md.
When reviewing or modifying this repository, prioritize these questions:
- Does markdown/file-memory remain the only long-term memory truth source?
- Does SQLite stay limited to raw sessions, runtime state, and traces?
- Does recall preserve the intended flow:
none / user / project_memory, then single-project manifest selection? - Does Dream reorganize and rewrite files without reintroducing extra summary layers?
- Do index and Dream avoid duplicate writes and clean up
_tmpcorrectly? - Do tool outputs and dashboard views reflect real file-memory state rather than stale derived state?
- If prompts or rule files change, do the surrounding code-side guardrails still match them?
Recommended review order:
clawxmemory/src/index.tsclawxmemory/src/runtime.tsclawxmemory/src/core/retrieval/reasoning-loop.tsclawxmemory/src/core/review/dream-review.tsclawxmemory/src/core/pipeline/heartbeat.tsclawxmemory/src/core/skills/llm-extraction.tsclawxmemory/src/core/storage/sqlite.tsclawxmemory/src/core/file-memory.tsclawxmemory/src/tools.ts
Keep documentation split by audience:
AGENTS.mdRepository-specific guidance for coding agents and implementation reviews.README.mdUser-facing English overview, installation, and development basics.docs/README_zh.mdUser-facing Chinese overview.
Do not create new design-review or prompt-audit documents under docs/ when the intended audience is coding agents. Extend this file instead.
Run commands from clawxmemory/ unless a command explicitly needs the repository root:
npm run build
npm run typecheck
npm run test
npm run debug:retrieve -- --query "project progress"Useful integration commands:
npm run relink
npm run reload
npm run uninstall
openclaw plugins inspect openbmb-clawxmemory --json