@xsok/dsh-enhanced 0.2.2-8 → 0.2.2-9

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
@@ -2,7 +2,19 @@
2
2
 
3
3
  版本号前三位对应主程序版本,最后一段是插件自身的发布序号。
4
4
 
5
- ## Preview version
5
+ ## 0.2.2-9
6
+
7
+ ### 修复
8
+
9
+ - **进一步修复空白会话守卫功能:**仅有缓存分片、没有会话日志的会话不再参与同步;云端分片仍标记为空会话时,用本机分片覆盖修正。
10
+
11
+ ### 优化
12
+
13
+ - 归档/取消归档双向传播:任一台设备的归档状态会同步到其他设备,并在被动变化后自动重启生效。
14
+ - 同步日志默认显示最近 20 次,并保留各次的文件明细供悬停查看。
15
+ - 启动时的自动同步同样在右下角状态行显示进度与完成提示。
16
+
17
+ ## 0.2.2-8
6
18
 
7
19
  ### 新增
8
20
 
package/client.js CHANGED
@@ -176,6 +176,7 @@ window.__ModuleLoader__.load({
176
176
  'sync.attachments': 'Sync attachments',
177
177
  'sync.probe': 'Check',
178
178
  'sync.run': 'Sync now',
179
+ 'sync.run.hint': 'Ctrl+Alt+Shift+T',
179
180
  'sync.running': 'Syncing…',
180
181
  'sync.done': 'Sessions synced',
181
182
  'sync.never': 'Not run yet.',
@@ -378,6 +379,7 @@ window.__ModuleLoader__.load({
378
379
  'sync.attachments': '同步附件',
379
380
  'sync.probe': '检查',
380
381
  'sync.run': '立即同步',
382
+ 'sync.run.hint': 'Ctrl+Alt+Shift+T',
381
383
  'sync.running': '正在同步…',
382
384
  'sync.done': '会话同步完成',
383
385
  'sync.never': '尚未运行。',
@@ -619,7 +621,7 @@ window.__ModuleLoader__.load({
619
621
  deleteBusy: false,
620
622
  deleteError: null,
621
623
  move: { open: false, sessionId: null, title: '', loading: false, current: null, workspaces: [], targetId: null, error: null, busy: false },
622
- sync: { loading: false, busy: false, target: null, state: null, error: null, showLog: false, webdav: null, webdavBusy: false, history: [], historyOpen: null, historyLimit: 5, auto: null },
624
+ sync: { loading: false, busy: false, target: null, state: null, error: null, showLog: false, webdav: null, webdavBusy: false, history: [], historyOpen: null, historyLimit: 20, auto: null },
623
625
  overwrite: { open: false, direction: 'cloud', busy: false, preview: null, error: null },
624
626
  restartConfirm: false,
625
627
  syncLive: false,
@@ -718,14 +720,25 @@ window.__ModuleLoader__.load({
718
720
  // Launch-time catch-up: unconditional on the sync switch, but it must not
719
721
  // run while a turn is in progress.
720
722
  if (store.get().sync.busy === true) return;
723
+ // The composer status line follows the launch run just like a manual one.
724
+ store.set({ sync: { ...store.get().sync, busy: true, error: null }, syncDone: false });
721
725
  try {
722
726
  const data = await runtime.rpc('sync.run', { quiet: true });
723
- if (data?.skipped === 'busy') return;
724
- store.set({ sync: { ...store.get().sync, state: data, error: null } });
727
+ if (data?.skipped === 'busy') {
728
+ store.set({ sync: { ...store.get().sync, busy: false } });
729
+ return;
730
+ }
731
+ store.set({
732
+ sync: { ...store.get().sync, busy: false, state: data, error: null },
733
+ syncDone: data?.ok !== false,
734
+ });
725
735
  await store.loadSync();
726
736
  const pulled = Number(data?.summary?.sessions?.pulled) || Number(data?.summary?.sessions?.created) || 0;
727
- if (pulled > 0) store.restartSoon('restart.reason.sync');
737
+ const repaired = Number(data?.summary?.blankGuard?.repaired) || 0;
738
+ const archiveChanged = Number(data?.summary?.archive?.changed) || 0;
739
+ if (pulled > 0 || repaired > 0 || archiveChanged > 0) store.restartSoon('restart.reason.sync');
728
740
  } catch (error) {
741
+ store.set({ sync: { ...store.get().sync, busy: false } });
729
742
  console.warn('[dsh-enhanced] startup sync failed:', error);
730
743
  }
731
744
  },
@@ -1062,7 +1075,9 @@ window.__ModuleLoader__.load({
1062
1075
  );
1063
1076
  await store.loadSync();
1064
1077
  const pulled = Number(data?.summary?.sessions?.pulled) || Number(data?.summary?.sessions?.created) || 0;
1065
- if (pulled > 0) {
1078
+ const repaired = Number(data?.summary?.blankGuard?.repaired) || 0;
1079
+ const archiveChanged = Number(data?.summary?.archive?.changed) || 0;
1080
+ if (pulled > 0 || repaired > 0 || archiveChanged > 0) {
1066
1081
  store.restartSoon('restart.reason.sync');
1067
1082
  }
1068
1083
  } catch (error) {
@@ -1320,10 +1335,10 @@ window.__ModuleLoader__.load({
1320
1335
  },
1321
1336
  toggleSyncLog() {
1322
1337
  const open = state.sync.showLog !== true;
1323
- store.set({ sync: { ...state.sync, showLog: open, historyOpen: open ? 0 : null, historyLimit: 5 } });
1338
+ store.set({ sync: { ...state.sync, showLog: open, historyOpen: open ? 0 : null, historyLimit: 20 } });
1324
1339
  },
1325
1340
  showMoreHistory() {
1326
- store.set({ sync: { ...state.sync, historyLimit: (Number(state.sync.historyLimit) || 5) + 50 } });
1341
+ store.set({ sync: { ...state.sync, historyLimit: (Number(state.sync.historyLimit) || 20) + 50 } });
1327
1342
  },
1328
1343
  openHistory(index) {
1329
1344
  const next = state.sync.historyOpen === index ? null : index;
@@ -2616,6 +2631,7 @@ const displayName = (value) => {
2616
2631
  h('button', {
2617
2632
  type: 'button',
2618
2633
  className: 'dshe-action',
2634
+ title: runtime.t('sync.run.hint'),
2619
2635
  disabled: state.sync.busy === true,
2620
2636
  onClick: () => runtime.store.runSyncNow(),
2621
2637
  }, runtime.t('sync.run')),
@@ -2671,7 +2687,7 @@ const displayName = (value) => {
2671
2687
  ? h('div', {},
2672
2688
  h('div', { className: 'dshe-row-desc' }, runtime.t('sync.historyCount', { n: logEntries(state).length })),
2673
2689
  h('div', { className: 'dshe-log-list dshe-log-scroll' },
2674
- logEntries(state).slice(0, Number(state.sync.historyLimit) || 5).map((item, index) => {
2690
+ logEntries(state).slice(0, Number(state.sync.historyLimit) || 20).map((item, index) => {
2675
2691
  const open = state.sync.historyOpen === index;
2676
2692
  return h('div', { key: item.at ?? String(index), className: 'dshe-log-item' },
2677
2693
  h('button', {
@@ -2684,7 +2700,7 @@ const displayName = (value) => {
2684
2700
  open ? h('div', { className: 'dshe-sync-log dshe-log-body' }, (item.log ?? []).map((line, lineIndex) => h(LogLine, { key: lineIndex, line, files: item.details?.[lineIndex] ?? [] }))) : null);
2685
2701
  }),
2686
2702
  ),
2687
- logEntries(state).length > (Number(state.sync.historyLimit) || 5)
2703
+ logEntries(state).length > (Number(state.sync.historyLimit) || 20)
2688
2704
  ? h('button', { type: 'button', className: 'dshe-action', onClick: () => runtime.store.showMoreHistory() }, runtime.t('sync.more'))
2689
2705
  : null,
2690
2706
  )
@@ -104,16 +104,30 @@ export function pruneArchiveEvents(events, keepIds) {
104
104
  return { events: kept, removed };
105
105
  }
106
106
 
107
- /** Drop ids whose latest event says `active`. */
107
+ /**
108
+ * Apply the merged event table to this machine's archived set.
109
+ *
110
+ * An `active` event releases a local entry; an `archived` event from another
111
+ * machine adds one, so archiving propagates in both directions.
112
+ */
108
113
  export function applyArchiveEvents(archived, events) {
109
- const kept = [];
114
+ const own = archived instanceof Set ? archived : new Set(archived ?? []);
115
+ const kept = new Set();
110
116
  const released = [];
111
- for (const id of archived) {
117
+ const added = [];
118
+ for (const id of own) {
112
119
  const event = events[id];
113
120
  if (event !== undefined && event.state === 'active') released.push(id);
114
- else kept.push(id);
121
+ else kept.add(id);
122
+ }
123
+ for (const [id, event] of Object.entries(events)) {
124
+ if (event?.state !== 'archived') continue;
125
+ if (own.has(id)) continue;
126
+ if (kept.has(id)) continue;
127
+ kept.add(id);
128
+ added.push(id);
115
129
  }
116
- return { kept, released };
130
+ return { kept: [...kept], released, added };
117
131
  }
118
132
 
119
133
  /**
@@ -128,7 +142,9 @@ export async function syncArchiveState(deps) {
128
142
  const incoming = diffArchiveEvents(localArchived, previous, machineId);
129
143
  const merged = mergeArchiveEvents(existing, incoming);
130
144
  if (apply && Object.keys(incoming).length > 0) await writeArchiveEvents(stateDir, merged);
131
- const { kept, released } = applyArchiveEvents(localArchived, merged);
145
+ const { kept, released, added } = applyArchiveEvents(localArchived, merged);
132
146
  if (apply) await writeArchiveSnapshot(stateDir, machineId, kept);
133
- return { archived: kept, released, emitted: incoming, events: merged };
147
+ // Any difference against the local set came from the share, so it needs a
148
+ // restart to show; a purely local change does not.
149
+ return { archived: kept, released, added, changed: released.length + added.length, emitted: incoming, events: merged };
134
150
  }
@@ -142,7 +142,7 @@ async function runSyncJsInner(deps) {
142
142
 
143
143
  let sessions = { pushed: 0, pulled: 0, skipped: 0, created: 0, missing: 0, aborted: null };
144
144
  let prune = { quarantined: 0, hardDeleted: 0, sharedDeleted: 0, kept: 0, throttled: 0, quarantinePurged: 0 };
145
- let archive = { archived: [], released: [], events: {} };
145
+ let archive = { archived: [], released: [], added: [], changed: 0, events: {} };
146
146
  let workspace = { local: null, shared: null, missing: [] };
147
147
  let projcache = { parsed: 0, updated: 0, mirrored: 0, untouched: 0 };
148
148
  let pluginList = { count: 0, file: '' };
@@ -234,6 +234,13 @@ async function runSyncJsInner(deps) {
234
234
  const merged = new Set([...own, ...effective].filter((id) => id && !released.has(id)));
235
235
  doc.global.archivedSessionIds = [...merged].sort();
236
236
  }
237
+ // What the merge actually produced for this machine decides whether the list
238
+ // changes: it covers both archive events and ids arriving via workspace.json.
239
+ const finalLocalArchived = new Set(workspace.local.global?.archivedSessionIds ?? []);
240
+ let mergedArchiveChanged = 0;
241
+ for (const id of finalLocalArchived) if (!archivedBefore.has(id)) mergedArchiveChanged += 1;
242
+ for (const id of archivedBefore) if (!finalLocalArchived.has(id)) mergedArchiveChanged += 1;
243
+ archive.changed = mergedArchiveChanged;
237
244
  if (apply) {
238
245
  if (validWorkspaceDoc(workspace.local)) {
239
246
  await writeJson(path.join(dshHome, 'storages', 'workspace.json'), workspace.local);
@@ -298,9 +305,9 @@ async function runSyncJsInner(deps) {
298
305
  prune: { quarantined: prune.quarantined, hardDeleted: prune.hardDeleted, sharedDeleted: prune.sharedDeleted, kept: prune.kept, throttled: prune.throttled, quarantinePurged: prune.quarantinePurged ?? 0 },
299
306
  workspace: { local: Object.keys(workspace.local?.tables?.workspaces ?? {}).length, shared: Object.keys(workspace.shared?.tables?.workspaces ?? {}).length, skipped: workspace.skipped ?? null, error: workspace.error ?? null },
300
307
  titleMerge: projcache,
301
- blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
308
+ blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: (sessions.blankGuard?.repaired ?? 0) + (sessions.blankRepaired ?? 0) },
302
309
  plugins: pluginList.count,
303
- archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
310
+ archive: { released: archive.released.length, archived: archive.archived.length, changed: archive.changed ?? 0, eventsPruned: prunedEvents.removed },
304
311
  missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
305
312
  paths: { created: sessions.created ?? 0, failed: sessions.missing ?? 0 },
306
313
  };
@@ -333,9 +340,9 @@ async function runSyncJsInner(deps) {
333
340
  },
334
341
  workspace: { local: Object.keys(workspace.local?.tables?.workspaces ?? {}).length, shared: Object.keys(workspace.shared?.tables?.workspaces ?? {}).length, skipped: workspace.skipped ?? null, error: workspace.error ?? null },
335
342
  titleMerge: projcache,
336
- blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
343
+ blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: (sessions.blankGuard?.repaired ?? 0) + (sessions.blankRepaired ?? 0) },
337
344
  plugins: pluginList.count,
338
- archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
345
+ archive: { released: archive.released.length, archived: archive.archived.length, changed: archive.changed ?? 0, eventsPruned: prunedEvents.removed },
339
346
  missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
340
347
  paths: { created: sessions.created ?? 0, failed: sessions.missing ?? 0 },
341
348
  };
@@ -56,6 +56,13 @@ function setTitle(doc, winner) {
56
56
  record.rows.title = winner;
57
57
  }
58
58
 
59
+ /** Whether one shard still claims its session was never used. */
60
+ function isBlank(doc) {
61
+ if (doc === null || typeof doc !== 'object') return false;
62
+ const record = doc.record !== undefined && doc.record !== null ? doc.record : doc;
63
+ return record?.rows?.sessionListMetadata?.val?.blank === true;
64
+ }
65
+
59
66
  /** Map of session id -> { file, mtime } for one shard directory. */
60
67
  async function indexShards(dir) {
61
68
  const map = new Map();
@@ -158,6 +165,22 @@ export async function mergeProjcacheTitles(deps) {
158
165
  } else {
159
166
  mirrored += 1;
160
167
  }
168
+ } else if (localEntry !== undefined && sharedEntry !== undefined
169
+ && isBlank(sharedDoc) && !isBlank(localDoc)) {
170
+ // The local shard says the session has a conversation while the share still
171
+ // says it is empty: overwrite the share, or every other machine that pulls
172
+ // it keeps hiding the conversation.
173
+ if (apply) {
174
+ try {
175
+ await fsp.copyFile(localEntry.file, sharedEntry.file);
176
+ await fsp.utimes(sharedEntry.file, new Date(localEntry.mtime), new Date(localEntry.mtime)).catch(() => {});
177
+ mirrored += 1;
178
+ } catch {
179
+ // Retried next round.
180
+ }
181
+ } else {
182
+ mirrored += 1;
183
+ }
161
184
  }
162
185
  }
163
186
 
@@ -9,7 +9,7 @@ import { promises as fsp } from 'node:fs';
9
9
  import { randomUUID } from 'node:crypto';
10
10
  import path from 'node:path';
11
11
  import { scanSessions, projectKey } from './scan.js';
12
- import { buildBlankGuard } from './blank-guard.js';
12
+ import { buildBlankGuard, repairPulledSessions } from './blank-guard.js';
13
13
  import { lastContentSeq, readSessionFile, rewriteCwd, writeSessionFile } from './session.js';
14
14
  import {
15
15
  SESSION_LEDGER,
@@ -325,6 +325,7 @@ export async function syncSessions(deps) {
325
325
  // 4. Pull shared sessions this machine lacks or holds in an older state.
326
326
  let created = 0;
327
327
  let missing = 0;
328
+ const pulledLocal = [];
328
329
  for (const [id, entry] of refreshedShare) {
329
330
  if (ledger.deleted[id] !== undefined) continue;
330
331
  if (guardedIds.has(id)) continue;
@@ -357,6 +358,7 @@ export async function syncSessions(deps) {
357
358
  await writeSessionFile(target, texts);
358
359
  const seconds = entry.mtime / 1000;
359
360
  await fsp.utimes(target, seconds, seconds).catch(() => {});
361
+ pulledLocal.push({ id, file: target });
360
362
  }
361
363
  pulled += 1;
362
364
  if (pulledIds.length < 300) pulledIds.push(id);
@@ -365,6 +367,19 @@ export async function syncSessions(deps) {
365
367
  }
366
368
  }
367
369
 
370
+ // The regular guard ran before these sessions existed locally, so a shard that
371
+ // still says "blank" is repaired now, in the same run, before the config phase
372
+ // pushes it back to the share.
373
+ let blankRepaired = 0;
374
+ if (apply && pulledLocal.length > 0) {
375
+ try {
376
+ const fixed = await repairPulledSessions({ items: pulledLocal, cacheDir, apply });
377
+ blankRepaired = fixed.repaired;
378
+ } catch {
379
+ blankRepaired = 0;
380
+ }
381
+ }
382
+
368
383
  // 5. Remember what this machine holds so the next run can spot deletions.
369
384
  const keys = {};
370
385
  for (const [id, entry] of (await scanSessions(localRoot))) keys[id] = new Date(entry.mtime).toISOString();
@@ -376,5 +391,5 @@ export async function syncSessions(deps) {
376
391
  await writeJsonAtomic(legacyFile, { version: 1, deleted: {} });
377
392
  }
378
393
 
379
- return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds, blankGuard };
394
+ return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds, blankGuard, blankRepaired };
380
395
  }
package/host/schedule.js CHANGED
@@ -121,7 +121,11 @@ export function installSyncScheduler(ctx, deps) {
121
121
  */
122
122
  async function restartForNewSessions(record, context) {
123
123
  const pulled = Number(record?.summary?.sessions?.pulled) || Number(record?.summary?.sessions?.created) || 0;
124
- if (pulled <= 0) return false;
124
+ const repaired = Number(record?.summary?.blankGuard?.repaired) || 0;
125
+ const archiveChanged = Number(record?.summary?.archive?.changed) || 0;
126
+ // A repaired shard or a share-side archive change alters the list just like a
127
+ // new session does.
128
+ if (pulled <= 0 && repaired <= 0 && archiveChanged <= 0) return false;
125
129
  const { paths, settings, agents } = context;
126
130
  const busy = (agents?.list?.() ?? []).some((agent) => agent?.status === 'running');
127
131
  if (busy) {
@@ -147,7 +151,7 @@ async function restartForNewSessions(record, context) {
147
151
  } catch {
148
152
  // A missing marker only means the next run may restart sooner.
149
153
  }
150
- trace(`restarting for ${String(pulled)} new sessions`);
154
+ trace(`restarting for ${String(pulled)} pulled / ${String(repaired)} repaired / ${String(archiveChanged)} archive`);
151
155
  await restartApplication(paths);
152
156
  return true;
153
157
  }
package/host/sync.js CHANGED
@@ -506,7 +506,16 @@ async function appendHistory(file, record) {
506
506
  paths: record.summary?.paths ?? null,
507
507
  missing: record.summary?.missing ?? null,
508
508
  log: Array.isArray(record.log) ? record.log.slice(-60) : [],
509
+ // File lists per log line, bounded so the history file stays small.
510
+ details: Array.isArray(record.details)
511
+ ? record.details.map((files) => (Array.isArray(files) ? files.slice(0, 40) : []))
512
+ : [],
509
513
  });
514
+ // Only the newest runs keep their file lists; older rows stay text-only.
515
+ const DETAIL_KEEP = 20;
516
+ for (let i = DETAIL_KEEP; i < list.length; i += 1) {
517
+ if (Object.prototype.hasOwnProperty.call(list[i], 'details')) delete list[i].details;
518
+ }
510
519
  await writeJson(file, pruneHistory(list));
511
520
  }
512
521
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsok/dsh-enhanced",
3
- "version": "0.2.2-8",
3
+ "version": "0.2.2-9",
4
4
  "description": "DeepSeek Harness 增强插件:会话删除与找回、跨工作区移动、全库内容搜索、自动加载历史,以及多设备同步(本地目录 / WebDAV)。",
5
5
  "type": "module",
6
6
  "license": "MIT",