@sparkleideas/claude-flow-patch 3.1.0-alpha.44.patch.10 → 3.1.0-alpha.44.patch.11

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 (79) hide show
  1. package/CLAUDE.md +87 -8
  2. package/README.md +156 -4
  3. package/check-patches.sh +90 -16
  4. package/lib/categories.json +3 -1
  5. package/lib/common.py +15 -0
  6. package/package.json +6 -3
  7. package/patch/010-CF-001-doctor-yaml/sentinel +1 -1
  8. package/patch/020-CF-002-config-export-yaml/README.md +1 -1
  9. package/patch/020-CF-002-config-export-yaml/fix.py +3 -43
  10. package/patch/060-DM-004-worker-stubs/README.md +35 -0
  11. package/patch/060-DM-004-worker-stubs/fix.py +83 -0
  12. package/patch/{070-DM-005-consolidation-worker-stub → 060-DM-004-worker-stubs}/sentinel +1 -0
  13. package/patch/320-SG-004-wizard-parity/fix.py +1 -1
  14. package/patch/340-SG-006-wizard-capture/README.md +29 -0
  15. package/patch/340-SG-006-wizard-capture/fix.py +23 -0
  16. package/patch/340-SG-006-wizard-capture/sentinel +2 -0
  17. package/patch/350-WM-001-memory-wiring/README.md +50 -0
  18. package/patch/350-WM-001-memory-wiring/fix.py +385 -0
  19. package/patch/350-WM-001-memory-wiring/sentinel +3 -0
  20. package/patch/360-WM-002-config-respect/README.md +31 -0
  21. package/patch/360-WM-002-config-respect/fix.py +37 -0
  22. package/patch/360-WM-002-config-respect/sentinel +3 -0
  23. package/patch/370-WM-003-auto-memory-bridge/README.md +37 -0
  24. package/patch/370-WM-003-auto-memory-bridge/fix.py +261 -0
  25. package/patch/370-WM-003-auto-memory-bridge/sentinel +6 -0
  26. package/patch/380-CF-003-doctor-native-deps/README.md +46 -0
  27. package/patch/380-CF-003-doctor-native-deps/fix.py +157 -0
  28. package/patch/380-CF-003-doctor-native-deps/sentinel +4 -0
  29. package/patch/385-SG-007-init-shallow-copy/README.md +25 -0
  30. package/patch/385-SG-007-init-shallow-copy/fix.py +44 -0
  31. package/patch/385-SG-007-init-shallow-copy/sentinel +3 -0
  32. package/patch/390-WM-004-source-hook-fail-loud/README.md +33 -0
  33. package/patch/390-WM-004-source-hook-fail-loud/fix.py +164 -0
  34. package/patch/390-WM-004-source-hook-fail-loud/sentinel +2 -0
  35. package/patch/420-CF-004-config-export-json/README.md +24 -0
  36. package/patch/420-CF-004-config-export-json/fix.py +24 -0
  37. package/patch/420-CF-004-config-export-json/sentinel +2 -0
  38. package/patch/440-SG-008-init-config-json/README.md +21 -0
  39. package/patch/440-SG-008-init-config-json/fix.py +116 -0
  40. package/patch/440-SG-008-init-config-json/sentinel +2 -0
  41. package/patch/450-CF-006-config-yaml-to-json/README.md +42 -0
  42. package/patch/450-CF-006-config-yaml-to-json/fix.py +138 -0
  43. package/patch/450-CF-006-config-yaml-to-json/sentinel +7 -0
  44. package/patch/480-DOC-001-readme-docs/README.md +52 -0
  45. package/patch/480-DOC-001-readme-docs/fix.py +273 -0
  46. package/patch/480-DOC-001-readme-docs/sentinel +11 -0
  47. package/patch/490-SG-009-remove-v3-mode/README.md +47 -0
  48. package/patch/490-SG-009-remove-v3-mode/fix.py +204 -0
  49. package/patch/490-SG-009-remove-v3-mode/sentinel +8 -0
  50. package/patch/500-CF-009-minimal-v3-defaults/README.md +25 -0
  51. package/patch/500-CF-009-minimal-v3-defaults/fix.py +32 -0
  52. package/patch/500-CF-009-minimal-v3-defaults/sentinel +2 -0
  53. package/patch/530-WM-007-wire-dead-config-keys/README.md +49 -0
  54. package/patch/530-WM-007-wire-dead-config-keys/fix.py +254 -0
  55. package/patch/530-WM-007-wire-dead-config-keys/sentinel +15 -0
  56. package/patch/540-SG-010-init-cli-options/README.md +47 -0
  57. package/patch/540-SG-010-init-cli-options/fix.py +418 -0
  58. package/patch/540-SG-010-init-cli-options/sentinel +19 -0
  59. package/patch/550-SG-011-topology-hierarchical-refs/README.md +34 -0
  60. package/patch/550-SG-011-topology-hierarchical-refs/fix.py +28 -0
  61. package/patch/550-SG-011-topology-hierarchical-refs/sentinel +5 -0
  62. package/patch/560-WM-008-agentdb-v3-upgrade/README.md +57 -0
  63. package/patch/560-WM-008-agentdb-v3-upgrade/fix.py +257 -0
  64. package/patch/560-WM-008-agentdb-v3-upgrade/fix.sh +49 -0
  65. package/patch/560-WM-008-agentdb-v3-upgrade/sentinel +13 -0
  66. package/patch/570-WM-009-agentdb-learning-loop/README.md +35 -0
  67. package/patch/570-WM-009-agentdb-learning-loop/fix.py +141 -0
  68. package/patch/570-WM-009-agentdb-learning-loop/sentinel +3 -0
  69. package/patch/580-WM-010-witness-chain-verify/README.md +33 -0
  70. package/patch/580-WM-010-witness-chain-verify/fix.py +45 -0
  71. package/patch/580-WM-010-witness-chain-verify/sentinel +1 -0
  72. package/patch/590-WM-011-reasoning-bank-controller/README.md +34 -0
  73. package/patch/590-WM-011-reasoning-bank-controller/fix.py +381 -0
  74. package/patch/590-WM-011-reasoning-bank-controller/sentinel +4 -0
  75. package/patch/060-DM-004-preload-worker-stub/README.md +0 -11
  76. package/patch/060-DM-004-preload-worker-stub/fix.py +0 -34
  77. package/patch/060-DM-004-preload-worker-stub/sentinel +0 -1
  78. package/patch/070-DM-005-consolidation-worker-stub/README.md +0 -11
  79. package/patch/070-DM-005-consolidation-worker-stub/fix.py +0 -46
