🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(auto-memory): snapshot store ids before dedup so id-less entries are not re-added by the merge (#4058)
r3111685d3714
diff --git a/.claude/helpers/intelligence.cjs b/.claude/helpers/intelligence.cjsindex 4266dfa67a..0e51a56cae 100755--- a/.claude/helpers/intelligence.cjs+++ b/.claude/helpers/intelligence.cjs@@ -141,16 +141,22 @@ function withStoreLock(filePath, fn) {try { return fn(); } finally { if (held) { try { fs.rmdirSync(lock); } catch { /* already gone */ } } }}+// IDs present when the store was read. Take this BEFORE deduping: those passes+// assign IDs to entries in place, and an entry that had none must still count as+// ours (not as something another writer added).+function storeIds(loaded) {+ return new Set((Array.isArray(loaded) ? loaded : []).map((e) => e && e.id));+}+// Write the store, keeping entries another writer added after we read it.-function writeStoreMerged(filePath, next, loaded) {- const loadedIds = new Set((Array.isArray(loaded) ? loaded : []).map((e) => e && e.id));+function writeStoreMerged(filePath, next, loadedIds) {withStoreLock(filePath, () => {let out = next;try {const current = JSON.parse(fs.readFileSync(filePath, 'utf-8'));if (Array.isArray(current)) {const have = new Set(next.map((e) => e && e.id));- const added = current.filter((e) => e && !loadedIds.has(e.id) && !have.has(e.id));+ const added = current.filter((e) => e && e.id != null && !loadedIds.has(e.id) && !have.has(e.id));if (added.length) out = next.concat(added);}} catch { /* missing or unreadable: write ours */ }@@ -520,13 +526,14 @@ function init() {// Check if graph-state.json is fresh (within 60s of store)const graphState = readJSON(GRAPH_PATH);let store = readJSON(STORE_PATH);+ const loadedIds = storeIds(store);// Bootstrap from MEMORY.md files if store is emptyif (!store || !Array.isArray(store) || store.length === 0) {const bootstrapped = bootstrapFromMemoryFiles();if (bootstrapped.length > 0) {store = bootstrapped;- writeStoreMerged(STORE_PATH, store, []);+ writeStoreMerged(STORE_PATH, store, loadedIds);} else {return { nodes: 0, edges: 0, message: 'No memory entries to index' };}@@ -548,7 +555,7 @@ function init() {`[INTELLIGENCE] Deduped store: ${store.length} -> ${deduped.length} entries ` +`(by-id: ${store.length - beforeContentDedup} dropped, by-content: ${beforeContentDedup - deduped.length} dropped)\n`);- writeStoreMerged(STORE_PATH, deduped, store);+ writeStoreMerged(STORE_PATH, deduped, loadedIds);}// Skip rebuild if graph is fresh and store hasn't changed. #2920: nodeCount@@ -879,7 +886,7 @@ function consolidate() {return { entries: 0, edges: 0, newEntries: 0, message: 'No store to consolidate' };}- const loadedStore = store;+ const loadedIds = storeIds(store);// Deduplicate store entries by ID before processing (fixes #1518)const preDedupCount = store.length;store = deduplicateById(store);@@ -1025,7 +1032,7 @@ function consolidate() {// RANKED_PATH are rewritten unconditionally just above; writing the// (already deduped, size-bounded per ADR-095 G6) store alongside them// costs nothing near the <500ms budget and removes the whole bug class.- writeStoreMerged(STORE_PATH, store, loadedStore);+ writeStoreMerged(STORE_PATH, store, loadedIds);// 9. Save snapshot for delta trackingconst updatedGraph = readJSON(GRAPH_PATH);diff --git a/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json b/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.jsonindex dede55f015..cc47df3950 100644--- a/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json+++ b/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json@@ -4,11 +4,11 @@"files": {"auto-memory-hook.mjs": "631fac9d518835e2852a406888316bbbddddb49e7ed8e406d2e971f46833df9a","hook-handler.cjs": "0f855c667b8d2d04cb4fe91b14b351d14c3dfb30516dcd9d7ae156acbe0a689d",- "intelligence.cjs": "f172483416381593d103130c96adc8dfd2eb1f4c85eee27a84c5ad1eba7d0ef2",+ "intelligence.cjs": "f486be296eb2f0518f34b8f4453d9d0a988845e4aec6d18d8d47725aca6dd38b","statusline.cjs": "d72417ecb38634011a19f095a30e07b9929e6f97663520172ece9be7491b2eaa","router.cjs": "16648b3c0d73b6681ac2d8d13def6a68286c57f5a11004de5b19a0fa088c833d"}},- "signature": "ExTq6zXk6QpG2EoNKRS8D8G46q0Uje/5K0JoByXiW6+veZYvJF0xa4ASwTyNSZE0F0eg5LgyIH6W6oAwUoQFBg==",+ "signature": "4g0PLbLPrkTg0vMfU01LQAUc8o351z5W0VnfTo1Rnk9NavvC2uLZ7b+qGpqQV7jWT8mxAomfaIIsyjNwpMVhBA==","algorithm": "ed25519"}diff --git a/v3/@claude-flow/cli/.claude/helpers/intelligence.cjs b/v3/@claude-flow/cli/.claude/helpers/intelligence.cjsindex 4266dfa67a..0e51a56cae 100755--- a/v3/@claude-flow/cli/.claude/helpers/intelligence.cjs+++ b/v3/@claude-flow/cli/.claude/helpers/intelligence.cjs@@ -141,16 +141,22 @@ function withStoreLock(filePath, fn) {try { return fn(); } finally { if (held) { try { fs.rmdirSync(lock); } catch { /* already gone */ } } }}+// IDs present when the store was read. Take this BEFORE deduping: those passes+// assign IDs to entries in place, and an entry that had none must still count as+// ours (not as something another writer added).+function storeIds(loaded) {+ return new Set((Array.isArray(loaded) ? loaded : []).map((e) => e && e.id));+}+// Write the store, keeping entries another writer added after we read it.-function writeStoreMerged(filePath, next, loaded) {- const loadedIds = new Set((Array.isArray(loaded) ? loaded : []).map((e) => e && e.id));+function writeStoreMerged(filePath, next, loadedIds) {withStoreLock(filePath, () => {let out = next;try {const current = JSON.parse(fs.readFileSync(filePath, 'utf-8'));if (Array.isArray(current)) {const have = new Set(next.map((e) => e && e.id));- const added = current.filter((e) => e && !loadedIds.has(e.id) && !have.has(e.id));+ const added = current.filter((e) => e && e.id != null && !loadedIds.has(e.id) && !have.has(e.id));if (added.length) out = next.concat(added);}} catch { /* missing or unreadable: write ours */ }@@ -520,13 +526,14 @@ function init() {// Check if graph-state.json is fresh (within 60s of store)const graphState = readJSON(GRAPH_PATH);let store = readJSON(STORE_PATH);+ const loadedIds = storeIds(store);// Bootstrap from MEMORY.md files if store is emptyif (!store || !Array.isArray(store) || store.length === 0) {const bootstrapped = bootstrapFromMemoryFiles();if (bootstrapped.length > 0) {store = bootstrapped;- writeStoreMerged(STORE_PATH, store, []);+ writeStoreMerged(STORE_PATH, store, loadedIds);} else {return { nodes: 0, edges: 0, message: 'No memory entries to index' };}@@ -548,7 +555,7 @@ function init() {`[INTELLIGENCE] Deduped store: ${store.length} -> ${deduped.length} entries ` +`(by-id: ${store.length - beforeContentDedup} dropped, by-content: ${beforeContentDedup - deduped.length} dropped)\n`);- writeStoreMerged(STORE_PATH, deduped, store);+ writeStoreMerged(STORE_PATH, deduped, loadedIds);}// Skip rebuild if graph is fresh and store hasn't changed. #2920: nodeCount@@ -879,7 +886,7 @@ function consolidate() {return { entries: 0, edges: 0, newEntries: 0, message: 'No store to consolidate' };}- const loadedStore = store;+ const loadedIds = storeIds(store);// Deduplicate store entries by ID before processing (fixes #1518)const preDedupCount = store.length;store = deduplicateById(store);@@ -1025,7 +1032,7 @@ function consolidate() {// RANKED_PATH are rewritten unconditionally just above; writing the// (already deduped, size-bounded per ADR-095 G6) store alongside them// costs nothing near the <500ms budget and removes the whole bug class.- writeStoreMerged(STORE_PATH, store, loadedStore);+ writeStoreMerged(STORE_PATH, store, loadedIds);// 9. Save snapshot for delta trackingconst updatedGraph = readJSON(GRAPH_PATH);