From 9fcbe9751cd60ac1cfc7a4cdbc9940a3bdda1dad Mon Sep 17 00:00:00 2001 From: yang1002378395-cmyk Date: Tue, 17 Mar 2026 04:38:47 +0800 Subject: [PATCH] fix: export run() to avoid Windows spawnSync issues (#431) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - session-end-marker.js now exports run() function - Enables in-process execution via run-with-flags.js - Avoids spawnSync cross-platform issues on Windows - Maintains backward compatibility with direct CLI execution Fixes #429 Co-authored-by: 阳虎 --- scripts/hooks/session-end-marker.js | 38 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/scripts/hooks/session-end-marker.js b/scripts/hooks/session-end-marker.js index 54918410..c635a93d 100755 --- a/scripts/hooks/session-end-marker.js +++ b/scripts/hooks/session-end-marker.js @@ -1,15 +1,29 @@ #!/usr/bin/env node 'use strict'; -const MAX_STDIN = 1024 * 1024; -let raw = ''; -process.stdin.setEncoding('utf8'); -process.stdin.on('data', chunk => { - if (raw.length < MAX_STDIN) { - const remaining = MAX_STDIN - raw.length; - raw += chunk.substring(0, remaining); - } -}); -process.stdin.on('end', () => { - process.stdout.write(raw); -}); +/** + * Session end marker hook - outputs stdin to stdout unchanged. + * Exports run() for in-process execution (avoids spawnSync issues on Windows). + */ + +function run(rawInput) { + return rawInput || ''; +} + +// Legacy CLI execution (when run directly) +if (require.main === module) { + const MAX_STDIN = 1024 * 1024; + let raw = ''; + process.stdin.setEncoding('utf8'); + process.stdin.on('data', chunk => { + if (raw.length < MAX_STDIN) { + const remaining = MAX_STDIN - raw.length; + raw += chunk.substring(0, remaining); + } + }); + process.stdin.on('end', () => { + process.stdout.write(raw); + }); +} + +module.exports = { run };