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); +};