From f615ea9476b318dc5ef43586d728e737f2100089 Mon Sep 17 00:00:00 2001 From: ttxenonmarketing-ux Date: Wed, 20 May 2026 13:40:59 +0700 Subject: [PATCH] fix(cost-tracker): spawnSync npx ENOENT on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows + Node >=21, spawnSync('npx', [...]) returns ENOENT because Node cannot resolve the npx.cmd shim without shell:true (CVE-2024-27980 batBadButLong mitigation). The 7 cost-tracker scripts all failed silently: - cost track: Persisted: FAILED (exit null) - cost summary/report/conversation/budget/export/federation/optimize: return empty arrays from memory list+retrieve Add shell: process.platform === 'win32' to every spawnSync options object. POSIX behavior unchanged. Affected files (15 lines changed): - scripts/track.mjs - scripts/budget.mjs - scripts/summary.mjs - scripts/conversation.mjs - scripts/export.mjs - scripts/federation.mjs - scripts/outcome.mjs Verified on Win10 + Node 24.15.0: cost track now persists records to cost-tracking namespace successfully. Related: #2073 (CLI memory retrieve corrupts nested JSON — separate upstream blocker for the read pipeline). --- plugins/ruflo-cost-tracker/scripts/budget.mjs | 10 +++++----- plugins/ruflo-cost-tracker/scripts/conversation.mjs | 4 ++-- plugins/ruflo-cost-tracker/scripts/export.mjs | 4 ++-- plugins/ruflo-cost-tracker/scripts/federation.mjs | 4 ++-- plugins/ruflo-cost-tracker/scripts/outcome.mjs | 2 +- plugins/ruflo-cost-tracker/scripts/summary.mjs | 4 ++-- plugins/ruflo-cost-tracker/scripts/track.mjs | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/ruflo-cost-tracker/scripts/budget.mjs b/plugins/ruflo-cost-tracker/scripts/budget.mjs index f90c0c3225..8553388ef4 100755 --- a/plugins/ruflo-cost-tracker/scripts/budget.mjs +++ b/plugins/ruflo-cost-tracker/scripts/budget.mjs @@ -36,7 +36,7 @@ function memoryStore(key, value) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'store', '--namespace', NS, '--key', stamped, '--value', JSON.stringify(value), - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) throw new Error(`memory store failed: ${r.stderr?.slice(0, 200) || r.status}`); // The "current pointer" is found at retrieval time by listing all // budget-config-* keys and picking the lexicographically-largest @@ -46,7 +46,7 @@ function memoryStore(key, value) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'store', '--namespace', NS, '--key', key, '--value', JSON.stringify(value), - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) throw new Error(`memory store failed: ${r.stderr?.slice(0, 200) || r.status}`); } @@ -54,7 +54,7 @@ function memoryRetrieveOne(key) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'retrieve', '--namespace', NS, '--key', key, - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return null; const m = /\{[\s\S]*\}/.exec(r.stdout || ''); if (!m) return null; @@ -67,7 +67,7 @@ function memoryRetrieve(key) { const list = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', NS, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (list.status !== 0) return null; const m = /\[[\s\S]*\]/.exec(list.stdout || ''); if (!m) return null; @@ -92,7 +92,7 @@ function memoryListSessionRecords() { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', NS, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return []; // CLI may emit a small banner before the JSON array; extract the first '['..']' block. const m = /\[[\s\S]*\]/.exec(r.stdout || ''); diff --git a/plugins/ruflo-cost-tracker/scripts/conversation.mjs b/plugins/ruflo-cost-tracker/scripts/conversation.mjs index f714ba5769..fb3f3bf4a8 100755 --- a/plugins/ruflo-cost-tracker/scripts/conversation.mjs +++ b/plugins/ruflo-cost-tracker/scripts/conversation.mjs @@ -23,7 +23,7 @@ function memoryListSessionKeys() { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', NS, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return []; const m = /\[[\s\S]*\]/.exec(r.stdout || ''); if (!m) return []; @@ -38,7 +38,7 @@ function memoryRetrieve(key) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'retrieve', '--namespace', NS, '--key', key, - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return null; const m = /\{[\s\S]*\}/.exec(r.stdout || ''); if (!m) return null; diff --git a/plugins/ruflo-cost-tracker/scripts/export.mjs b/plugins/ruflo-cost-tracker/scripts/export.mjs index 1d92c6ed57..25f214ce36 100755 --- a/plugins/ruflo-cost-tracker/scripts/export.mjs +++ b/plugins/ruflo-cost-tracker/scripts/export.mjs @@ -28,7 +28,7 @@ function memoryListKeys() { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', NS, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return []; const m = /\[[\s\S]*\]/.exec(r.stdout || ''); if (!m) return []; @@ -38,7 +38,7 @@ function memoryRetrieve(key) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'retrieve', '--namespace', NS, '--key', key, - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return null; const m = /\{[\s\S]*\}/.exec(r.stdout || ''); if (!m) return null; diff --git a/plugins/ruflo-cost-tracker/scripts/federation.mjs b/plugins/ruflo-cost-tracker/scripts/federation.mjs index 946edef1d5..58e6b9ed88 100755 --- a/plugins/ruflo-cost-tracker/scripts/federation.mjs +++ b/plugins/ruflo-cost-tracker/scripts/federation.mjs @@ -31,7 +31,7 @@ function memoryList() { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', NS, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return []; const m = /\[[\s\S]*\]/.exec(r.stdout || ''); if (!m) return []; @@ -41,7 +41,7 @@ function memoryRetrieve(key) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'retrieve', '--namespace', NS, '--key', key, - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return null; const m = /\{[\s\S]*\}/.exec(r.stdout || ''); if (!m) return null; diff --git a/plugins/ruflo-cost-tracker/scripts/outcome.mjs b/plugins/ruflo-cost-tracker/scripts/outcome.mjs index cb17ccab74..27213cef27 100755 --- a/plugins/ruflo-cost-tracker/scripts/outcome.mjs +++ b/plugins/ruflo-cost-tracker/scripts/outcome.mjs @@ -33,7 +33,7 @@ function main() { const r = spawnSync('npx', [ '@claude-flow/cli@latest', 'hooks', 'model-outcome', '-t', task, '-m', model, '-o', outcome, - ], { stdio: 'inherit' }); + ], { stdio: 'inherit', shell: process.platform === 'win32' }); if (r.status !== 0) { console.error(`emit failed (exit ${r.status})`); process.exit(r.status || 1); diff --git a/plugins/ruflo-cost-tracker/scripts/summary.mjs b/plugins/ruflo-cost-tracker/scripts/summary.mjs index 4680f6233e..a12cfabccc 100755 --- a/plugins/ruflo-cost-tracker/scripts/summary.mjs +++ b/plugins/ruflo-cost-tracker/scripts/summary.mjs @@ -36,7 +36,7 @@ function memoryListKeys(ns) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'list', '--namespace', ns, '--format', 'json', - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return []; const m = /\[[\s\S]*\]/.exec(r.stdout || ''); if (!m) return []; @@ -46,7 +46,7 @@ function memoryRetrieve(ns, key) { const r = spawnSync('npx', [ CLI_PKG, 'memory', 'retrieve', '--namespace', ns, '--key', key, - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) return null; const m = /\{[\s\S]*\}/.exec(r.stdout || ''); if (!m) return null; diff --git a/plugins/ruflo-cost-tracker/scripts/track.mjs b/plugins/ruflo-cost-tracker/scripts/track.mjs index c71593b69d..73697a7440 100755 --- a/plugins/ruflo-cost-tracker/scripts/track.mjs +++ b/plugins/ruflo-cost-tracker/scripts/track.mjs @@ -132,7 +132,7 @@ function persistToMemory(summary) { '--namespace', ns, '--key', key, '--value', JSON.stringify(summary), - ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8' }); + ], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' }); if (r.status !== 0) { return { ok: false, reason: r.stderr?.slice(0, 300) || `exit ${r.status}` }; }