@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
@@ -0,0 +1,244 @@
1
+ # OpenClawBrain v2 — Definitive End-State Guide
2
+
3
+ This is the canonical implementation guide for finishing the current repo to an honest 1.0.
4
+
5
+ The correct posture is:
6
+
7
+ - **no reroll**
8
+ - **keep the current trunk**
9
+ - **preserve the inherited lossless-claw substrate**
10
+ - **finish proof, operator hardening, evidence quality, mutation gating, and packaging truth**
11
+
12
+ ## Canonical surfaces
13
+
14
+ These files should anchor future work:
15
+
16
+ - `README.md` — public front door and fast operator truth
17
+ - `docs/RELEASE_CONTRACT.md` — what is true now vs not frozen vs not done
18
+ - `docs/END_STATE.md` — this implementation guide
19
+ - `docs/EVIDENCE.md` — proof ladder and artifact contract
20
+ - `scripts/validate-openclaw-install.mjs` — disposable host-surface harness
21
+ - `scripts/validate-brain-runtime-behavior.ts` — deterministic runtime proof harness
22
+
23
+ ## Keep these boundaries intact
24
+
25
+ ### Protected inherited substrate — do not rewrite casually
26
+ These are inherited LCM / lossless-claw surfaces and should stay stable unless a failing test forces a narrow change:
27
+
28
+ - `src/assembler.ts`
29
+ - `src/compaction.ts`
30
+ - `src/engine.ts`
31
+ - `src/expansion*.ts`
32
+ - `src/retrieval.ts`
33
+ - `src/store/*`
34
+ - `src/summarize.ts`
35
+ - `src/transcript-repair.ts`
36
+ - `tui/*`
37
+
38
+ ### Hard guardrails
39
+ - Do **not** add intermediate shaping rewards to the core learning rule.
40
+ - Do **not** replace the stochastic learning-time policy with a deterministic scorer.
41
+ - Do **not** let serving read mutable training state.
42
+ - Do **not** treat old planning docs or archived prototypes as authority.
43
+
44
+ ## Current code map
45
+
46
+ ### Runtime decisioning and assembly
47
+ - `src/brain-runtime/assembler-extension.ts`
48
+ - `src/brain-runtime/service.ts`
49
+ - `src/brain-runtime/tools.ts`
50
+ - Tests: `test/brain-runtime/assembler-extension.test.ts`, `test/brain-runtime/service.test.ts`
51
+
52
+ ### Brain core
53
+ - `src/brain-core/traverse.ts`
54
+ - `src/brain-core/policy.ts`
55
+ - `src/brain-core/update.ts`
56
+ - `src/brain-core/pack.ts`
57
+ - `src/brain-core/replay.ts`
58
+ - `src/brain-core/mutator.ts`
59
+ - Tests: `test/brain-core/*.test.ts`
60
+
61
+ ### Evidence pipeline
62
+ - `src/brain-runtime/harvester-extension.ts`
63
+ - `src/brain-runtime/evidence-detectors.ts`
64
+ - `src/brain-harvest/human.ts`
65
+ - `src/brain-harvest/self.ts`
66
+ - `src/brain-harvest/scanner.ts`
67
+ - `src/brain-store/store.ts`
68
+ - `src/brain-store/migrations.ts`
69
+ - `src/brain-worker/worker.ts`
70
+ - Tests: `test/brain-runtime/harvester.test.ts`, `test/brain-worker/worker.test.ts`, `test/engine.test.ts`
71
+
72
+ ### Child worker and operator surface
73
+ - `src/brain-runtime/service.ts`
74
+ - `src/brain-worker/child-runner.ts`
75
+ - `src/brain-cli.ts`
76
+ - `openclaw.plugin.json`
77
+ - Tests: `test/brain-runtime/service.test.ts`
78
+
79
+ ### Validation and release proof
80
+ - `scripts/validate-openclaw-install.mjs`
81
+ - `scripts/validate-brain-runtime-behavior.ts`
82
+ - `docs/EVIDENCE.md`
83
+ - `docs/evidence/`
84
+
85
+ ## Finish order
86
+
87
+ ## Phase 0 — Align repo truth with repo reality
88
+
89
+ Goal: make it obvious, within a minute, what is already real, what is implemented-but-not-frozen, and what is still open.
90
+
91
+ ### Work in
92
+ - `README.md`
93
+ - `docs/RELEASE_CONTRACT.md`
94
+ - `docs/END_STATE.md`
95
+ - `docs/EVIDENCE.md`
96
+
97
+ ### What success looks like
98
+ - the README front page does not contradict the current code
99
+ - no duplicate root planning docs compete with the canonical docs set
100
+ - another session can orient from the docs above without spelunking old plans
101
+
102
+ ## Phase 1 — Finish the real host-surface validation harness
103
+
104
+ Goal: prove behavior on the actual OpenClaw host surface, not just the lower-level runtime harness.
105
+
106
+ ### Main files
107
+ - `scripts/validate-openclaw-install.mjs`
108
+ - `scripts/validate-brain-runtime-behavior.ts`
109
+ - `src/brain-runtime/assembler-extension.ts`
110
+ - `src/brain-runtime/service.ts`
111
+ - `src/brain-runtime/tools.ts`
112
+ - future: `.github/workflows/validate-openclaw-install.yml`
113
+
114
+ ### Already true
115
+ - recurrent host routing checks run
116
+ - shadow-mode host assertion wiring exists
117
+ - current local-Ollama harness runs end to end on the non-skipped matrix
118
+
119
+ ### Still open
120
+ - adapt the current OpenClaw host seam first (`plugins.slots.contextEngine` / `api.registerContextEngine` drift), then rerun host-path proof on that repaired boundary
121
+ - deterministic host-surface worker-down / last-promoted-pack fail-open proof
122
+ - explicit `skip_no_embedding` and `skip_uninitialized` assertions on the host surface
123
+ - frozen evidence bundle per run under `docs/evidence/YYYY-MM-DD/<git-sha>/`
124
+ - short-static-lookup host semantics on the adapted current host seam
125
+
126
+ ### Key reality to remember
127
+ `openclaw agent --local` currently exposes session targeting, timeout, delivery, and verbose controls, but no explicit deterministic “force this tool call” control. Deterministic `brain_teach` proof is now closed by the session-bound harness; raw host-path semantic claims still have to respect the current host/plugin seam that actually exists.
128
+
129
+ ## Phase 2 — Harden the child worker
130
+
131
+ Goal: make the child worker the real learner boundary without affecting serving.
132
+
133
+ ### Main files
134
+ - `src/brain-runtime/service.ts`
135
+ - `src/brain-runtime/worker-supervisor.ts`
136
+ - `src/brain-worker/child-runner.ts`
137
+ - `src/brain-worker/protocol.ts`
138
+ - `src/brain-cli.ts`
139
+ - `test/brain-runtime/service.test.ts`
140
+
141
+ ### What is already real
142
+ - `brainWorkerMode` supports `child` and `in_process`
143
+ - child lifecycle logic now lives behind `WorkerSupervisor` instead of staying embedded in `service.ts`
144
+ - explicit worker protocol messages now exist for `ready`, `heartbeat`, `reload-graph`, `reload-graph-ack`, `tick-result`, `shutdown`, and `fatal-error`
145
+ - restart accounting and richer operator truth now surface through runtime status + CLI doctor/status
146
+ - `in_process` is now marked and surfaced as a dev-only fallback
147
+ - crash / stale-lease / second-writer / reload-ack coverage now exists in `test/brain-runtime/service.test.ts`
148
+
149
+ ### What remains
150
+ - keep child-worker operator truth frozen while later phases evolve the evidence pipeline and replay bundle gates
151
+ - preserve the narrow production claim: serving continues from immutable promoted packs even when the worker crashes or restarts
152
+
153
+ ## Phase 3 — Finish the evidence pipeline
154
+
155
+ Goal: make structured evidence tied to exact episodes the dominant learning input.
156
+
157
+ ### Main files
158
+ - `src/brain-runtime/harvester-extension.ts`
159
+ - `src/brain-runtime/evidence-detectors.ts`
160
+ - `src/brain-harvest/human.ts`
161
+ - `src/brain-harvest/self.ts`
162
+ - `src/brain-harvest/scanner.ts`
163
+ - `src/brain-worker/worker.ts`
164
+ - `src/brain-store/store.ts`
165
+ - `src/brain-store/migrations.ts`
166
+
167
+ ### What is already real
168
+ - `brain_evidence` and `brain_resolved_labels` exist
169
+ - explicit episode attribution improved materially
170
+ - trust-ordered one-winner-per-episode resolution is real
171
+ - `brain_teach` records evidence metadata against the corrected episode path
172
+
173
+ ### What remains
174
+ - expand evidence schema (`messageId`, `partId`, `toolName`, `command`, `exitCode`, `filesTouched`, `artifactPath`, `taughtNodeId`, `correctedEpisodeId`)
175
+ - push harvesters toward raw evidence only, with final label resolution in the worker
176
+ - reduce “most recent message” fallback to a genuine fallback
177
+ - build richer scanner extractors (runbook/tool-chain/reuse/bridge/issue→PR→commit)
178
+
179
+ ## Phase 4 — Replay-gated mutation bundles
180
+
181
+ Goal: stop thinking proposal-by-proposal and move to bundle-level replay decisions.
182
+
183
+ ### Main files
184
+ - `src/brain-core/mutator.ts`
185
+ - `src/brain-core/pack.ts`
186
+ - `src/brain-worker/worker.ts`
187
+ - `src/brain-store/store.ts`
188
+ - `src/brain-store/migrations.ts`
189
+
190
+ ### Current truth
191
+ Mutation proposals and replay-gated promotion exist, but the bundle-level end state does not.
192
+
193
+ ### What remains
194
+ - persist mutation bundles
195
+ - cluster proposals by graph neighborhood
196
+ - evaluate bundles against comparative replay (`base` vs `candidate`)
197
+ - reject on regression / collapse / context bloat / orphan spikes
198
+ - keep split/merge behind flags until the bundle harness is strong enough
199
+
200
+ ## Phase 5 — Freeze the proof ladder
201
+
202
+ Goal: make public claims map to frozen artifact evidence.
203
+
204
+ ### Main files
205
+ - `docs/EVIDENCE.md`
206
+ - `docs/evidence/`
207
+ - `scripts/validate-openclaw-install.mjs`
208
+ - `scripts/validate-brain-runtime-behavior.ts`
209
+ - `test/brain-runtime/service.test.ts`
210
+ - `test/brain-core/replay.test.ts`
211
+
212
+ ### What remains
213
+ - define proof ladder levels clearly
214
+ - require date/SHA artifact directories
215
+ - capture host-install evidence bundles, not just ad hoc command output
216
+ - add release-candidate summary markdown for every serious release proof run
217
+
218
+ ## Phase 6 — Clean packaging and type surface
219
+
220
+ Goal: make installation and operator recovery boring.
221
+
222
+ ### Main files
223
+ - future: `src/openclaw-sdk-compat.ts` (or equivalent compatibility wrapper)
224
+ - `tsconfig.json`
225
+ - `package.json`
226
+ - `openclaw.plugin.json`
227
+ - `README.md`
228
+
229
+ ### What remains
230
+ - isolate SDK drift behind a narrow compatibility boundary
231
+ - make `npx tsc --noEmit` green
232
+ - document `brainWorkerMode=child` as the practical default
233
+ - clarify embedding support as tested reality, not wishful compatibility
234
+ - verify package contents with `npm pack --dry-run`
235
+
236
+ ## What to ignore now
237
+
238
+ Do not use removed root planning docs or archived prototype code as design authority. The canonical truth lives in:
239
+
240
+ - `README.md`
241
+ - `docs/RELEASE_CONTRACT.md`
242
+ - `docs/END_STATE.md`
243
+ - `docs/EVIDENCE.md`
244
+ - the current runtime/tests/scripts in `src/`, `test/`, and `scripts/`
@@ -0,0 +1,128 @@
1
+ # OpenClawBrain v2 — Evidence Ladder
2
+
3
+ This document defines what proof must exist before public claims are treated as frozen.
4
+
5
+ ## Artifact layout
6
+
7
+ Store release and benchmark artifacts under:
8
+
9
+ ```text
10
+ docs/evidence/YYYY-MM-DD/<git-sha>/
11
+ ```
12
+
13
+ Each bundle should contain at minimum:
14
+
15
+ - `status.json`
16
+ - `doctor.json`
17
+ - `trace.json`
18
+ - `validation-report.json`
19
+ - `config-snapshot.json`
20
+ - `logs.txt`
21
+ - `summary.md`
22
+
23
+ For Level 4 host-install runs, the bundle should also include the pre-run diagnostic ladder outputs:
24
+
25
+ - `status-all.txt`
26
+ - `gateway-probe.txt`
27
+ - `gateway-status.txt`
28
+ - `channels-status.txt`
29
+
30
+ If a proof run is partial, the `summary.md` should say exactly what was and was not proven.
31
+
32
+ ## Proof ladder
33
+
34
+ ### Level 1 — Mechanism proofs
35
+
36
+ Purpose: prove the math/runtime primitives in isolation.
37
+
38
+ Primary surfaces:
39
+ - `test/brain-core/policy.test.ts`
40
+ - `test/brain-core/traverse.test.ts`
41
+ - `test/brain-core/update.test.ts`
42
+ - `test/brain-core/seed-policy.test.ts`
43
+ - `test/brain-runtime/service.test.ts`
44
+ - `test/brain-runtime/harvester.test.ts`
45
+ - `src/brain-runtime/worker-supervisor.ts`
46
+ - `src/brain-worker/protocol.ts`
47
+ - `scripts/validate-brain-runtime-behavior.ts`
48
+
49
+ Required claims:
50
+ - finite-horizon traversal with `STOP`
51
+ - full-trajectory update behavior
52
+ - seed routing is learnable
53
+ - immediate `brain_teach` retrieval works
54
+ - serve-from-last-promoted-pack survives worker crash at runtime level
55
+ - child-worker supervision records restart truth, reload acknowledgements, stale-lease takeover, and second-writer refusal
56
+ - raw harvesting preserves multiple concurrent evidence signals with extractor metadata before worker-side trust resolution collapses them into labels
57
+ - structured tool-result/function-output parts can generate self-evidence even when flattened stored text is empty
58
+ - explicit episode attribution, resolver attribution, and recent-conversation fallback are all audited rather than implied
59
+
60
+ ### Level 2 — Recorded replay proofs
61
+
62
+ Purpose: prove candidate changes do not regress protected behavior.
63
+
64
+ Primary surfaces:
65
+ - `src/brain-core/replay.ts`
66
+ - `src/brain-core/pack.ts`
67
+ - `src/brain-worker/worker.ts`
68
+ - `test/brain-core/replay.test.ts`
69
+
70
+ Required claims:
71
+ - promotion replay gate blocks regressions
72
+ - human-positive episodes do not regress silently
73
+ - candidate packs explain why they passed or failed
74
+
75
+ ### Level 3 — Shadow proofs
76
+
77
+ Purpose: prove the runtime can record decisions safely without injecting learned context.
78
+
79
+ Primary surfaces:
80
+ - `src/brain-runtime/assembler-extension.ts`
81
+ - `src/brain-runtime/service.ts`
82
+ - `scripts/validate-openclaw-install.mjs`
83
+
84
+ Required claims:
85
+ - shadow mode records episode/trace ids
86
+ - shadow mode does not visibly inject the brain block
87
+ - host-surface status/trace stay truthful
88
+
89
+ ### Level 4 — Disposable host-install proofs
90
+
91
+ Purpose: prove the plugin on the real OpenClaw host surface.
92
+
93
+ Primary surfaces:
94
+ - `scripts/validate-openclaw-install.mjs`
95
+ - future: `.github/workflows/validate-openclaw-install.yml`
96
+ - `openclaw.plugin.json`
97
+ - `README.md`
98
+
99
+ Required claims:
100
+ - recurrent route used
101
+ - static lookup bypassed when appropriate, or the remaining host-surface drift is explicitly classified/truth-frozen
102
+ - shadow mode recorded
103
+ - `brain_teach` proven by a deterministic session-bound harness (`scripts/validate-brain-teach-session-bound.ts`) with 20/20 identical passes, or honestly classified as out of scope for raw prompt-driven host proof
104
+ - worker-down host proof stays narrow: last-promoted-pack serving continues and host status surfaces unhealthy/exit truth
105
+ - `skip_no_embedding` and `skip_uninitialized` asserted explicitly
106
+
107
+ ## Release checklist
108
+
109
+ Do not claim a release candidate is fully proven unless the artifact bundle includes:
110
+
111
+ - the exact commit SHA
112
+ - the validation command(s)
113
+ - the model + embedding configuration used
114
+ - pass/fail results for host harness assertions
115
+ - status and doctor snapshots
116
+ - at least one trace proving the routed path being claimed
117
+ - a short markdown summary of what remains open
118
+
119
+ ## Current proof truth
120
+
121
+ As of the current trunk:
122
+
123
+ - **Level 1:** materially real
124
+ - **Level 2:** present but not yet bundle-complete
125
+ - **Level 3:** partially real on the host surface
126
+ - **Level 4:** not frozen; deterministic session-bound `brain_teach` proof now exists under `docs/evidence/YYYY-MM-DD/<git-sha>/brain-teach-session-bound/`, short-static host classification is currently truth-frozen as stale current-OpenClaw host seam drift under `docs/evidence/YYYY-MM-DD/<git-sha>/short-static-classification/`, and the final narrow worker-down host claim still remains open
127
+
128
+ That means the repo is already beyond theory-only, but it does **not** yet have a frozen release-evidence ladder.
@@ -0,0 +1,91 @@
1
+ # OpenClawBrain v2 — Release Contract
2
+
3
+ This is the fast truth surface for the repo.
4
+
5
+ Use these public labels consistently:
6
+
7
+ - **paper-faithful core**
8
+ - **live-path implemented**
9
+ - **operationally validated**
10
+
11
+ Current truthful state:
12
+
13
+ - **paper-faithful core:** yes
14
+ - **live-path implemented:** yes
15
+ - **operationally validated:** not yet
16
+
17
+ That is the contract. The repo is already beyond "foundation only," but it is not yet at an honest 1.0 operating state.
18
+
19
+ ## 1. True in code now
20
+
21
+ These are safe public claims today.
22
+
23
+ ### Paper-faithful routing core
24
+ - **Finite-horizon traversal with `STOP`**
25
+ - Code: `src/brain-core/traverse.ts`, `test/brain-core/traverse.test.ts`
26
+ - **Terminal reward with baseline, not shaping rewards**
27
+ - Code: `src/brain-core/episode.ts`, `src/brain-core/update.ts`, `src/brain-worker/worker.ts`, `test/brain-core/update.test.ts`
28
+ - **Stochastic policy over actions**
29
+ - Code: `src/brain-core/policy.ts`, `src/brain-core/traverse.ts`, `test/brain-core/policy.test.ts`
30
+ - **Full-trajectory REINFORCE updates**
31
+ - Code: `src/brain-core/update.ts`, `src/brain-worker/worker.ts`, `test/brain-core/integration.test.ts`
32
+ - **Learned seed routing as part of the policy surface**
33
+ - Code: `src/brain-core/types.ts`, `src/brain-core/traverse.ts`, `src/brain-core/update.ts`, `src/brain-store/store.ts`, `test/brain-core/seed-policy.test.ts`
34
+ - **Immutable promoted packs for serving**
35
+ - Code: `src/brain-core/pack.ts`, `src/brain-runtime/service.ts`, `src/brain-store/store.ts`, `test/brain-runtime/service.test.ts`
36
+
37
+ ### Live runtime path
38
+ - **Explicit runtime decisions** (`use_brain`, `shadow`, named skip modes)
39
+ - Code: `src/brain-runtime/assembler-extension.ts`, `test/brain-runtime/assembler-extension.test.ts`
40
+ - **Correction-first assembly**
41
+ - Code: `src/brain-runtime/assembler-extension.ts`
42
+ - **Immediate `brain_teach` retrieval path**
43
+ - Code: `src/brain-runtime/service.ts`, `src/brain-runtime/tools.ts`, `test/brain-runtime/service.test.ts`
44
+ - **Episode and trace recording on the live path**
45
+ - Code: `src/brain-runtime/service.ts`, `src/brain-core/trace.ts`, `test/brain-runtime/service.test.ts`
46
+ - **Serve from the last promoted pack even when the worker is unavailable**
47
+ - Code: `src/brain-runtime/service.ts`, `test/brain-runtime/service.test.ts`, `scripts/validate-brain-runtime-behavior.ts`
48
+ - **Child-worker mode exists and is real**
49
+ - Code: `openclaw.plugin.json`, `src/brain-runtime/service.ts`, `src/brain-worker/child-runner.ts`, `test/brain-runtime/service.test.ts`
50
+
51
+ ## 2. Implemented but not frozen
52
+
53
+ These are real enough to build on, but not frozen enough to oversell.
54
+
55
+ - **Host-surface validation harness**
56
+ - Current files: `scripts/validate-openclaw-install.mjs`, `scripts/validate-brain-runtime-behavior.ts`, `scripts/validate-short-static-classification.ts`
57
+ - Truth: recurrent routing, shadow mode, and current host checks run inside a dedicated sterile validation lane with per-run diagnostic artifacts; deterministic session-bound `brain_teach` proof now exists, but the current raw host lane is blocked by stale OpenClaw seam drift (`plugins.slots.contextEngine` rejected, `api.registerContextEngine` removed) and the final narrow worker-down host claim is still incomplete.
58
+ - Boundary: raw prompt-driven `openclaw agent --local` is **not** the release proof boundary for `brain_teach`; that claim is now closed by the deterministic session-bound harness rather than raw host prompting.
59
+ - Boundary: short-static host drift is currently truth-frozen as stale current-OpenClaw host seam drift, not as a resolved semantic behavior claim.
60
+ - Boundary: worker-down host proof is claimed only at the exact host-visible boundary actually proven (continued serving from the last promoted pack + unhealthy worker status / exit truth), not as a stronger deterministic crash-observation claim.
61
+ - **Child-worker serving boundary**
62
+ - Current files: `src/brain-runtime/service.ts`, `src/brain-runtime/worker-supervisor.ts`, `src/brain-worker/child-runner.ts`, `src/brain-worker/protocol.ts`, `src/brain-cli.ts`
63
+ - Truth: the child worker now runs behind a dedicated supervisor boundary with explicit protocol messages, restart accounting, reload acknowledgements, lease protection, and stronger status/doctor truth. `in_process` mode remains available only as a dev-only fallback and must not be treated as the production operator boundary.
64
+ - **Raw evidence → resolved labels flow**
65
+ - Current files: `src/brain-runtime/harvester-extension.ts`, `src/brain-runtime/evidence-detectors.ts`, `src/brain-harvest/*.ts`, `src/brain-worker/worker.ts`, `src/brain-store/store.ts`, `src/engine.ts`
66
+ - Truth: explicit evidence tables and trust-ordered resolution are real; harvested assistant/tool messages 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 extraction itself still leans heavily on heuristics, especially for scanner-style evidence.
67
+ - **Replay-gated promotion**
68
+ - Current files: `src/brain-core/replay.ts`, `src/brain-core/pack.ts`, `src/brain-worker/worker.ts`
69
+ - Truth: promotion gates exist, but mutation evaluation is still closer to proposal-by-proposal than bundle-level replay decisions.
70
+
71
+ ## 3. Not done yet
72
+
73
+ These are still active work and must not be described as complete.
74
+
75
+ - **Frozen host-surface proof for worker-down fail-open on the current host seam**
76
+ - Primary files: `scripts/validate-openclaw-install.mjs`, `scripts/validate-brain-teach-session-bound.ts`, `scripts/validate-short-static-classification.ts`, `src/brain-runtime/tools.ts`, `src/brain-runtime/service.ts`
77
+ - Required truth before this is marked done: keep deterministic session-bound `brain_teach` proof frozen, adapt the current OpenClaw host seam, and then land a narrow host worker-down claim that matches the actual artifact bundle.
78
+ - **Resolved short-static-lookup host-surface semantics on the adapted current host seam**
79
+ - Primary files: `src/brain-runtime/assembler-extension.ts`, `scripts/validate-openclaw-install.mjs`, `scripts/validate-short-static-classification.ts`
80
+ - **Bundle-based mutation evaluation with clear pass/fail explanations**
81
+ - Primary files: `src/brain-core/mutator.ts`, `src/brain-worker/worker.ts`, `src/brain-store/store.ts`, `src/brain-store/migrations.ts`
82
+ - **Frozen proof ladder with dated release artifacts**
83
+ - Primary files: `docs/EVIDENCE.md`, `docs/evidence/`, `scripts/validate-openclaw-install.mjs`
84
+ - **Green full-repo `npx tsc --noEmit`**
85
+ - Primary files: `tsconfig.json`, `package.json`, SDK-boundary imports
86
+ - **Boring install / recovery path for another operator**
87
+ - Primary files: `README.md`, `docs/configuration.md`, `openclaw.plugin.json`, future release workflow/evidence files
88
+
89
+ ## Safe public summary
90
+
91
+ > OpenClawBrain v2 already has a paper-faithful routing core and a real live runtime path. What remains is the operational hardening, host-surface proof, mutation-bundle evaluation, and release-evidence layer.
@@ -0,0 +1,106 @@
1
+ # Agent tools
2
+
3
+ OpenClawBrain exposes two tool families:
4
+
5
+ 1. **LCM recall tools** — search and expand compacted conversation history
6
+ 2. **Brain runtime tools** — teach the live routing layer, inspect status, inspect traces
7
+
8
+ ## LCM recall tools
9
+
10
+ Use these when you need recall from compacted history.
11
+
12
+ ### Escalation pattern: `lcm_grep` → `lcm_describe` → `lcm_expand_query`
13
+
14
+ 1. **`lcm_grep`** — find relevant summaries or messages by keyword/regex
15
+ 2. **`lcm_describe`** — inspect a specific summary or file cheaply
16
+ 3. **`lcm_expand_query`** — deep recall through bounded sub-agent expansion
17
+
18
+ Start with grep. Expand only when the summary is too compressed for the task.
19
+
20
+ ### `lcm_grep`
21
+ Search across messages and/or summaries using regex or full-text search.
22
+
23
+ ### `lcm_describe`
24
+ Read the full content and metadata for a summary or stored large file.
25
+
26
+ ### `lcm_expand_query`
27
+ Answer a focused question by expanding summaries through the DAG.
28
+
29
+ ### `lcm_expand`
30
+ Low-level DAG expansion tool used internally by the delegated expansion sub-agent.
31
+
32
+ ## Brain runtime tools
33
+
34
+ Use these when working with the learned routing layer directly.
35
+
36
+ ### `brain_teach`
37
+ Teach the brain a correction or reusable guidance.
38
+
39
+ Current truth:
40
+ - immediate retrieval is wired into the runtime
41
+ - taught nodes are embedded immediately when embeddings are configured
42
+ - taught corrections bind most strongly when invoked from a live tool session on the active conversation
43
+
44
+ Primary code:
45
+ - `src/brain-runtime/tools.ts`
46
+ - `src/brain-runtime/service.ts`
47
+ - `test/brain-runtime/service.test.ts`
48
+
49
+ ### `brain_status`
50
+ Inspect operator/runtime truth for the brain layer.
51
+
52
+ Typical surfaces include:
53
+ - enabled / disabled state
54
+ - embedding configuration truth
55
+ - worker mode / PID / heartbeat / health
56
+ - current promoted pack metadata
57
+ - last assembly decision
58
+ - graph/health counters
59
+
60
+ Primary code:
61
+ - `src/brain-runtime/tools.ts`
62
+ - `src/brain-runtime/service.ts`
63
+ - `src/brain-cli.ts`
64
+
65
+ ### `brain_trace`
66
+ Inspect the most recent trace or a specific trace id.
67
+
68
+ Typical surfaces include:
69
+ - chosen seed
70
+ - seed scores
71
+ - fired nodes
72
+ - pack version
73
+ - route footer / summary
74
+ - episode linkage
75
+
76
+ Primary code:
77
+ - `src/brain-runtime/tools.ts`
78
+ - `src/brain-runtime/service.ts`
79
+ - `src/brain-core/trace.ts`
80
+
81
+ ## When to use what
82
+
83
+ - Need compacted history recall? use **LCM tools**
84
+ - Need to teach/update the current routing layer? use **`brain_teach`**
85
+ - Need current runtime/operator truth? use **`brain_status`**
86
+ - Need to inspect a specific routing decision? use **`brain_trace`**
87
+
88
+ ## Prompting guidance for agents
89
+
90
+ A good agent prompt should make both tool families explicit:
91
+
92
+ ```markdown
93
+ ## Memory and routing tools
94
+
95
+ For recall from compacted history:
96
+ - `lcm_grep`
97
+ - `lcm_describe`
98
+ - `lcm_expand_query`
99
+
100
+ For the live learned routing layer:
101
+ - `brain_teach`
102
+ - `brain_status`
103
+ - `brain_trace`
104
+
105
+ Use LCM tools for recall. Use brain tools only when you are teaching or auditing the routing layer itself.
106
+ ```