dsh-client-ui-skin-tianlight 2.0.3 → 2.0.5

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.
package/README.md CHANGED
@@ -6,6 +6,14 @@
6
6
  >
7
7
  > npm 包名 `dsh-client-ui-skin-tianlight`(v2.0.2 起;旧链接安装包名 `@dsh-external/dsh-client-ui-skin-tianlight`)· 布线行 `ui-skin-tianlight` · body 属性 `data-dsh-tianlight`
8
8
 
9
+ ## v2.0.5 · 天气兜底版
10
+
11
+ 有些网络会把浏览器(Chromium/OpenSSL)到 `api.open-meteo.com` 的 **TLS 握手**丢掉——同一域名走明文 HTTP、或走系统 TLS 栈(curl/PowerShell)却正常。桌面端页面是 `dsh-app://` 安全源,渲染层不能自己降级,于是天气卡一直停在 `获取失败:请求超时(静默重试)`。这一版给宿主加了只读的 `_weather` 兜底路由:客户端直连失败后请宿主代取(宿主先试 HTTPS,失败才用同一域名的明文 HTTP),拿到数据后照旧走原来的天气模型与配额;直连正常时完全不会走到它。详见 [RELEASE-NOTES-v2.0.5.md](RELEASE-NOTES-v2.0.5.md)。
12
+
13
+ ## v2.0.4 · 安全修复版(建议升级)
14
+
15
+ 修复了 v2.0.3 验收中发现的问题,其中最重要的一条:Wallpaper Engine 网页壁纸的页面以前会以 DSH 源的身份运行,现在一律沙箱化。2.0.2 和 2.0.3 都受影响,请升级:先完全退出 DSH,再运行 `npx dsh-client-ui-skin-tianlight@latest`。另外 `npx` 不再顺带下载整套 DSH 依赖,安装快很多。详见 [RELEASE-NOTES-v2.0.4.md](RELEASE-NOTES-v2.0.4.md)。
16
+
9
17
  ## v2.0.3 · 一条命令安装
10
18
 
