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(memory,daemon): stop destroying a user index, honour autoStart:false, and finish the sibling disclosure (#3282)

rUv13880e3aa43d
diff --git a/v3/@claude-flow/cli/__tests__/issue-3278-daemon-autostart-consent.test.ts b/v3/@claude-flow/cli/__tests__/issue-3278-daemon-autostart-consent.test.ts
new file mode 100644
index 0000000000..28a2e990d2
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/issue-3278-daemon-autostart-consent.test.ts
@@ -0,0 +1,54 @@
+/**
+ * #3278 β€” `autoStart: false` must actually prevent autostart.
+ *
+ * The disable check read `claude-flow.config.json` β†’ `daemon.autostart`, while
+ * `init` generates `.claude/settings.json` β†’ `claudeFlow.daemon.autoStart`.
+ * A different file and a different capital S, so the one setting a fresh project
+ * ships was never consulted and the daemon spawned anyway β€” spending exactly the
+ * tokens that generated comment says it prevents (#1427, #1330).
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+const load = async () => await import('../src/services/daemon-autostart.js');
+let dir: string;
+beforeEach(() => { dir = mkdtempSync(join(tmpdir(), 'd3278-')); });
+afterEach(() => { try { rmSync(dir, { recursive: true, force: true }); } catch { /* */ } });
+
+function settings(json: unknown) {
+ mkdirSync(join(dir, '.claude'), { recursive: true });
+ writeFileSync(join(dir, '.claude', 'settings.json'), JSON.stringify(json));
+}
+
+describe('#3278 daemon autostart consent', () => {
+ it('honours claudeFlow.daemon.autoStart:false from the file init actually writes', async () => {
+ const { ensureDaemonRunning } = await load();
+ settings({ claudeFlow: { daemon: { autoStart: false, workers: ['map'] } } });
+ const r = ensureDaemonRunning(dir) as { started?: boolean; reason?: string };
+ expect(r.started, 'a generated autoStart:false must not spawn a daemon').not.toBe(true);
+ });
+
+ it('still honours the legacy lowercase key in claude-flow.config.json', async () => {
+ const { ensureDaemonRunning } = await load();
+ writeFileSync(join(dir, 'claude-flow.config.json'), JSON.stringify({ daemon: { autostart: false } }));
+ const r = ensureDaemonRunning(dir) as { started?: boolean };
+ expect(r.started).not.toBe(true);
+ });
+
+ it('accepts either spelling in either file, so a plausible config is not ignored', async () => {
+ const { ensureDaemonRunning } = await load();
+ settings({ claudeFlow: { daemon: { autostart: false } } }); // lowercase in settings.json
+ expect((ensureDaemonRunning(dir) as { started?: boolean }).started).not.toBe(true);
+ });
+
+ it('a settings file with no daemon opinion is not treated as consent to disable', async () => {
+ const { ensureDaemonRunning } = await load();
+ settings({ claudeFlow: { hooks: {} } });
+ // Nothing asserted about starting here β€” only that an absent opinion is not
+ // read as `false`, which would be the mirror-image bug.
+ const r = ensureDaemonRunning(dir) as { started?: boolean; reason?: string };
+ expect(r.reason ?? '').not.toMatch(/autostart disabled/i);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts
index cedfe97611..ca06bcaeae 100644
--- a/v3/@claude-flow/cli/src/commands/memory.ts
+++ b/v3/@claude-flow/cli/src/commands/memory.ts
@@ -12,6 +12,26 @@ import { backupCommand } from './memory-backup.js';
import { countSiblingStoreRows } from '../memory/sibling-store.js';
import { resolveDbPath } from '../memory/memory-initializer.js';
+/**
+ * #3228: a miss in one store is not a miss in the memory.
+ *
+ * 3.41.1 disclosed the sibling AgentDB store from `memory list` only. `retrieve`,
+ * `search` and `stats` kept reporting a clean negative β€” "Key not found", "No
+ * results" β€” while the rows sat in the file this interface does not read. On the
+ * reported Windows install that is 31,673 rows in the other store answering
+ * `found:false`. A confident negative is worse than an error, because nothing
+ * prompts anyone to look further.
+ */
+async function warnIfSiblingHasRows(pathFlag: unknown): Promise<void> {
+ const unread = await countSiblingStoreRows(resolveDbPath(pathFlag as string | undefined));
+ if (unread && unread.rows > 0) {
+ output.printWarning(
+ `This read covered one store. ${unread.rows} entries are in ${unread.path} and were not searched. ` +
+ `That store is written by the MCP/AgentDB path; read it with --path ${unread.path}.`,
+ );
+ }
+}
+
// Memory backends
const BACKENDS = [
{ value: 'agentdb', label: 'AgentDB', hint: 'Vector database with HNSW indexing (150x-12,500x faster)' },
@@ -309,6 +329,7 @@ const retrieveCommand: Command = {
if (!result.found || !result.entry) {
output.printWarning(`Key not found: ${key}`);
+ await warnIfSiblingHasRows(ctx.flags.path);
return { success: false, exitCode: 1, data: { key, found: false } };
}
@@ -710,6 +731,7 @@ const searchCommand: Command = {
if (results.length === 0) {
output.printWarning('No results found');
+ await warnIfSiblingHasRows(ctx.flags.path);
output.writeln(output.dim('Try: claude-flow memory store -k "key" --value "data"'));
return { success: true, data: [] };
}
@@ -798,6 +820,7 @@ const listCommand: Command = {
if (entries.length === 0) {
output.printWarning('No entries found');
+ await warnIfSiblingHasRows(ctx.flags.path);
output.printInfo('Store data: claude-flow memory store -k "key" --value "data"');
return { success: true, data: [] };
}
diff --git a/v3/@claude-flow/cli/src/services/daemon-autostart.ts b/v3/@claude-flow/cli/src/services/daemon-autostart.ts
index d45fa17dff..3ca941775e 100644
--- a/v3/@claude-flow/cli/src/services/daemon-autostart.ts
+++ b/v3/@claude-flow/cli/src/services/daemon-autostart.ts
@@ -50,13 +50,30 @@ export function isDaemonAlive(projectRoot: string): boolean {
/** Project-local opt-out: `{ "daemon": { "autostart": false } }` in claude-flow.config.json. */
function autostartDisabledByProjectConfig(projectRoot: string): boolean {
- try {
- const raw = fs.readFileSync(path.join(projectRoot, 'claude-flow.config.json'), 'utf-8');
- const cfg = JSON.parse(raw);
- return cfg?.daemon?.autostart === false;
- } catch {
- return false; // absent/malformed config = not disabled
+ // #3278: read BOTH files, and both spellings.
+ //
+ // This used to consult only `claude-flow.config.json` with the key
+ // `daemon.autostart`. But `init` generates `.claude/settings.json` with
+ // `claudeFlow.daemon.autoStart` β€” a different file and a different capital S β€”
+ // and writes it `false` under the comment "Opt-in only β€” prevents unintended
+ // token consumption (#1427, #1330)". So the one setting a fresh project
+ // actually ships was never read, and the runtime spent tokens the generated
+ // config existed to prevent. Accept either spelling in either file: a user who
+ // wrote the word "autostart: false" anywhere sensible meant it.
+ const readsFalse = (v: unknown) => v === false;
+ for (const [file, pick] of [
+ ['claude-flow.config.json', (c: any) => c?.daemon],
+ [path.join('.claude', 'settings.json'), (c: any) => c?.claudeFlow?.daemon],
+ ] as const) {
+ try {
+ const cfg = JSON.parse(fs.readFileSync(path.join(projectRoot, file), 'utf-8'));
+ const d = pick(cfg);
+ if (readsFalse(d?.autostart) || readsFalse(d?.autoStart)) return true;
+ } catch {
+ // absent/malformed config = this file says nothing; keep checking the others
+ }
}
+ return false;
}
function autostartDisabled(projectRoot: string): boolean {
diff --git a/v3/@claude-flow/memory/src/auto-memory-bridge.ts b/v3/@claude-flow/memory/src/auto-memory-bridge.ts
index 94e1373ab5..374bc54b66 100644
--- a/v3/@claude-flow/memory/src/auto-memory-bridge.ts
+++ b/v3/@claude-flow/memory/src/auto-memory-bridge.ts
@@ -507,7 +507,42 @@ export class AutoMemoryBridge extends EventEmitter {
sectionOrder,
);
- await fs.writeFile(this.getIndexPath(), lines.join('\n'), 'utf-8');
+ // #3224: never let a curate shrink somebody's index.
+ //
+ // The #1556 guard above only fires when NOTHING matched. Once the bridge has
+ // written its own first topic file, that guard stops applying, and this write
+ // replaces a hand-maintained MEMORY.md with a generated stub β€” 75 curated
+ // lines and 49 links down to 6 in the reported case. The bridge only knows
+ // about its own topic files, so "everything else" looks like nothing to it.
+ //
+ // Rule: a curate may grow or reorder the index, never shrink it. When the
+ // generated view is smaller than what is on disk, keep the file, write the
+ // generated view beside it, and say so.
+ const indexPath = this.getIndexPath();
+ const generated = lines.join('\n');
+ let existing = '';
+ try { existing = await fs.readFile(indexPath, 'utf-8'); } catch { /* first run */ }
+
+ const linksIn = (text: string) => (text.match(/\]\(/g) ?? []).length;
+ const wouldLose = existing.trim().length > 0
+ && (linksIn(existing) > linksIn(generated) || existing.split('\n').length > lines.length);
+
+ if (wouldLose) {
+ const sidecar = indexPath.replace(/\.md$/, '') + '.generated.md';
+ await fs.writeFile(sidecar, generated, 'utf-8');
+ this.emit('index:preserved', {
+ reason: 'would-shrink-user-index',
+ indexPath,
+ sidecar,
+ existingLines: existing.split('\n').length,
+ generatedLines: lines.length,
+ existingLinks: linksIn(existing),
+ generatedLinks: linksIn(generated),
+ });
+ return;
+ }
+
+ await fs.writeFile(indexPath, generated, 'utf-8');
this.emit('index:curated', { lines: lines.length });
}
diff --git a/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts b/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts
new file mode 100644
index 0000000000..cf96a0476d
--- /dev/null
+++ b/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts
@@ -0,0 +1,54 @@
+/**
+ * #3224 β€” a curate may grow or reorder the index, never shrink it.
+ *
+ * `curateIndex()` rebuilds MEMORY.md from the bridge's own topic files. The
+ * #1556 guard only skips the write when NOTHING matched β€” but the bridge writes
+ * the first topic file itself, so after the first insight the guard stops
+ * applying and the rebuild replaces a hand-maintained index with a stub. The
+ * reported case lost 75 lines and 49 links.
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { AutoMemoryBridge } from './auto-memory-bridge.js';
+
+let dir: string;
+beforeEach(() => { dir = mkdtempSync(join(tmpdir(), 'm3224-')); });
+afterEach(() => { try { rmSync(dir, { recursive: true, force: true }); } catch { /* */ } });
+
+/** A hand-maintained index: many links, no relation to the bridge's topic files. */
+function writeUserIndex(): string {
+ const lines = ['# Project Memory', ''];
+ for (let i = 0; i < 49; i++) lines.push(`- [Note ${i}](note_${i}.md) β€” something I wrote`);
+ const body = lines.join('\n');
+ writeFileSync(join(dir, 'MEMORY.md'), body, 'utf-8');
+ return body;
+}
+
+describe('#3224 curateIndex must not destroy a user index', () => {
+ it('keeps a larger hand-maintained index and writes the generated view beside it', async () => {
+ const before = writeUserIndex();
+ // One topic file exists, so the #1556 guard no longer applies β€” the exact
+ // state the bridge puts itself in after its first insight.
+ writeFileSync(join(dir, 'patterns.md'), '# Patterns\n\n- one generated line\n', 'utf-8');
+
+ const bridge = new AutoMemoryBridge({} as never, { memoryDir: dir } as never);
+ const preserved: unknown[] = [];
+ bridge.on('index:preserved', (e: unknown) => preserved.push(e));
+ await bridge.curateIndex();
+
+ const after = readFileSync(join(dir, 'MEMORY.md'), 'utf-8');
+ expect(after, 'the user index must survive verbatim').toBe(before);
+ expect((after.match(/\]\(/g) ?? []).length).toBe(49);
+ expect(preserved.length, 'and the bridge must say it declined').toBe(1);
+ expect(existsSync(join(dir, 'MEMORY.generated.md')), 'generated view goes beside it').toBe(true);
+ });
+
+ it('still writes the index when there is nothing to lose', async () => {
+ writeFileSync(join(dir, 'patterns.md'), '# Patterns\n\n- generated\n', 'utf-8');
+ const bridge = new AutoMemoryBridge({} as never, { memoryDir: dir } as never);
+ await bridge.curateIndex();
+ expect(existsSync(join(dir, 'MEMORY.md'))).toBe(true);
+ });
+});