无损爪 — LCM (无损上下文管理) 插件,用于 OpenClaw
Lossless Context Management plugin for OpenClaw, based on the LCM paper from Voltropy. Replaces OpenClaw's built-in sliding-window compaction with a DAG-based summarization system that preserves every message while keeping active context within model token limits.
Two ways to learn: read the below, or check out this super cool animated visualization.
When a conversation grows beyond the model's context window, OpenClaw (just like all of the other agents) normally truncates older messages. LCM instead:
lcm_grep, lcm_describe, lcm_expand) so agents can search and recall details from compacted historyNothing is lost. Raw messages stay in the database. Summaries link back to their source messages. Agents can drill into any summary to recover the original detail.
It feels like talking to an agent that never forgets. Because it doesn't. In normal operation, you'll never need to think about compaction again.
The package installs an agent-oriented lcm shell CLI and includes a bundled lossless-claw skill plus plugin commands for supported OpenClaw chat/native command providers.
The shell CLI reads lcm.db without modifying conversation data. Its only write command sets one validated Lossless config value in openclaw.json:
lcm status
lcm conversations show --session-key 'agent:main:example'
lcm messages tail --conversation-id 42
lcm summaries list --conversation-id 42 --depth 0 --recency 7d
lcm config get freshTailCount
lcm config set freshTailCount 96
JSON is the default output. List commands use bounded keyset pagination. See Lossless Claw CLI for commands, filters, path precedence, output fields, config-write safety, and exit codes.
The native OpenClaw command surface provides in-session operations:
/lossless shows version, enablement/selection state, DB path and size, summary counts, and summary-health status/lossless backup creates a timestamped backup of the current LCM SQLite database/lossless doctor scans for broken or truncated summaries/lossless doctor maintenance reports active actionable compaction debt separately from inactive historical debt, grouped by reason, without writing/lossless doctor apply maintenance <conversation-id> confirm-inactive administratively closes one eligible inactive debt row after creating a SQLite backup/lossless doctor apply repairs broken summaries in the current conversation after the normal safety preflight/lossless doctor apply <conversation-id> confirm-offline repairs a specific conversation after its active channel path has been paused or moved away; targeted repair is restricted to authorized OpenClaw command senders and always requires the explicit offline confirmation/lossless doctor clean shows read-only high-confidence junk diagnostics for archived subagents and cron sessions under every configured OpenClaw agent id, plus NULL-key orphaned subagent runs/lossless status shows plugin, conversation, and maintenance state including deferred compaction debt/lcm is the shorter alias for /losslessSupported native command examples:
/lossless/lossless backup/lossless doctor/lossless doctor maintenance/lossless doctor apply maintenance 42 confirm-inactive/lossless doctor apply 42 confirm-offline/lossless doctor clean/lcmThe package does not register these OpenClaw root subcommands:
openclaw losslessopenclaw lcmopenclaw /losslessopenclaw /lcmThe bundled skill focuses on configuration, diagnostics, architecture, and recall-tool usage. Its reference set lives under skills/lossless-claw/references/.
Deferred compaction debt on an active conversation is actionable maintenance pressure. Debt on an archived or otherwise inactive conversation is historical: normal stable-session maintenance cannot select that conversation, so /lossless doctor maintenance reports it separately and shows a bounded set of recent examples. Closing historical debt requires the exact confirm-inactive token and a successful file-backed SQLite backup. The close records an operator-ignored resolution on the maintenance row only; it does not run compaction and does not delete or rewrite conversations, messages, summaries, or context items. If that conversation later receives a genuine new debt request, the prior administrative resolution is cleared and the row becomes pending again.
Lossless-claw also exposes an optional host-facing context-engine control contract for OpenClaw gateways that support context-engine capabilities and control dispatch. The contract is intentionally smaller than the native slash command surface:
status returns whether an LCM conversation is active and the current stored message count.doctor returns a bounded, sanitized warning list for summary-health issues.Programmatic control never returns transcript text, local database paths, backup paths, credentials, provider debug, or shell output.
This surface is capability-gated by the OpenClaw host. At the time of this change there is not yet a stable OpenClaw release with the required context-engine control endpoints; downstream users should treat it as unavailable unless their host advertises the matching capability, for example through the pending openclaw/openclaw#98060 contract or an equivalent downstream gateway.
lossless-claw-migrate-sessions is a one-time shell CLI for backfilling OpenClaw JSONL session files into lcm.db after lossless-claw was disabled, missing, or installed after sessions already existed. It is not a background replay loop and it does not run summarization.
Run it in dry-run mode first:
npx --package @martian-engineering/lossless-claw@latest lossless-claw-migrate-sessions --state-dir ~/.openclaw
Apply the import only after reviewing the dry-run output:
npx --package @martian-engineering/lossless-claw@latest lossless-claw-migrate-sessions --state-dir ~/.openclaw --apply
The command defaults to ${OPENCLAW_STATE_DIR:-~/.openclaw} and ${OPENCLAW_STATE_DIR:-~/.openclaw}/lcm.db. --apply creates a timestamped SQLite backup before writing when the database already exists. Use --file <path> or repeatable --sessions-dir <path> for targeted imports, --since <iso-date> or --limit <n> to narrow a batch, and --json for machine-readable output.
Compatibility:
lossless-clawrequires OpenClaw2026.7.2-beta.2or newer. That beta is the first published build with the branch-safe visible transcript projection used to bootstrap SQLite-backed sessions; stable2026.7.1does not provide it. If you cannot use a beta or upgrade OpenClaw, stay on alossless-clawrelease compatible with your installed OpenClaw version.
On OpenClaw hosts that advertise the durable context-engine turn contract,
LosslessClaw declares current-turn transcript fencing and commits each accepted
turn through an atomic idempotency ledger. Older supported hosts continue to use
the existing afterTurn compatibility path.
Upgrade compatibility: Lossless Claw 1.x accepts
transcriptGcEnabledandautoRotateSessionFilesso 0.15 configs continue to load. It ignores both settings and warns at startup. Remove them after upgrading; OpenClaw owns active transcript storage and session-file rotation.
Lossless Claw 1.0 stable releases use npm's latest channel. The beta
channel remains available for prerelease testing.
Use OpenClaw's plugin installer (recommended):
openclaw plugins install @martian-engineering/lossless-claw@latest
If you're running from a local OpenClaw checkout, use:
pnpm openclaw plugins install @martian-engineering/lossless-claw@latest
Use exact versions only for rollback or reproducible canary testing. OpenClaw records an exact install spec such as @martian-engineering/[email protected] as a pinned update track, so OpenClaw plugin update sync will keep that version until you move back to the stable track:
openclaw plugins update @martian-engineering/lossless-claw@latest
For local plugin development, build your working copy first, then link it instead of copying files:
cd /path/to/lossless-claw
pnpm build
openclaw plugins install --link /path/to/lossless-claw
# or from a local OpenClaw checkout:
# pnpm openclaw plugins install --link /path/to/lossless-claw
Re-run pnpm build after local source changes so the linked plugin's dist/ output stays current.
The install command records the plugin, enables it, and applies compatible slot selection (including contextEngine when applicable).
Note: If your OpenClaw config uses
plugins.allow, allowlist the plugin idlossless-clawplus any other active plugins you rely on. Do not add command tokens or aliases likelosslessor/lcmtoplugins.allow; that setting only accepts plugin ids. In some setups, narrowing the allowlist can prevent plugin-backed integrations from loading, even iflossless-clawitself is installed correctly. Restart the gateway after plugin config changes.
Ensure the context engine slot points at lossless-claw and explicitly allow its conversation prompt hook:
{
"plugins": {
"slots": {
"contextEngine": "lossless-claw"
},
"entries": {
"lossless-claw": {
"hooks": {
"allowConversationAccess": true
}
}
}
}
}
OpenClaw builds that protect before_prompt_build as a conversation-access hook
require this grant. Without it, the context engine still loads, but OpenClaw
blocks Lossless's static recall-policy prompt hook and logs the missing setting.
The grant belongs beside config, not inside it.
Restart OpenClaw after configuration changes.
LCM is configured through a combination of plugin config and environment variables. Environment variables take precedence for backward compatibility.
Add a lossless-claw entry under plugins.entries in your OpenClaw config:
…
The ignoreSessionPatterns entries in this example are storage exclusions. Matching cron, active-memory, and OpenClaw memory-core dreaming narrative sessions do not create LCM conversation rows or store messages in LCM.
leafChunkTokens controls how many source tokens can accumulate in a leaf compaction chunk before summarization is triggered. The default is 20000, but quota-limited summary providers may benefit from a larger value to reduce compaction frequency. summaryModel and summaryProvider let you request a cheaper or faster compaction model through OpenClaw's api.runtime.llm.complete capability; OpenClaw still owns provider dispatch and auth. Explicit summary model requests require llm.allowModelOverride and matching llm.allowedModels policy entr
暂无开放 Issues,或尚未同步最近议题。