dsh-windows-tray 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ $URL = "http://127.0.0.1:$PORT"
12
12
  $LOG_DIR = Join-Path (Join-Path $env:USERPROFILE '.dsh\logs') 'dsh-windows-tray' # 本插件专属日志目录 (logs\<插件名>\, 边界规则见 release-standards §3.1)
13
13
  $WT = "$env:LOCALAPPDATA\Microsoft\WindowsApps\wt.exe"
14
14
  $PWSH = 'D:\Program Files (x86)\PowerShell-7.6.4\pwsh.exe'
15
- $TRAY_VERSION = '1.0.10' # 托盘版本 (与 npm 包版本同步, 用于日志/排查)
15
+ $TRAY_VERSION = '1.0.11' # 托盘版本 (与 npm 包版本同步, 用于日志/排查)
16
16
  $TRAY_PKG = 'dsh-windows-tray' # npm 包名 (托盘自更新)
17
17
  $TRAY_SCRIPT = Join-Path $PSScriptRoot 'dsh-tray.ps1'
18
18
 
@@ -216,6 +216,63 @@ function Stop-Tui {
216
216
  $WEB_TITLE_PREFIX = 'DeepSeek Harness' # dsh web 页面 <title> 关键标识 (含匹配, 见上)
217
217
  $BROWSER_PROGID_MAP = @{ 'MSEdgeHTM' = 'msedge'; 'ChromeHTML' = 'chrome' } # Chromium ProgId → 进程名; 查不到=降级新开
218
218
 
219
+ # ---- dsh 0.1.2+ 一次性 launch token 鉴权 (1.0.11) ----
220
+ # rc.1 起 dsh web 每次启动生成随机 launch token, 横幅打印 「dsh web: http://127.0.0.1:<port>/?token=...」;
221
+ # 该 URL 首次访问签发持久签名 cookie (跨重启有效), 此后裸 URL 才可直访——因此托盘打开 Web UI
222
+ # 必须用带 token 的 URL (或命中已授权标签页)。
223
+ # 向后兼容: 旧版 dsh 无 token 行 / token 失效 → 全部回退裸 URL (行为同 1.0.10 及以前)。
224
+ $WEB_TOKEN_LOG = Join-Path $LOG_DIR 'web-menu.out.log' # 与 Start-Dsh 的重定向输出同文件 (每 boot 覆写)
225
+
226
+ # 解析启动日志中的 launch token URL (最后一条命中; 纯读, 网络探活在 Get-WebLaunchUrl 里做)
227
+ function Parse-WebLaunchTokenUrl {
228
+ param([string]$LogPath = $WEB_TOKEN_LOG)
229
+ if (-not (Test-Path $LogPath)) { return '' }
230
+ $found = ''
231
+ foreach ($line in (Get-Content -LiteralPath $LogPath -ErrorAction SilentlyContinue)) {
232
+ if ($line -match '(https?://\S*\?token=[A-Za-z0-9_-]+)') { $found = $Matches[1] }
233
+ }
234
+ return $found
235
+ }
236
+
237
+ # 探活: token URL 对无 cookie 请求应 303 (签发 Set-Cookie 后重定向到净 URL); 39x/200 均算有效。
238
+ # 用 HttpWebRequest 不自动跟随重定向; 401 (token 过期/被拒) 或网络异常 → 无效
239
+ function Test-WebLaunchUrl {
240
+ param([string]$Url)
241
+ foreach ($u in @($Url)) {
242
+ try {
243
+ $req = [System.Net.HttpWebRequest]::Create($u)
244
+ $req.AllowAutoRedirect = $false
245
+ $req.Timeout = 3000
246
+ $resp = $req.GetResponse()
247
+ $code = [int]$resp.StatusCode
248
+ $resp.Close()
249
+ if ($code -ge 200 -and $code -lt 400) { return $true }
250
+ } catch {
251
+ $resp = $_.Exception.Response
252
+ if ($null -ne $resp) {
253
+ $code = [int]$resp.StatusCode
254
+ $resp.Close()
255
+ if ($code -ge 200 -and $code -lt 400) { return $true }
256
+ }
257
+ }
258
+ }
259
+ return $false
260
+ }
261
+
262
+ # 决定打开哪个 URL: 日志有 token 且探活有效 → 带 token URL; 否则裸 URL (旧版 dsh 直访 200)
263
+ function Get-WebLaunchUrl {
264
+ param(
265
+ [string]$Fallback = $URL,
266
+ [string]$LogPath = $WEB_TOKEN_LOG,
267
+ [switch]$SkipProbe # 单测注入: 跳过网络探活, 只测解析与回退逻辑
268
+ )
269
+ $tokenUrl = Parse-WebLaunchTokenUrl -LogPath $LogPath
270
+ if ($tokenUrl -ne '') {
271
+ if ($SkipProbe -or (Test-WebLaunchUrl -Url $tokenUrl)) { return $tokenUrl }
272
+ }
273
+ return $Fallback
274
+ }
275
+
219
276
  function Open-DshWeb {
220
277
  param([string]$Url = $URL)
221
278
  try {
@@ -256,7 +313,9 @@ namespace DSH {
256
313
  } catch {
257
314
  Write-Host "[web] 切换检测不可用($($_.Exception.Message)), 新开" -ForegroundColor DarkGray
258
315
  }
259
- Start-Process $Url
316
+ $openUrl = Get-WebLaunchUrl -Fallback $Url
317
+ Write-Host "[web] 打开: $openUrl" -ForegroundColor DarkGray
318
+ Start-Process $openUrl
260
319
  }
261
320
 
262
321
  function Show-Status {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-windows-tray",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "DSH (DeepSeek Harness) Windows 系统托盘: 蓝/灰鲸鱼状态图标 + Web/TUI 一键启停控制。纯 PowerShell + WinForms, 零依赖。",
5
5
  "license": "MIT",
6
6
  "author": "jankin_lv",