From aeeeff72f59ad6150db2ab0230b43cdafc622508 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 3 May 2026 17:34:22 -0400 Subject: [PATCH] fix(cli): extract suppression to side-effect module imported FIRST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3.6.18 smoke test caught that the [AgentDB Patch] warning still leaked through the ruflo wrapper — even after iteration #11's "move to src/index.ts" attempt. Root cause: ES module imports hoist above any top-level code in the same module, so the inline suppression block ran AFTER `import { commands } from './commands/index.js'`, by which point agentic-flow had already been loaded transitively and emitted its warning. Fix: extracted the patch into `src/log-filters.ts` as a side-effect module and imported it as the FIRST import statement in src/index.ts: import './log-filters.js'; // ← evaluated first in import graph import { readFileSync } from 'fs'; import { commands } from './commands/index.js'; ... ES module evaluation order is the source order of imports, so log-filters.js runs its side effect (patches console.warn/log) before any sibling import can transitively load agentic-flow. bin/cli.js and bin/mcp-server.js keep their inline suppression as defense-in-depth (covers cases where the bin file's own crypto/etc. imports run before src/index.js loads). Verified via ruflo wrapper: $ node ruflo/bin/ruflo.js --version ruflo v3.6.18 # no warning prefix anymore Co-Authored-By: RuFlo --- v3/@claude-flow/cli/src/index.ts | 32 ++++++----------------- v3/@claude-flow/cli/src/log-filters.ts | 35 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 v3/@claude-flow/cli/src/log-filters.ts diff --git a/v3/@claude-flow/cli/src/index.ts b/v3/@claude-flow/cli/src/index.ts index f452dc9bfe..bce02b9e47 100644 --- a/v3/@claude-flow/cli/src/index.ts +++ b/v3/@claude-flow/cli/src/index.ts @@ -5,31 +5,13 @@ * Created with ❤️ by ruv.io */ -// MUST run before any agentic-flow / agentdb imports — this file is -// imported by every entry point (bin/cli.js, ruflo/bin/ruflo.js via -// dist/src/index.js, and tests). Patching the console here ensures the -// suppression applies regardless of how the CLI was invoked. Previously -// the suppression lived only in bin/cli.js, so the ruflo wrapper (which -// imports dist/src/index.js directly) leaked the cosmetic warning. -// -// Tight match: requires BOTH "[AgentDB Patch]" AND "Controller index not -// found" so other [AgentDB Patch] messages (real issues) still flow. -{ - const _isCosmeticAgentdbPatchNoise = (msg: unknown): boolean => { - const s = String(msg ?? ''); - return s.includes('[AgentDB Patch]') && s.includes('Controller index not found'); - }; - const _origWarn = console.warn.bind(console); - const _origLog = console.log.bind(console); - console.warn = (...args: unknown[]) => { - if (_isCosmeticAgentdbPatchNoise(args[0])) return; - _origWarn(...args); - }; - console.log = (...args: unknown[]) => { - if (_isCosmeticAgentdbPatchNoise(args[0])) return; - _origLog(...args); - }; -} +// MUST be the first import — installs console filter for the cosmetic +// "[AgentDB Patch] Controller index not found" warning before any +// agentic-flow / agentdb code can load. ES module imports are evaluated +// in source order, so this file runs its side effects before any other +// import in this module's import graph (including transitive imports of +// agentic-flow via commands/index.js). +import './log-filters.js'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; diff --git a/v3/@claude-flow/cli/src/log-filters.ts b/v3/@claude-flow/cli/src/log-filters.ts new file mode 100644 index 0000000000..83426167e3 --- /dev/null +++ b/v3/@claude-flow/cli/src/log-filters.ts @@ -0,0 +1,35 @@ +/** + * Console filter for the cosmetic "[AgentDB Patch] Controller index not found" + * warning emitted by agentic-flow's runtime patch (it expects agentdb v1.x + * layout but we use v3). This file MUST be imported as the first side-effect + * import in any entry point so the patch is in place before agentic-flow + * (and anything that transitively imports it) loads. + * + * The previous attempt put the suppression as a top-level code block inside + * src/index.ts, but ES module imports are evaluated before the file's own + * top-level code, so transitive imports of agentic-flow were still + * triggering the warning before the suppression took effect. A dedicated + * side-effect module imported FIRST avoids that. + * + * Tight match: requires BOTH "[AgentDB Patch]" AND "Controller index not + * found". Other [AgentDB Patch] messages (real issues) flow through. + * Audit log audit_1776483149979 flagged the previous broad filter as too + * aggressive — this one is tight enough to be safe. + */ + +const isCosmeticAgentdbPatchNoise = (msg: unknown): boolean => { + const s = String(msg ?? ''); + return s.includes('[AgentDB Patch]') && s.includes('Controller index not found'); +}; + +const origWarn = console.warn.bind(console); +const origLog = console.log.bind(console); + +console.warn = (...args: unknown[]) => { + if (isCosmeticAgentdbPatchNoise(args[0])) return; + origWarn(...args); +}; +console.log = (...args: unknown[]) => { + if (isCosmeticAgentdbPatchNoise(args[0])) return; + origLog(...args); +};