11
19
  ```bash
package/bin/cli.mjs CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  pruneBackups,
29
29
  readJson,
30
30
  removeInstalledFiles,
31
+ isUncPath,
31
32
  resolveDshHome,
32
33
  scanPatches,
33
34
  writeJsonAtomic,
@@ -59,6 +60,7 @@ const M = {
59
60
  home: (p) => `DSH 数据目录:${p}`,
60
61
  noHome: (p) => `找不到 DSH 数据目录 ${p}\n 请先安装并启动一次 DeepSeek Harness;数据目录不在默认位置时用 --dsh-home <目录> 指定。`,
61
62
  noProfiles: '这个 DSH 数据目录里还没有 profile。请先启动一次 DSH 再运行本命令。',
63
+ unc: '不支持网络路径(\\\\服务器\\共享)作为 DSH 数据目录,请使用本机磁盘上的目录。',
62
64
  profileMissing: (p, list) => `没有名为 "${p}" 的 profile。现有:${list.join('、') || '(无)'}`,
63
65
  profileAmbiguous: (list) => `有多个 profile:${list.join('、')}\n 请用 --profile <名称> 指定要装到哪一个。`,
64
66
  profile: (p) => `目标 profile:${p}`,
@@ -120,6 +122,7 @@ const M = {
120
122
  home: (p) => `DSH home: ${p}`,
121
123
  noHome: (p) => `DSH home not found: ${p}\n Install and start DeepSeek Harness once first, or pass --dsh-home <dir>.`,
122
124
  noProfiles: 'This DSH home has no profile yet. Start DSH once, then run this command again.',
125
+ unc: 'Network paths (\\\\server\\share) are not supported as the DSH home; use a local directory.',
123
126
  profileMissing: (p, list) => `No profile named "${p}". Existing: ${list.join(', ') || '(none)'}`,
124
127
  profileAmbiguous: (list) => `Several profiles exist: ${list.join(', ')}\n Pick one with --profile <name>.`,
125
128
  profile: (p) => `Target profile: ${p}`,
@@ -186,7 +189,10 @@ const die = (line, code = 1) => {
186
189
 
187
190
  // ---- shared steps -----------------------------------------------------------
188
191
  function locate() {
192
+ const requestedHome = value('--dsh-home') ?? process.env.DSH_HOME ?? ''
193
+ if (isUncPath(requestedHome)) die(M.unc)
189
194
  const dshHome = resolveDshHome({ dshHome: value('--dsh-home') })
195
+ if (isUncPath(dshHome)) die(M.unc)
190
196
  say(M.home(dshHome))
191
197
  if (existsSync(dshHome) === false) die(M.noHome(dshHome))
192
198
  const profiles = listProfiles(dshHome)
package/bin/installer.mjs CHANGED
@@ -59,6 +59,11 @@ export function writeJsonAtomic(file, value) {
59
59
 
60
60
  // ---- locating DSH -----------------------------------------------------------
61
61
 
62
+ /** `\\server\share` / `//server/share` (and `\\?\UNC\...`): network locations are refused. */
63
+ export function isUncPath(value) {
64
+ return typeof value === 'string' && /^(?:\\\\|\/\/)/.test(value.trim())
65
+ }
66
+
62
67
  export function resolveDshHome({ dshHome = null, env = process.env, home = homedir() } = {}) {
63
68
  if (typeof dshHome === 'string' && dshHome.trim() !== '') return resolve(dshHome.trim())
64
69
  if (typeof env.DSH_HOME === 'string' && env.DSH_HOME.trim() !== '') return resolve(env.DSH_HOME.trim())
@@ -401,37 +406,57 @@ export function pruneBackups(profileDir, keep = KEEP_BACKUPS) {
401
406
  * backup folder (a link is just unlinked), then swap the staged copy in. If the swap
402
407
  * fails the previous copy is put back.
403
408
  */
409
+ export const STAGING_PREFIX = `.${PKG_NAME}.tl-staging-`
410
+
411
+ /** v2.0.4 (L1): staging copies left behind by an interrupted/failed earlier run. */
412
+ export function cleanStaleStaging(modulesDir) {
413
+ const removed = []
414
+ if (existsSync(modulesDir) === false) return removed
415
+ for (const name of readdirSync(modulesDir)) {
416
+ if (name.startsWith(STAGING_PREFIX) === false) continue
417
+ safeRemoveTree(join(modulesDir, name))
418
+ removed.push(name)
419
+ }
420
+ return removed
421
+ }
422
+
404
423
  export function installFiles({ srcRoot = SELF_ROOT, profileDir, backupDir, entries = packageEntries(srcRoot) }) {
405
424
  const modules = join(profileDir, 'node_modules')
406
425
  mkdirSync(modules, { recursive: true })
426
+ cleanStaleStaging(modules)
407
427
  const target = join(modules, PKG_NAME)
408
- const staging = join(modules, `.${PKG_NAME}.tl-staging-${process.pid}`)
409
- rmSync(staging, { recursive: true, force: true })
410
- mkdirSync(staging, { recursive: true })
411
- for (const entry of entries) cpSync(join(srcRoot, entry), join(staging, entry), { recursive: true })
412
- const stagedManifestPath = join(staging, 'package.json')
413
- const stagedManifest = readJson(stagedManifestPath)
414
- if (stagedManifest.private !== undefined) {
415
- delete stagedManifest.private
416
- writeFileSync(stagedManifestPath, JSON.stringify(stagedManifest, null, 2) + '\n', 'utf8')
417
- }
418
-
419
- const before = inspectInstalled(profileDir)
428
+ const staging = join(modules, `${STAGING_PREFIX}${process.pid}`)
420
429
  let parked = null
421
- if (before.kind === 'link') {
422
- removeLink(target)
423
- } else if (before.kind === 'dir') {
424
- parked = join(backupDir, 'previous-package')
425
- renameSync(target, parked)
426
- }
430
+ let swapped = false
427
431
  try {
428
- renameSync(staging, target)
429
- } catch (error) {
430
- if (parked !== null && existsSync(target) === false) renameSync(parked, target)
431
- rmSync(staging, { recursive: true, force: true })
432
- throw error
432
+ mkdirSync(staging, { recursive: true })
433
+ for (const entry of entries) cpSync(join(srcRoot, entry), join(staging, entry), { recursive: true })
434
+ const stagedManifestPath = join(staging, 'package.json')
435
+ const stagedManifest = readJson(stagedManifestPath)
436
+ if (stagedManifest.private !== undefined) {
437
+ delete stagedManifest.private
438
+ writeFileSync(stagedManifestPath, JSON.stringify(stagedManifest, null, 2) + '\n', 'utf8')
439
+ }
440
+ const before = inspectInstalled(profileDir)
441
+ if (before.kind === 'link') {
442
+ removeLink(target)
443
+ } else if (before.kind === 'dir') {
444
+ parked = join(backupDir, 'previous-package')
445
+ renameSync(target, parked)
446
+ }
447
+ try {
448
+ renameSync(staging, target)
449
+ swapped = true
450
+ } catch (error) {
451
+ if (parked !== null && existsSync(target) === false) renameSync(parked, target)
452
+ throw error
453
+ }
454
+ return { previous: before, parked }
455
+ } finally {
456
+ // v2.0.4 (L1): whatever failed — copy, parking (EPERM on a locked file), swap —
457
+ // never leave the ~37 MB staging copy behind.
458
+ if (swapped === false) safeRemoveTree(staging)
433
459
  }
434
- return { previous: before, parked }
435
460
  }
436
461
 
437
462
  export function removeInstalledFiles({ profileDir, backupDir }) {
package/build-info.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "product": "dsh-client-ui-skin-tianlight",
4
- "version": "2.0.3",
5
- "commit": "e257c5800dbf9dafeba84093f8c57a292ce0eb9c",
6
- "builtAt": "2026-11-12T23:55:42+08:00",
4
+ "version": "2.0.5",
5
+ "commit": "73c8d1f23eb0752a3607fa7e4853242e2a69545e",
6
+ "builtAt": "2026-11-14T17:30:25+08:00",
7
7
  "source": "pack"
8
8
  }
@@ -0,0 +1,161 @@
1
+ # 第三方组件与许可
2
+
3
+ 天光皮肤本体是 MIT(见根目录 `LICENSE`)。本文件列出随仓库分发(或作为实现依据)的第三方组件、
4
+ 版本、许可与归属;发布包(`node tools/pack.mjs`)会带上 `lib/we-wallpaper/`、`vendor/we-wallpaper/`、
5
+ `vendor/webwallgl/` 及各自的许可文件。
6
+
7
+ ## 1. dsh-we-wallpaper 宿主半(MIT)
8
+
9
+ v0.6.0 的 Wallpaper Engine 库集成把上游 **dsh-we-wallpaper** 的宿主半(MIT)**以源码形式内嵌**,
10
+ 使皮肤能在**不填写任何目录**的前提下浏览本机 Wallpaper Engine 库。
11
+
12
+ | 项 | 值 |
13
+ |---|---|
14
+ | 上游 | <https://github.com/pbadgpmeb22791-sketch/dsh-we-wallpaper> |
15
+ | 版本 / 提交 | `v0.4.0` @ `61ccaa2`(把 v0.4.0 提升到仓库根的 restructure commit) |
16
+ | 归属 | Copyright (c) 2026 **dsh-we-wallpaper contributors** |
17
+ | 内嵌文件 | `lib/we-wallpaper/host.mjs`(单 ESM,仅 Node 内置模块;上游 `lib/index.js`,由上游 TS 源码构建) |
18
+ | 许可全文 | [`lib/we-wallpaper/LICENSE`](../lib/we-wallpaper/LICENSE) |
19
+ | 修改说明 | [`lib/we-wallpaper/README.md`](../lib/we-wallpaper/README.md)(grep `TIANLIGHT` 可定位全部改动) |
20
+
21
+ 保留:无框架扫描器、无依赖 `.pkg`/TEX 解码器、HTTP 路由族。
22
+ 未内嵌:上游 cordis/settings 插件接线与上游客户端半(由本皮肤自己的客户端渲染列表并播放壁纸)。
23
+
24
+ 对本仓库的修改(摘要,详细见上表 README):去掉插件接线改为纯函数导出;同源校验放宽到 DSH Desktop
25
+ webview 与 `127.0.0.1/localhost`(跨站仍 403);运行状态/缓存从 `~/.dsh` 移到插件 gitignored `state/`
26
+ (`TIANLIGHT_WE_HOME` 可覆盖);wcap 路径指向 `vendor/we-wallpaper/wcap/`;本地 project 的 `.pkg` 也支持解出;
27
+ 场景动态缓存 503 语义明确;扫描器结果映射为本皮肤的 `_wallpapers`/`_engines` 形状。
28
+
29
+ ```text
30
+ MIT License
31
+
32
+ Copyright (c) 2026 dsh-we-wallpaper contributors
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy
35
+ of this software and associated documentation files (the "Software"), to deal
36
+ in the Software without restriction, including without limitation the rights
37
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
+ copies of the Software, and to permit persons to whom the Software is
39
+ furnished to do so, subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all
42
+ copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
+ SOFTWARE.
51
+ ```
52
+
53
+ ## 2. wcap(Unlicense / 公有领域)
54
+
55
+ 可选的「场景动态缓存」(Windows-only)使用上游 dsh-we-wallpaper 随附的窗口捕获工具 `wcap`:
56
+
57
+ | 文件 | 来源 | 许可 |
58
+ |---|---|---|
59
+ | `vendor/we-wallpaper/wcap/wcap-x64.exe` | 上游 `tools/wcap/wcap-x64.exe` | Unlicense(public domain) |
60
+ | `vendor/we-wallpaper/wcap/scene-capture-desktop.ps1` | 上游 `tools/wcap/` | Unlicense |
61
+ | `vendor/we-wallpaper/wcap/send-window-capture-hotkey.ps1` | 上游 `tools/wcap/` | Unlicense |
62
+ | 许可全文 | 上游 `tools/wcap/LICENSE`,逐字内嵌 | [`vendor/we-wallpaper/wcap/LICENSE`](../vendor/we-wallpaper/wcap/LICENSE) |
63
+
64
+ ```text
65
+ This is free and unencumbered software released into the public domain.
66
+
67
+ Anyone is free to copy, modify, publish, use, compile, sell, or distribute
68
+ this software, either in source code form or as a compiled binary, for any
69
+ purpose, commercial or non-commercial, and by any means.
70
+
71
+ In jurisdictions that recognize copyright laws, the author or authors of
72
+ this software dedicate any and all copyright interest in the software to the
73
+ public domain. We make this dedication for the benefit of the public at large
74
+ and to the detriment of our heirs and successors. We intend this dedication
75
+ to be an overt act of relinquishment in perpetuity of all present and future
76
+ rights to this software under copyright law.
77
+
78
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
79
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
80
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
81
+ AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
82
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
83
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84
+
85
+ For more information, please refer to <https://unlicense.org>.
86
+ ```
87
+
88
+ > `wcap` 只在用户显式请求「生成动态」时被 `POST /api/we-wallpaper/scene-video/generate/<id>` 调用;
89
+ > 仓库测试套件用 `TIANLIGHT_WE_DISABLE_SCENE_VIDEO=1` 跳过它(不会在维护者桌面弹窗)。
90
+
91
+ ## 3. RePKG(MIT,DXT 解码的实现依据)
92
+
93
+ `lib/we-wallpaper/host.mjs` 的 `pkg-tex` 解包/解码器在格式实现上参考并移植了 **RePKG** 的 DXT 解码
94
+ (LibSquish 派生的 C# 实现);上游 dsh-we-wallpaper 同样以此为实现依据。
95
+
96
+ | 项 | 值 |
97
+ |---|---|
98
+ | 项目 | <https://github.com/notscuffed/repkg> |
99
+ | 归属 | Copyright (c) **Xalcon @ mmowned.com**(见上游文件头) |
100
+ | 许可 | MIT |
101
+ | 使用方式 | 格式/算法参考与 DXT 解码移植;未整份复制其 C# 实现 |
102
+
103
+ RePKG 的 MIT 许可全文(v2.0.4 起逐字附在这里,随 npm 包分发):
104
+
105
+ ```
106
+ MIT License
107
+
108
+ Copyright (c) Xalcon @ mmowned.com
109
+
110
+ Permission is hereby granted, free of charge, to any person obtaining a copy
111
+ of this software and associated documentation files (the "Software"), to deal
112
+ in the Software without restriction, including without limitation the rights
113
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114
+ copies of the Software, and to permit persons to whom the Software is
115
+ furnished to do so, subject to the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be included in all
118
+ copies or substantial portions of the Software.
119
+
120
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
121
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
122
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
123
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
124
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
125
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
126
+ SOFTWARE.
127
+ ```
128
+
129
+ ## 4. WebWallGL(MIT)
130
+
131
+ Wallpaper Engine 场景通道使用仓库内 `vendor/webwallgl/` 的 WebWallGL 3.0(可选依赖,不内联进
132
+ `lib/client.js`):
133
+
134
+ | 项 | 值 |
135
+ |---|---|
136
+ | 位置 | `vendor/webwallgl/webwallgl.global.min.js`(+ `README.upstream.md`) |
137
+ | 归属 | Copyright (c) 2026 **oneincase** `<462534624@qq.com>` |
138
+ | 许可 | MIT;全文见 [`vendor/webwallgl/LICENSE`](../vendor/webwallgl/LICENSE) |
139
+
140
+ ## 4.1 二进制与压缩代码(v2.0.4 起公布校验值)
141
+
142
+ 下面两个文件不是从本仓库源码构建的,包内无法审计其源码,只能按来源与校验值核对。`wcap-x64.exe` 未做代码签名,且只在用户显式点击「生成动态」时才会运行。
143
+
144
+ | 文件 | SHA-256 | 来源 |
145
+ |---|---|---|
146
+ | `vendor/we-wallpaper/wcap/wcap-x64.exe` | `4bd124febf537f0f569bd5cb7486ddbb9e664b509f39e421e6949767829b6be6` | 上游 dsh-we-wallpaper `tools/wcap/wcap-x64.exe`,原样复制 |
147
+ | `vendor/webwallgl/webwallgl.global.min.js` | `2f86ab955f3377e2fa2cfd5ffa72f5813fe8f6e4a272295fed36f4c1e626b1e5` | WebWallGL 3.0 发布的压缩构建,原样复制(见 `vendor/webwallgl/README.upstream.md`) |
148
+
149
+ `tools/test.mjs` 会断言这两个校验值,文件被替换时测试会变红。
150
+
151
+ ## 5. 默认演示素材
152
+
153
+ 仓库完整版附带的 `assets/bg-4k.mp4` / `assets/cat.png` 是演示素材,
154
+ **不在 MIT 代码许可范围内**:桌宠形象与视频版权归各自权利方,替换或再分发前请确认你有使用权;
155
+ 发布包默认**包含**这两个文件(`node tools/pack.mjs` 的随包演示素材白名单,Release 附件同源;
156
+ 需要纯代码包时用 `node tools/pack.mjs --code-only`,此时只带代码、清单、`lib/`、`vendor/`、
157
+ `presets/` 与 `assets/README.md`)。
158
+
159
+ ---
160
+
161
+ *本文件随 v0.6.0 新增;若后续再内嵌第三方代码,请在同一 PR 里补行并附许可全文。*
package/lib/client.js CHANGED
@@ -15742,6 +15742,8 @@ body[data-dsh-tianlight] [data-tl-group="context"] .tl-fx-hint {
15742
15742
  let weatherRetryTimer = 0;
15743
15743
  let weatherRetryUsed = false;
15744
15744
  let weatherRequestToken = 0;
15745
+ /** v2.0.5:直连被网络打断过一次、且宿主兜底能用时为 true(本页会话内有效)。 */
15746
+ let weatherDirectBlocked = false;
15745
15747
  let weatherScheduleKey = "";
15746
15748
  /** 最近一次天气请求的开始时间:切回可见时只按间隔决定是否补一次请求。 */
15747
15749
  let lastWeatherFetchAt = 0;
@@ -15870,6 +15872,55 @@ body[data-dsh-tianlight] [data-tl-group="context"] .tl-fx-hint {
15870
15872
  if (left === null || left === undefined || right === null || right === undefined) return false;
15871
15873
  return left.code === right.code && left.temperatureC === right.temperatureC && left.isDay === right.isDay;
15872
15874
  };
15875
+ /**
15876
+ * v2.0.5:直连失败时的宿主兜底。
15877
+ *
15878
+ * 有些网络会把 Chromium/OpenSSL 到 api.open-meteo.com 的 TLS 握手丢掉,
15879
+ * 而同一个域名走明文 HTTP、或走系统 TLS 栈(curl/PowerShell)却正常。
15880
+ * 桌面端页面是 `dsh-app://` 安全源,渲染层不能自己降级(mixed content 会拦),
15881
+ * 所以这里请宿主代取;宿主没这条路由(旧版本)时返回 null,错误照旧上报。
15882
+ */
15883
+ const weatherViaHost = async (state) => {
15884
+ try {
15885
+ const response = await fetch(
15886
+ ASSET_BASE +
15887
+ "/_weather?latitude=" +
15888
+ encodeURIComponent(String(state.latitude)) +
15889
+ "&longitude=" +
15890
+ encodeURIComponent(String(state.longitude)),
15891
+ { cache: "no-store" },
15892
+ );
15893
+ if (response === null || response === undefined || response.ok !== true) return null;
15894
+ const body = await response.json();
15895
+ if (body === null || body === undefined || body.ok !== true) return null;
15896
+ const payload = body.payload;
15897
+ return payload !== null && payload !== undefined && typeof payload === "object" ? payload : null;
15898
+ } catch {
15899
+ return null;
15900
+ }
15901
+ };
15902
+ /** 一次直连尝试:只返回结果、不写状态,由调用方决定要不要兜底。 */
15903
+ const fetchWeatherDirect = async (state) => {
15904
+ const token = (weatherRequestToken += 1);
15905
+ const request = weatherOpenRequest();
15906
+ try {
15907
+ const response = await fetch(weatherForecastUrl(state), { signal: request.controller.signal, cache: "no-store" });
15908
+ if (alive === false || token !== weatherRequestToken) return { ok: false, error: "aborted" };
15909
+ if (response === null || response === undefined || response.ok !== true) {
15910
+ return { ok: false, error: "network" };
15911
+ }
15912
+ const payload = await response.json();
15913
+ if (alive === false || token !== weatherRequestToken) return { ok: false, error: "aborted" };
15914
+ return { ok: true, payload };
15915
+ } catch (error) {
15916
+ if (alive === false || token !== weatherRequestToken) return { ok: false, error: "aborted" };
15917
+ const timedOut =
15918
+ request.timedOut === true || (error !== null && error !== undefined && error.name === "AbortError");
15919
+ return { ok: false, error: timedOut ? "timeout" : "network" };
15920
+ } finally {
15921
+ weatherCloseRequest(request);
15922
+ }
15923
+ };
15873
15924
  const fetchWeather = async (source) => {
15874
15925
  if (alive === false) return false;
15875
15926
  if (typeof AbortController !== "function") return false;
@@ -15877,20 +15928,33 @@ body[data-dsh-tianlight] [data-tl-group="context"] .tl-fx-hint {
15877
15928
  if (state.enabled !== true || weatherHasLocation() !== true) return false;
15878
15929
  if (source !== "retry") weatherRetryUsed = false;
15879
15930
  lastWeatherFetchAt = Date.now();
15880
- const token = (weatherRequestToken += 1);
15881
- const request = weatherOpenRequest();
15882
- try {
15883
- const response = await fetch(weatherForecastUrl(state), { signal: request.controller.signal, cache: "no-store" });
15884
- if (alive === false || token !== weatherRequestToken) return false;
15885
- if (response === null || response === undefined || response.ok !== true) {
15886
- setWeatherError("network");
15887
- scheduleWeatherRetry();
15888
- return false;
15931
+ let result;
15932
+ if (weatherDirectBlocked === false) {
15933
+ result = await fetchWeatherDirect(state);
15934
+ if (result.ok === false && result.error === "aborted") return false;
15935
+ if (result.ok === false) {
15936
+ // 直连栽在网络上:问一次宿主。只有宿主真的取到了,才记住“直连不可用”,
15937
+ // 这样网络恢复后下一次仍会先试直连(宿主失败时也会清掉这个捷径)。
15938
+ const payload = await weatherViaHost(state);
15939
+ if (payload !== null) {
15940
+ result = { ok: true, payload };
15941
+ weatherDirectBlocked = true;
15942
+ tl5Diag("context", { weatherFallback: "host" });
15943
+ }
15889
15944
  }
15890
- const payload = await response.json();
15891
- if (alive === false || token !== weatherRequestToken) return false;
15945
+ } else {
15946
+ const payload = await weatherViaHost(state);
15947
+ if (payload !== null) {
15948
+ result = { ok: true, payload };
15949
+ } else {
15950
+ weatherDirectBlocked = false;
15951
+ result = await fetchWeatherDirect(state);
15952
+ }
15953
+ }
15954
+ if (alive === false) return false;
15955
+ if (result.ok === true) {
15892
15956
  if (weatherController.state().enabled !== true) return false;
15893
- const last = normalizeWeatherForecast(payload);
15957
+ const last = normalizeWeatherForecast(result.payload);
15894
15958
  if (last === null) {
15895
15959
  setWeatherError("invalid");
15896
15960
  scheduleWeatherRetry();
@@ -15908,18 +15972,10 @@ body[data-dsh-tianlight] [data-tl-group="context"] .tl-fx-hint {
15908
15972
  weatherController.apply({ last, lastError: "" });
15909
15973
  applyWeatherAmbience(last.code, last.isDay);
15910
15974
  return true;
15911
- } catch (error) {
15912
- if (alive === false || token !== weatherRequestToken) return false;
15913
- const reason =
15914
- request.timedOut === true || (error !== null && error !== undefined && error.name === "AbortError")
15915
- ? "timeout"
15916
- : "network";
15917
- setWeatherError(reason);
15918
- scheduleWeatherRetry();
15919
- return false;
15920
- } finally {
15921
- weatherCloseRequest(request);
15922
15975
  }
15976
+ setWeatherError(result.error === "timeout" ? "timeout" : "network");
15977
+ scheduleWeatherRetry();
15978
+ return false;
15923
15979
  };
15924
15980
  const resolveWeatherCity = async (query) => {
15925
15981
  if (alive === false) return { ok: false, error: "aborted" };
package/lib/index.js CHANGED
@@ -29,6 +29,7 @@ import { frameCacheStatus, handleFrameCache, handleFrameCacheStatus } from './me
29
29
  import { derivedPath, ffmpegStatus, handleTranscode, handleTranscodeStatus, listDerived } from './transcode.js'
30
30
  import { handleWebProject, listWebProjects } from './web-project.js'
31
31
  import { buildFingerprint, formatFingerprintLine } from './fingerprint.js'
32
+ import { handleWeatherProxy } from './weather-proxy.js'
32
33
  import {
33
34
  PET_CHAT_CODES,
34
35
  computePetLlmCapability,
@@ -73,7 +74,7 @@ const HOST_API = '2'
73
74
  * manifest is stamped with it. The handshake no longer compares it, so a
74
75
  * browser-half-only update can run against an unchanged host process.
75
76
  */
76
- const BUILD = '2.0.3'
77
+ const BUILD = '2.0.5'
77
78
 
78
79
  function readRoots() {
79
80
  try {
@@ -472,6 +473,22 @@ function handle(ctx, req, res) {
472
473
  )
473
474
  return
474
475
  }
476
+ if (rest === '_weather') {
477
+ // v2.0.5: transport shim for networks where the renderer's TLS handshake to
478
+ // Open-Meteo is dropped. Read-only, no state, no caching.
479
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
480
+ sendText(res, 405, 'method not allowed')
481
+ return
482
+ }
483
+ void handleWeatherProxy(url, res).catch(() => {
484
+ try {
485
+ sendJson(res, 502, { ok: false, error: 'network' })
486
+ } catch {
487
+ // response already gone
488
+ }
489
+ })
490
+ return
491
+ }
475
492
  if (rest === '_fingerprint') {
476
493
  // v2.0.1: exact installed-build identity for the hub's self-test / feedback panels.
477
494
  // Additive route; it carries versions, hashes and the install method only — never a
@@ -5,7 +5,7 @@
5
5
  // list is exactly how "the upload accepted a format the player cannot decode"
6
6
  // bugs happen. One table, imported by every route.
7
7
 
8
- import { statSync } from 'node:fs'
8
+ import { realpathSync, statSync } from 'node:fs'
9
9
  import { dirname, resolve, sep } from 'node:path'
10
10
  import { fileURLToPath } from 'node:url'
11
11
 
@@ -198,7 +198,17 @@ export function isSafeSvgBuffer(buffer) {
198
198
  if (SVG_NAMED_ENTITIES.has(entity[1]) === false) return { ok: false, reason: 'named entity' }
199
199
  entity = entityPattern.exec(text)
200
200
  }
201
- const tagPattern = /<\s*\/?\s*([A-Za-z_][\w.-]*:)?([A-Za-z_][\w.-]*)([^>]*?)>/g
201
+ // v2.0.4 (M1): a raw `>` inside a quoted attribute value (`alt=">"`) used to end
202
+ // the tag early so the attributes after it were never inspected. Two layers now:
203
+ // a document-wide raw scan that does not depend on where a tag ends, and a tag
204
+ // scanner whose attribute part consumes whole quoted strings.
205
+ if (/[\s/"']on[a-z]+\s*=/i.test(text)) return { ok: false, reason: 'inline event handler' }
206
+ for (const denied of SVG_DENY_ELEMENTS) {
207
+ if (new RegExp('<\\s*(?:[A-Za-z_][\\w.-]*:)?' + denied + '(?![\\w.:-])', 'i').test(text)) {
208
+ return { ok: false, reason: 'dangerous element: ' + denied }
209
+ }
210
+ }
211
+ const tagPattern = /<\s*\/?\s*([A-Za-z_][\w.-]*:)?([A-Za-z_][\w.-]*)((?:[^>"']|"[^"]*"|'[^']*')*?)>/g
202
212
  let firstLocalName = ''
203
213
  let match = tagPattern.exec(text)
204
214
  while (match !== null) {
@@ -250,16 +260,43 @@ export function isSafeSvgBuffer(buffer) {
250
260
  }
251
261
 
252
262
  /**
253
- * Resolves `name` inside `root` and proves the result stays inside it. Symlinks and
254
- * `..` are both defeated by comparing the RESOLVED path against the resolved root
255
- * with a trailing separator, which is the only containment test that cannot be
256
- * fooled by a crafted filename.
263
+ * v2.0.4 (M2): true when the REAL path of `target` (symlinks and Windows junctions
264
+ * resolved) is `root` itself or inside the real path of `root`. Lexical checks
265
+ * (`resolve()` + startsWith) cannot see links; this one can. A path that cannot be
266
+ * resolved (missing, permission) is reported as outside — callers fail closed.
267
+ */
268
+ export function realPathInside(root, target) {
269
+ try {
270
+ const realRoot = realpathSync.native(root)
271
+ const realTarget = realpathSync.native(target)
272
+ const fold = (value) => (process.platform === 'win32' ? value.toLowerCase() : value)
273
+ const prefix = realRoot.endsWith(sep) ? realRoot : realRoot + sep
274
+ return fold(realTarget) === fold(realRoot) || fold(realTarget).startsWith(fold(prefix))
275
+ } catch {
276
+ return false
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Resolves `name` inside `root` and proves the result stays inside it: `..` and
282
+ * separators are refused by SAFE_NAME plus a lexical prefix test, and an existing
283
+ * entry must also resolve (through any symlink/junction) to a real path inside the
284
+ * real root (v2.0.4; before that the comment claimed this but the code did not).
257
285
  */
258
286
  export function safeJoin(root, name) {
259
287
  if (typeof name !== 'string' || SAFE_NAME.test(name) === false) return null
260
288
  const joined = resolve(root, name)
261
289
  const prefix = root.endsWith(sep) ? root : root + sep
262
- return joined.startsWith(prefix) ? joined : null
290
+ if (joined.startsWith(prefix) === false) return null
291
+ let exists = false
292
+ try {
293
+ statSync(joined)
294
+ exists = true
295
+ } catch {
296
+ exists = false
297
+ }
298
+ if (exists && realPathInside(root, joined) === false) return null
299
+ return joined
263
300
  }
264
301
 
265
302
  /** Card metadata: size is cheap (one stat) and lets the library show real weight. */
package/lib/pet-chat.js CHANGED
@@ -31,6 +31,15 @@ export const PET_CHAT_MAX_CHARS = 4000
31
31
  export const PET_CHAT_MAX_TOKENS = 600
32
32
  /** Whole-call deadline; the browser adapter also races at 20 s. */
33
33
  export const PET_CHAT_TIMEOUT_MS = 20000
34
+ /**
35
+ * v2.0.4 (M3): host-side call budget. The browser keeps its own (stricter, user
36
+ * configurable) quota, but any same-origin script could call this route directly,
37
+ * so the host enforces a ceiling of its own. Set just above the most the UI can ever
38
+ * spend (user daily limit max 120 + 12 autonomous thoughts) so normal use never hits
39
+ * it. Every accepted call counts, including failures and timeouts.
40
+ */
41
+ export const PET_CHAT_HOST_PER_MINUTE = 8
42
+ export const PET_CHAT_HOST_PER_DAY = 140
34
43
 
35
44
  /**
36
45
  * Fixed system prompt. It must not be assembled from Host or page data: the page
@@ -203,7 +212,33 @@ export function createPetChat(options = {}) {
203
212
  ? Math.floor(options.maxBodyBytes)
204
213
  : PET_CHAT_MAX_BODY_BYTES
205
214
  const maxChars = Number.isFinite(options.maxChars) && options.maxChars > 0 ? Math.floor(options.maxChars) : PET_CHAT_MAX_CHARS
215
+ const perMinute =
216
+ Number.isFinite(options.perMinute) && options.perMinute > 0 ? Math.floor(options.perMinute) : PET_CHAT_HOST_PER_MINUTE
217
+ const perDay = Number.isFinite(options.perDay) && options.perDay > 0 ? Math.floor(options.perDay) : PET_CHAT_HOST_PER_DAY
218
+ const now = typeof options.now === 'function' ? options.now : () => Date.now()
206
219
  let busy = false
220
+ /** Accepted-call timestamps of the last minute + the per-local-day counter. */
221
+ let recent = []
222
+ let dayKey = ''
223
+ let dayCount = 0
224
+ const localDayKey = (ms) => {
225
+ const d = new Date(ms)
226
+ return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
227
+ }
228
+ /** Reserve one call from the host budget; false when the minute or day is spent. */
229
+ const takeBudget = () => {
230
+ const t = now()
231
+ recent = recent.filter((stamp) => t - stamp < 60000)
232
+ const key = localDayKey(t)
233
+ if (key !== dayKey) {
234
+ dayKey = key
235
+ dayCount = 0
236
+ }
237
+ if (recent.length >= perMinute || dayCount >= perDay) return false
238
+ recent.push(t)
239
+ dayCount += 1
240
+ return true
241
+ }
207
242
 
208
243
  /**
209
244
  * Handle one request. Never throws, never rejects; the response body is always
@@ -287,6 +322,11 @@ export function createPetChat(options = {}) {
287
322
  respond(429, { ok: false, code: PET_CHAT_CODES.BUSY })
288
323
  return
289
324
  }
325
+ if (takeBudget() === false) {
326
+ req?.resume?.()
327
+ respond(429, { ok: false, code: PET_CHAT_CODES.RATE_LIMIT })
328
+ return
329
+ }
290
330
  busy = true
291
331
  acquired = true
292
332
  controller = new AbortController()
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
14
14
  import { join, resolve, sep } from 'node:path'
15
- import { ROUTE, SAFE_NAME, fileSize } from './media-types.js'
15
+ import { ROUTE, SAFE_NAME, fileSize, realPathInside } from './media-types.js'
16
16
 
17
17
  /** Extensions a scene renderer may legitimately request. No HTML/JS/EXE. */
18
18
  export const SCENE_FILE_EXT = new Set([
@@ -81,6 +81,8 @@ export function sceneFilePath(projectDir, segments) {
81
81
  current = resolve(current, segment)
82
82
  if (current.startsWith(prefix) === false) return null
83
83
  }
84
+ // v2.0.4 (M2): a junction/symlink inside the project must not lead outside it.
85
+ if (existsSync(current) && realPathInside(base, current) === false) return null
84
86
  const ext = current.slice(current.lastIndexOf('.')).toLowerCase()
85
87
  if (SCENE_FILE_EXT.has(ext) === false) return null
86
88
  return current