From 4c1d0a1633c98ae5703addbf86ffe50b81545c08 Mon Sep 17 00:00:00 2001 From: liruifengv Date: Fri, 3 Jul 2026 11:32:31 +0800 Subject: [PATCH] fix: hide the background updater console window on Windows (#1336) A detached Windows child gets its own console window. With the shell: true introduced for the CVE-2024-27980 fix, a passive background auto-update could flash a command window even though stdio is ignored. Set windowsHide on the detached background child so the silent updater stays silent. The foreground `kimi upgrade` path is interactive (stdio: inherit, non-detached) and reuses the parent console, so it is left unchanged. --- .../fix-windows-update-console-flash.md | 5 +++++ apps/kimi-code/src/cli/update/preflight.ts | 4 ++++ .../test/cli/update/preflight.test.ts | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .changeset/fix-windows-update-console-flash.md diff --git a/.changeset/fix-windows-update-console-flash.md b/.changeset/fix-windows-update-console-flash.md new file mode 100644 index 000000000..26df3a34c --- /dev/null +++ b/.changeset/fix-windows-update-console-flash.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Keep automatic background updates from flashing a console window on Windows. diff --git a/apps/kimi-code/src/cli/update/preflight.ts b/apps/kimi-code/src/cli/update/preflight.ts index fe388882f..5fda96d6a 100644 --- a/apps/kimi-code/src/cli/update/preflight.ts +++ b/apps/kimi-code/src/cli/update/preflight.ts @@ -607,6 +607,10 @@ async function startBackgroundInstall( detached: true, stdio: 'ignore', shell: platform === 'win32' ? true : undefined, + // On Windows a detached child gets its own console window; with shell:true + // that window would flash during a passive background update. Hide it so + // the silent updater stays silent. + windowsHide: platform === 'win32' ? true : undefined, }); child.once('error', () => { finish(false); }); child.once('exit', (code) => { finish(code === 0); }); diff --git a/apps/kimi-code/test/cli/update/preflight.test.ts b/apps/kimi-code/test/cli/update/preflight.test.ts index 664bc4982..7c3a61a03 100644 --- a/apps/kimi-code/test/cli/update/preflight.test.ts +++ b/apps/kimi-code/test/cli/update/preflight.test.ts @@ -600,6 +600,27 @@ describe('runUpdatePreflight', () => { })); }); + it('win32 background auto-update hides the console window', async () => { + mocks.readUpdateCache.mockResolvedValue(cacheWith('0.5.0')); + mocks.readUpdateInstallState.mockResolvedValue(installState()); + mocks.refreshUpdateCache.mockResolvedValue(cacheWith('0.5.0')); + mocks.detectInstallSource.mockResolvedValue('npm-global'); + mockSpawnExit(0); + const originalPlatform = process.platform; + Object.defineProperty(process, 'platform', { value: 'win32' }); + try { + const { options } = captureOutput(); + await expect(runUpdatePreflight('0.4.0', options)).resolves.toBe('continue'); + expect(mocks.spawn).toHaveBeenCalledWith( + 'npm.cmd', + ['install', '-g', '@moonshot-ai/kimi-code@0.5.0'], + { detached: true, stdio: 'ignore', shell: true, windowsHide: true }, + ); + } finally { + Object.defineProperty(process, 'platform', { value: originalPlatform }); + } + }); + it('tracks and logs successful background update installs', async () => { mocks.readUpdateCache.mockResolvedValue(cacheWith('0.5.0')); mocks.readUpdateInstallState.mockResolvedValue(installState());