@jonathangu/openclawbrain 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +412 -0
  3. package/bin/openclawbrain.js +15 -0
  4. package/docs/END_STATE.md +244 -0
  5. package/docs/EVIDENCE.md +128 -0
  6. package/docs/RELEASE_CONTRACT.md +91 -0
  7. package/docs/agent-tools.md +106 -0
  8. package/docs/architecture.md +224 -0
  9. package/docs/configuration.md +178 -0
  10. package/docs/evidence/2026-03-16/3188b50c4ed30f07dea111e35ce52aabefaced63/brain-teach-session-bound/status.json +87 -0
  11. package/docs/evidence/2026-03-16/3188b50c4ed30f07dea111e35ce52aabefaced63/brain-teach-session-bound/summary.md +16 -0
  12. package/docs/evidence/2026-03-16/3188b50c4ed30f07dea111e35ce52aabefaced63/brain-teach-session-bound/trace.json +273 -0
  13. package/docs/evidence/2026-03-16/3188b50c4ed30f07dea111e35ce52aabefaced63/brain-teach-session-bound/validation-report.json +652 -0
  14. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/channels-status.txt +31 -0
  15. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/config-snapshot.json +66 -0
  16. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/doctor.json +14 -0
  17. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/gateway-probe.txt +34 -0
  18. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/gateway-status.txt +41 -0
  19. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/logs.txt +428 -0
  20. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/status-all.txt +60 -0
  21. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/status.json +223 -0
  22. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/summary.md +13 -0
  23. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/trace.json +4 -0
  24. package/docs/evidence/2026-03-16/4941429588810da5d6f7ef1509f229f83fa08031/validation-report.json +334 -0
  25. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/channels-status.txt +25 -0
  26. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/config-snapshot.json +91 -0
  27. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/doctor.json +14 -0
  28. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/gateway-probe.txt +36 -0
  29. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/gateway-status.txt +44 -0
  30. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/logs.txt +428 -0
  31. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/short-static-classification/preflight-doctor.json +10 -0
  32. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/short-static-classification/preflight-sdk-probe.json +11 -0
  33. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/short-static-classification/preflight-setup-only.json +12 -0
  34. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/short-static-classification/summary.md +30 -0
  35. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/short-static-classification/validation-report.json +72 -0
  36. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/status-all.txt +63 -0
  37. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/status.json +200 -0
  38. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/summary.md +13 -0
  39. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/trace.json +4 -0
  40. package/docs/evidence/2026-03-16/7f8dbcb27e741abdeefd5656c210639d0acdd440/validation-report.json +311 -0
  41. package/docs/evidence/README.md +16 -0
  42. package/docs/fts5.md +161 -0
  43. package/docs/tui.md +506 -0
  44. package/index.ts +1372 -0
  45. package/openclaw.plugin.json +136 -0
  46. package/package.json +66 -0
  47. package/src/assembler.ts +804 -0
  48. package/src/brain-cli.ts +316 -0
  49. package/src/brain-core/decay.ts +35 -0
  50. package/src/brain-core/episode.ts +82 -0
  51. package/src/brain-core/graph.ts +321 -0
  52. package/src/brain-core/health.ts +116 -0
  53. package/src/brain-core/mutator.ts +281 -0
  54. package/src/brain-core/pack.ts +117 -0
  55. package/src/brain-core/policy.ts +153 -0
  56. package/src/brain-core/replay.ts +1 -0
  57. package/src/brain-core/teacher.ts +105 -0
  58. package/src/brain-core/trace.ts +40 -0
  59. package/src/brain-core/traverse.ts +230 -0
  60. package/src/brain-core/types.ts +405 -0
  61. package/src/brain-core/update.ts +123 -0
  62. package/src/brain-harvest/human.ts +46 -0
  63. package/src/brain-harvest/scanner.ts +98 -0
  64. package/src/brain-harvest/self.ts +147 -0
  65. package/src/brain-runtime/assembler-extension.ts +230 -0
  66. package/src/brain-runtime/evidence-detectors.ts +68 -0
  67. package/src/brain-runtime/graph-io.ts +72 -0
  68. package/src/brain-runtime/harvester-extension.ts +98 -0
  69. package/src/brain-runtime/service.ts +659 -0
  70. package/src/brain-runtime/tools.ts +109 -0
  71. package/src/brain-runtime/worker-state.ts +106 -0
  72. package/src/brain-runtime/worker-supervisor.ts +169 -0
  73. package/src/brain-store/embedding.ts +179 -0
  74. package/src/brain-store/init.ts +347 -0
  75. package/src/brain-store/migrations.ts +188 -0
  76. package/src/brain-store/store.ts +816 -0
  77. package/src/brain-worker/child-runner.ts +321 -0
  78. package/src/brain-worker/jobs.ts +12 -0
  79. package/src/brain-worker/mutation-job.ts +5 -0
  80. package/src/brain-worker/promotion-job.ts +5 -0
  81. package/src/brain-worker/protocol.ts +79 -0
  82. package/src/brain-worker/teacher-job.ts +5 -0
  83. package/src/brain-worker/update-job.ts +5 -0
  84. package/src/brain-worker/worker.ts +422 -0
  85. package/src/compaction.ts +1332 -0
  86. package/src/db/config.ts +265 -0
  87. package/src/db/connection.ts +72 -0
  88. package/src/db/features.ts +42 -0
  89. package/src/db/migration.ts +561 -0
  90. package/src/engine.ts +1995 -0
  91. package/src/expansion-auth.ts +351 -0
  92. package/src/expansion-policy.ts +303 -0
  93. package/src/expansion.ts +383 -0
  94. package/src/integrity.ts +600 -0
  95. package/src/large-files.ts +527 -0
  96. package/src/openclaw-bridge.ts +22 -0
  97. package/src/retrieval.ts +357 -0
  98. package/src/store/conversation-store.ts +748 -0
  99. package/src/store/fts5-sanitize.ts +29 -0
  100. package/src/store/full-text-fallback.ts +74 -0
  101. package/src/store/index.ts +29 -0
  102. package/src/store/summary-store.ts +918 -0
  103. package/src/summarize.ts +847 -0
  104. package/src/tools/common.ts +53 -0
  105. package/src/tools/lcm-conversation-scope.ts +76 -0
  106. package/src/tools/lcm-describe-tool.ts +234 -0
  107. package/src/tools/lcm-expand-query-tool.ts +594 -0
  108. package/src/tools/lcm-expand-tool.delegation.ts +556 -0
  109. package/src/tools/lcm-expand-tool.ts +448 -0
  110. package/src/tools/lcm-expansion-recursion-guard.ts +286 -0
  111. package/src/tools/lcm-grep-tool.ts +200 -0
  112. package/src/transcript-repair.ts +301 -0
  113. package/src/types.ts +149 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Josh Lehman / Martian Engineering
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,412 @@
1
+ # OpenClawBrain v2
2
+
3
+ OpenClawBrain v2 is a clean rebuild on top of [lossless-claw](https://github.com/Martian-Engineering/lossless-claw). The goal is a production-ready OpenClaw plugin that keeps lossless transcript memory while adding a correctly wired learning layer for retrieval and correction routing.
4
+
5
+ This repo is the active v2 codebase.
6
+
7
+ The earlier spike is archived at [jonathangu/openclawbrain-v1-spike-archive](https://github.com/jonathangu/openclawbrain-v1-spike-archive).
8
+
9
+ ## Release truth in 30 seconds
10
+
11
+ | Public label | Status | What it means right now |
12
+ | --- | --- | --- |
13
+ | **paper-faithful core** | true now | finite-horizon traversal, terminal reward, stochastic policy, full-trajectory REINFORCE updates, learned seed routing, and immutable promoted packs are all implemented in the current repo |
14
+ | **live-path implemented** | true now | the OpenClaw runtime already has recurrence gating, explicit skip reasons, shadow mode, correction-first context injection, immediate `brain_teach` retrieval, and replay-gated promotion wired into the live path |
15
+ | **operationally validated** | not yet | child-worker mode is real, but frozen host-surface teach/worker-down proof, bundle-level mutation validation, dated evidence artifacts, and full-repo `npx tsc --noEmit` are still unfinished |
16
+
17
+ If you want the exact contract rather than the pitch, read [docs/RELEASE_CONTRACT.md](docs/RELEASE_CONTRACT.md).
18
+
19
+ ## Table of contents
20
+
21
+ - [What it does](#what-it-does)
22
+ - [Quick start](#quick-start)
23
+ - [Configuration](#configuration)
24
+ - [Operator Commands](#operator-commands)
25
+ - [Fallback Behavior](#fallback-behavior)
26
+ - [Operational gaps still open](#operational-gaps-still-open)
27
+ - [Finish path to 1.0](#finish-path-to-10)
28
+ - [Documentation](#documentation)
29
+ - [Development](#development)
30
+ - [License](#license)
31
+
32
+ ## What it does today
33
+
34
+ When a conversation grows beyond the model's context window, OpenClaw (just like all of the other agents) normally truncates older messages. LCM instead:
35
+
36
+ 1. **Persists every message** in a SQLite database, organized by conversation
37
+ 2. **Summarizes chunks** of older messages into summaries using your configured LLM
38
+ 3. **Condenses summaries** into higher-level nodes as they accumulate, forming a DAG (directed acyclic graph)
39
+ 4. **Assembles context** each turn by combining summaries + recent raw messages
40
+ 5. **Provides tools** (`lcm_grep`, `lcm_describe`, `lcm_expand`) so agents can search and recall details from compacted history
41
+
42
+ Nothing 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.
43
+
44
+ Today this repo ships a working hybrid runtime:
45
+
46
+ 1. The LCM substrate still persists, compacts, and recalls transcript history.
47
+ 2. The brain runtime explicitly decides whether to route through learned retrieval or bypass with a concrete skip reason.
48
+ 3. Learned traversal now includes a seed-head policy over candidate seed regions, not just post-seed edge updates.
49
+ 4. `brain_teach` embeds taught nodes immediately, connects them into the recent route, and promotes a new immutable pack.
50
+ 5. The worker applies full-trajectory REINFORCE updates, decay, scanner/self/human/teacher labels, candidate-graph mutation replay, and replay-gated promotion.
51
+
52
+ ## Quick start
53
+
54
+ ### Prerequisites
55
+
56
+ - OpenClaw with plugin context engine support
57
+ - Node.js 22+
58
+ - An LLM provider configured in OpenClaw (used for summarization)
59
+
60
+ ### Install the plugin
61
+
62
+ Use OpenClaw's plugin installer once the package is published:
63
+
64
+ ```bash
65
+ openclaw plugins install @jonathangu/openclawbrain
66
+ ```
67
+
68
+ If you're running from a local OpenClaw checkout, use:
69
+
70
+ ```bash
71
+ pnpm openclaw plugins install @jonathangu/openclawbrain
72
+ ```
73
+
74
+ For local plugin development, link your working copy instead of copying files:
75
+
76
+ ```bash
77
+ openclaw plugins install --link /path/to/openclawbrain
78
+ # or from a local OpenClaw checkout:
79
+ # pnpm openclaw plugins install --link /path/to/openclawbrain
80
+ ```
81
+
82
+ The install command records the plugin and enables it.
83
+
84
+ ### Configure OpenClaw
85
+
86
+ In most cases, no manual JSON edits are needed after `openclaw plugins install`.
87
+
88
+ Important current truth: older OpenClaw builds exposed a `plugins.slots.contextEngine` seam, but the current host build used for Phase 1 validation no longer accepts that slot and no longer exposes `api.registerContextEngine`. Until OpenClawBrain adapts to the current plugin/memory seam, do **not** treat old `contextEngine` slot examples as valid host-surface setup guidance.
89
+
90
+ Restart OpenClaw after configuration changes.
91
+
92
+ ### Initialize the brain index
93
+
94
+ The lossless transcript path works immediately. Learned retrieval needs an explicit init pass:
95
+
96
+ ```bash
97
+ openclawbrain init /path/to/your/workspace
98
+ ```
99
+
100
+ `openclawbrain init` scans the workspace, chunks source material, computes embeddings, builds the initial graph, writes `state.db`, creates pack `v000001`, and promotes it.
101
+
102
+ ## Configuration
103
+
104
+ LCM is configured through a combination of plugin config and environment variables. Environment variables take precedence for backward compatibility.
105
+
106
+ ### Plugin config
107
+
108
+ Add an `openclawbrain` entry under `plugins.entries` in your OpenClaw config:
109
+
110
+ ```json
111
+ {
112
+ "plugins": {
113
+ "entries": {
114
+ "openclawbrain": {
115
+ "enabled": true,
116
+ "config": {
117
+ "freshTailCount": 32,
118
+ "contextThreshold": 0.75,
119
+ "incrementalMaxDepth": -1,
120
+ "brainRoot": "~/.openclaw/openclawbrain",
121
+ "brainEmbeddingProvider": "openai",
122
+ "brainEmbeddingModel": "text-embedding-3-large"
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ For local dogfood or other self-hosted installs, Ollama is now a first-class embedding option too:
131
+
132
+ ```json
133
+ {
134
+ "plugins": {
135
+ "entries": {
136
+ "openclawbrain": {
137
+ "enabled": true,
138
+ "config": {
139
+ "brainEmbeddingProvider": "ollama",
140
+ "brainEmbeddingModel": "bge-large:latest"
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ That defaults to Ollama's local OpenAI-compatible embeddings endpoint at `http://127.0.0.1:11434/v1`.
149
+
150
+ ### Environment variables
151
+
152
+ | Variable | Default | Description |
153
+ |----------|---------|-------------|
154
+ | `LCM_ENABLED` | `true` | Enable/disable the plugin |
155
+ | `LCM_DATABASE_PATH` | `~/.openclaw/lcm.db` | Path to the SQLite database |
156
+ | `LCM_CONTEXT_THRESHOLD` | `0.75` | Fraction of context window that triggers compaction (0.0–1.0) |
157
+ | `LCM_FRESH_TAIL_COUNT` | `32` | Number of recent messages protected from compaction |
158
+ | `LCM_LEAF_MIN_FANOUT` | `8` | Minimum raw messages per leaf summary |
159
+ | `LCM_CONDENSED_MIN_FANOUT` | `4` | Minimum summaries per condensed node |
160
+ | `LCM_CONDENSED_MIN_FANOUT_HARD` | `2` | Relaxed fanout for forced compaction sweeps |
161
+ | `LCM_INCREMENTAL_MAX_DEPTH` | `0` | How deep incremental compaction goes (0 = leaf only, -1 = unlimited) |
162
+ | `LCM_LEAF_CHUNK_TOKENS` | `20000` | Max source tokens per leaf compaction chunk |
163
+ | `LCM_LEAF_TARGET_TOKENS` | `1200` | Target token count for leaf summaries |
164
+ | `LCM_CONDENSED_TARGET_TOKENS` | `2000` | Target token count for condensed summaries |
165
+ | `LCM_MAX_EXPAND_TOKENS` | `4000` | Token cap for sub-agent expansion queries |
166
+ | `LCM_LARGE_FILE_TOKEN_THRESHOLD` | `25000` | File blocks above this size are intercepted and stored separately |
167
+ | `LCM_LARGE_FILE_SUMMARY_PROVIDER` | `""` | Provider override for large-file summarization |
168
+ | `LCM_LARGE_FILE_SUMMARY_MODEL` | `""` | Model override for large-file summarization |
169
+ | `LCM_SUMMARY_MODEL` | *(from OpenClaw)* | Model for summarization (e.g. `anthropic/claude-sonnet-4-20250514`) |
170
+ | `LCM_SUMMARY_PROVIDER` | *(from OpenClaw)* | Provider override for summarization |
171
+ | `LCM_AUTOCOMPACT_DISABLED` | `false` | Disable automatic compaction after turns |
172
+ | `LCM_PRUNE_HEARTBEAT_OK` | `false` | Retroactively delete `HEARTBEAT_OK` turn cycles from LCM storage |
173
+ | `OPENCLAWBRAIN_ENABLED` | `true` | Enable/disable the learning layer |
174
+ | `OPENCLAWBRAIN_ROOT` | `~/.openclaw/openclawbrain` | Root directory for `state.db` and immutable packs |
175
+ | `OPENCLAWBRAIN_EMBEDDING_PROVIDER` | `openai` | Embedding provider (`openai`, `openai-resp`, or `ollama`) |
176
+ | `OPENCLAWBRAIN_EMBEDDING_MODEL` | `""` | Embedding model required for `init`, retrieval, and `brain_teach` |
177
+ | `OPENCLAWBRAIN_EMBEDDING_BASE_URL` | `""` | Optional embeddings API base URL override; `ollama` defaults to `http://127.0.0.1:11434/v1` |
178
+ | `OPENCLAWBRAIN_EMBEDDING_API_KEY` | `""` | Optional explicit API key for authenticated embedding proxies / nonstandard OpenAI-compatible endpoints |
179
+ | `OPENCLAWBRAIN_MAX_HOPS` | `8` | Hard traversal cap |
180
+ | `OPENCLAWBRAIN_MAX_SEEDS` | `10` | Max seed nodes per query |
181
+ | `OPENCLAWBRAIN_SEMANTIC_THRESHOLD` | `0.7` | Minimum seed similarity |
182
+ | `OPENCLAWBRAIN_SHADOW_MODE` | `false` | Record brain routes and traces without injecting learned context into the prompt |
183
+ | `OPENCLAWBRAIN_TRAINER_INTERVAL_MS` | `30000` | Background worker interval |
184
+
185
+ ## Operator Commands
186
+
187
+ ```bash
188
+ openclawbrain init [workspace]
189
+ openclawbrain status
190
+ openclawbrain trace [traceId]
191
+ openclawbrain replay
192
+ openclawbrain promote
193
+ openclawbrain rollback [version]
194
+ openclawbrain disable
195
+ openclawbrain enable
196
+ openclawbrain doctor
197
+ ```
198
+
199
+ ## Fallback Behavior
200
+
201
+ - If the brain has not been initialized, the plugin serves LCM-only context.
202
+ - If embeddings are not configured, learned retrieval and `brain_teach` stay disabled.
203
+ - Local loopback embedding endpoints (for example Ollama on `127.0.0.1` / `localhost`) do not require a bearer token; remote OpenAI-compatible endpoints still do unless you provide `OPENCLAWBRAIN_EMBEDDING_API_KEY`.
204
+ - `openclawbrain status` and `openclawbrain doctor` expose the resolved embedding provider / model / base URL / auth mode so operator truth stays visible.
205
+ - If the background worker is unavailable, serving still uses the last promoted pack.
206
+ - `brain_teach` now binds taught corrections to the active conversation when invoked from a live tool session.
207
+ - Seed learning is persisted as explicit per-node seed weights and exposed in traces.
208
+
209
+ ## Operational gaps still open
210
+
211
+ This repo is already beyond “foundation only,” but it is **not** yet operationally validated end to end.
212
+
213
+ - Embedding support currently targets tested OpenAI-compatible `/v1/embeddings` APIs, including local Ollama-style endpoints.
214
+ - Child-worker mode now runs behind a dedicated supervisor with explicit protocol messages, restart accounting, reload acknowledgements, and stronger status/doctor truth; the remaining operator-proof gap is on the host-surface seam, not the learner boundary itself.
215
+ - Structured evidence harvesting now exists end to end (raw evidence → resolved labels with explicit episode attribution), harvested completions can now persist multiple concurrent raw signals with extractor metadata before worker resolution, and structured tool-result/function-output parts now feed self-evidence detection before regex fallback; the remaining gap is that source detection still leans on heuristics more than the intended richer human/self/scanner evidence flow.
216
+ - Deterministic session-bound `brain_teach` proof now exists, but the current raw host lane is blocked by stale OpenClaw seam drift (`plugins.slots.contextEngine` / `api.registerContextEngine`) and the final narrow worker-down host claim is still unfrozen.
217
+ - Replay-gated promotion exists, but mutation evaluation has not yet reached the intended bundle-level replay contract.
218
+ - Upstream `openclaw/plugin-sdk` type drift still affects full-repo `npx tsc --noEmit`.
219
+
220
+ ## Finish path to 1.0
221
+
222
+ 1. **Align repo truth with repo reality** so the README and canonical docs cleanly separate what is true now, implemented-but-not-frozen, and not done yet.
223
+ 2. **Finish the real OpenClaw host-surface validation harness** by adapting the stale current-OpenClaw plugin/config seam first, then freezing recurrent routing, static bypass, shadow mode, worker-down fail-open, and explicit skip modes on that repaired boundary.
224
+ 3. **Finish the evidence pipeline** so structured evidence tied to exact episodes outruns heuristic-only harvesting.
225
+ 4. **Upgrade mutation evaluation to replay-gated bundles** instead of proposal-by-proposal promotion.
226
+ 5. **Freeze the proof ladder** with dated artifact bundles under `docs/evidence/`.
227
+ 6. **Clean the packaging and type surface** until another OpenClaw operator can install, validate, and recover the plugin without tribal knowledge.
228
+
229
+ ### Recommended starting configuration
230
+
231
+ ```
232
+ LCM_FRESH_TAIL_COUNT=32
233
+ LCM_INCREMENTAL_MAX_DEPTH=-1
234
+ LCM_CONTEXT_THRESHOLD=0.75
235
+ ```
236
+
237
+ - **freshTailCount=32** protects the last 32 messages from compaction, giving the model enough recent context for continuity.
238
+ - **incrementalMaxDepth=-1** enables unlimited automatic condensation after each compaction pass — the DAG cascades as deep as needed. Set to `0` (default) for leaf-only, or a positive integer for a specific depth cap.
239
+ - **contextThreshold=0.75** triggers compaction when context reaches 75% of the model's window, leaving headroom for the model's response.
240
+
241
+ ### OpenClaw session reset settings
242
+
243
+ LCM preserves history through compaction, but it does **not** change OpenClaw's core session reset policy. If sessions are resetting sooner than you want, increase OpenClaw's `session.reset.idleMinutes` or use a channel/type-specific override.
244
+
245
+ ```json
246
+ {
247
+ "session": {
248
+ "reset": {
249
+ "mode": "idle",
250
+ "idleMinutes": 10080
251
+ }
252
+ }
253
+ }
254
+ ```
255
+
256
+ - `session.reset.mode: "idle"` keeps a session alive until the idle window expires.
257
+ - `session.reset.idleMinutes` is the actual reset interval in minutes.
258
+ - OpenClaw does **not** currently enforce a maximum `idleMinutes`; in source it is validated only as a positive integer.
259
+ - If you also use daily reset mode, `idleMinutes` acts as a secondary guard and the session resets when **either** the daily boundary or the idle window is reached first.
260
+ - Legacy `session.idleMinutes` still works, but OpenClaw prefers `session.reset.idleMinutes`.
261
+
262
+ Useful values:
263
+
264
+ - `1440` = 1 day
265
+ - `10080` = 7 days
266
+ - `43200` = 30 days
267
+ - `525600` = 365 days
268
+
269
+ For most long-lived LCM setups, a good starting point is:
270
+
271
+ ```json
272
+ {
273
+ "session": {
274
+ "reset": {
275
+ "mode": "idle",
276
+ "idleMinutes": 10080
277
+ }
278
+ }
279
+ }
280
+ ```
281
+
282
+ ## Documentation
283
+
284
+ Canonical starting docs:
285
+
286
+ - [Release contract](docs/RELEASE_CONTRACT.md)
287
+ - [Definitive end-state guide](docs/END_STATE.md)
288
+ - [Evidence ladder](docs/EVIDENCE.md)
289
+
290
+ Supporting docs:
291
+
292
+ - [Configuration guide](docs/configuration.md)
293
+ - [LCM architecture](docs/architecture.md)
294
+ - [Agent tools](docs/agent-tools.md)
295
+ - [TUI Reference](docs/tui.md)
296
+ - [lcm-tui](tui/README.md)
297
+ - [Optional: enable FTS5 for fast full-text search](docs/fts5.md)
298
+
299
+ ## Development
300
+
301
+ ```bash
302
+ # Run tests
303
+ npx vitest
304
+
305
+ # Type check
306
+ npx tsc --noEmit
307
+
308
+ # Run a specific test file
309
+ npx vitest test/engine.test.ts
310
+ ```
311
+
312
+ ### Validation harness (Phase 1 scaffold)
313
+
314
+ A disposable host-app validation scaffold now lives at:
315
+
316
+ ```bash
317
+ node scripts/validate-openclaw-install.mjs --setup-only
318
+ ```
319
+
320
+ For Phase 1 close-out work, prefer the explicit sterile validation lane instead of a mixed live-machine layout:
321
+
322
+ ```bash
323
+ OPENCLAWBRAIN_VALIDATION_LANE_NAME=ocbphase1 \
324
+ OPENCLAWBRAIN_VALIDATION_GATEWAY_PORT=19031 \
325
+ node scripts/validate-openclaw-install.mjs --sterile-lane --setup-only
326
+ ```
327
+
328
+ Full init + host-app routing checks require explicit embedding/model env:
329
+
330
+ ```bash
331
+ OPENCLAWBRAIN_VALIDATION_LANE_NAME=ocbphase1 \
332
+ OPENCLAWBRAIN_VALIDATION_GATEWAY_PORT=19031 \
333
+ OPENCLAWBRAIN_VALIDATION_EMBEDDING_MODEL=text-embedding-3-small \
334
+ OPENCLAWBRAIN_VALIDATION_MODEL=openai/gpt-4.1-mini \
335
+ node scripts/validate-openclaw-install.mjs --sterile-lane
336
+ ```
337
+
338
+ Each serious run now writes a predictable artifact bundle under `docs/evidence/YYYY-MM-DD/<git-sha>/`, including the pre-run diagnostic ladder (`openclaw status`, `status --all`, `gateway probe`, `gateway status`, `doctor`, and `channels status --probe`).
339
+
340
+ The deterministic session-bound `brain_teach` harness now lives at:
341
+
342
+ ```bash
343
+ pnpm exec tsx scripts/validate-brain-teach-session-bound.ts \
344
+ --state-dir "$HOME/.openclaw-ocbphase1" \
345
+ --workspace "$HOME/.openclaw/workspace-ocbphase1" \
346
+ --repetitions 20
347
+ ```
348
+
349
+ It binds the real registered `brain_teach` tool to a deterministic `ctx.sessionKey`, proves the teach action is recorded against the warmup episode, runs follow-up runtime assembly through the real retrieval path, and writes artifacts under `docs/evidence/YYYY-MM-DD/<git-sha>/brain-teach-session-bound/`.
350
+
351
+ The current short-static host-path classifier now lives at:
352
+
353
+ ```bash
354
+ pnpm exec tsx scripts/validate-short-static-classification.ts \
355
+ --state-dir "$HOME/.openclaw-ocbphase1-short-static" \
356
+ --workspace "$HOME/.openclaw/workspace-ocbphase1"
357
+ ```
358
+
359
+ On the current OpenClaw host build, that classifier truthfully freezes the remaining “short-static drift” question as **stale host seam drift first**: the host config rejects `plugins.slots.contextEngine`, and plugin register fails because `api.registerContextEngine` is gone. Until that seam is adapted, raw host-path short-static probing is not a valid semantic proof boundary.
360
+
361
+ Current state: install/config wiring + fixture workspace + `openclawbrain init/status/doctor` are wired, and the harness can now target either temp-home isolation or a named sterile lane. The deterministic runtime layer already proves immediate `brain_teach` retrieval plus worker-down fail-open serving, and the session-bound harness now proves `brain_teach` deterministically at the correct seam with 20/20 identical passes. Raw prompt-driven `openclaw agent --local` is **not** the release proof boundary for `brain_teach`; on the current OpenClaw host, the remaining host work is to adapt the stale plugin/config seam and then freeze recurrent/shadow/skip-mode plus the narrow worker-down serving claim on that repaired boundary.
362
+
363
+ ### Project structure
364
+
365
+ ```
366
+ index.ts # Plugin entry point and registration
367
+ src/
368
+ engine.ts # LcmContextEngine — implements ContextEngine interface
369
+ assembler.ts # Context assembly (summaries + messages → model context)
370
+ compaction.ts # CompactionEngine — leaf passes, condensation, sweeps
371
+ summarize.ts # Depth-aware prompt generation and LLM summarization
372
+ retrieval.ts # RetrievalEngine — grep, describe, expand operations
373
+ expansion.ts # DAG expansion logic for lcm_expand_query
374
+ expansion-auth.ts # Delegation grants for sub-agent expansion
375
+ expansion-policy.ts # Depth/token policy for expansion
376
+ large-files.ts # File interception, storage, and exploration summaries
377
+ integrity.ts # DAG integrity checks and repair utilities
378
+ transcript-repair.ts # Tool-use/result pairing sanitization
379
+ types.ts # Core type definitions (dependency injection contracts)
380
+ openclaw-bridge.ts # Bridge utilities
381
+ db/
382
+ config.ts # LcmConfig resolution from env vars
383
+ connection.ts # SQLite connection management
384
+ migration.ts # Schema migrations
385
+ store/
386
+ conversation-store.ts # Message persistence and retrieval
387
+ summary-store.ts # Summary DAG persistence and context item management
388
+ fts5-sanitize.ts # FTS5 query sanitization
389
+ tools/
390
+ lcm-grep-tool.ts # lcm_grep tool implementation
391
+ lcm-describe-tool.ts # lcm_describe tool implementation
392
+ lcm-expand-tool.ts # lcm_expand tool (sub-agent only)
393
+ lcm-expand-query-tool.ts # lcm_expand_query tool (main agent wrapper)
394
+ lcm-conversation-scope.ts # Conversation scoping utilities
395
+ common.ts # Shared tool utilities
396
+ test/ # Vitest test suite
397
+ scripts/ # Validation harnesses and operator helpers
398
+ openclaw.plugin.json # Plugin manifest with config schema and UI hints
399
+ tui/ # Interactive terminal UI (Go)
400
+ main.go # Entry point and bubbletea app
401
+ data.go # Data loading and SQLite queries
402
+ dissolve.go # Summary dissolution
403
+ repair.go # Corrupted summary repair
404
+ rewrite.go # Summary re-summarization
405
+ transplant.go # Cross-conversation DAG copy
406
+ prompts/ # Depth-aware prompt templates
407
+ .goreleaser.yml # GoReleaser config for TUI binary releases
408
+ ```
409
+
410
+ ## License
411
+
412
+ MIT
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+ import { dirname, join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const here = dirname(fileURLToPath(import.meta.url));
8
+ const entry = join(here, "../src/brain-cli.ts");
9
+ const result = spawnSync(
10
+ process.execPath,
11
+ ["--import", "tsx/esm", entry, ...process.argv.slice(2)],
12
+ { stdio: "inherit" },
13
+ );
14
+
15
+ process.exit(result.status ?? 1);