From 4467aeebba6207ffb59dd9cb552d18651b476882 Mon Sep 17 00:00:00 2001 From: ruv Date: Mon, 27 Jul 2026 10:11:07 -0400 Subject: [PATCH] fix(memory): ADR-125 CLI-flag precedence over RUFLO_MEMORY_SCAN_ON_WRITE (#2794) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verification agent (12-hour cadence, #2794) caught v3.32.17's #2752 MemPoison env var without the ADR-125 §"CLI flag wins" / ADR-130 §env-var-config-precedence pattern. CI on main red since 03:04 UTC. Fix (Option A per the report): restructure the read so the CLI flag takes precedence via nullish coalescing, with the exact ADR-125 comment the audit script scans for: // CLI flag ctx.flags.scanContent takes precedence over // RUFLO_MEMORY_SCAN_ON_WRITE env var (ADR-125 / ADR-130 — #2794). const scanContent = (ctx.flags.scanContent as boolean | undefined) ?? /^(1|true|yes|on)$/i.test(String(process.env.RUFLO_MEMORY_SCAN_ON_WRITE ?? '')); Removed `default: false` from the option definition so the parser leaves the flag `undefined` when the user doesn't pass it — required for `?? env` to see the env value. Explicit `--no-scan-content` still sets false and correctly wins over any env value. Audit script confirms: "ok: all CLAUDE_FLOW_* / RUFLO_* env var reads have documented CLI-flag precedence". Regression tests still pass: planflip-mempoison-2752 (6/6) + memory-search-2790 (4/4) — 10/10 total for the affected paths. Closes: #2794. Co-Authored-By: RuFlo --- v3/@claude-flow/cli/src/commands/memory.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts index 81db6da30a..a31bb40931 100644 --- a/v3/@claude-flow/cli/src/commands/memory.ts +++ b/v3/@claude-flow/cli/src/commands/memory.ts @@ -83,10 +83,13 @@ const storeCommand: Command = { // on the value BEFORE persistence and refuse the write if a // finding is present. Opt-in per-call; RUFLO_MEMORY_SCAN_ON_WRITE=1 // enables it globally. + // NOTE: no `default:` here — needed so the ADR-125 CLI-flag-wins + // precedence (`ctx.flags.scanContent ?? envVar`) can distinguish + // "user didn't pass the flag" (undefined) from "user explicitly + // said --no-scan-content" (false). Fixes #2794. name: 'scan-content', description: 'Scan the value for injection payloads before persisting (dream-cycle #2752 MemPoison gate)', type: 'boolean', - default: false }, DB_PATH_OPTION ], @@ -135,9 +138,11 @@ const storeCommand: Command = { } // #2752 MemPoison gate — scan before persist when opted in. - const scanContentFlag = ctx.flags.scanContent as boolean | undefined; - const scanContentEnv = /^(1|true|yes|on)$/i.test(String(process.env.RUFLO_MEMORY_SCAN_ON_WRITE ?? '')); - if (scanContentFlag || scanContentEnv) { + // CLI flag ctx.flags.scanContent takes precedence over RUFLO_MEMORY_SCAN_ON_WRITE env var + // (ADR-125 §"CLI flag wins" / ADR-130 §env-var-config-precedence — fix for #2794). + const scanContent = (ctx.flags.scanContent as boolean | undefined) + ?? /^(1|true|yes|on)$/i.test(String(process.env.RUFLO_MEMORY_SCAN_ON_WRITE ?? '')); + if (scanContent) { try { const { scanChannelMessage } = await import('../security/channel-guard.js'); const scan = scanChannelMessage(value);