@alexpeng/dsh-custom-plugin 0.4.0 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -4,6 +4,50 @@ All notable changes to this project are documented here. The format loosely
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions
5
5
  follow [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## 0.4.2 — 2026-09-12
8
+
9
+ ### Fixed
10
+
11
+ - **Exports fail on forked/resumed sessions with "读取会话失败: seeded
12
+ session constructor seed must equal its inherited prefix".** Newer dsh
13
+ builds replay-validate inside `sessionQuery.readSession()` through a
14
+ snapshot-mode constructor that rejects any seeded (forked or resumed) session
15
+ whose log outgrew its seed boundary, so timeline, export, in-session
16
+ search, and usage scans all failed on those sessions. Every read now goes
17
+ through a shared helper that falls back to `observeSession()` (the live and
18
+ restore paths dsh's own session page uses) when `readSession()` rejects, and
19
+ surfaces the original error only when no fallback exists.
20
+ - **The "PDF(含图片)" export button produced an `.html` file.** The button and
21
+ its description now say what actually lands on disk: "HTML(含图片)", a
22
+ print-ready HTML document you turn into a PDF via the browser print dialog.
23
+ - **Weather FX are invisible on light backgrounds.** Snow, rain, and sakura
24
+ colors were tuned for the dark theme only — pure-white flakes, 6%-alpha pale
25
+ rain, and 90%-lightness pink petals all vanish over the near-white palette
26
+ backgrounds. The FX canvas now picks a darker particle palette (cool slate
27
+ snow, steel-blue rain, deeper rose petals, each with a lifted alpha floor)
28
+ whenever the resolved theme is light or the saturated aurora background is
29
+ active, and swaps palettes live on theme/background changes without
30
+ rebuilding the particle field.
31
+
32
+ ## 0.4.1 — 2026-09-09
33
+
34
+ ### Fixed
35
+
36
+ - **Fresh installs show nothing after a "successful" install.** `keytar` (a
37
+ native optional dependency) tripped pnpm 11's strict build-script gate, so
38
+ `dsh plugin add` exited non-zero and the harness never reconciled the bundle
39
+ layer — the package sat inert in `dependencies` with no host half and no
40
+ browser half. `keytar` is no longer a dependency: the OS-keyring adapter
41
+ still detects a `keytar` module present in the profile's `node_modules`, and
42
+ users who want the OS keyring can add it themselves
43
+ (`dsh plugin --profile web add keytar`).
44
+ - The browser half now waits for the `slots` service (a child fiber) before
45
+ mounting its surfaces instead of reading it synchronously: newer dsh builds
46
+ activate the slots provider after this plugin's entry, and the synchronous
47
+ read lost that race every time, logging "slots service unavailable" and
48
+ skipping all UI. The mount stays fail-soft — the GUI boots even when the
49
+ service never appears.
50
+
7
51
  ## 0.4.0 — 2026-09-03
8
52
 
9
53
  ### Added
package/README.i18n.yaml CHANGED
@@ -1,7 +1,7 @@
1
- # Bilingual-pair consistency record: the git blob hash of each README as of
1
+ # Bilingual-pair consistency record: the git blob hash of each README as of
2
2
  # the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record the hashes:
4
4
  # git hash-object --path README.md README.md
5
5
  # git hash-object --path README.zh.md README.zh.md
6
- README.md: 8c5a4e55a1e687f1b6875d8d51f982416672ab14
7
- README.zh.md: 1cb41d78b883bc294d60e64cb68d43653653ae17
6
+ README.md: eb2b863638b101a7b1a768233e687218ec913549
7
+ README.zh.md: ec3625b6ef3a95adc4ce9519a6cda7c775e51f97
package/README.md CHANGED
@@ -178,7 +178,7 @@ Appearance and feature toggles (the `cfg` field, all with defaults):
178
178
  ## Security model
179
179
 
180
180
  - The browser talks to the host only through loopback `/api/custom-plugin` routes; every route checks a loopback socket address, a loopback Host header, and browser same-origin markers (`sec-fetch-site` / `Origin`). `X-Forwarded-For` is never trusted.
181
- - The browser never receives the saved DeepSeek API key. New panel keys use the optional OS credential store through `keytar`; older plaintext state keys are migrated on startup when that store is available.
181
+ - The browser never receives the saved DeepSeek API key. New panel keys use the OS credential store through `keytar` when it is present; older plaintext state keys are migrated on startup when that store is available. `keytar` ships as no dependency of this plugin (a native module would trip pnpm 11's strict build gate and silently keep the whole bundle from activating); users who want the OS keyring can add it to the profile themselves: `dsh plugin --profile web add keytar`.
182
182
  - If the OS credential store is unavailable, the plugin keeps a compatibility fallback in `$DSH_HOME/custom-plugin-state.json`; protect `$DSH_HOME` accordingly. DSH's own `$DSH_HOME/.credentials.yaml` remains a supported plaintext fallback.
183
183
  - Conversation exports and timeline data stay on the local host.
184
184
 
@@ -187,7 +187,7 @@ Appearance and feature toggles (the `cfg` field, all with defaults):
187
187
  - The Mermaid engine comes from the dependency installed with the plugin and works offline; only a missing dependency falls back to a CDN fetch (cached for the host process lifetime).
188
188
  - The usage ledger folds token counts from live `session/event` records, retains 90 Beijing calendar days, and a manual "scan" re-reads today's session logs with four concurrent reads when live events were missed.
189
189
  - The balance panel shows the peak/off-peak token and cost split plus a link to the official pricing page; legacy rows without peak counters are marked inexact and excluded from cost totals until rescanned.
190
- - OS credential storage depends on the optional `keytar` backend; when it cannot be loaded, the compatibility state-file fallback is used.
190
+ - OS credential storage detects a `keytar` module present in the profile's `node_modules` when the host starts; when it cannot be loaded, the compatibility state-file fallback is used.
191
191
  - Cost estimates use DeepSeek's official peak/off-peak list prices and are indicative only.
192
192
  - Dark-mode background restriction is deliberate: only "no color" and "aurora" are selectable in dark mode.
193
193
  - DSH currently exposes no archive-restore API; the plugin does not bypass that boundary by editing the underlying registry.
package/README.zh.md CHANGED
@@ -178,7 +178,7 @@ dsh plugin --profile web add link:F:/dsh-plugin-dev
178
178
  ## 安全模型
179
179
 
180
180
  - 浏览器仅通过回环地址上的 `/api/custom-plugin` 路由与宿主通信;每条路由同时校验回环 socket 地址、回环 Host 头与浏览器同源标记(`sec-fetch-site` / `Origin`),`X-Forwarded-For` 永不信任。
181
- - 浏览器永远不会收到已保存的 DeepSeek API Key。面板新输入的 Key 优先通过可选的 `keytar` 写入系统凭据存储;旧版状态文件中的明文 Key 会在系统存储可用时启动迁移。
181
+ - 浏览器永远不会收到已保存的 DeepSeek API Key。面板新输入的 Key 在 `keytar` 存在时优先写入系统凭据存储;旧版状态文件中的明文 Key 会在系统存储可用时启动迁移。`keytar` 不再作为本插件的依赖发布(原生模块会触发 pnpm 11 的严格构建门禁,导致整个插件包安装后无法激活);需要系统钥匙串的用户可自行加入 profile:`dsh plugin --profile web add keytar`。
182
182
  - 如果系统凭据存储不可用,插件会兼容回退到 `$DSH_HOME/custom-plugin-state.json`;请相应保护 `$DSH_HOME` 目录。DSH 自身的 `$DSH_HOME/.credentials.yaml` 明文凭据仍可复用。
183
183
  - 会话导出与时间线数据全部停留在本机。
184
184
 
@@ -187,7 +187,7 @@ dsh plugin --profile web add link:F:/dsh-plugin-dev
187
187
  - Mermaid 引擎来自随插件安装的本地依赖,离线可用;仅当依赖缺失时回退 CDN 拉取(宿主在进程生命周期内缓存)。
188
188
  - 用量账本折叠自实时 `session/event` 记录,只保留最近 90 个北京时间日;错过实时事件时可手动「扫描」,扫描最多并发读取 4 个会话日志。
189
189
  - 额度面板会显示峰/闲 token 与费用分布,并提供官方价目链接;没有峰时字段的历史行会标记为“不精确”,不计入费用总额,重新扫描后可更新。
190
- - 系统凭据存储依赖可选的 `keytar` 后端;无法加载时使用兼容的状态文件回退。
190
+ - 系统凭据存储会在宿主启动时检测 profile `node_modules` 中的 `keytar` 模块;无法加载时使用兼容的状态文件回退。
191
191
  - 费用按 DeepSeek 官方峰谷单价估算,仅供参考。
192
192
  - 深色模式下背景限制是刻意设计:仅「无颜色」与「极光」可选。
193
193
  - DSH 当前没有公开的归档恢复接口;插件不会绕过官方边界修改底层注册表。
package/lib/client.js CHANGED
@@ -2482,8 +2482,20 @@ window.__ModuleLoader__.load({
2482
2482
  "hsla(352, 55%, 93%, 0.8)",
2483
2483
  "hsla(348, 40%, 88%, 0.8)"
2484
2484
  ];
2485
- const SAKURA_SPRITES = [];
2485
+ /** 浅色背景变体:90% 亮度的淡粉在近白的调色板背景上会消失,
2486
+ * 换成更深的玫瑰粉保持可辨识度。 */
2487
+ const SAKURA_PALETTE_LIGHT = [
2488
+ "hsla(340, 60%, 72%, 0.9)",
2489
+ "hsla(342, 64%, 70%, 0.9)",
2490
+ "hsla(344, 66%, 68%, 0.9)",
2491
+ "hsla(346, 68%, 66%, 0.9)",
2492
+ "hsla(348, 70%, 64%, 0.9)",
2493
+ "hsla(350, 66%, 66%, 0.9)",
2494
+ "hsla(352, 60%, 68%, 0.9)",
2495
+ "hsla(348, 52%, 70%, 0.9)"
2496
+ ];
2486
2497
  const SAKURA_IMAGES = [];
2498
+ const SAKURA_IMAGES_LIGHT = [];
2487
2499
  function rand(a, b) {
2488
2500
  return a + Math.random() * (b - a);
2489
2501
  }
@@ -2499,32 +2511,30 @@ window.__ModuleLoader__.load({
2499
2511
  g.closePath();
2500
2512
  g.restore();
2501
2513
  }
2502
- function buildSakuraSprites() {
2503
- if (SAKURA_SPRITES.length > 0) return;
2514
+ function buildSakuraSpriteSet(palette, target) {
2515
+ if (target.length > 0) return;
2504
2516
  const cvs = (typeof document !== "undefined" ? document : null)?.createElement("canvas");
2505
2517
  if (cvs === void 0 || cvs === null) return;
2506
2518
  cvs.width = 48;
2507
2519
  cvs.height = 48;
2508
2520
  const g = cvs.getContext("2d");
2509
2521
  if (g === null) return;
2510
- for (let i = 0; i < SAKURA_PALETTE.length; i++) {
2522
+ for (const color of palette) {
2511
2523
  g.clearRect(0, 0, 48, 48);
2512
- g.fillStyle = SAKURA_PALETTE[i];
2524
+ g.fillStyle = color;
2513
2525
  tracePetal(g, 24, 24, 10, 0);
2514
2526
  g.fill();
2515
2527
  try {
2516
- SAKURA_SPRITES.push(cvs.toDataURL());
2517
- } catch {
2518
- SAKURA_SPRITES.push(null);
2519
- }
2520
- }
2521
- for (const sprite of SAKURA_SPRITES) {
2522
- if (sprite === null) continue;
2523
- const image = new Image();
2524
- image.src = sprite;
2525
- SAKURA_IMAGES.push(image);
2528
+ const image = new Image();
2529
+ image.src = cvs.toDataURL();
2530
+ target.push(image);
2531
+ } catch {}
2526
2532
  }
2527
2533
  }
2534
+ function buildSakuraSprites() {
2535
+ buildSakuraSpriteSet(SAKURA_PALETTE, SAKURA_IMAGES);
2536
+ buildSakuraSpriteSet(SAKURA_PALETTE_LIGHT, SAKURA_IMAGES_LIGHT);
2537
+ }
2528
2538
  function initFx(weather, w, h) {
2529
2539
  FX.snow = [];
2530
2540
  FX.rain = [];
@@ -2661,7 +2671,7 @@ window.__ModuleLoader__.load({
2661
2671
  h: rand(.4, 1.1)
2662
2672
  });
2663
2673
  }
2664
- function fxFrame(g, cvs, weather, time) {
2674
+ function fxFrame(g, cvs, weather, time, light) {
2665
2675
  const w = cvs.clientWidth || 0;
2666
2676
  const h = cvs.clientHeight || 0;
2667
2677
  if (w === 0 || h === 0) return;
@@ -2682,10 +2692,10 @@ window.__ModuleLoader__.load({
2682
2692
  }
2683
2693
  if (f.x > w + f.radius) f.x = -f.radius;
2684
2694
  else if (f.x < -f.radius) f.x = w + f.radius;
2685
- const q = Math.round(f.opacity * 50) / 50;
2695
+ const q = Math.round((light ? Math.min(.9, f.opacity + .15) : f.opacity) * 50) / 50;
2686
2696
  if (q !== currentOpacity) {
2687
2697
  currentOpacity = q;
2688
- g.fillStyle = `rgba(255,255,255,${q})`;
2698
+ g.fillStyle = light ? `rgba(125,146,170,${q})` : `rgba(255,255,255,${q})`;
2689
2699
  }
2690
2700
  g.beginPath();
2691
2701
  g.arc(f.x, f.y, f.radius, 0, Math.PI * 2);
@@ -2708,10 +2718,10 @@ window.__ModuleLoader__.load({
2708
2718
  d.x = Math.random() * (w + 100) - 50;
2709
2719
  }
2710
2720
  if (d.x > w + 50) d.x = -50;
2711
- const qo = Math.round(d.opacity * 30) / 30;
2721
+ const qo = Math.round((light ? Math.min(.5, d.opacity + .08) : d.opacity) * 30) / 30;
2712
2722
  if (qo !== currentOpacity) {
2713
2723
  currentOpacity = qo;
2714
- g.strokeStyle = `rgba(180,200,220,${qo})`;
2724
+ g.strokeStyle = light ? `rgba(104,130,156,${qo})` : `rgba(180,200,220,${qo})`;
2715
2725
  }
2716
2726
  const qw = Math.round(d.lineWidth * 4) / 4;
2717
2727
  if (qw !== currentWidth) {
@@ -2735,48 +2745,60 @@ window.__ModuleLoader__.load({
2735
2745
  }
2736
2746
  g.save();
2737
2747
  g.globalAlpha = Math.max(0, sp.life);
2738
- g.strokeStyle = "rgba(180,200,220,0.8)";
2748
+ g.strokeStyle = light ? "rgba(104,130,156,0.8)" : "rgba(180,200,220,0.8)";
2739
2749
  g.lineWidth = .8;
2740
2750
  g.beginPath();
2741
2751
  g.ellipse(sp.x, sp.y, sp.w, sp.h, 0, 0, Math.PI * 2);
2742
2752
  g.stroke();
2743
2753
  g.restore();
2744
2754
  }
2745
- } else if (weather === "sakura") for (const f of FX.sakura) {
2746
- f.y += f.speedY;
2747
- f.x += Math.sin(f.phase + time * f.swayFreq) * f.drift;
2748
- if (f.y > h + f.size) {
2749
- f.y = -f.size;
2750
- f.x = Math.random() * w;
2751
- }
2752
- if (f.x > w + f.size) f.x = -f.size;
2753
- else if (f.x < -f.size) f.x = w + f.size;
2754
- const rot = Math.sin(f.phase + time * f.swayFreq * 1.7) * .9 + time * f.spin;
2755
- const wob = 1 + .12 * Math.sin(f.phase * 2 + time * f.swayFreq * 2.3);
2756
- if (f.spriteIndex >= 0 && SAKURA_IMAGES[f.spriteIndex] !== void 0) {
2757
- g.save();
2758
- g.globalAlpha = f.opacity;
2759
- g.translate(f.x, f.y);
2760
- g.rotate(rot);
2761
- g.scale(f.size * f.wobble * wob / 18, f.size * f.wobble / 18);
2762
- g.drawImage(SAKURA_IMAGES[f.spriteIndex], -18, -18, 36, 36);
2763
- g.restore();
2764
- } else {
2765
- g.save();
2766
- g.globalAlpha = f.opacity;
2767
- g.translate(f.x, f.y);
2768
- g.rotate(rot);
2769
- g.scale(f.size * f.wobble * wob / 10, f.size * f.wobble / 10);
2770
- g.fillStyle = SAKURA_PALETTE[0];
2771
- tracePetal(g, 0, 0, 1, 0);
2772
- g.fill();
2773
- g.restore();
2755
+ } else if (weather === "sakura") {
2756
+ const imgs = light ? SAKURA_IMAGES_LIGHT : SAKURA_IMAGES;
2757
+ const alpha = (f) => light ? Math.min(1, f.opacity + .2) : f.opacity;
2758
+ for (const f of FX.sakura) {
2759
+ f.y += f.speedY;
2760
+ f.x += Math.sin(f.phase + time * f.swayFreq) * f.drift;
2761
+ if (f.y > h + f.size) {
2762
+ f.y = -f.size;
2763
+ f.x = Math.random() * w;
2764
+ }
2765
+ if (f.x > w + f.size) f.x = -f.size;
2766
+ else if (f.x < -f.size) f.x = w + f.size;
2767
+ const rot = Math.sin(f.phase + time * f.swayFreq * 1.7) * .9 + time * f.spin;
2768
+ const wob = 1 + .12 * Math.sin(f.phase * 2 + time * f.swayFreq * 2.3);
2769
+ const img = f.spriteIndex >= 0 ? imgs[f.spriteIndex] : void 0;
2770
+ if (img !== void 0) {
2771
+ g.save();
2772
+ g.globalAlpha = alpha(f);
2773
+ g.translate(f.x, f.y);
2774
+ g.rotate(rot);
2775
+ g.scale(f.size * f.wobble * wob / 18, f.size * f.wobble / 18);
2776
+ g.drawImage(img, -18, -18, 36, 36);
2777
+ g.restore();
2778
+ } else {
2779
+ g.save();
2780
+ g.globalAlpha = alpha(f);
2781
+ g.translate(f.x, f.y);
2782
+ g.rotate(rot);
2783
+ g.scale(f.size * f.wobble * wob / 10, f.size * f.wobble / 10);
2784
+ g.fillStyle = light ? SAKURA_PALETTE_LIGHT[0] : SAKURA_PALETTE[0];
2785
+ tracePetal(g, 0, 0, 1, 0);
2786
+ g.fill();
2787
+ g.restore();
2788
+ }
2774
2789
  }
2775
2790
  }
2776
2791
  }
2777
2792
  function FxCanvas() {
2778
2793
  const s = useS();
2779
2794
  const ref = react.useRef(null);
2795
+ /** 粒子配色跟随背景亮度:浅色主题(以及任何主题下的高饱和极光)
2796
+ * 需要更深的粒子颜色才可辨识。ref 让 RAF 循环每帧读到最新值,
2797
+ * 主题/背景切换时无需重建粒子场。 */
2798
+ const lightRef = react.useRef(!(s.dark === true) || s.cfg.bg === "aurora");
2799
+ react.useEffect(() => {
2800
+ lightRef.current = !(s.dark === true) || s.cfg.bg === "aurora";
2801
+ }, [s.dark, s.cfg.bg]);
2780
2802
  react.useEffect(() => {
2781
2803
  const cvs = ref.current;
2782
2804
  if (cvs === null) return;
@@ -2796,7 +2818,7 @@ window.__ModuleLoader__.load({
2796
2818
  return;
2797
2819
  }
2798
2820
  raf = requestAnimationFrame(loop);
2799
- fxFrame(g, cvs, weather, Date.now() - t0);
2821
+ fxFrame(g, cvs, weather, Date.now() - t0, lightRef.current);
2800
2822
  };
2801
2823
  loop();
2802
2824
  return () => {
@@ -4893,7 +4915,7 @@ window.__ModuleLoader__.load({
4893
4915
  }
4894
4916
  function ExportTab() {
4895
4917
  const s = useS();
4896
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "将当前会话导出为文件:JSON 可导入其他工具,Markdown 便于阅读分享,PDF 内嵌图片(打印时另存为 PDF)。"), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
4918
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "将当前会话导出为文件:JSON 可导入其他工具,Markdown 便于阅读分享,HTML 内嵌图片(导出 .html 文件,浏览器打开后打印即可另存为 PDF)。"), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
4897
4919
  className: "vx-btn big",
4898
4920
  disabled: s.exporting === true,
4899
4921
  onClick: () => runExport("json")
@@ -4914,7 +4936,7 @@ window.__ModuleLoader__.load({
4914
4936
  }, react.createElement(Icon, {
4915
4937
  n: "download",
4916
4938
  size: 14
4917
- }), " PDF(含图片)")), s.exporting === true ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "导出中…") : null, react.createElement(BackupControls, null));
4939
+ }), " HTML(含图片)")), s.exporting === true ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "导出中…") : null, react.createElement(BackupControls, null));
4918
4940
  }
4919
4941
  function MermaidTab() {
4920
4942
  const [engine, setEngine] = react.useState(mermaidState.status);
@@ -6025,27 +6047,30 @@ window.__ModuleLoader__.load({
6025
6047
  //#endregion
6026
6048
  //#region src/client/index.ts
6027
6049
  /**
6028
- * Required services. Deliberately empty: every surface is looked up lazily
6029
- * (with a graceful no-op fallback), so this plugin can never sit "pending
6030
- * (waiting for services)" — a fiber that waits on a service name the client
6031
- * runtime never provides would block the whole web boot behind the
6032
- * "Loading plugins…" gate forever.
6050
+ * Required services. Deliberately empty: the mount waits on `slots` inside
6051
+ * `apply` (a child fiber) instead of declaring it here, so this entry can
6052
+ * never sit "pending (waiting for services)" — a top-level fiber that waits
6053
+ * on a service name the client runtime never provides would block the whole
6054
+ * web boot behind the "Loading plugins…" gate forever.
6033
6055
  */
6034
6056
  const inject = [];
6035
6057
  /**
6036
- * Mount the Custom suite.
6058
+ * Mount the Custom suite once the slots service is available.
6037
6059
  * @param ctx - client root context.
6038
6060
  */
6039
6061
  function apply(ctx) {
6040
6062
  ctx.effect(() => {
6041
- try {
6042
- return installCustomPlugin(ctx, apiDiagReport);
6043
- } catch (error) {
6044
- const message = `install failed: ${String(error?.message ?? error)}`;
6045
- console.error(`[custom-plugin] ${message}`);
6046
- apiDiagReport(message);
6047
- return () => {};
6048
- }
6063
+ ctx.inject(["slots"], (slotCtx) => {
6064
+ try {
6065
+ return installCustomPlugin(slotCtx, apiDiagReport);
6066
+ } catch (error) {
6067
+ const message = `install failed: ${String(error?.message ?? error)}`;
6068
+ console.error(`[custom-plugin] ${message}`);
6069
+ apiDiagReport(message);
6070
+ return () => {};
6071
+ }
6072
+ });
6073
+ return () => {};
6049
6074
  }, "custom-plugin: surfaces");
6050
6075
  }
6051
6076
  //#endregion