Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(cli-core): measure JSON memory size in UTF-8 bytes

Rudy Celeklic7314d700a31
diff --git a/tests/json-memory-size.test.mjs b/tests/json-memory-size.test.mjs
new file mode 100644
index 0000000000..61f12ebcca
--- /dev/null
+++ b/tests/json-memory-size.test.mjs
@@ -0,0 +1,10 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtempSync, rmSync, statSync } from 'node:fs';
+import { join } from 'node:path';
+import { tmpdir } from 'node:os';
+import { JsonMemoryBackend } from '../v3/@claude-flow/cli-core/src/memory/json-backend.ts';
+for (const value of ['plain ASCII', '東京🙂'.repeat(100)]) test(`sizeBytes matches actual UTF-8 file size for ${value.slice(0, 8)}`, async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'json-size-')); const path = join(dir, 'memory.json');
+ try { const b = new JsonMemoryBackend({ path }); await b.store('key', value); assert.equal((await b.stats()).sizeBytes, statSync(path).size); } finally { rmSync(dir, { recursive: true, force: true }); }
+});
diff --git a/v3/@claude-flow/cli-core/src/memory/json-backend.ts b/v3/@claude-flow/cli-core/src/memory/json-backend.ts
index 50fe873ec2..cb16c3c660 100644
--- a/v3/@claude-flow/cli-core/src/memory/json-backend.ts
+++ b/v3/@claude-flow/cli-core/src/memory/json-backend.ts
@@ -193,7 +193,7 @@ export class JsonMemoryBackend implements MemoryBackend {
const entries = Object.values(state.entries);
const namespaces = [...new Set(entries.map((e) => e.namespace))].sort();
const sizeBytes = existsSync(this.path)
- ? readFileSync(this.path, 'utf-8').length
+ ? Buffer.byteLength(readFileSync(this.path, 'utf-8'), 'utf-8')
: 0;
return {
totalEntries: entries.length,