Strategic Memory Augmentation and Context Distillation for OpenClaw.
Moon is a Rust CLI plus an OpenClaw context-engine plugin for long-session context control. It keeps the active context window under Moon control while leaving the final provider request envelope to OpenClaw.
Moon has two runtime lanes:
- Active lane:
moon context-engine- records the current session checkpoint
- refreshes the hot projection
- runs
cleanseonly when pressure says compaction is needed - assembles the next active context packet
- Maintenance lane:
moon watch- projects library docs
- embeds searchable collections
- runs distillation and daily memory synthesis
Current active control flow:
record- routine hot
project - conditional
cleanse - operator
assemble - active context packet generation
Moon does not own the final provider payload. The boundary is:
- Moon owns:
- checkpointing
- hot projection refresh
- conditional
cleanse - operator assembly artifacts
- active context packet generation
- transcript compaction entries
- OpenClaw owns:
- final system prompt
- message replay
- tool definitions
- provider dispatch
- Routine Moon
systemPromptAdditionstays unused. - Moon injects model-facing active context through the
messageslane. - Moon
cleansesummaries still travel through transcriptcompactionentries and replay ascompactionSummary.
Moon now uses three distinct surfaces:
- Operator artifact
- written under
$MOON_HOME/mce/ - rich debugging/control artifact
- not shipped directly to the model
- written under
- Active context packet
- written under
$MOON_HOME/mcp/ - deterministic, model-facing packet
- injected by the plugin into the OpenClaw
messageslane
- written under
cleansesummary- written under
$MOON_HOME/cleanse/ - appended to transcript compaction when compaction runs
- replayed later as
compactionSummary
- written under
The plugin can also run a gated Moon-owned curator subagent over the packet when configured, but deterministic local retrieval stays the first stage.
Source install:
export MOON_HOME="${MOON_HOME:-$HOME/.moon}"
mkdir -p "$MOON_HOME"
cp .env.example "$MOON_HOME/.env"
cp moon.toml.example "$MOON_HOME/moon.toml"
cargo install --path . --force
moon install
moon verify --strict
moon status
moon healthmoon install does the following:
- installs the OpenClaw Moon plugin into the OpenClaw extensions dir
- writes Moon runtime docs into
$MOON_HOME - writes Moon runtime skills into the OpenClaw state dir
- patches OpenClaw config to:
- enable the Moon plugin
- set
plugins.slots.contextEngine = "moon" - set
plugins.slots.memory = "none" - set
agents.defaults.memorySearch.enabled = false
- wires Moon runtime paths and a managed
contextEngineTimeoutMsintoplugins.entries.moon.config.* - configures macOS launchd autostart when running from an installed binary
- repairs secret-bearing Moon runtime paths to owner-only permissions:
$MOON_HOME/.env$MOON_HOME/auth/$MOON_HOME/auth/openai-codex.json$MOON_HOME/logs/$MOON_HOME/logs/audit.log$MOON_HOME/logs/distill.audit.log
Recommended upgrade path:
moon updatemoon update:
- upgrades to latest stable tag by default
- supports
--channel main - supports
--checkand--dry-run - reruns
moon install - reruns
moon verify --strict - preserves existing
$MOON_HOME/.envand$MOON_HOME/moon.toml - repairs owner-only permissions for Moon-managed secret/runtime log paths
Moon supports OpenClaw-style OpenAI Codex OAuth for its remote lanes.
moon login --provider openai-codexMoon stores managed auth in:
$MOON_HOME/auth/openai-codex.json
Moon keeps the auth store owner-only on Unix:
- auth dir:
0700 - auth file:
0600
Moon uses that auth for:
cleansewithMOON_CLEANSE_PROVIDER=openai-codex- remote
distill - remote wisdom synthesis
Moon treats these runtime paths as secret-bearing or privacy-sensitive:
$MOON_HOME/.env$MOON_HOME/auth/$MOON_HOME/auth/openai-codex.json$MOON_HOME/logs/$MOON_HOME/logs/audit.log$MOON_HOME/logs/distill.audit.log
Security contract:
moon installandmoon updaterepair those paths to owner-only permissions on Unix (0600for files,0700for directories).moon verify --strictfails if any of those paths are broader than owner-only.moon statusandmoon verifycontinue masking configured API keys instead of printing them.- Remote provider failures now log only status plus request id when available; Moon no longer persists arbitrary remote error bodies into its audit paths.
Default runtime root:
$HOME/.moon
Key paths:
- raw checkpoints:
$MOON_HOME/raw/ - hot projections:
$MOON_HOME/mds/ - library projections:
$MOON_HOME/mlib/ - cleanse summaries:
$MOON_HOME/cleanse/ - operator assembly artifacts:
$MOON_HOME/mce/ - active context packets:
$MOON_HOME/mcp/ - daily memory:
$MOON_HOME/memory/ - durable memory:
$MOON_HOME/MEMORY.md - state:
$MOON_HOME/state/moon_state.json - qmd runtime:
$MOON_HOME/qmd/
MOON_HOME=$HOME/.moon
OPENCLAW_BIN=<optional-path-to-openclaw>
QMD_BIN=<path-to-qmd>
MOON_RAW_DIR=$MOON_HOME/raw
MOON_MDS_DIR=$MOON_HOME/mds
MOON_MLIB_DIR=$MOON_HOME/mlib
MOON_CLEANSE_DIR=$MOON_HOME/cleanse
MOON_MEMORY_DIR=$MOON_HOME/memory
MOON_MEMORY_FILE=$MOON_HOME/MEMORY.md
MOON_LOGS_DIR=$MOON_HOME/logs
MOON_CONFIG_PATH=$MOON_HOME/moon.toml
MOON_STATE_FILE=$MOON_HOME/state/moon_state.json
QMD_DB=$MOON_HOME/qmd/index.sqlite
QMD_CONFIG_DIR=$MOON_HOME/qmd/config
OPENCLAW_STATE_DIR=$HOME/.openclaw
OPENCLAW_CONFIG_PATH=$OPENCLAW_STATE_DIR/openclaw.json
OPENCLAW_SESSIONS_DIR=$OPENCLAW_STATE_DIR/agents/main/sessionsProvider examples:
# Gemini
MOON_CLEANSE_PROVIDER=gemini
MOON_CLEANSE_MODEL=gemini-3.1-flash-lite-preview
GEMINI_API_KEY=...
# OpenAI Responses
MOON_CLEANSE_PROVIDER=openai
MOON_CLEANSE_MODEL=gpt-4.1-mini
OPENAI_API_KEY=...
# OpenAI Codex OAuth
MOON_CLEANSE_PROVIDER=openai-codex
MOON_CLEANSE_MODEL=gpt-5.4
OPENAI_CODEX_BASE_URL=https://chatgpt.com/backend-api
# OpenAI-compatible
MOON_CLEANSE_PROVIDER=openai-compatible
MOON_CLEANSE_MODEL=deepseek-chat
AI_BASE_URL=https://api.deepseek.com
AI_API_KEY=...[context]
window_mode = "fixed"
window_tokens = 200000
compaction_authority = "moon"
cleanse_trigger_ratio = 0.50
cleanse_emergency_ratio = 0.90
[context_packet]
enabled = true
max_chars = 6000
max_candidates = 18
qmd_limit = 6
recent_memory_files = 4
recent_distill_docs = 4
[watcher]
poll_interval_secs = 60
cooldown_secs = 60
[distill]
max_per_cycle = 3
residential_timezone = "UTC"
syns_trigger_time_local = "00:00"
topic_discovery = true
[embed]
mode = "auto"
cooldown_secs = 60
max_docs_per_cycle = 3
min_pending_docs = 1
max_cycle_secs = 300
[hot_collection]
lifecycle_mode = "degrade"
lifecycle_command_mode = "primary"Global flags:
--json--allow-out-of-bounds--version/-V
Commands:
install [--force] [--dry-run] [--apply true|false]uninstall [--dry-run] [--purge] [--remove-binary]login [--provider openai-codex] [--headless]update [--check] [--dry-run] [--channel stable|main]verify [--strict] [--verbose]repair [--force]statushealthrecord [--source <path>] [--session-id <id>] [--dry-run]project [--source <path>] [--session-id <id>] [--lane hot|library|lib] [--dry-run]cleanse [--source <path>] [--session-id <id>] [--dry-run]assemble [--source <path>] [--session-id <id>] [--dry-run] [--replay-has-compaction-summary]context-engine [--source <path>] [--session-id <id>] [--used-tokens <N>] [--max-tokens <N>] [--force-cleanse] [--replay-has-compaction-summary]watch [--once] [--daemon] [--dry-run]stoprestartrecall --query <text> [--name <collection>] [--limit <N>]embed [--name <collection>] [--max-docs <N>] [--dry-run] [--watcher-trigger]distill [--mode norm|syns] [--archive <path>] [--file <path> ...] [--session-id <id>] [--dry-run]config [--show]
Exit codes:
0:ok=true2:ok=false1: process/runtime error
One-command upgrade:
moon updateStrict integration verification:
moon verify --strictManual active-window checkpoint:
moon context-engine --used-tokens 65000 --max-tokens 200000One maintenance cycle:
moon watch --onceManual search and memory operations:
moon recall --name history_lib --query "recent decision about context packets"
moon embed --name history_lib --max-docs 25
moon distill --mode norm
moon distill --mode synsstatusincludes daemon lock and OpenClaw contract diagnostics.verify --strictfails when plugin/runtime integration is unhealthy.verify --strictalso fails when Moon secret-bearing runtime files are not owner-only.watch --daemonis blocked from development binaries for safety.moon installmay add a managedMOON_HOMEblock to~/.zprofile.- macOS installed-binary mode uses launchd label
com.moon.watch. - Scheduled watcher
synsruns once per local day at or afterdistill.syns_trigger_time_local; if Moon misses the exact window, it catches up later the same day. - Scheduled watcher
synsuses the previous local day's$MOON_HOME/memory/<day>.mdplus durableMEMORY.md; it does not fall back to the current day's daily-memory file.
See docs/troubleshooting.md for known failure modes, diagnostics, and recovery steps.
Moon now has a real uninstall command.
Safe default uninstall:
moon uninstallDefault uninstall removes:
- OpenClaw Moon plugin assets
- OpenClaw Moon install/config wiring
- Moon runtime-generated artifacts:
raw/mds/mlib/cleanse/mce/mcp/logs/state/qmd/- generated runtime docs
- Moon runtime skills under the OpenClaw state dir
- the managed
MOON_HOMEshell block in~/.zprofile - launchd watcher plist on macOS
Default uninstall preserves:
$MOON_HOME/memory/$MOON_HOME/MEMORY.md$MOON_HOME/.env$MOON_HOME/moon.toml$MOON_HOME/auth/
Full wipe:
moon uninstall --purge--purge removes the entire resolved MOON_HOME.
Optional binary removal:
moon uninstall --purge --remove-binary--remove-binary attempts:
cargo uninstall moon
Use --dry-run first if you want the exact cleanup plan without mutating
anything.