@xsok/dsh-enhanced 0.2.2-3 → 0.2.2-4

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 ADDED
@@ -0,0 +1,25 @@
1
+ # 更新记录
2
+
3
+ 版本号前三位对应主程序版本,最后一段是插件自身的发布序号。
4
+
5
+ ## 0.2.2-4
6
+
7
+ ### 改进
8
+
9
+ - **自动加载更早消息**:改为距顶部 800 像素即开始预取,加载期间不打断滚轮滚动,内容插入后保持视口位置不变。
10
+ - **会话同步**:下载到新会话后自动重启应用,仅在无任务运行且距上次自动重启超过同步冷却时间时执行。
11
+
12
+ ### 修复
13
+
14
+ - 内容寻址附件被反复下载:云端清单缺少哈希时,改为按文件名自校验后跳过。
15
+ - 云端清单缺 hash 的条目会自我维持,导致每次同步都判定为“云端更新”。
16
+
17
+ ## 0.2.2-3
18
+
19
+ 首个公开版本,包含:
20
+
21
+ - **会话同步**:WebDAV 或本地共享目录双向同步,覆盖会话、工作区、附件与配置;支持立即同步、覆盖云端、覆盖本机、同步日志与文件明细。
22
+ - **会话管理**:会话删除进回收站、按保留天数清理、跨工作区移动。
23
+ - **内容搜索**:`Ctrl+F` 全库搜索会话标题、消息正文与工具输出。
24
+ - **阅读**:滚动到历史处自动加载更早消息。
25
+ - **运维**:环境检测、重启应用、主程序版本变化提醒。
package/README.md CHANGED
@@ -145,6 +145,20 @@
145
145
 
146
146
  ---
147
147
 
148
+ ## 更新记录
149
+
150
+ 完整记录见 [CHANGELOG.md](./CHANGELOG.md)。
151
+
152
+ ### 0.2.2-4
153
+
154
+ - 自动加载更早消息改为提前预取:距顶部 800 像素即开始加载,加载期间不打断滚动,插入后保持视口位置不动。
155
+ - 会话同步在下载到新会话后自动重启,仅在无任务运行且超过同步冷却时间时执行。
156
+ - 修复内容寻址附件被反复下载、云端清单缺哈希。
157
+
158
+ ### 0.2.2-3
159
+
160
+ 首个公开版本:会话同步(WebDAV / 本地目录)、会话删除与找回、跨工作区移动、`Ctrl+F` 全库搜索、自动加载更早消息、环境检测与重启。
161
+
148
162
  ## 许可证
149
163
 
150
164
  [MIT](./LICENSE)
package/client.js CHANGED
@@ -2648,22 +2648,19 @@ const displayName = (value) => {
2648
2648
  }, 'dsh-enhanced: restart shortcut');
2649
2649
 
