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

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.
@@ -164,6 +164,9 @@ async function runSyncJsInner(deps) {
164
164
  }
165
165
  }
166
166
 
167
+ // A session that was created but never used carries a blank projection shard;
168
+ // uploading it hides the conversation on every machine that later pulls it.
169
+ // The session phase applies that guard while it already holds the scan.
167
170
  sessions = await step('sessions', () => syncSessions({
168
171
  localRoot: localSessions,
169
172
  sharedRoot: sharedSessions,
@@ -171,6 +174,8 @@ async function runSyncJsInner(deps) {
171
174
  machineId,
172
175
  resolveCwd,
173
176
  apply,
177
+ cacheDir: path.join(dshHome, 'storages', 'session_projcache', 'sessions'),
178
+ guardStateFile: path.join(dshHome, 'dsh-enhanced', 'blank-guard-state.json'),
174
179
  journalFile: path.join(dshHome, 'dsh-enhanced', 'delete-journal.json'),
175
180
  }));
176
181
 
@@ -250,6 +255,7 @@ async function runSyncJsInner(deps) {
250
255
  machineId,
251
256
  force: !apply,
252
257
  apply,
258
+ skipIds: sessions.blankGuard?.skipIds ?? new Set(),
253
259
  }));
254
260
 
255
261
  pluginList = await step('plugins', () => (apply
@@ -292,6 +298,7 @@ async function runSyncJsInner(deps) {
292
298
  prune: { quarantined: prune.quarantined, hardDeleted: prune.hardDeleted, sharedDeleted: prune.sharedDeleted, kept: prune.kept, throttled: prune.throttled, quarantinePurged: prune.quarantinePurged ?? 0 },
293
299
  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 },
294
300
  titleMerge: projcache,
301
+ blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
295
302
  plugins: pluginList.count,
296
303
  archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
297
304
  missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
@@ -326,6 +333,7 @@ async function runSyncJsInner(deps) {
326
333
  },
327
334
  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 },
328
335
  titleMerge: projcache,
336
+ blankGuard: { skipped: sessions.blankGuard?.skipped ?? 0, repaired: sessions.blankGuard?.repaired ?? 0 },
329
337
  plugins: pluginList.count,
330
338
  archive: { released: archive.released.length, archived: archive.archived.length, eventsPruned: prunedEvents.removed },
331
339
  missing: { sessions: sessions.missing ?? 0, groups: missingGroups.length },
@@ -83,7 +83,17 @@ async function indexShards(dir) {
83
83
  * @returns counters for the run summary.
84
84
  */
85
85
  export async function mergeProjcacheTitles(deps) {
86
- const { localDir, sharedDir, stateDir, machineId, force = false, apply = true } = deps;
86
+ const {
87
+ localDir,
88
+ sharedDir,
89
+ stateDir,
90
+ machineId,
91
+ force = false,
92
+ apply = true,
93
+ // Sessions the blank-session guard keeps out of the share this run: their
94
+ // shard must not be mirrored either, or the empty state would still travel.
95
+ skipIds = new Set(),
96
+ } = deps;
87
97
  const localIndex = await indexShards(localDir);
88
98
  const sharedIndex = await indexShards(sharedDir);
89
99
  if (localIndex.size === 0 && sharedIndex.size === 0) {
@@ -101,6 +111,10 @@ export async function mergeProjcacheTitles(deps) {
101
111
  let untouched = 0;
102
112
 
103
113
  for (const id of new Set([...localIndex.keys(), ...sharedIndex.keys()])) {
114
+ if (skipIds.has(id)) {
115
+ untouched += 1;
116
+ continue;
117
+ }
104
118
  const localEntry = localIndex.get(id);
105
119
  const sharedEntry = sharedIndex.get(id);
106
120
  const currentLocal = localEntry === undefined ? -1 : localEntry.mtime;
@@ -9,6 +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
13
  import { lastContentSeq, readSessionFile, rewriteCwd, writeSessionFile } from './session.js';
13
14
  import {
14
15
  SESSION_LEDGER,
@@ -143,6 +144,8 @@ export async function syncSessions(deps) {
143
144
  skipIds = new Set(),
144
145
  apply = true,
145
146
  journalFile = null,
147
+ cacheDir = null,
148
+ guardStateFile = null,
146
149
  sharedTrashRoot = path.join(path.dirname(sharedRoot), 'trash'),
147
150
  } = deps;
148
151
 
@@ -255,24 +258,42 @@ export async function syncSessions(deps) {
255
258
  }
256
259
 
257
260
  // 3. Push local sessions the share does not have (or has in an older state).
261
+ // A session that was created but never used carries a blank projection
262
+ // shard; letting it reach the share hides the conversation on every machine
263
+ // that later pulls it, so the guard keeps it (and its shard) out. The scan
264
+ // above is reused: no second walk of the sessions root.
265
+ let blankGuard = { skipIds: new Set(), skipped: 0, repaired: 0 };
266
+ if (cacheDir !== null) {
267
+ try {
268
+ blankGuard = await buildBlankGuard({ sessions: local, cacheDir, apply, stateFile: guardStateFile });
269
+ } catch {
270
+ blankGuard = { skipIds: new Set(), skipped: 0, repaired: 0 };
271
+ }
272
+ }
273
+ const guardedIds = new Set([...skipIds, ...blankGuard.skipIds]);
274
+
258
275
  for (const [id, entry] of local) {
259
276
  if (ledger.deleted[id] !== undefined) continue;
260
- if (skipIds.has(id)) {
277
+ if (guardedIds.has(id)) {
261
278
  skipped += 1;
262
279
  continue;
263
280
  }
264
281
  const sharedEntry = shared.get(id);
265
- // A session parked under another workspace folder was moved here: the file
266
- // is authoritative locally even when no new event was appended.
282
+ // A session under another workspace folder was moved: the folder says nothing
283
+ // about which copy is newer, so the event count still decides. Treating the
284
+ // local folder as authoritative pushed a stale copy back over a newer share
285
+ // and undid the move.
267
286
  const relocated = sharedEntry !== undefined
268
287
  && path.basename(path.dirname(entry.file)) !== path.basename(path.dirname(sharedEntry.file));
269
288
  // Append-only logs: the one holding more events is the newer one. Upload and
270
289
  // download timestamps are meaningless here because each transfer rewrites them.
271
- if (sharedEntry !== undefined && !relocated) {
290
+ if (sharedEntry !== undefined) {
272
291
  const localSeq = await lastContentSeq(entry.file);
273
292
  const sharedSeq = await lastContentSeq(sharedEntry.file);
274
293
  if (sharedSeq >= 0 && localSeq >= 0) {
275
294
  if (sharedSeq >= localSeq) {
295
+ // The share is as new or newer — including a moved session it already
296
+ // holds; the pull pass below brings it over and drops the local copy.
276
297
  skipped += 1;
277
298
  continue;
278
299
  }
@@ -306,7 +327,7 @@ export async function syncSessions(deps) {
306
327
  let missing = 0;
307
328
  for (const [id, entry] of refreshedShare) {
308
329
  if (ledger.deleted[id] !== undefined) continue;
309
- if (skipIds.has(id)) continue;
330
+ if (guardedIds.has(id)) continue;
310
331
  const localEntry = local.get(id);
311
332
  if (localEntry !== undefined) {
312
333
  const sharedSeq = await lastContentSeq(entry.file);
@@ -355,5 +376,5 @@ export async function syncSessions(deps) {
355
376
  await writeJsonAtomic(legacyFile, { version: 1, deleted: {} });
356
377
  }
357
378
 
358
- return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds };
379
+ return { pushed, pulled, skipped, revived, tombstoned, created, missing, failed, trashed: Object.keys(ledger.deleted).length, pushedIds, pulledIds, blankGuard };
359
380
  }
package/host/schedule.js CHANGED
@@ -80,11 +80,22 @@ export function installSyncScheduler(ctx, deps) {
80
80
  let retryTimer = null;
81
81
  let disposed = false;
82
82
  let running = false;
83
+ // Subscribers are told about start and finish so a reader can follow the run
84
+ // without polling.
85
+ const watchers = new Set();
86
+ const notifyWatchers = () => {
87
+ for (const watcher of [...watchers]) {
88
+ try {
89
+ watcher();
90
+ } catch {
91
+ // A broken watcher must not affect the run.
92
+ }
93
+ }
94
+ };
83
95
  let cooldownUntil = 0;
84
96
  let failures = 0;
85
97
  let paused = false;
86
98
  let pausedAt = null;
87
- let startupTimer = null;
88
99
  let lastIntervalAt = 0;
89
100
  let lastDailyKey = '';
90
101
 
@@ -177,6 +188,7 @@ async function autoRun(reason) {
177
188
  return false;
178
189
  }
179
190
  running = true;
191
+ notifyWatchers();
180
192
  trace(`autoRun ${reason}: start`);
181
193
  try {
182
194
  const record = await runSync({ paths, settings, agents }, { probe: false });
@@ -213,6 +225,7 @@ async function autoRun(reason) {
213
225
  note(`${reason}: ${String(error?.message ?? error)}${paused ? ', auto sync paused' : ''}`, 'error');
214
226
  } finally {
215
227
  running = false;
228
+ notifyWatchers();
216
229
  cooldownUntil = Date.now() + Math.max(1, Number(settings.syncCooldownMinutes) || 5) * 60_000;
217
230
  }
218
231
  }
@@ -254,6 +267,12 @@ async function autoRun(reason) {
254
267
 
255
268
  const status = () => ({ paused, failures, pausedAt, cooldownUntil, running });
256
269
 
270
+ /** Wake every waiting reader; the returned function unsubscribes. */
271
+ const subscribe = (watcher) => {
272
+ watchers.add(watcher);
273
+ return () => watchers.delete(watcher);
274
+ };
275
+
257
276
  const resume = () => {
258
277
  failures = 0;
259
278
  paused = false;
@@ -263,12 +282,8 @@ async function autoRun(reason) {
263
282
  return status();
264
283
  };
265
284
 
266
- // Catch up with other machines right after launch: the first idle edge may be
267
- // minutes away. The cooldown still applies, so a restart right after a sync
268
- // costs nothing.
269
- startupTimer = setTimeout(() => {
270
- void autoRun('startup');
271
- }, 5000);
285
+ // Launch-time catch-up is driven by the client, so the reader sees the restart
286
+ // countdown before the window closes. Host-side runs stay on idle/interval/daily.
272
287
 
273
288
  const statusListener = ctx.on('agent/status', (payload) => {
274
289
  trace(`agent/status=${String(payload?.status)}`);
@@ -288,9 +303,9 @@ async function autoRun(reason) {
288
303
  if (tick !== null) clearInterval(tick);
289
304
  if (idleTimer !== null) clearTimeout(idleTimer);
290
305
  if (retryTimer !== null) clearTimeout(retryTimer);
291
- if (startupTimer !== null) clearTimeout(startupTimer);
292
306
  if (typeof statusListener === 'function') statusListener();
307
+ watchers.clear();
293
308
  };
294
309
 
295
- return { dispose, status, resume };
310
+ return { dispose, status, resume, subscribe };
296
311
  }
package/host/search.js CHANGED
@@ -13,17 +13,58 @@ const MAX_SEGMENT_CHARS = 24000;
13
13
  const MAX_MATCHES_PER_SESSION = Number.POSITIVE_INFINITY;
14
14
  const MAX_TOTAL_MATCHES = 500;
15
15
  const CONTEXT_CHARS = 42;
16
+ // The hover preview needs a readable passage, not just one line around the hit.
17
+ const PREVIEW_CHARS = 420;
18
+
19
+ /**
20
+ * Wrappers the app injects into a message but never shows in the conversation.
21
+ * Matching inside them would surface hits the reader cannot see on screen.
22
+ */
23
+ const HIDDEN_WRAPPERS = ['system-reminder', 'available_skills', 'compacted-summary'];
24
+
25
+ /**
26
+ * User-message sources the transcript actually renders. Everything else the log
27
+ * stores as a `user/message` is model-facing context: runtime snapshots, time
28
+ * stamps, skill catalogs, model switches, approval notes, background-job
29
+ * notices, and compaction checkpoints. Those never appear in the conversation,
30
+ * so indexing them would return hits the reader cannot see.
31
+ */
32
+ const VISIBLE_USER_SOURCES = new Set(['user', 'user-question-reply']);
33
+
34
+ /** True when a stored user message is one the transcript shows. */
35
+ function isVisibleUserMessage(message) {
36
+ const source = message?.source;
37
+ // Logs written before sources existed have no marker; keep them searchable.
38
+ if (source === null || typeof source !== 'object') return true;
39
+ return VISIBLE_USER_SOURCES.has(source.kind);
40
+ }
41
+
42
+ /** Drop hidden wrapper blocks (and stray closing tags) from one text block. */
43
+ function stripHidden(text) {
44
+ let out = text;
45
+ // Only a leading wrapper is model-facing context. A wrapper quoted inside
46
+ // prose or a fenced code block is visible content and stays searchable.
47
+ for (const tag of HIDDEN_WRAPPERS) {
48
+ const leading = new RegExp(`^\\s*<${tag}>[\\s\\S]*?</${tag}>`, 'iu');
49
+ while (leading.test(out)) out = out.replace(leading, ' ');
50
+ }
51
+ // A block that is only a closing tag belongs to a wrapper split across blocks.
52
+ if (/^<\/[a-z-]+>$/iu.test(out.trim())) return '';
53
+ return out;
54
+ }
16
55
 
17
56
  /** Text blocks of one message, tolerating every message shape the log stores. */
18
57
  function messageText(message) {
19
58
  if (message === null || typeof message !== 'object') return '';
20
59
  const content = message.content;
21
- if (typeof content === 'string') return content.trim();
60
+ if (typeof content === 'string') return stripHidden(content).trim();
22
61
  if (!Array.isArray(content)) return '';
23
62
  const parts = [];
24
63
  for (const block of content) {
25
64
  if (block === null || typeof block !== 'object') continue;
26
- if (block.type === 'text' && typeof block.text === 'string' && block.text.trim() !== '') parts.push(block.text);
65
+ if (block.type !== 'text' || typeof block.text !== 'string') continue;
66
+ const text = stripHidden(block.text);
67
+ if (text.trim() !== '') parts.push(text);
27
68
  }
28
69
  return parts.join('\n').trim();
29
70
  }
@@ -39,20 +80,23 @@ function buildDocument(sessionId, header, events) {
39
80
  let title = '';
40
81
  let updatedAt = typeof header.createdAt === 'number' ? header.createdAt : 0;
41
82
  let firstUserText = '';
83
+ let turn = 0;
42
84
  for (const event of events) {
85
+ if (event.type === 'turn/start' && typeof event.data?.turn === 'number') turn = event.data.turn;
43
86
  if (typeof event.time === 'number' && event.time > updatedAt) updatedAt = event.time;
44
87
  if (event.type === 'user/message') {
88
+ if (!isVisibleUserMessage(event.data)) continue;
45
89
  const text = messageText(event.data);
46
90
  if (text !== '') {
47
91
  if (firstUserText === '') firstUserText = text;
48
- segments.push({ seq: event.seq, role: 'user', text: clip(text) });
92
+ segments.push({ seq: event.seq, role: 'user', text: clip(text), time: event.time, turn });
49
93
  }
50
94
  } else if (event.type === 'assistant/message') {
51
95
  const text = messageText(event.data?.message);
52
- if (text !== '') segments.push({ seq: event.seq, role: 'assistant', text: clip(text) });
96
+ if (text !== '') segments.push({ seq: event.seq, role: 'assistant', text: clip(text), time: event.time, turn });
53
97
  } else if (event.type === 'tool/result') {
54
98
  const text = messageText(event.data?.message);
55
- if (text !== '') segments.push({ seq: event.seq, role: 'tool', text: clip(text) });
99
+ if (text !== '') segments.push({ seq: event.seq, role: 'tool', text: clip(text), time: event.time, turn });
56
100
  } else if (event.type === 'session/title') {
57
101
  const value = event.data?.title;
58
102
  if (typeof value === 'string' && value.trim() !== '') title = value.trim();
@@ -72,6 +116,7 @@ async function readDocument(persistence, sessionId, header, signal) {
72
116
  }
73
117
  }
74
118
 
119
+ /** The excerpt around one hit plus the offset of that hit inside it. */
75
120
  function snippetAround(text, index, length) {
76
121
  const start = Math.max(0, index - CONTEXT_CHARS);
77
122
  const end = Math.min(text.length, index + length + CONTEXT_CHARS);
@@ -80,12 +125,23 @@ function snippetAround(text, index, length) {
80
125
  return `${prefix}${text.slice(start, end)}${suffix}`;
81
126
  }
82
127
 
128
+ function previewAround(text, index, length) {
129
+ const start = Math.max(0, index - PREVIEW_CHARS);
130
+ const end = Math.min(text.length, index + length + PREVIEW_CHARS);
131
+ const prefix = start > 0 ? '…' : '';
132
+ const suffix = end < text.length ? '…' : '';
133
+ return {
134
+ text: `${prefix}${text.slice(start, end)}${suffix}`,
135
+ hit: index - start + prefix.length,
136
+ };
137
+ }
138
+
83
139
  /** One document's matches, capped per session. */
84
140
  function matchDocument(document, needle, settings, budget) {
85
141
  const matches = [];
86
142
  if (settings.matchTitle === true && document.title !== '') {
87
143
  if (document.title.toLowerCase().includes(needle)) {
88
- matches.push({ kind: 'title', role: 'title', snippet: document.title, at: document.title.toLowerCase().indexOf(needle) });
144
+ matches.push({ kind: 'title', role: 'title', snippet: document.title, preview: document.title, previewHit: 0, at: document.title.toLowerCase().indexOf(needle), time: document.updatedAt });
89
145
  budget.total += 1;
90
146
  }
91
147
  }
@@ -100,17 +156,24 @@ function matchDocument(document, needle, settings, budget) {
100
156
  while (matches.length < MAX_MATCHES_PER_SESSION && budget.total < MAX_TOTAL_MATCHES) {
101
157
  const at = haystack.indexOf(needle, from);
102
158
  if (at < 0) break;
159
+ const preview = previewAround(segment.text, at, needle.length);
103
160
  matches.push({
104
161
  kind: 'body',
105
162
  role: segment.role,
106
163
  seq: segment.seq,
164
+ turn: segment.turn,
107
165
  snippet: snippetAround(segment.text, at, needle.length),
166
+ preview: preview.text,
167
+ previewHit: preview.hit,
108
168
  at,
169
+ time: segment.time,
109
170
  });
110
171
  budget.total += 1;
111
172
  from = at + needle.length;
112
173
  }
113
174
  }
175
+ // Newest first inside one session; rows without a timestamp sink to the end.
176
+ matches.sort((left, right) => (Number(right.time) || 0) - (Number(left.time) || 0));
114
177
  return matches;
115
178
  }
116
179
 
@@ -165,7 +228,12 @@ export function createSearch(options) {
165
228
  }
166
229
  // Drop cache rows whose session log no longer exists.
167
230
  for (const id of cache.keys()) if (!seen.has(id)) cache.delete(id);
168
- groups.sort((a, b) => b.updatedAt - a.updatedAt);
231
+ // Newest hit first: a session with a fresh match outranks one whose file is newer.
232
+ const newestHit = (group) => (group.matches ?? []).reduce(
233
+ (max, match) => Math.max(max, Number(match.time) || 0),
234
+ 0,
235
+ );
236
+ groups.sort((a, b) => newestHit(b) - newestHit(a) || b.updatedAt - a.updatedAt);
169
237
  return {
170
238
  groups,
171
239
  scanned: snapshotList.length,
package/host/sync.js CHANGED
@@ -195,6 +195,12 @@ function logLines(summary, transport, titleMap = new Map()) {
195
195
  ...(summary.sessions?.pushedIds ?? []).map((id) => `推送上云:${titleMap.get(id) ?? id}`),
196
196
  ...(summary.sessions?.pulledIds ?? []).map((id) => `从云取回:${titleMap.get(id) ?? id}`),
197
197
  ]);
198
+ const guardSkipped = Number(summary.blankGuard?.skipped) || 0;
199
+ const guardRepaired = Number(summary.blankGuard?.repaired) || 0;
200
+ if (guardSkipped > 0 || guardRepaired > 0) {
201
+ const repaired = guardRepaired > 0 ? `,修复过期缓存 ${counts(guardRepaired)} 个` : '';
202
+ push(`空白会话:跳过 ${counts(guardSkipped)} 个${repaired}`);
203
+ }
198
204
  push(configCopied === 0 && attachCopied === 0
199
205
  ? '配置附件:双端一致,无更新'
200
206
  : `配置附件:更新配置 ${counts(configCopied)} 个、附件 ${counts(attachCopied)} 个`,
package/index.js CHANGED
@@ -79,6 +79,27 @@ export function apply(ctx, config = {}) {
79
79
  }
80
80
  })();
81
81
 
82
+ // Bumped for every committed user message; the composer badge watches it to
83
+ // know the reader sent something and the finished-sync line may go away.
84
+ let userMessageSeq = 0;
85
+ const watchWaiters = new Set();
86
+ try {
87
+ ctx.effect(() => ctx.on('session/event', (session, event) => {
88
+ if (event?.type !== 'user/message') return;
89
+ userMessageSeq += 1;
90
+ // Wake the waiting call so the client sees the new count immediately.
91
+ for (const wake of [...watchWaiters]) {
92
+ try {
93
+ wake();
94
+ } catch {
95
+ // A broken waiter must not affect the others.
96
+ }
97
+ }
98
+ }), 'dsh-enhanced: user message counter');
99
+ } catch {
100
+ // Without the event the line simply clears on the next sync instead.
101
+ }
102
+
82
103
  const dependencies = (settings) => ({
83
104
  paths,
84
105
  settings,
@@ -148,8 +169,49 @@ export function apply(ctx, config = {}) {
148
169
  const history = await readSyncHistory({ paths, settings });
149
170
  return { settings: { syncEnabled: settings.syncEnabled, syncDir: settings.syncDir, syncScript: settings.syncScript, syncMachineId: settings.syncMachineId, syncSkipAttachments: settings.syncSkipAttachments }, target, state, history, auto: scheduler.status(), running: live };
150
171
  }
172
+ case 'sync.watch': {
173
+ // Resolve as soon as the automatic run starts or stops (or after 25 s),
174
+ // so the client follows the state without a polling timer.
175
+ const current = () => {
176
+ const live = typeof ctx.get('agents')?.list === 'function'
177
+ ? ctx.get('agents').list().filter((agent) => agent?.status === 'running').length
178
+ : 0;
179
+ return { auto: scheduler.status(), running: live, userSeq: userMessageSeq };
180
+ };
181
+ return await new Promise((resolve) => {
182
+ let settled = false;
183
+ let unsubscribe = () => {};
184
+ const finish = () => {
185
+ if (settled) return;
186
+ settled = true;
187
+ unsubscribe();
188
+ watchWaiters.delete(finish);
189
+ clearTimeout(timer);
190
+ resolve(current());
191
+ };
192
+ const timer = setTimeout(finish, 25_000);
193
+ unsubscribe = scheduler.subscribe(finish);
194
+ watchWaiters.add(finish);
195
+ signal?.addEventListener?.('abort', finish, { once: true });
196
+ });
197
+ }
198
+ case 'sync.auto': {
199
+ const live = typeof ctx.get('agents')?.list === 'function'
200
+ ? ctx.get('agents').list().filter((agent) => agent?.status === 'running').length
201
+ : 0;
202
+ return { auto: scheduler.status(), running: live };
203
+ }
151
204
  case 'sync.probe':
152
205
  case 'sync.run': {
206
+ // A running turn is writing session files; syncing then risks reading a
207
+ // half-written log. The launch-time call asks for quiet so it can skip.
208
+ if (action === 'sync.run') {
209
+ const busy = (ctx.get('agents')?.list?.() ?? []).some((agent) => agent?.status === 'running');
210
+ if (busy) {
211
+ if (request?.quiet === true) return { skipped: 'busy' };
212
+ throw failure('sync-task-running', '有会话正在运行,稍后再同步。');
213
+ }
214
+ }
153
215
  const settings = await readSettings(paths);
154
216
  return runSync({ paths, settings, agents: ctx.get('agents'), registry: ctx.workspaceRegistry }, { probe: action === 'sync.probe' });
155
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xsok/dsh-enhanced",
3
- "version": "0.2.2-6",
3
+ "version": "0.2.2-8",
4
4
  "description": "DeepSeek Harness 增强插件:会话删除与找回、跨工作区移动、全库内容搜索、自动加载历史,以及多设备同步(本地目录 / WebDAV)。",
5
5
  "type": "module",
6
6
  "license": "MIT",