From 44a10cff393923f1783d3c223f9359dbf36c04e1 Mon Sep 17 00:00:00 2001 From: ArizeSky <97787713+ArizeSky@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:14:45 +0800 Subject: [PATCH] fix(deepseek): skip a tokenless banner line while scanning The scanner now takes the first `dsh web:` line that parses as an http(s) URL AND carries a token, as the boot contract describes, instead of settling on an earlier plain URL and reporting no launch URL. The tokenless line is still what identifies an older, ungated dsh in the wait loop. --- src/deepseek-web-server.ts | 19 +++++++++++-------- test/deepseek-web-server.test.ts | 6 ++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/deepseek-web-server.ts b/src/deepseek-web-server.ts index 6b68d24a..656bf9ce 100644 --- a/src/deepseek-web-server.ts +++ b/src/deepseek-web-server.ts @@ -169,9 +169,11 @@ function stripSgr(output: string): string { * The first `dsh web:` payload that parses as an absolute http(s) URL. * * Lines whose payload is not a URL are skipped, which is what makes a - * `dsh web: loading profiles` diagnostic harmless. Null when no line carries one. + * `dsh web: loading profiles` diagnostic harmless. `requireToken` skips an + * http(s) URL that carries no `token` as well, so a diagnostic that happens to + * contain a plain link cannot shadow the real banner. Null when no line qualifies. */ -function firstLaunchBannerUrl(output: string): string | null { +function firstLaunchBannerUrl(output: string, requireToken = false): string | null { // Fresh per call: a module-level /g pattern carries lastIndex between calls. const line = /dsh web:\s*(\S+)/g; for (const match of stripSgr(output).matchAll(line)) { @@ -181,7 +183,9 @@ function firstLaunchBannerUrl(output: string): string | null { } catch { continue; } - if (url.protocol === 'http:' || url.protocol === 'https:') return url.href; + if (url.protocol !== 'http:' && url.protocol !== 'https:') continue; + if (requireToken && !url.searchParams.get('token')) continue; + return url.href; } return null; } @@ -195,8 +199,9 @@ function firstLaunchBannerUrl(output: string): string | null { * after it. The token is per process, so it can be neither guessed nor carried * across restarts — it has to be read out of the boot output. * - * Scans EVERY `dsh web:` line and returns the first one that is a usable URL, - * because dsh also prints diagnostics under the same prefix before the banner. + * Scans EVERY `dsh web:` line and returns the first one that is a usable URL + * carrying a token, because dsh also prints diagnostics under the same prefix + * before the banner. * * Null for output without one, which is the older-dsh case and stays working. * @@ -204,9 +209,7 @@ function firstLaunchBannerUrl(output: string): string | null { * @returns absolute http(s) URL carrying a `token`, or null. */ export function parseLaunchUrl(output: string): string | null { - const href = firstLaunchBannerUrl(output); - if (!href) return null; - return new URL(href).searchParams.get('token') ? href : null; + return firstLaunchBannerUrl(output, true); } /** diff --git a/test/deepseek-web-server.test.ts b/test/deepseek-web-server.test.ts index 63791b99..a50e61b5 100644 --- a/test/deepseek-web-server.test.ts +++ b/test/deepseek-web-server.test.ts @@ -106,6 +106,12 @@ describe('parseLaunchUrl: the one-time token dsh prints on boot', () => { ); }); + it('skips a URL without a token and keeps scanning for the token one', () => { + expect(parseLaunchUrl('dsh web: http://127.0.0.1:3080/\ndsh web: http://127.0.0.1:3080/?token=abc\n')).toBe( + 'http://127.0.0.1:3080/?token=abc' + ); + }); + it('returns null for a token-less banner, which is the older dsh', () => { expect(parseLaunchUrl('dsh web: http://127.0.0.1:3080/\n')).toBeNull(); });