@@ -0,0 +1,257 @@
1
+ # WM-008: Upgrade AgentDB v2 to v3 (RVF backend, self-learning, witness chain)
2
+ # GitHub: #1207
3
+
4
+ # ── Op A: DEFAULT_CONFIG vectorBackend 'auto' -> 'rvf' ──
5
+ patch("WM-008a: change default vectorBackend from 'auto' to 'rvf'",
6
+ AGENTDB_BACKEND,
7
+ """ vectorBackend: 'auto',""",
8
+ """ vectorBackend: 'rvf',""")
9
+
10
+ # ── Op B: shutdown() — save unified .rvf before close + destroy learning backend ──
11
+ patch("WM-008b: save unified .rvf before close, destroy learning backend in shutdown",
12
+ AGENTDB_BACKEND,
13
+ """ async shutdown() {
14
+ if (!this.initialized)
15
+ return;
16
+ if (this.agentdb) {
17
+ await this.agentdb.close();
18
+ }""",
19
+ """ async shutdown() {
20
+ if (!this.initialized)
21
+ return;
22
+ if (this.agentdb) {
23
+ // WM-008b: Save unified .rvf file before closing (v3)
24
+ if (this.agentdb.isUnifiedMode && typeof this.agentdb.save === 'function') {
25
+ try { await this.agentdb.save(); } catch {}
26
+ }
27
+ // WM-008b: Destroy learning backend if active
28
+ if (this.learningBackend) {
29
+ try { await this.learningBackend.destroy(); } catch {}
30
+ this.learningBackend = null;
31
+ }
32
+ await this.agentdb.close();
33
+ }""")
34
+
35
+ # ── Op C: Import SelfLearningRvfBackend alongside AgentDB ──
36
+ patch("WM-008c: add SelfLearningRvfBackend variable declaration",
37
+ AGENTDB_BACKEND,
38
+ """let AgentDB;
39
+ let HNSWIndex;
40
+ let isHnswlibAvailable;""",
41
+ """let AgentDB;
42
+ let HNSWIndex;
43
+ let isHnswlibAvailable;
44
+ let SelfLearningRvfBackend;""")
45
+
46
+ patch("WM-008c2: import SelfLearningRvfBackend in ensureAgentDBImport",
47
+ AGENTDB_BACKEND,
48
+ """ AgentDB = agentdbModule.AgentDB || agentdbModule.default;
49
+ HNSWIndex = agentdbModule.HNSWIndex;
50
+ isHnswlibAvailable = agentdbModule.isHnswlibAvailable;""",
51
+ """ AgentDB = agentdbModule.AgentDB || agentdbModule.default;
52
+ HNSWIndex = agentdbModule.HNSWIndex;
53
+ isHnswlibAvailable = agentdbModule.isHnswlibAvailable;
54
+ // WM-008c: Import SelfLearningRvfBackend (v3-only, undefined on v2)
55
+ SelfLearningRvfBackend = agentdbModule.SelfLearningRvfBackend;""")
56
+
57
+ # ── Op D: After initialize, create learning backend + capture witness chain hash ──
58
+ patch("WM-008d: create learning backend and capture witness chain in initialize",
59
+ AGENTDB_BACKEND,
60
+ """ this.initialized = true;
61
+ this.emit('initialized', {
62
+ backend: this.agentdb.vectorBackendName,
63
+ isWasm: this.agentdb.isWasm,
64
+ });""",
65
+ """ this.initialized = true;
66
+ // WM-008d: Create self-learning backend when enabled (v3-only)
67
+ if (this.config.enableLearning && SelfLearningRvfBackend) {
68
+ try {
69
+ this.learningBackend = await SelfLearningRvfBackend.create({
70
+ dimension: this.config.vectorDimension || 1536,
71
+ metric: 'cosine',
72
+ storagePath: this.config.dbPath || ':memory:',
73
+ learning: true,
74
+ positiveThreshold: this.config.learningPositiveThreshold ?? 0.7,
75
+ negativeThreshold: this.config.learningNegativeThreshold ?? 0.3,
76
+ trainingBatchSize: this.config.learningBatchSize ?? 32,
77
+ tickIntervalMs: this.config.learningTickInterval ?? 30000,
78
+ });
79
+ } catch (learnErr) {
80
+ // Non-fatal: self-learning is an optional enhancement
81
+ }
82
+ }
83
+ // WM-008f: Capture witness chain hash at init (v3-only)
84
+ let witnessChainHash;
85
+ if (this.agentdb && typeof this.agentdb.getWitnessChain === 'function') {
86
+ try {
87
+ const chain = this.agentdb.getWitnessChain();
88
+ witnessChainHash = chain?.currentHash;
89
+ } catch {}
90
+ }
91
+ this.emit('initialized', {
92
+ backend: this.agentdb.vectorBackendName,
93
+ isWasm: this.agentdb.isWasm,
94
+ learning: !!this.learningBackend,
95
+ unifiedMode: !!this.agentdb.isUnifiedMode,
96
+ witnessChainHash,
97
+ });""")
98
+
99
+ # ── Op E+F: Add recordFeedback, getWitnessChain, verifyWitnessChain methods ──
100
+ patch("WM-008ef: add recordFeedback + witness chain methods",
101
+ AGENTDB_BACKEND,
102
+ """ getAgentDB() {
103
+ return this.agentdb;
104
+ }
105
+ }""",
106
+ """ getAgentDB() {
107
+ return this.agentdb;
108
+ }
109
+ /**
110
+ * WM-008e: Record search feedback for self-learning (v3-only)
111
+ */
112
+ async recordFeedback(queryId, quality) {
113
+ if (!this.learningBackend || typeof this.learningBackend.recordFeedback !== 'function') return;
114
+ try {
115
+ await this.learningBackend.recordFeedback(queryId, quality);
116
+ } catch {}
117
+ }
118
+ /**
119
+ * WM-008f: Get witness chain for tamper detection (v3-only)
120
+ */
121
+ getWitnessChain() {
122
+ if (!this.agentdb) return null;
123
+ if (typeof this.agentdb.getWitnessChain === 'function') {
124
+ try { return this.agentdb.getWitnessChain(); } catch { return null; }
125
+ }
126
+ return null;
127
+ }
128
+ /**
129
+ * WM-008f: Verify witness chain integrity (v3-only)
130
+ */
131
+ async verifyWitnessChain() {
132
+ if (!this.agentdb) return { valid: false, reason: 'agentdb not initialized' };
133
+ if (typeof this.agentdb.verifyWitnessChain === 'function') {
134
+ try { return await this.agentdb.verifyWitnessChain(); } catch (e) { return { valid: false, reason: String(e) }; }
135
+ }
136
+ return { valid: false, reason: 'witness chain not available (requires agentdb v3)' };
137
+ }
138
+ }""")
139
+
140
+ # ── Op G: memory-initializer.js — .db -> .rvf + vectorBackend + learning config ──
141
+ # Targets the state AFTER WM-007a2 has been applied (execution order 530 < 560)
142
+ patch("WM-008g1: change agentdb path from .db to .rvf",
143
+ MI,
144
+ """ const agentDbPath = path.join(swarmDir, 'agentdb-memory.db');""",
145
+ """ const agentDbPath = path.join(swarmDir, 'agentdb-memory.rvf');""")
146
+
147
+ patch("WM-008g2: replace v2 agentdb config with v3 RVF + learning config",
148
+ MI,
149
+ """ if (backendChoice === 'hybrid' || backendChoice === 'agentdb') {
150
+ hybridConfig.agentdb = {
151
+ dbPath: agentDbPath,
152
+ vectorDimension: modelDimensions,
153
+ indexType: enableHNSW ? 'hnsw' : 'flat',
154
+ };
155
+ }""",
156
+ """ if (backendChoice === 'hybrid' || backendChoice === 'agentdb') {
157
+ // WM-008g: AgentDB v3 config with RVF backend + self-learning
158
+ const agentdbCfg = cfgMemory.agentdb || {};
159
+ hybridConfig.agentdb = {
160
+ dbPath: agentDbPath,
161
+ vectorDimension: modelDimensions,
162
+ vectorBackend: 'rvf',
163
+ enableLearning: agentdbCfg.enableLearning !== false,
164
+ learningPositiveThreshold: agentdbCfg.learningPositiveThreshold ?? 0.7,
165
+ learningNegativeThreshold: agentdbCfg.learningNegativeThreshold ?? 0.3,
166
+ learningBatchSize: agentdbCfg.learningBatchSize ?? 32,
167
+ learningTickInterval: agentdbCfg.learningTickInterval ?? 30000,
168
+ };
169
+ }""")
170
+
171
+ # ── Op H: executor.js — add agentdb subsection to config.json template ──
172
+ # Targets the state AFTER SG-010c has been applied (execution order 540 < 560)
173
+ patch("WM-008h: add agentdb v3 config subsection to config.json template",
174
+ EXECUTOR,
175
+ """ agentScopes: {
176
+ enabled: !!(options.runtime.enableAgentScopes ?? true),
177
+ defaultScope: options.runtime.defaultScope || 'project',
178
+ },
179
+ },
180
+ neural: {""",
181
+ """ agentScopes: {
182
+ enabled: !!(options.runtime.enableAgentScopes ?? true),
183
+ defaultScope: options.runtime.defaultScope || 'project',
184
+ },
185
+ // WM-008h: AgentDB v3 self-learning config
186
+ agentdb: {
187
+ vectorBackend: 'rvf',
188
+ enableLearning: !!(options.runtime.enableAgentdbLearning ?? true),
189
+ learningPositiveThreshold: options.runtime.agentdbPositiveThreshold ?? 0.7,
190
+ learningNegativeThreshold: options.runtime.agentdbNegativeThreshold ?? 0.3,
191
+ learningBatchSize: options.runtime.agentdbBatchSize ?? 32,
192
+ learningTickInterval: options.runtime.agentdbTickInterval ?? 30000,
193
+ },
194
+ },
195
+ neural: {""")
196
+
197
+ # ── Op I: @claude-flow/memory package.json — update agentdb dep version ──
198
+ patch("WM-008i: update @claude-flow/memory agentdb dep from v2 to v3",
199
+ MEMORY_PKG_JSON,
200
+ """ "agentdb": "2.0.0-alpha.3.7",""",
201
+ """ "agentdb": "3.0.0-alpha.3",""")
202
+
203
+ # ── Op J: agentdb-backend.js header comment — update version ref ──
204
+ patch("WM-008j: update agentdb-backend.js header comment to v3",
205
+ AGENTDB_BACKEND,
206
+ """ * AgentDB Backend - Integration with agentdb@2.0.0-alpha.3.4""",
207
+ """ * AgentDB Backend - Integration with agentdb@3.0.0-alpha.3""")
208
+
209
+ # ── Op K: helpers-generator.js — .db -> .rvf + v3 config (3 HybridBackend blocks) ──
210
+ # All 3 blocks have identical agentdb config; patch_all replaces them all at once
211
+ patch_all("WM-008k: helpers-generator.js agentdb-memory.db -> .rvf + v3 config",
212
+ HELPERS_GEN,
213
+ """ agentdb: { dbPath: join(PROJECT_ROOT, '.swarm', 'agentdb-memory.db') },""",
214
+ """ agentdb: { dbPath: join(PROJECT_ROOT, '.swarm', 'agentdb-memory.rvf'), vectorBackend: 'rvf' },""")
215
+
216
+ # ── Op L: auto-memory-hook.mjs (source helper) — .db -> .rvf + v3 config ──
217
+ # createBackend() uses swarmDir variable; patch_all covers any remaining PROJECT_ROOT variants
218
+ patch("WM-008l: auto-memory-hook.mjs createBackend agentdb-memory.db -> .rvf",
219
+ SRC_AUTO_MEMORY_HOOK,
220
+ """ agentdb: { dbPath: join(swarmDir, 'agentdb-memory.db') },""",
221
+ """ agentdb: { dbPath: join(swarmDir, 'agentdb-memory.rvf'), vectorBackend: 'rvf', enableLearning: config.agentdb?.enableLearning !== false },""")
222
+
223
+ patch_all("WM-008l2: auto-memory-hook.mjs remaining agentdb-memory.db -> .rvf",
224
+ SRC_AUTO_MEMORY_HOOK,
225
+ """agentdb-memory.db""",
226
+ """agentdb-memory.rvf""")
227
+
228
+ # ── Op M: @claude-flow/neural reasoning-bank.js — vectorBackend 'auto' -> 'rvf' ──
229
+ patch("WM-008m: reasoning-bank.js vectorBackend auto -> rvf",
230
+ NEURAL_REASONING_BANK,
231
+ """ vectorBackend: 'auto',""",
232
+ """ vectorBackend: 'rvf',""")
233
+
234
+ # ── Op N: @claude-flow/shared defaults.js — replace v2 indexType with v3 vectorBackend ──
235
+ patch("WM-008n: shared defaults.js add vectorBackend rvf to agentdb defaults",
236
+ SHARED_DEFAULTS,
237
+ """ agentdb: {
238
+ dimensions: 1536,
239
+ indexType: 'hnsw',
240
+ efConstruction: 200,
241
+ m: 16,
242
+ quantization: 'none',
243
+ },""",
244
+ """ agentdb: {
245
+ dimensions: 1536,
246
+ vectorBackend: 'rvf',
247
+ indexType: 'hnsw',
248
+ efConstruction: 200,
249
+ m: 16,
250
+ quantization: 'none',
251
+ },""")
252
+
253
+ # ── Op O: executor.js — update version table from v2 to v3 ──
254
+ patch("WM-008o: executor.js version table agentdb 2.x -> 3.x",
255
+ EXECUTOR,
256
+ """| agentdb | 2.0.0-alpha.3.4 | Vector database |""",
257
+ """| agentdb | 3.0.0-alpha.3 | Vector database (RVF + self-learning) |""")
@@ -0,0 +1,49 @@
1
+ #!/bin/bash
2
+ # WM-008: Upgrade agentdb v2 -> v3 in npm cache
3
+ # GitHub: #1207
4
+ # Skips if agentdb is already v3 or not installed
5
+
6
+ set -euo pipefail
7
+
8
+ # BASE is set by patch-all.sh to the dist/src directory
9
+ if [ -z "${BASE:-}" ] || [ "$BASE" = "/dev/null" ]; then
10
+ exit 0 # No @claude-flow/cli found
11
+ fi
12
+
13
+ # node_modules/@claude-flow/cli/dist/src -> node_modules
14
+ NM_ROOT="$(cd "$BASE/../../../.." 2>/dev/null && pwd)" || exit 0
15
+ AGENTDB_DIR="$NM_ROOT/agentdb"
16
+
17
+ # Skip if agentdb not installed
18
+ [ -d "$AGENTDB_DIR" ] || exit 0
19
+
20
+ # Check current version
21
+ CURRENT_VERSION=$(node -e "console.log(require('$AGENTDB_DIR/package.json').version)" 2>/dev/null || echo "unknown")
22
+ if [[ "$CURRENT_VERSION" == 3.* ]]; then
23
+ echo " WM-008: agentdb already at v$CURRENT_VERSION (skip)"
24
+ exit 0
25
+ fi
26
+
27
+ echo " WM-008: Upgrading agentdb from v$CURRENT_VERSION to 3.0.0-alpha.3..."
28
+
29
+ # Pack v3 into a tarball
30
+ WORK=$(mktemp -d)
31
+ trap "rm -rf $WORK" EXIT
32
+
33
+ (cd "$WORK" && npm pack agentdb@3.0.0-alpha.3 --silent 2>/dev/null) || {
34
+ echo " WM-008: WARN -- npm pack failed (offline?), skipping agentdb upgrade"
35
+ exit 0
36
+ }
37
+
38
+ TARBALL=$(ls "$WORK"/agentdb-*.tgz 2>/dev/null | head -1)
39
+ if [ -z "$TARBALL" ]; then
40
+ echo " WM-008: WARN -- tarball not found, skipping"
41
+ exit 0
42
+ fi
43
+
44
+ # Remove old, extract new
45
+ rm -rf "$AGENTDB_DIR"
46
+ mkdir -p "$AGENTDB_DIR"
47
+ tar xzf "$TARBALL" -C "$AGENTDB_DIR" --strip-components=1
48
+
49
+ echo " Applied: WM-008 agentdb upgrade to v3.0.0-alpha.3"
@@ -0,0 +1,13 @@
1
+ grep "agentdb-memory.rvf" memory/memory-initializer.js
2
+ grep "vectorBackend: 'rvf'" memory/memory-initializer.js
3
+ grep "enableAgentdbLearning" init/executor.js
4
+ grep "agentdb-memory.rvf" init/helpers-generator.js
5
+ grep "agentdb-memory.rvf" .claude/helpers/auto-memory-hook.mjs
6
+ package: @claude-flow/memory
7
+ grep "SelfLearningRvfBackend" agentdb-backend.js
8
+ grep "vectorBackend: 'rvf'" agentdb-backend.js
9
+ grep "3.0.0-alpha.3" package.json
10
+ package: @claude-flow/neural
11
+ grep "vectorBackend: 'rvf'" dist/reasoning-bank.js
12
+ package: @claude-flow/shared
13
+ grep "vectorBackend: 'rvf'" dist/core/config/defaults.js
@@ -0,0 +1,35 @@
1
+ # WM-009: Wire AgentDB learning loop (recordFeedback)
2
+
3
+ **Severity**: High
4
+ **GitHub**: [#1209](https://github.com/ruvnet/claude-flow/issues/1209)
5
+
6
+ ## Root Cause
7
+
8
+ WM-008 upgraded AgentDB v2 to v3 and exposed `recordFeedback(queryId, quality)` on the
9
+ agentdb-backend, but no MCP handler or CLI command ever calls it. The self-learning
10
+ feedback loop is wired at the backend level but dead from the user-facing layer.
11
+
12
+ `memory-tools.js` MCP handlers (`memory_search`, `memory_retrieve`) never track which
13
+ search results the agent subsequently retrieves. Without this implicit signal, the
14
+ `SelfLearningRvfBackend` cannot learn which results were useful.
15
+
16
+ ## Fix
17
+
18
+ | Op | Target | Change |
19
+ |----|--------|--------|
20
+ | A | `memory/memory-initializer.js` | Export `recordSearchFeedback(entryId, quality)` that delegates to `_hybridBackend.recordFeedback()` |
21
+ | B | `mcp-tools/memory-tools.js` | Add module-level `_recentSearchHits` Map; populate after `memory_search` returns results |
22
+ | C | `mcp-tools/memory-tools.js` | In `memory_retrieve`, call `recordSearchFeedback` when retrieved key was a recent search hit |
23
+
24
+ **Implicit feedback signal**: When an agent searches, then retrieves a specific result,
25
+ the retrieval is implicit positive feedback (quality = 1.0). The Map tracks
26
+ `namespace:key` -> `entryId` from the most recent search, enabling the feedback call.
27
+
28
+ ## Files Patched
29
+
30
+ - `memory/memory-initializer.js`
31
+ - `mcp-tools/memory-tools.js`
32
+
33
+ ## Ops
34
+
35
+ 3 ops in fix.py
@@ -0,0 +1,141 @@
1
+ # WM-009: Wire AgentDB learning loop (recordFeedback)
2
+ # GitHub: #1209
3
+
4
+ # ── Op A: Export recordSearchFeedback from memory-initializer.js ──
5
+ # Adds a thin wrapper that delegates to _hybridBackend.recordFeedback()
6
+ # Targets the code just before `export default {` at end of file
7
+ patch("WM-009a: add recordSearchFeedback export to memory-initializer.js",
8
+ MI,
9
+ """export default {
10
+ initializeMemoryDatabase,""",
11
+ """// WM-009a: Expose search feedback for self-learning loop
12
+ export async function recordSearchFeedback(entryId, quality) {
13
+ if (!_hybridBackend) return;
14
+ if (typeof _hybridBackend.recordFeedback === 'function') {
15
+ try { await _hybridBackend.recordFeedback(entryId, quality); } catch {}
16
+ }
17
+ }
18
+ export default {
19
+ initializeMemoryDatabase,""")
20
+
21
+ # ── Op B: Track search result entry IDs in memory-tools.js ──
22
+ # Adds a module-level Map and patches the import to include recordSearchFeedback.
23
+ patch("WM-009b: import recordSearchFeedback and add _recentSearchHits Map",
24
+ MCP_MEMORY,
25
+ """async function getMemoryFunctions() {
26
+ const { storeEntry, searchEntries, listEntries, getEntry, deleteEntry, initializeMemoryDatabase, checkMemoryInitialization, } = await import('../memory/memory-initializer.js');
27
+ return {
28
+ storeEntry,
29
+ searchEntries,
30
+ listEntries,
31
+ getEntry,
32
+ deleteEntry,
33
+ initializeMemoryDatabase,
34
+ checkMemoryInitialization,
35
+ };
36
+ }""",
37
+ """// WM-009b: Track recent search hits for implicit feedback
38
+ const _recentSearchHits = new Map();
39
+ async function getMemoryFunctions() {
40
+ const { storeEntry, searchEntries, listEntries, getEntry, deleteEntry, initializeMemoryDatabase, checkMemoryInitialization, recordSearchFeedback, } = await import('../memory/memory-initializer.js');
41
+ return {
42
+ storeEntry,
43
+ searchEntries,
44
+ listEntries,
45
+ getEntry,
46
+ deleteEntry,
47
+ initializeMemoryDatabase,
48
+ checkMemoryInitialization,
49
+ recordSearchFeedback,
50
+ };
51
+ }""")
52
+
53
+ # ── Op C: Populate _recentSearchHits after search returns results ──
54
+ # After results are mapped and before the return, record entry IDs in the Map.
55
+ # The raw result.results from searchEntries include .id fields from the backend.
56
+ patch("WM-009c: populate _recentSearchHits after memory_search",
57
+ MCP_MEMORY,
58
+ """ const results = result.results.map(r => {
59
+ let value = r.content;
60
+ try {
61
+ value = JSON.parse(r.content);
62
+ }
63
+ catch {
64
+ // Keep as string
65
+ }
66
+ return {
67
+ key: r.key,
68
+ namespace: r.namespace,
69
+ value,
70
+ similarity: r.score,
71
+ };
72
+ });
73
+ return {
74
+ query,
75
+ results,
76
+ total: results.length,
77
+ searchTime: `${duration.toFixed(2)}ms`,
78
+ backend: 'HNSW + sql.js',
79
+ };""",
80
+ """ const results = result.results.map(r => {
81
+ let value = r.content;
82
+ try {
83
+ value = JSON.parse(r.content);
84
+ }
85
+ catch {
86
+ // Keep as string
87
+ }
88
+ // WM-009c: Track entry ID for implicit feedback on later retrieve
89
+ if (r.id && r.key) {
90
+ const ns = r.namespace || 'default';
91
+ _recentSearchHits.set(`${ns}:${r.key}`, r.id);
92
+ }
93
+ return {
94
+ key: r.key,
95
+ namespace: r.namespace,
96
+ value,
97
+ similarity: r.score,
98
+ };
99
+ });
100
+ return {
101
+ query,
102
+ results,
103
+ total: results.length,
104
+ searchTime: `${duration.toFixed(2)}ms`,
105
+ backend: 'HNSW + sql.js',
106
+ };""")
107
+
108
+ # ── Op D: Record implicit positive feedback on retrieve ──
109
+ # When memory_retrieve successfully finds an entry that was in recent search results,
110
+ # call recordSearchFeedback with quality 1.0 (positive implicit feedback).
111
+ patch("WM-009d: call recordSearchFeedback on retrieve of recent search hit",
112
+ MCP_MEMORY,
113
+ """ handler: async (input) => {
114
+ await ensureInitialized();
115
+ const { getEntry } = await getMemoryFunctions();
116
+ const key = input.key;
117
+ const namespace = input.namespace;
118
+ if (!namespace || namespace === 'all') {
119
+ throw new Error('Namespace is required (cannot be "all"). Use namespace: "patterns", "solutions", or "tasks"');
120
+ }
121
+ try {
122
+ const result = await getEntry({ key, namespace });
123
+ if (result.found && result.entry) {""",
124
+ """ handler: async (input) => {
125
+ await ensureInitialized();
126
+ const { getEntry, recordSearchFeedback } = await getMemoryFunctions();
127
+ const key = input.key;
128
+ const namespace = input.namespace;
129
+ if (!namespace || namespace === 'all') {
130
+ throw new Error('Namespace is required (cannot be "all"). Use namespace: "patterns", "solutions", or "tasks"');
131
+ }
132
+ try {
133
+ const result = await getEntry({ key, namespace });
134
+ if (result.found && result.entry) {
135
+ // WM-009d: Implicit positive feedback — agent retrieved a search hit
136
+ const hitKey = `${namespace}:${key}`;
137
+ const trackedId = _recentSearchHits.get(hitKey);
138
+ if (trackedId && recordSearchFeedback) {
139
+ _recentSearchHits.delete(hitKey);
140
+ recordSearchFeedback(trackedId, 1.0).catch(() => {});
141
+ }""")
@@ -0,0 +1,3 @@
1
+ grep "_recentSearchHits" mcp-tools/memory-tools.js
2
+ grep "recordSearchFeedback" memory/memory-initializer.js
3
+ grep "WM-009d" mcp-tools/memory-tools.js
@@ -0,0 +1,33 @@
1
+ # WM-010: Wire witness chain verification at session start
2
+
3
+ **Severity**: High
4
+ **GitHub**: [#1208](https://github.com/ruvnet/claude-flow/issues/1208)
5
+
6
+ ## Root Cause
7
+
8
+ WM-008 exposed `verifyWitnessChain()` and `getWitnessChain()` methods on the
9
+ AgentDB backend, but no code in the session lifecycle actually calls them. The
10
+ witness chain hash is captured at init time (WM-008d) but never verified during
11
+ `doImport()`, so tampered memory databases go undetected at session start.
12
+
13
+ ## Fix
14
+
15
+ Patch `doImport()` in both the helpers-generator template and the source hook
16
+ to call `backend.verifyWitnessChain()` after `backend.initialize()`. The
17
+ verification is wrapped in try/catch so it is non-fatal -- if the backend
18
+ doesn't support witness chains (e.g. JSON backend or AgentDB v2), it silently
19
+ skips.
20
+
21
+ | Op | Target | Change |
22
+ |----|--------|--------|
23
+ | WM-010a | `init/helpers-generator.js` | After `await backend.initialize()` + busy_timeout in doImport template, add witness chain verification |
24
+ | WM-010b | `.claude/helpers/auto-memory-hook.mjs` | After `await backend.initialize()` + busy_timeout in doImport, add witness chain verification |
25
+
26
+ ## Files Patched
27
+
28
+ - `init/helpers-generator.js`
29
+ - `.claude/helpers/auto-memory-hook.mjs` (source hook)
30
+
31
+ ## Ops
32
+
33
+ 2 ops in fix.py
@@ -0,0 +1,45 @@
1
+ # WM-010: Wire witness chain verification at session start
2
+ # GitHub: #1208
3
+
4
+ # ── Op A: helpers-generator.js doImport() — add witness chain verify after init ──
5
+ # Targets the state AFTER WM-003a (doImport HybridBackend) has been applied.
6
+ # Unique context: "const sqlBe = backend.getSQLiteBackend();" only appears in doImport
7
+ # (doSync uses different code after initialize).
8
+ patch("WM-010a: helpers-generator doImport() witness chain verification",
9
+ HELPERS_GEN,
10
+ """ await backend.initialize();
11
+ const sqlBe = backend.getSQLiteBackend();
12
+ if (sqlBe && sqlBe.db) sqlBe.db.pragma('busy_timeout = 5000');
13
+ const bridge = new AutoMemoryBridge(backend, {""",
14
+ """ await backend.initialize();
15
+ const sqlBe = backend.getSQLiteBackend();
16
+ if (sqlBe && sqlBe.db) sqlBe.db.pragma('busy_timeout = 5000');
17
+ // WM-010a: Verify witness chain integrity at session start
18
+ try {
19
+ if (typeof backend.verifyWitnessChain === 'function') {
20
+ const wc = await backend.verifyWitnessChain();
21
+ if (wc && !wc.valid) dim('WARNING: witness chain verification failed \\u2014 memory may be tampered');
22
+ }
23
+ } catch (e) { /* witness chain not available, skip */ }
24
+ const bridge = new AutoMemoryBridge(backend, {""")
25
+
26
+ # ── Op B: auto-memory-hook.mjs doImport() — add witness chain verify after init ──
27
+ # Targets the state AFTER WM-004b (createBackend).
28
+ # Unique context: "await backend.initialize();\n\n const bridgeConfig" only in doImport
29
+ # (doSync has "const entryCount" after initialize, not "const bridgeConfig").
30
+ patch("WM-010b: source hook doImport() witness chain verification",
31
+ SRC_AUTO_MEMORY_HOOK,
32
+ """ await backend.initialize();
33
+
34
+ const bridgeConfig = {""",
35
+ """ await backend.initialize();
36
+
37
+ // WM-010b: Verify witness chain integrity at session start
38
+ try {
39
+ if (typeof backend.verifyWitnessChain === 'function') {
40
+ const wc = await backend.verifyWitnessChain();
41
+ if (wc && !wc.valid) dim('WARNING: witness chain verification failed \u2014 memory may be tampered');
42
+ }
43
+ } catch { /* witness chain not available, skip */ }
44
+
45
+ const bridgeConfig = {""")
@@ -0,0 +1 @@
1
+ grep "WM-010a" init/helpers-generator.js
@@ -0,0 +1,34 @@
1
+ # WM-011: Instantiate ReasoningBank controller
2
+
3
+ **Severity**: High
4
+ **GitHub**: [#1210](https://github.com/ruvnet/claude-flow/issues/1210)
5
+
6
+ ## Root Cause
7
+
8
+ `memory-initializer.js` creates HybridBackend + AgentDB v3 but never instantiates `ReasoningBank` from `@claude-flow/neural`. The `hooks_intelligence_pattern-store` and `hooks_intelligence_pattern-search` MCP tools use generic `storeEntry`/`searchEntries` which lack the ReasoningBank's 4-step learning pipeline (retrieve, judge, distill, consolidate), MMR-diverse retrieval, deduplication, and contradiction detection.
9
+
10
+ As a result:
11
+ - Patterns stored as plain key-value entries instead of trajectory-backed patterns
12
+ - Pattern search uses generic SQLite/keyword search instead of MMR-diverse vector retrieval
13
+ - Consolidation pipeline never runs (dedup, contradiction detection, pruning)
14
+ - Pattern evolution tracking and quality history are lost
15
+
16
+ ## Fix
17
+
18
+ | Op | Target | Change |
19
+ |----|--------|--------|
20
+ | WM-011a | `memory/memory-initializer.js` | After HybridBackend init, import `ReasoningBank` from `@claude-flow/neural` and create+initialize an instance sharing the AgentDB RVF path |
21
+ | WM-011a2 | `memory/memory-initializer.js` | Add `_reasoningBank` module-level variable declaration |
22
+ | WM-011a3 | `memory/memory-initializer.js` | Export `getReasoningBank()` getter function |
23
+ | WM-011b | `mcp-tools/hooks-tools.js` | Add `getReasoningBankInstance()` lazy loader |
24
+ | WM-011c | `mcp-tools/hooks-tools.js` | Replace `hooksPatternStore` handler to use ReasoningBank trajectory distillation with fallback |
25
+ | WM-011d | `mcp-tools/hooks-tools.js` | Replace `hooksPatternSearch` handler to use ReasoningBank MMR-diverse retrieval with fallback |
26
+
27
+ ## Files Patched
28
+
29
+ - `memory/memory-initializer.js`
30
+ - `mcp-tools/hooks-tools.js`
31
+
32
+ ## Ops
33
+
34
+ 6 ops in fix.py