2650
2650
  ctx.effect(() => {
2651
- let lastTop = 0;
2652
- let cooldownUntil = 0;
2653
- let framePending = false;
2654
- let gestureAt = 0;
2651
+ // Prefetch distance from the top of the loaded history, in pixels.
2652
+ const PREFETCH_PX = 800;
2653
+ // Do not stack requests closer than this, so one flick loads one page.
2654
+ const MIN_GAP_MS = 120;
2655
2655
  let cachedScroller = null;
2656
- let wheelTimer = null;
2657
2656
  let loading = null;
2657
+ let scheduled = null;
2658
+ let lastStartAt = 0;
2658
2659
 
2659
- const markGesture = () => {
2660
- gestureAt = Date.now();
2661
- };
2660
+ const flowNode = () => document.querySelector('[data-chat-flow]');
2662
2661
 
2663
2662
  const followingTail = () => document.querySelector('[data-chat-following-tail]') !== null;
2664
2663
 
2665
- const flowNode = () => document.querySelector('[data-chat-flow]');
2666
-
2667
2664
  const scrollerFor = () => {
2668
2665
  if (cachedScroller !== null && cachedScroller.isConnected === true) return cachedScroller;
2669
2666
  cachedScroller = null;
@@ -2695,89 +2692,100 @@ const displayName = (value) => {
2695
2692
  return null;
2696
2693
  };
2697
2694
 
2698
- const nearTop = (limit) => {
2695
+ const scrollHeightOf = (scroller) => (scroller === null ? 0 : scroller.scrollHeight);
2696
+
2697
+ /**
2698
+ * Load one page without moving the viewport.
2699
+ *
2700
+ * The click inserts content above; the reader keeps the same messages on
2701
+ * screen because scrollTop grows by exactly the height that was added.
2702
+ */
2703
+ const loadPage = () => {
2704
+ if (loading !== null) return;
2705
+ if (Date.now() - lastStartAt < MIN_GAP_MS) return;
2706
+ if (runtime.store.get().settings.autoLoadEnabled !== true) return;
2707
+ if (followingTail()) return;
2708
+ const button = findOlderButton();
2709
+ if (button === null || button.disabled === true) return;
2710
+
2699
2711
  const scroller = scrollerFor();
2700
- if (scroller === null) return true;
2701
- return scroller.scrollTop <= limit;
2702
- };
2712
+ if (scroller === null) return;
2713
+ const before = { height: scroller.scrollHeight, top: scroller.scrollTop };
2703
2714
 
2704
- const isVisible = (button) => {
2705
- const rect = button.getBoundingClientRect();
2706
- return rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.top < (window.innerHeight || 1024);
2707
- };
2715
+ loading = { height: before.height, top: before.top, at: Date.now() };
2716
+ lastStartAt = Date.now();
2717
+ try {
2718
+ button.blur();
2719
+ } catch {
2720
+ // A button without focus support is fine.
2721
+ }
2722
+ button.click();
2708
2723
 
2709
- const attempt = (button) => {
2710
- if (runtime.store.get().settings.autoLoadEnabled !== true) return;
2711
- if (Date.now() < cooldownUntil) return;
2712
- if (loading !== null) return;
2713
- const target = button ?? findOlderButton();
2714
- if (target === null || target.disabled === true) return;
2715
-
2716
- // One page at a time: hold every further trigger until the flow grows,
2717
- // so a single continuous scroll never stacks two jumps.
2718
- const before = flowNode()?.querySelectorAll('[data-chat-flow-key]').length ?? 0;
2719
- loading = { before, at: Date.now() };
2720
- cooldownUntil = Date.now() + 1500;
2721
- target.click();
2722
2724
  const settle = () => {
2723
2725
  if (loading === null) return;
2724
- const now = flowNode()?.querySelectorAll('[data-chat-flow-key]').length ?? before;
2725
- if (now !== before || Date.now() - loading.at > 5000) {
2726
- loading = null;
2726
+ const heightNow = scroller.scrollHeight;
2727
+ const grown = heightNow - before.height;
2728
+ const elapsed = Date.now() - loading.at;
2729
+ if (grown <= 0 && elapsed < 8000) {
2730
+ window.setTimeout(settle, 100);
2727
2731
  return;
2728
2732
  }
2729
- window.setTimeout(settle, 200);
2733
+ // The browser may already have anchored the view; only correct when it
2734
+ // did not, or the two compensations would add up into a jump.
2735
+ const moved = Math.abs(scroller.scrollTop - before.top) > 4;
2736
+ if (grown > 0 && !moved) scroller.scrollTop = before.top + grown;
2737
+ loading = null;
2738
+ // Chain straight into the next page while the reader is still near the top.
2739
+ schedule(80);
2730
2740
  };
2731
- window.setTimeout(settle, 250);
2741
+ window.setTimeout(settle, 100);
2732
2742
  };
2733
2743
 
2734
- const onWheel = (event) => {
2735
- markGesture();
2736
- if (event.deltaY >= 0) return;
2737
- if (followingTail()) return;
2738
- if (!nearTop(600)) return;
2739
- // Wait for the gesture to pause: clicking mid-flick is what made the
2740
- // reader jump between pages.
2741
- if (wheelTimer !== null) window.clearTimeout(wheelTimer);
2742
- wheelTimer = window.setTimeout(() => {
2743
- wheelTimer = null;
2744
- attempt(null);
2745
- }, 200);
2744
+ const schedule = (delay) => {
2745
+ if (scheduled !== null) window.clearTimeout(scheduled);
2746
+ scheduled = window.setTimeout(() => {
2747
+ scheduled = null;
2748
+ const scroller = scrollerFor();
2749
+ if (scroller === null) return;
2750
+ if (scroller.scrollTop > PREFETCH_PX) return;
2751
+ loadPage();
2752
+ }, delay);
2746
2753
  };
2747
2754
 
2748
- const onScroll = (event) => {
2749
- if (followingTail()) return;
2750
- if (Date.now() - gestureAt > 1200) return;
2751
- const target = event.target;
2752
- if (event.target instanceof Element && event.target.closest('[data-chat-flow]') === null && event.target.querySelector('[data-chat-flow]') === null) return;
2755
+ let framePending = false;
2756
+ let lastTop = null;
2757
+ const onScroll = () => {
2753
2758
  if (framePending) return;
2754
2759
  framePending = true;
2755
2760
  window.requestAnimationFrame(() => {
2756
2761
  framePending = false;
2762
+ if (runtime.store.get().settings.autoLoadEnabled !== true) return;
2763
+ if (followingTail()) return;
2757
2764
  const scroller = scrollerFor();
2758
- const top = scroller !== null ? scroller.scrollTop : (target instanceof Element ? target.scrollTop : 0);
2759
- const goingUp = top < lastTop - 2;
2765
+ if (scroller === null) return;
2766
+ const top = scroller.scrollTop;
2767
+ const goingUp = lastTop !== null && top < lastTop - 2;
2760
2768
  lastTop = top;
2761
- if (!goingUp || top > 600) return;
2762
- const button = findOlderButton();
2763
- if (button === null) return;
2764
- if (top <= 8 || isVisible(button)) attempt(button);
2769
+ if (!goingUp) return;
2770
+ if (top > PREFETCH_PX) return;
2771
+ loadPage();
2765
2772
  });
2766
2773
  };
2767
2774
 
2768
- const onKeyDown = (event) => {
2769
- if (event.key === 'PageUp' || event.key === 'ArrowUp' || event.key === 'Home') markGesture();
2775
+ const onWheel = (event) => {
2776
+ if (event.deltaY >= 0) return;
2777
+ const scroller = scrollerFor();
2778
+ if (scroller === null) return;
2779
+ if (scroller.scrollTop > PREFETCH_PX) return;
2780
+ schedule(0);
2770
2781
  };
2771
2782
 
2772
- window.addEventListener('wheel', onWheel, { capture: true, passive: true });
2773
2783
  window.addEventListener('scroll', onScroll, { capture: true, passive: true });
2774
- window.addEventListener('keydown', onKeyDown, true);
2775
- window.addEventListener('touchstart', markGesture, { capture: true, passive: true });
2784
+ window.addEventListener('wheel', onWheel, { capture: true, passive: true });
2776
2785
  return () => {
2777
- window.removeEventListener('wheel', onWheel, true);
2778
2786
  window.removeEventListener('scroll', onScroll, true);
2779
- window.removeEventListener('keydown', onKeyDown, true);
2780
- window.removeEventListener('touchstart', markGesture, true);
2787
+ window.removeEventListener('wheel', onWheel, true);
2788
+ if (scheduled !== null) window.clearTimeout(scheduled);
2781
2789
  };
2782
2790
  }, 'dsh-enhanced: auto load earlier');
2783
2791
 
@@ -2801,6 +2809,7 @@ const displayName = (value) => {
2801
2809
  return () => window.clearTimeout(timer);
2802
2810
  }, 'dsh-enhanced: open session after reload');
2803
2811
 
2812
+
2804
2813
  ctx.effect(() => {
2805
2814
  runtime.store.init();
2806
2815
  return () => {};
@@ -2832,6 +2841,7 @@ const displayName = (value) => {
2832
2841
  locale: NS,
2833
2842
  }, SessionMoveRow));
2834
2843
 
2844
+
2835
2845
  ctx.slots.inject('shell.overlay', () => ctx.slots.register({
2836
2846
  name: 'shell.overlay',
2837
2847
  id: 'dsh-enhanced.search',
package/host/envcheck.js CHANGED
@@ -12,7 +12,7 @@ import zlib from 'node:zlib';
12
12
  import { scanFrames } from './engine/zstd.js';
13
13
  import { scanSessions, projectKey } from './engine/scan.js';
14
14
 
15
- const PLUGIN_VERSION = '0.2.2-3';
15
+ const PLUGIN_VERSION = '0.2.2-4';
16
16
 
17
17
  async function readJson(file) {
18
18
  try {
package/host/mirror.js CHANGED
@@ -115,6 +115,11 @@ export async function measureMirror(root) {
115
115
  return result;
116
116
  }
117
117
 
118
+ /** Attachment objects are named after their own sha256. */
119
+ function isContentAddressed(rel) {
120
+ return /^attachments\/v1\/objects\/[0-9a-f]{2}\/[0-9a-f]{64}$/u.test(rel);
121
+ }
122
+
118
123
  /** Content hash used to decide whether a file really changed. */
119
124
  function sha256(buffer) {
120
125
  return createHash('sha256').update(buffer).digest('hex');
@@ -254,6 +259,19 @@ export async function pullMirror(deps, signal) {
254
259
  }
255
260
  // A rewritten server timestamp is not a content change: trust the manifest
256
261
  // hash before paying for a download.
262
+ if (mine !== undefined && info.size === mine.size && isContentAddressed(rel)) {
263
+ // attachments/v1/objects/<ab>/<sha256>: the file name is its own hash.
264
+ try {
265
+ if (sha256(await fsp.readFile(target)) === rel.split('/').pop()) {
266
+ const authored = Number(known[rel]?.mtime) > 0 ? Number(known[rel].mtime) : info.mtime;
267
+ if (authored > 0) await fsp.utimes(target, authored / 1000, authored / 1000).catch(() => {});
268
+ skipped += 1;
269
+ continue;
270
+ }
271
+ } catch {
272
+ // Unreadable copy: fall through to the download.
273
+ }
274
+ }
257
275
  if (mine !== undefined && info.size === mine.size && typeof known[rel]?.hash === 'string') {
258
276
  try {
259
277
  if (sha256(await fsp.readFile(target)) === known[rel].hash) {
@@ -341,7 +359,17 @@ export async function pushMirror(deps, signal) {
341
359
 
342
360
  if (entryIsCurrent && (remote === undefined || !differs(remote, info))) {
343
361
  // Untouched locally since the last push, and the share agrees.
344
- manifest[rel] = { size: info.size, mtime: info.mtime, hash: entry.hash };
362
+ let hash = entry.hash;
363
+ if (typeof hash !== 'string') {
364
+ // Older manifests recorded size and time only; without a hash every later
365
+ // pull sees a differing server stamp and downloads the file again.
366
+ try {
367
+ hash = sha256(await fsp.readFile(localPathFor(mirror, rel)));
368
+ } catch {
369
+ hash = undefined;
370
+ }
371
+ }
372
+ manifest[rel] = { size: info.size, mtime: info.mtime, hash };
345
373
  skipped += 1;
346
374
  continue;
347
375
  }
package/host/schedule.js CHANGED
@@ -14,6 +14,7 @@ import { promises as fsp } from 'node:fs';
14
14
  import path from 'node:path';
15
15
  import { readSettings } from './trash.js';
16
16
  import { runSync } from './sync.js';
17
+ import { restartApplication } from './restart.js';
17
18
 
18
19
  const TICK_MS = 60_000;
19
20
  const IDLE_DELAY_MS = 30_000;
@@ -103,7 +104,44 @@ export function installSyncScheduler(ctx, deps) {
103
104
  }
104
105
  };
105
106
 
106
- async function autoRun(reason) {
107
+ /**
108
+ * Restart so newly synced sessions become visible, but only when nobody is
109
+ * working and the last automatic restart was long enough ago.
110
+ */
111
+ async function restartForNewSessions(record, context) {
112
+ const pulled = Number(record?.summary?.sessions?.pulled) || Number(record?.summary?.sessions?.created) || 0;
113
+ if (pulled <= 0) return false;
114
+ const { paths, settings, agents } = context;
115
+ const busy = (agents?.list?.() ?? []).some((agent) => agent?.status === 'running');
116
+ if (busy) {
117
+ trace(`restart skipped: a session is running (${String(pulled)} new)`);
118
+ return false;
119
+ }
120
+ const marker = path.join(paths.base, 'restart-last.json');
121
+ let last = 0;
122
+ try {
123
+ const stored = JSON.parse(await fsp.readFile(marker, 'utf8'));
124
+ if (Number.isFinite(Number(stored?.at))) last = Number(stored.at);
125
+ } catch {
126
+ last = 0;
127
+ }
128
+ // Reuse the sync cooldown: it already describes how often this machine acts.
129
+ const gapMs = Math.max(0, Number(settings.syncCooldownMinutes) || 0) * 60_000;
130
+ if (last > 0 && Date.now() - last < gapMs) {
131
+ trace(`restart skipped: only ${String(Math.round((Date.now() - last) / 1000))}s since the last one`);
132
+ return false;
133
+ }
134
+ try {
135
+ await fsp.writeFile(marker, JSON.stringify({ at: Date.now(), pulled }), 'utf8');
136
+ } catch {
137
+ // A missing marker only means the next run may restart sooner.
138
+ }
139
+ trace(`restarting for ${String(pulled)} new sessions`);
140
+ await restartApplication(paths);
141
+ return true;
142
+ }
143
+
144
+ async function autoRun(reason) {
107
145
  if (disposed || running || paused) {
108
146
  trace(`autoRun ${reason}: ignored (disposed=${String(disposed)} running=${String(running)} paused=${String(paused)})`);
109
147
  return false;
@@ -145,6 +183,7 @@ export function installSyncScheduler(ctx, deps) {
145
183
  if (record.ok === true) {
146
184
  failures = 0;
147
185
  note(`${reason}: ok in ${String(record.durationMs)} ms`, 'info');
186
+ await restartForNewSessions(record, { paths, settings, agents }).catch(() => {});
148
187
  } else {
149
188
  failures += 1;
150
189
  paused = failures >= FAILURE_LIMIT;
package/index.js CHANGED
@@ -22,7 +22,8 @@ import {
22
22
  resolvePaths,
23
23
  writeSettings,
24
24
  } from './host/trash.js';
25
- import { appendFile } from 'node:fs';
25
+ import path from 'node:path';
26
+ import { appendFile } from 'node:fs/promises';
26
27
  import { createSearch } from './host/search.js';
27
28
  import { restartApplication } from './host/restart.js';
28
29
  import { inspectOverride, overwriteCloud, overwriteLocal } from './host/overwrite.js';
@@ -215,7 +216,7 @@ export function apply(ctx, config = {}) {
215
216
  const record = await readEnvRecord(paths);
216
217
  return {
217
218
  appVersion: current.version,
218
- pluginVersion: '0.2.2-3',
219
+ pluginVersion: '0.2.2-4',
219
220
  lastAppVersion: record.lastAppVersion ?? null,
220
221
  changed: current.version !== null && record.lastAppVersion !== undefined && record.lastAppVersion !== current.version,
221
222
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsok/dsh-enhanced",
3
- "version": "0.2.2-3",
3
+ "version": "0.2.2-4",
4
4
  "description": "DeepSeek Harness 增强插件:会话删除与找回、跨工作区移动、全库内容搜索、自动加载历史,以及多设备同步(本地目录 / WebDAV)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,7 +55,8 @@
55
55
  "host/engine/prune.js",
56
56
  "host/engine/atomic.js",
57
57
  "host/engine/ledger.js",
58
- "host/envcheck.js"
58
+ "host/envcheck.js",
59
+ "CHANGELOG.md"
59
60
  ],
60
61
  "dsh": {
61
62
  "bundle": {